Agent: Improve InvalidExploitTemplateError messages

This commit is contained in:
Mike Salvatore 2021-12-21 15:17:46 -05:00
parent 4d5a2511c6
commit fddaa16931
1 changed files with 6 additions and 2 deletions

View File

@ -1,6 +1,8 @@
import struct import struct
from pathlib import Path from pathlib import Path
# This code has been adapted from https://github.com/alexandre-lavoie/python-log4rce
EXPLOIT_TEMPLATE_PATH = Path(__file__).parent / "Exploit.class.template" EXPLOIT_TEMPLATE_PATH = Path(__file__).parent / "Exploit.class.template"
INJECTION_TAG = "###" INJECTION_TAG = "###"
@ -34,7 +36,7 @@ def _load_template_bytecode(exploit_template_path: Path) -> bytes:
if not template_bytecode.startswith(b"\xca\xfe\xba\xbe"): if not template_bytecode.startswith(b"\xca\xfe\xba\xbe"):
raise InvalidExploitTemplateError( raise InvalidExploitTemplateError(
f"Trying to load non-compiled Java class `{EXPLOIT_TEMPLATE_PATH}`." f'The file "{EXPLOIT_TEMPLATE_PATH}" is not a compiled Java class'
) )
return template_bytecode return template_bytecode
@ -44,7 +46,9 @@ def _inject_payload(payload: str, template_bytecode: bytes):
payload_bytes = payload.encode() payload_bytes = payload.encode()
if not INJECTION_TAG.encode() in template_bytecode: if not INJECTION_TAG.encode() in template_bytecode:
raise InvalidExploitTemplateError(f'No "{INJECTION_TAG}" tag to inject payload into.') raise InvalidExploitTemplateError(
f'Unable to find "{INJECTION_TAG}" tag in the template bytecode'
)
index = template_bytecode.index(INJECTION_TAG.encode()) index = template_bytecode.index(INJECTION_TAG.encode())