mirror of
https://github.com/rapid7/metasploit-payloads
synced 2025-01-02 11:36:22 +01:00
Merge branch 'master' into python-arp-linux
This commit is contained in:
commit
541d8c1e17
@ -1,6 +1,6 @@
|
||||
# -*- coding:binary -*-
|
||||
module MetasploitPayloads
|
||||
VERSION = '2.0.113'
|
||||
VERSION = '2.0.114'
|
||||
|
||||
def self.version
|
||||
VERSION
|
||||
|
@ -744,6 +744,7 @@ PROCESS_TERMINATE = 0x0001
|
||||
PROCESS_VM_READ = 0x0010
|
||||
PROCESS_QUERY_INFORMATION = 0x0400
|
||||
PROCESS_QUERY_LIMITED_INFORMATION = 0x1000
|
||||
PROCESS_ALL_ACCESS = 0x1fffff
|
||||
VER_NT_WORKSTATION = 0x0001
|
||||
VER_NT_DOMAIN_CONTROLLER = 0x0002
|
||||
VER_NT_SERVER = 0x0003
|
||||
@ -1335,13 +1336,10 @@ def stdapi_sys_config_sysinfo(request, response):
|
||||
|
||||
@register_function
|
||||
def stdapi_sys_process_close(request, response):
|
||||
proc_h_id = packet_get_tlv(request, TLV_TYPE_HANDLE)
|
||||
proc_h_id = packet_get_tlv(request, TLV_TYPE_HANDLE)['value']
|
||||
if not proc_h_id:
|
||||
return ERROR_SUCCESS, response
|
||||
proc_h_id = proc_h_id['value']
|
||||
if proc_h_id in meterpreter.processes:
|
||||
del meterpreter.processes[proc_h_id]
|
||||
if not meterpreter.close_channel(proc_h_id):
|
||||
if not meterpreter.close_process(proc_h_id):
|
||||
return ERROR_FAILURE, response
|
||||
return ERROR_SUCCESS, response
|
||||
|
||||
@ -1384,6 +1382,7 @@ def stdapi_sys_process_execute(request, response):
|
||||
proc_h.start()
|
||||
else:
|
||||
proc_h = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||
|
||||
proc_h_id = meterpreter.add_process(proc_h)
|
||||
response += tlv_pack(TLV_TYPE_PID, proc_h.pid)
|
||||
response += tlv_pack(TLV_TYPE_PROCESS_HANDLE, proc_h_id)
|
||||
@ -1902,7 +1901,6 @@ def stdapi_net_config_get_arp_table(request, response):
|
||||
|
||||
with open(arp_cache_file, 'r') as arp_cache:
|
||||
lines = arp_cache.readlines()
|
||||
import binascii
|
||||
for line in lines[1:]:
|
||||
fields = line.split()
|
||||
ip_address = fields[0]
|
||||
|
@ -1260,11 +1260,37 @@ class PythonMeterpreter(object):
|
||||
return idx
|
||||
|
||||
def add_process(self, process):
|
||||
idx = self.next_process_id
|
||||
self.processes[idx] = process
|
||||
debug_print('[*] added process id: ' + str(idx))
|
||||
self.next_process_id += 1
|
||||
return idx
|
||||
if has_windll:
|
||||
PROCESS_ALL_ACCESS = 0x1fffff
|
||||
OpenProcess = ctypes.windll.kernel32.OpenProcess
|
||||
OpenProcess.argtypes = [ctypes.c_ulong, ctypes.c_long, ctypes.c_ulong]
|
||||
OpenProcess.restype = ctypes.c_void_p
|
||||
handle = OpenProcess(PROCESS_ALL_ACCESS, False, process.pid)
|
||||
else:
|
||||
handle = self.next_process_id
|
||||
self.next_process_id += 1
|
||||
self.processes[handle] = process
|
||||
debug_print('[*] added process id: ' + str(process.pid) + ', handle: ' + str(handle))
|
||||
return handle
|
||||
|
||||
def close_process(self, proc_h_id):
|
||||
proc_h = self.processes.pop(proc_h_id, None)
|
||||
if not proc_h:
|
||||
return False
|
||||
for channel_id, channel in self.channels.items():
|
||||
if not isinstance(channel, MeterpreterProcess):
|
||||
continue
|
||||
if not channel.proc_h is proc_h:
|
||||
continue
|
||||
self.close_channel(channel_id)
|
||||
break
|
||||
if has_windll:
|
||||
CloseHandle = ctypes.windll.kernel32.CloseHandle
|
||||
CloseHandle.argtypes = [ctypes.c_void_p]
|
||||
CloseHandle.restype = ctypes.c_long
|
||||
CloseHandle(proc_h_id)
|
||||
debug_print('[*] closed and removed process id: ' + str(proc_h.pid) + ', handle: ' + str(proc_h_id))
|
||||
return True
|
||||
|
||||
def close_channel(self, channel_id):
|
||||
if channel_id not in self.channels:
|
||||
|
Loading…
Reference in New Issue
Block a user