DLL Injection in python
print "[+] Universal DLL Injector by Y"
print "[+] contact : If you know me then give me a shout"
print "[+] usage: ./dll_injector.py <PID> <DLLPATH>"
print "\n"
 
from ctypes import *
import sys,ctypes
 
# Define constants we use
PAGE_RW_PRIV = 0x04
PROCESS_ALL_ACCESS = 0x1F0FFF
VIRTUAL_MEM = 0x3000
 
#CTYPES handler
kernel32 = windll.kernel32
 
def dll_inject(PID,DLL_PATH):
    print "[+] Starting DLL Injector"
    LEN_DLL = len(DLL_PATH)# get the length of the DLL PATH 
    print "\t[+] Getting process handle for PID:%d " % PID 
    hProcess = kernel32.OpenProcess(PROCESS_ALL_ACCESS,False,PID)
     
    if hProcess == None:
        print "\t[+] Unable to get process handle"
        sys.exit(0)
    print "\t[+] Allocating space for DLL PATH"
    DLL_PATH_ADDR = kernel32.VirtualAllocEx(hProcess, 
                                            0,
                                            LEN_DLL,
                                            VIRTUAL_MEM,
                                            PAGE_RW_PRIV)
    bool_Written = c_int(0)
    print "\t[+] Writing DLL PATH to current process space"
    kernel32.WriteProcessMemory(hProcess,
                                DLL_PATH_ADDR,
                                DLL_PATH,
                                LEN_DLL,
                                byref(bool_Written))
    print "\t[+] Resolving Call Specific functions & libraries"
    kernel32DllHandler_addr = kernel32.GetModuleHandleA("kernel32")
    print "\t\t[+] Resolved kernel32 library at 0x%08x" % kernel32DllHandler_addr
    LoadLibraryA_func_addr = kernel32.GetProcAddress(kernel32DllHandler_addr,"LoadLibraryA")
    print "\t\t[+] Resolve LoadLibraryA function at 0x%08x" %LoadLibraryA_func_addr
     
    thread_id = c_ulong(0) # for our thread id
    print "\t[+] Creating Remote Thread to load our DLL"
    if not kernel32.CreateRemoteThread(hProcess,
                                None,
                                0,
                                LoadLibraryA_func_addr,
                                DLL_PATH_ADDR,
                                0,
                                byref(thread_id)):
        print "Injection Failed, exiting"
        sys.exit(0)
    else:
        print "Remote Thread 0x%08x created, DLL code injected" % thread_id.value
PID = int(sys.argv[1])
DLL_PATH = str(sys.argv[2])
dll_inject(PID, DLL_PATH)
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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
	
print "[+] Universal DLL Injector by Y"
print "[+] contact : If you know me then give me a shout"
print "[+] usage: ./dll_injector.py <PID> <DLLPATH>"
print "\n"
 
from ctypes import *
import sys,ctypes
 
# Define constants we use
PAGE_RW_PRIV = 0x04
PROCESS_ALL_ACCESS = 0x1F0FFF
VIRTUAL_MEM = 0x3000
 
#CTYPES handler
kernel32 = windll.kernel32
 
def dll_inject(PID,DLL_PATH):
    print "[+] Starting DLL Injector"
    LEN_DLL = len(DLL_PATH)# get the length of the DLL PATH 
    print "\t[+] Getting process handle for PID:%d " % PID 
    hProcess = kernel32.OpenProcess(PROCESS_ALL_ACCESS,False,PID)
     
    if hProcess == None:
        print "\t[+] Unable to get process handle"
        sys.exit(0)
    print "\t[+] Allocating space for DLL PATH"
    DLL_PATH_ADDR = kernel32.VirtualAllocEx(hProcess, 
                                            0,
                                            LEN_DLL,
                                            VIRTUAL_MEM,
                                            PAGE_RW_PRIV)
    bool_Written = c_int(0)
    print "\t[+] Writing DLL PATH to current process space"
    kernel32.WriteProcessMemory(hProcess,
                                DLL_PATH_ADDR,
                                DLL_PATH,
                                LEN_DLL,
                                byref(bool_Written))
    print "\t[+] Resolving Call Specific functions & libraries"
    kernel32DllHandler_addr = kernel32.GetModuleHandleA("kernel32")
    print "\t\t[+] Resolved kernel32 library at 0x%08x" % kernel32DllHandler_addr
    LoadLibraryA_func_addr = kernel32.GetProcAddress(kernel32DllHandler_addr,"LoadLibraryA")
    print "\t\t[+] Resolve LoadLibraryA function at 0x%08x" %LoadLibraryA_func_addr
     
    thread_id = c_ulong(0) # for our thread id
    print "\t[+] Creating Remote Thread to load our DLL"
    if not kernel32.CreateRemoteThread(hProcess,
                                None,
                                0,
                                LoadLibraryA_func_addr,
                                DLL_PATH_ADDR,
                                0,
                                byref(thread_id)):
        print "Injection Failed, exiting"
        sys.exit(0)
    else:
        print "Remote Thread 0x%08x created, DLL code injected" % thread_id.value
PID = int(sys.argv[1])
DLL_PATH = str(sys.argv[2])
dll_inject(PID, DLL_PATH)

Python相关代码片段

python parquet file to csv

python best practices

yolov5 without net

save variable as pkl python

python [-9:]

eigenface python

'DataFrame' object has no attribute 'dtype'

unable to enable maximize window tkinter

rabbit and fox numpy python

lstm in keras

neural network in keras

resnet50 in keras

autoencoder in keras

cnn in keras

tensor in keras

pyTelegramBotAPI edit photo

print api python

how to get values but not index from pandas series

how to get mode of a column from pandas

bayesian neural network pymcmc

lda python

back propagation python

logical syntax is not none python

register model django

Descending Selection sort

Selection sort with while loops

Selection sort with for loops

Doubling Algorithm for cluster analysis in python

Tkinter widgets

nameerror: name 'callable' is not defined

NameError: name 'Union' is not defined

Make a widget customtkinter python

nn module pytorch

import tf python

Spark SEssion object

Implement Bubble sort with while loops

Unoptimized bubble sort algorithm

Optimized bubble sort algorithm

how to get today's date in python

st_aggrid install

python venv pip blocked by admin windows

numpy matrix from lists of different leght

python postgres auto commit

dotenv install python

np mean axis

LinkExtractor Object

admin django documentation

Python native Convolution implementation

is django monolithic

what is function call with an llm

np array to series

dht22 micropython pico

disable slash command discord.py

python docker compose not printing

tabnet probabilities

python venv: no such file or directory

find most common words in string python

histogram equalization using pillow

Django squash migrations

swap first and last letter in string in array

sor a lit in python

torch clear cuda cache

multi line comment python

password login and logout in python

string to array iin python

no organize imports action available

different clustering algorithms

python colur text

anki addons how to use external libraries

Python Modbus TCP

install python3 latest version with conda

semantics python

python find mode of a list

add more inputs to the user model in django

pycharm pdm __pypackages__

splitlines in python

flask opencv streamer

pytorch create dataset from tensor

statics in django

python anywhere selenium