@@ -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
@@ -666,12 +670,11 @@ def stdapi_sys_config_sysinfo(request, response):
666
670
667
671
@meterpreter .register_function
668
672
def stdapi_sys_process_close (request , response ):
669
- proc_h_id = packet_get_tlv (request , TLV_TYPE_PROCESS_HANDLE )
673
+ proc_h_id = packet_get_tlv (request , TLV_TYPE_HANDLE )
670
674
if not proc_h_id :
671
675
return ERROR_SUCCESS , response
672
676
proc_h_id = proc_h_id ['value' ]
673
- proc_h = meterpreter .channels [proc_h_id ]
674
- proc_h .kill ()
677
+ del meterpreter .processes [proc_h_id ]
675
678
return ERROR_SUCCESS , response
676
679
677
680
@meterpreter .register_function
@@ -720,6 +723,23 @@ def stdapi_sys_process_getpid(request, response):
720
723
response += tlv_pack (TLV_TYPE_PID , os .getpid ())
721
724
return ERROR_SUCCESS , response
722
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
+
723
743
def stdapi_sys_process_get_processes_via_proc (request , response ):
724
744
for pid in os .listdir ('/proc' ):
725
745
pgroup = bytes ()
@@ -772,9 +792,6 @@ def stdapi_sys_process_get_processes_via_ps(request, response):
772
792
773
793
def stdapi_sys_process_get_processes_via_windll (request , response ):
774
794
TH32CS_SNAPPROCESS = 2
775
- PROCESS_QUERY_INFORMATION = 0x0400
776
- PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
777
- PROCESS_VM_READ = 0x10
778
795
TOKEN_QUERY = 0x0008
779
796
TokenUser = 1
780
797
k32 = ctypes .windll .kernel32
0 commit comments