Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 41 additions & 0 deletions modules/signatures/windows/injection_thread.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,44 @@ def on_call(self, call, process):

def on_complete(self):
return self.ret


class ApcInjection(Signature):
name = "apc_injection"
description = "Queues an Asynchronous Procedure Call (APC) to a thread, indicative of injection"
severity = 3
confidence = 80
categories = ["injection", "evasion"]
authors = ["Kevin Ross"]
minimum = "1.3"
evented = True
ttps = ["T1055", "T1055.004"]
mbcs = ["E1055", "E1055.004"]

filter_apinames = {"NtQueueApcThread", "QueueUserAPC"}

def __init__(self, *args, **kwargs):
Signature.__init__(self, *args, **kwargs)
self.ret = False
self.apc_targets = set()

def on_call(self, call, process):
if call["api"] == "NtQueueApcThread":
target_thread = self.get_argument(call, "ThreadId")
apc_routine = self.get_argument(call, "ApcRoutine")
else:
target_thread = self.get_argument(call, "ThreadHandle")
apc_routine = self.get_argument(call, "pfnAPC")

Comment on lines +83 to +85
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

There is trailing whitespace on line 83 and an unnecessary blank line on line 85. These should be removed to improve code style and readability.

Suggested change
target_thread = self.get_argument(call, "ThreadHandle")
apc_routine = self.get_argument(call, "pfnAPC")
target_thread = self.get_argument(call, "ThreadHandle")
apc_routine = self.get_argument(call, "pfnAPC")

if target_thread and apc_routine:
pid = process.get("process_id")
targetpid = self.get_argument(call, "ProcessId")

if str(apc_routine) != "0x00000000" and str(pid) != str(targetpid):
if target_thread not in self.apc_targets:
self.apc_targets.add(target_thread)
self.mark_call()
self.ret = True

def on_complete(self):
return self.ret