|
1 |
| -import ctypes |
2 | 1 | import fnmatch
|
3 | 2 | import getpass
|
4 | 3 | import os
|
|
10 | 9 | import subprocess
|
11 | 10 | import sys
|
12 | 11 |
|
13 |
| -has_windll = hasattr(ctypes, 'windll') |
| 12 | +try: |
| 13 | + import ctypes |
| 14 | + has_ctypes = True |
| 15 | + has_windll = hasattr(ctypes, 'windll') |
| 16 | +except: |
| 17 | + has_windll = False |
| 18 | + has_ctypes = False |
14 | 19 |
|
15 | 20 | try:
|
16 | 21 | import pty
|
|
36 | 41 | except ImportError:
|
37 | 42 | has_winreg = False
|
38 | 43 |
|
39 |
| -class PROCESSENTRY32(ctypes.Structure): |
40 |
| - _fields_ = [("dwSize", ctypes.c_uint32), |
41 |
| - ("cntUsage", ctypes.c_uint32), |
42 |
| - ("th32ProcessID", ctypes.c_uint32), |
43 |
| - ("th32DefaultHeapID", ctypes.c_void_p), |
44 |
| - ("th32ModuleID", ctypes.c_uint32), |
45 |
| - ("cntThreads", ctypes.c_uint32), |
46 |
| - ("th32ParentProcessID", ctypes.c_uint32), |
47 |
| - ("thPriClassBase", ctypes.c_int32), |
48 |
| - ("dwFlags", ctypes.c_uint32), |
49 |
| - ("szExeFile", (ctypes.c_char * 260))] |
50 |
| - |
51 |
| -class SYSTEM_INFO(ctypes.Structure): |
52 |
| - _fields_ = [("wProcessorArchitecture", ctypes.c_uint16), |
53 |
| - ("wReserved", ctypes.c_uint16), |
54 |
| - ("dwPageSize", ctypes.c_uint32), |
55 |
| - ("lpMinimumApplicationAddress", ctypes.c_void_p), |
56 |
| - ("lpMaximumApplicationAddress", ctypes.c_void_p), |
57 |
| - ("dwActiveProcessorMask", ctypes.c_uint32), |
58 |
| - ("dwNumberOfProcessors", ctypes.c_uint32), |
59 |
| - ("dwProcessorType", ctypes.c_uint32), |
60 |
| - ("dwAllocationGranularity", ctypes.c_uint32), |
61 |
| - ("wProcessorLevel", ctypes.c_uint16), |
62 |
| - ("wProcessorRevision", ctypes.c_uint16),] |
63 |
| - |
64 |
| -class SID_AND_ATTRIBUTES(ctypes.Structure): |
65 |
| - _fields_ = [("Sid", ctypes.c_void_p), |
66 |
| - ("Attributes", ctypes.c_uint32),] |
| 44 | +if has_ctypes: |
| 45 | + class PROCESSENTRY32(ctypes.Structure): |
| 46 | + _fields_ = [("dwSize", ctypes.c_uint32), |
| 47 | + ("cntUsage", ctypes.c_uint32), |
| 48 | + ("th32ProcessID", ctypes.c_uint32), |
| 49 | + ("th32DefaultHeapID", ctypes.c_void_p), |
| 50 | + ("th32ModuleID", ctypes.c_uint32), |
| 51 | + ("cntThreads", ctypes.c_uint32), |
| 52 | + ("th32ParentProcessID", ctypes.c_uint32), |
| 53 | + ("thPriClassBase", ctypes.c_int32), |
| 54 | + ("dwFlags", ctypes.c_uint32), |
| 55 | + ("szExeFile", (ctypes.c_char * 260))] |
| 56 | + |
| 57 | + class SYSTEM_INFO(ctypes.Structure): |
| 58 | + _fields_ = [("wProcessorArchitecture", ctypes.c_uint16), |
| 59 | + ("wReserved", ctypes.c_uint16), |
| 60 | + ("dwPageSize", ctypes.c_uint32), |
| 61 | + ("lpMinimumApplicationAddress", ctypes.c_void_p), |
| 62 | + ("lpMaximumApplicationAddress", ctypes.c_void_p), |
| 63 | + ("dwActiveProcessorMask", ctypes.c_uint32), |
| 64 | + ("dwNumberOfProcessors", ctypes.c_uint32), |
| 65 | + ("dwProcessorType", ctypes.c_uint32), |
| 66 | + ("dwAllocationGranularity", ctypes.c_uint32), |
| 67 | + ("wProcessorLevel", ctypes.c_uint16), |
| 68 | + ("wProcessorRevision", ctypes.c_uint16),] |
| 69 | + |
| 70 | + class SID_AND_ATTRIBUTES(ctypes.Structure): |
| 71 | + _fields_ = [("Sid", ctypes.c_void_p), |
| 72 | + ("Attributes", ctypes.c_uint32),] |
67 | 73 |
|
68 | 74 | ##
|
69 | 75 | # STDAPI
|
@@ -675,12 +681,12 @@ def stdapi_fs_ls(request, response):
|
675 | 681 |
|
676 | 682 | @meterpreter.register_function
|
677 | 683 | def stdapi_fs_md5(request, response):
|
678 |
| - if sys.version_info[0] == 2 and sys.version_info[1] < 5: |
679 |
| - import md5 |
680 |
| - m = md5.new() |
681 |
| - else: |
| 684 | + try: |
682 | 685 | import hashlib
|
683 | 686 | m = hashlib.md5()
|
| 687 | + except ImportError: |
| 688 | + import md5 |
| 689 | + m = md5.new() |
684 | 690 | path = packet_get_tlv(request, TLV_TYPE_FILE_PATH)['value']
|
685 | 691 | m.update(open(path, 'rb').read())
|
686 | 692 | response += tlv_pack(TLV_TYPE_FILE_NAME, m.digest())
|
@@ -722,12 +728,12 @@ def stdapi_fs_separator(request, response):
|
722 | 728 |
|
723 | 729 | @meterpreter.register_function
|
724 | 730 | def stdapi_fs_sha1(request, response):
|
725 |
| - if sys.version_info[0] == 2 and sys.version_info[1] < 5: |
726 |
| - import sha1 |
727 |
| - m = sha1.new() |
728 |
| - else: |
| 731 | + try: |
729 | 732 | import hashlib
|
730 | 733 | m = hashlib.sha1()
|
| 734 | + except ImportError: |
| 735 | + import sha |
| 736 | + m = sha.new() |
731 | 737 | path = packet_get_tlv(request, TLV_TYPE_FILE_PATH)['value']
|
732 | 738 | m.update(open(path, 'rb').read())
|
733 | 739 | response += tlv_pack(TLV_TYPE_FILE_NAME, m.digest())
|
|
0 commit comments