-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathinject.py
More file actions
46 lines (38 loc) · 1.3 KB
/
inject.py
File metadata and controls
46 lines (38 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import psutil
from injector import DLLInjector
import time
import os
agent = DLLInjector()
dll_file = os.path.join(os.getcwd(), "DLLHooks.dll")
if not os.path.exists(dll_file):
dll_file = os.path.join(os.getcwd(), "DLLHooks/Release/DLLHooks.dll")
if not os.path.exists(dll_file):
raise FileNotFoundError("DLLHooks.dll not found in expected directories.")
monitored_process = "LockDownBrowser"
for task in psutil.process_iter(['name']):
task_name = task.name()
if monitored_process in task_name:
try:
print(f"Terminating: {task_name} (PID: {task.pid})")
task.kill()
except Exception as err:
print("Could not terminate:", err)
print("Monitoring for target process...")
while True:
found = False
for task in psutil.process_iter(['name']):
task_name = task.name()
if monitored_process in task_name:
pid = task.pid
print(f"Target detected: {task_name} (PID: {pid})")
try:
agent.attach_to_pid(pid)
agent.inject_shared_library(dll_file)
agent.cleanup()
found = True
break
except Exception as err:
print("Injection error:", err)
if found:
break
print("Operation completed.")