From 728c9cb3972a841a405078c2619cea2b86379b8e Mon Sep 17 00:00:00 2001
From: Alex Romero <ntalexio2@gmail.com>
Date: Wed, 15 Feb 2023 16:33:45 -0500
Subject: [PATCH 1/2] minor fixes to make python meterpreter comptaible with
 Python 2.5

---
 python/meterpreter/ext_server_stdapi.py |  2 +-
 python/meterpreter/meterpreter.py       | 25 +++++++++++++------------
 2 files changed, 14 insertions(+), 13 deletions(-)

diff --git a/python/meterpreter/ext_server_stdapi.py b/python/meterpreter/ext_server_stdapi.py
index b2a5bf3f..23fde171 100644
--- a/python/meterpreter/ext_server_stdapi.py
+++ b/python/meterpreter/ext_server_stdapi.py
@@ -1777,7 +1777,7 @@ def stdapi_net_config_get_arp_table(request, response):
     result = GetIpNetTable(ipnet_table, size, False)
 
     if result == ERROR_INSUFFICIENT_BUFFER:
-        ipnet_table = ctypes.cast(ctypes.create_string_buffer(b'', size.value), ctypes.c_void_p)
+        ipnet_table = ctypes.cast(ctypes.create_string_buffer(bytes(''), size.value), ctypes.c_void_p)
 
     elif result != ERROR_SUCCESS and result != ERROR_NO_DATA:
         return error_result_windows(result), response
diff --git a/python/meterpreter/meterpreter.py b/python/meterpreter/meterpreter.py
index 882de6cf..bfeb2692 100644
--- a/python/meterpreter/meterpreter.py
+++ b/python/meterpreter/meterpreter.py
@@ -361,18 +361,19 @@ if DEBUGGING:
         file_handler.setLevel(logging.DEBUG)
         logging.getLogger().addHandler(file_handler)
 
-class SYSTEM_INFO(ctypes.Structure):
-    _fields_ = [("wProcessorArchitecture", ctypes.c_uint16),
-        ("wReserved", ctypes.c_uint16),
-        ("dwPageSize", ctypes.c_uint32),
-        ("lpMinimumApplicationAddress", ctypes.c_void_p),
-        ("lpMaximumApplicationAddress", ctypes.c_void_p),
-        ("dwActiveProcessorMask", ctypes.c_uint32),
-        ("dwNumberOfProcessors", ctypes.c_uint32),
-        ("dwProcessorType", ctypes.c_uint32),
-        ("dwAllocationGranularity", ctypes.c_uint32),
-        ("wProcessorLevel", ctypes.c_uint16),
-        ("wProcessorRevision", ctypes.c_uint16)]
+if has_windll:
+    class SYSTEM_INFO(ctypes.Structure):
+        _fields_ = [("wProcessorArchitecture", ctypes.c_uint16),
+            ("wReserved", ctypes.c_uint16),
+            ("dwPageSize", ctypes.c_uint32),
+            ("lpMinimumApplicationAddress", ctypes.c_void_p),
+            ("lpMaximumApplicationAddress", ctypes.c_void_p),
+            ("dwActiveProcessorMask", ctypes.c_uint32),
+            ("dwNumberOfProcessors", ctypes.c_uint32),
+            ("dwProcessorType", ctypes.c_uint32),
+            ("dwAllocationGranularity", ctypes.c_uint32),
+            ("wProcessorLevel", ctypes.c_uint16),
+            ("wProcessorRevision", ctypes.c_uint16)]
 
 def rand_bytes(n):
     return os.urandom(n)

From d93a38a6043423a1eba717b433aee41fad05b4c3 Mon Sep 17 00:00:00 2001
From: Alex Romero <ntalexio2@gmail.com>
Date: Fri, 17 Feb 2023 10:47:13 -0500
Subject: [PATCH 2/2] remove single qoutes from bytes() in order to Python 3.10
 compatibility

---
 python/meterpreter/ext_server_stdapi.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/python/meterpreter/ext_server_stdapi.py b/python/meterpreter/ext_server_stdapi.py
index 23fde171..6d43a52b 100644
--- a/python/meterpreter/ext_server_stdapi.py
+++ b/python/meterpreter/ext_server_stdapi.py
@@ -1777,7 +1777,7 @@ def stdapi_net_config_get_arp_table(request, response):
     result = GetIpNetTable(ipnet_table, size, False)
 
     if result == ERROR_INSUFFICIENT_BUFFER:
-        ipnet_table = ctypes.cast(ctypes.create_string_buffer(bytes(''), size.value), ctypes.c_void_p)
+        ipnet_table = ctypes.cast(ctypes.create_string_buffer(bytes(), size.value), ctypes.c_void_p)
 
     elif result != ERROR_SUCCESS and result != ERROR_NO_DATA:
         return error_result_windows(result), response