@@ -472,10 +472,14 @@ class RTATTR(ctypes.Structure):
472
472
ERROR_CONNECTION_ERROR = 10000
473
473
474
474
# 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
479
483
480
484
WIN_AF_INET = 2
481
485
WIN_AF_INET6 = 23
@@ -719,6 +723,23 @@ def stdapi_sys_process_getpid(request, response):
719
723
response += tlv_pack (TLV_TYPE_PID , os .getpid ())
720
724
return ERROR_SUCCESS , response
721
725
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
+
722
743
def stdapi_sys_process_get_processes_via_proc (request , response ):
723
744
for pid in os .listdir ('/proc' ):
724
745
pgroup = bytes ()
@@ -771,9 +792,6 @@ def stdapi_sys_process_get_processes_via_ps(request, response):
771
792
772
793
def stdapi_sys_process_get_processes_via_windll (request , response ):
773
794
TH32CS_SNAPPROCESS = 2
774
- PROCESS_QUERY_INFORMATION = 0x0400
775
- PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
776
- PROCESS_VM_READ = 0x10
777
795
TOKEN_QUERY = 0x0008
778
796
TokenUser = 1
779
797
k32 = ctypes .windll .kernel32
0 commit comments