-
Notifications
You must be signed in to change notification settings - Fork 0
/
strings.py
executable file
·168 lines (122 loc) · 3.64 KB
/
strings.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
#! /usr/bin/python
import os
import md5
import sys
import subprocess
import datetime
import pefile
import peutils
#******************
#** INIT *********
#******************
#parse args
#TODO - do this right
#get filename from argument
filename = sys.argv[1]
##GET MD5 Hash of malware
try:
mal_file = open(sys.argv[1],'rb')
mal_file_data = mal_file.read()
MD5 = md5.md5(mal_file_data).hexdigest().upper()
mal_file.close()
except:
print sys.argv[1],'not found.'
sys.exit()
#---------------------
#GET Strings from file
#---------------------
#frisbie's regexes
#input = subprocess.check_output(['strings','-n','8','-a',filename])
#ips = re.findall( r'[0-9]+(?:\.[0-9]{1,3}){3}', input)
#ips = list(set(ips))
#domains = re.findall( r'([_a-zA-Z0-9.\-]+\.[_a-zA-Z]{2,4})', input)
#domains = list(set(domains))
STRINGS = subprocess.check_output(['strings','-n','8','-a',filename]).split('\n')
NEAT_STRINGS = []
NEAT_WORDS = ['www','http','.exe','.rar','.ini','.dll','.txt',
'C:\\','LoadLibrary','Create','write','User-Agent',
'ControlSet','CurrentVersion','.sys','.dat','.pdb','.com','Active Setup','.mdt',
'service','mozilla','socket','admin','Microsoft','Hook','EventLog','GetKeyState']
OTHER_STRINGS = []
for STRING in STRINGS:
for WORD in NEAT_WORDS:
if WORD.lower() in STRING.lower():
NEAT_STRINGS.append(STRING)
#---------------------
#GET entropy
#---------------------
try:
pe = pefile.PE(filename)
ENTROPY = "SECTIONS ENTROPY:"
for section in pe.sections:
ENTROPY = ENTROPY + "\n %-12s %.2f" % (section.Name.rstrip('\0') + ":", section.get_entropy())
#-----------------------
#GET compile timestamp
#-----------------------
COMPILE_TIME = "\nCOMPILE_TIME:\n "+pe.FILE_HEADER.dump()[3][60:-1]
except:
ENTROPY = "SECTIONS ENTROPY:\n *FAILED*"
COMPILE_TIME = "\nCOMPILE_TIME:\n *FAILED*"
#---------------------------
#GET result of file command
#---------------------------
FILE_INFO = subprocess.check_output(['file',filename]).split(';')[1]
#check DLL stuff
DLL_EXPORTS = ''
DLL_IMPORTS = ''
try:
pe = pefile.PE(filename)
if pe.FILE_HEADER.IMAGE_FILE_DLL == True:
if len(pe.DIRECTORY_ENTRY_EXPORT.symbols) > 0:
DLL_EXPORTS = "\n\nDLL_EXPORTS:"
for export in pe.DIRECTORY_ENTRY_EXPORT.symbols:
DLL_EXPORTS += "\n " + export.name
addr_name = pe.DIRECTORY_ENTRY_EXPORT.struct.Name
name = pe.get_memory_mapped_image()[addr_name:addr_name+256].split('\0', 1)[0]
DLL_EXPORTS += "\n\nThe DLL exports its original name as " + name
except:
DLL_EXPORTS = "\n\nDLL_EXPORTS:\n ERROR"
# try:
# DLL_IMPORTS = "\n\nDLL_IMPORTS:"
# for entry in pe.DIRECTORY_ENTRY_IMPORT:
# DLL_IMPORTS += '\n\n ' + entry.dll
# for imp in entry.imports:
# DLL_IMPORTS += '\n ' + imp.name
# except:
# DLL_IMPORTS = "\n\nDLL_IMPORTS:\n ERROR"
#*******************************
#** WRITE **********************
#*******************************
OUT = ''
#Filename
OUT += '\n\nFILE: \n '
OUT += filename
#MD5
OUT += '\n\nMD5: \n '
OUT += MD5
#FILE_INFO
OUT += '\n\nFILE_INFO: \n '
OUT += FILE_INFO
#Compile Date
OUT += COMPILE_TIME
#ENTROPY
OUT += '\n\n'
OUT += ENTROPY
#DLL_EXPORTS
OUT += DLL_EXPORTS
#DLL_IMPORTS
OUT += DLL_IMPORTS
#Strings
OUT += '\n\nSTRINGS:\n'
for NEAT in NEAT_STRINGS:
OUT += ' '
OUT += NEAT
OUT += '\n'
OUT += '\n --------------------------------------\n\n'
for STRING in STRINGS:
if STRING not in NEAT_STRINGS:
OUT += ' '
OUT += STRING
OUT += '\n'
print OUT
imports_i_care_about = ['RegSetValue','GetWindowText','SetWindowsHook','CallNextHook','WriteFile',]