Skip to content

Commit 766a69e

Browse files
committed
Add sys_process_kill to the python meterpreter
1 parent 7da22d0 commit 766a69e

File tree

1 file changed

+25
-7
lines changed

1 file changed

+25
-7
lines changed

data/meterpreter/ext_server_stdapi.py

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -472,10 +472,14 @@ class RTATTR(ctypes.Structure):
472472
ERROR_CONNECTION_ERROR = 10000
473473

474474
# Windows Constants
475-
GAA_FLAG_SKIP_ANYCAST = 0x0002
476-
GAA_FLAG_SKIP_MULTICAST = 0x0004
477-
GAA_FLAG_INCLUDE_PREFIX = 0x0010
478-
GAA_FLAG_SKIP_DNS_SERVER = 0x0080
475+
GAA_FLAG_SKIP_ANYCAST = 0x0002
476+
GAA_FLAG_SKIP_MULTICAST = 0x0004
477+
GAA_FLAG_INCLUDE_PREFIX = 0x0010
478+
GAA_FLAG_SKIP_DNS_SERVER = 0x0080
479+
PROCESS_TERMINATE = 0x0001
480+
PROCESS_VM_READ = 0x0010
481+
PROCESS_QUERY_INFORMATION = 0x0400
482+
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
479483

480484
WIN_AF_INET = 2
481485
WIN_AF_INET6 = 23
@@ -719,6 +723,23 @@ def stdapi_sys_process_getpid(request, response):
719723
response += tlv_pack(TLV_TYPE_PID, os.getpid())
720724
return ERROR_SUCCESS, response
721725

726+
@meterpreter.register_function
727+
def stdapi_sys_process_kill(request, response):
728+
for pid in packet_enum_tlvs(request, TLV_TYPE_PID):
729+
pid = pid['value']
730+
if has_windll:
731+
k32 = ctypes.windll.kernel32
732+
proc_h = k32.OpenProcess(PROCESS_TERMINATE, False, pid)
733+
if not proc_h:
734+
return ERROR_FAILURE, response
735+
if not k32.TerminateProcess(proc_h, 0):
736+
return ERROR_FAILURE, response
737+
elif hasattr(os, 'kill'):
738+
os.kill(pid, 9)
739+
else:
740+
return ERROR_FAILURE, response
741+
return ERROR_SUCCESS, response
742+
722743
def stdapi_sys_process_get_processes_via_proc(request, response):
723744
for pid in os.listdir('/proc'):
724745
pgroup = bytes()
@@ -771,9 +792,6 @@ def stdapi_sys_process_get_processes_via_ps(request, response):
771792

772793
def stdapi_sys_process_get_processes_via_windll(request, response):
773794
TH32CS_SNAPPROCESS = 2
774-
PROCESS_QUERY_INFORMATION = 0x0400
775-
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
776-
PROCESS_VM_READ = 0x10
777795
TOKEN_QUERY = 0x0008
778796
TokenUser = 1
779797
k32 = ctypes.windll.kernel32

0 commit comments

Comments
 (0)