-
Notifications
You must be signed in to change notification settings - Fork 7
/
http-web.py
271 lines (197 loc) · 7.4 KB
/
http-web.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
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
#!/usr/bin/env python
# Owner : Jayesh Patel
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
from SimpleHTTPServer import SimpleHTTPRequestHandler
from SocketServer import ThreadingMixIn
import threading
import SocketServer
import commands
import os
from deflat import deflate_zip
from base64_encode import base64_encode
from utf_encode import utf_encode
from padding import setPadding
class S(BaseHTTPRequestHandler):
def _set_headers(self):
print self.headers
if self.headers['Content-Type']:
contentType = self.headers['Content-Type']
else:
contentType = "None"
if self.headers['Content-Encoding']:
contentEncoding = self.headers['Content-Encoding']
else:
contentType = "None"
self.send_response(200)
if "UTF-7" in contentType:
self.send_header('Content-type', 'text/html; charset=utf-7' )
if "UTF-8" in contentType:
self.send_header('Content-type', 'text/html; charset=utf-8' )
if "UTF-16" in contentType:
self.send_header('Content-type', 'text/html; charset=utf-16' )
if "UTF-16LE" in contentType:
self.send_header('Content-type', 'text/html; charset=utf-16le' )
if "UTF-16BE" in contentType:
self.send_header('Content-type', 'text/html; charset=utf-16be' )
if "UTF-32" in contentType:
self.send_header('Content-type', 'text/html; charset=utf-32' )
if "UTF-32LE" in contentType:
self.send_header('Content-type', 'text/html; charset=utf-32le' )
if "UTF-32BE" in contentType:
self.send_header('Content-type', 'text/html; charset=utf-32be' )
if "base64" in contentType:
self.send_header('Content-type', 'text/html')
self.send_header('Content-Transfer-Encoding', 'BASE64' )
if "deflate" in contentEncoding:
self.send_header('Content-Encoding', 'deflate')
if "gzip" in contentEncoding:
self.send_header('Content-Encoding', 'gzip')
if "chunked" in contentEncoding:
self.send_header('Transfer-Encoding', 'chunked')
self.end_headers()
def run_evasion(self, payload, file_type, evasion_name):
if evasion_name == "scripts_encryptor":
if os.path.exists("SrcEnv/%s_se" % payload.split('/')[1]):
status, output = commands.getstatusoutput('cp SrcEnv/%s_se /tmp/%s' %(payload.split('/')[1], self.file_name))
command = 'cp SrcEnv/%s_se /tmp/%s' %(payload.split('/')[1], self.file_name)
print command
return "Done"
else:
return "None"
else:
status, output = commands.getstatusoutput('python obfuscate-js.py -i %s -t %s -o /tmp/ -e %s' % (payload, file_type, evasion_name))
command = 'python obfuscate-js.py -i %s -t %s -o /tmp/ -e %s' % (payload, file_type, evasion_name)
print "============== %s" % command
print status
print output
if status != 0:
return "None"
else:
return "Done"
def chunks(self, s, n):
for start in range(0, len(s), n):
yield s[start:start+n]
def do_GET(self):
self._set_headers()
payload_name = self.path.split('?')[0][1:]
next_str = self.path.split('?')[1]
next_final_str = next_str.split('%26')
str_array = dict(s.split('=') for s in next_final_str)
file_type = str_array['type']
evasion_name = str_array['evasion']
compress = str_array['compress']
chunked = str_array['chunked']
characterSet = str_array['characterset']
padding = str_array['padding']
if ("None") in padding:
padding = "None"
print "jayesh %s" % padding
print "payload name %s" % payload_name
print "filetype %s" % file_type
print "evasion name %s" % evasion_name
file_name = payload_name.split('.')[0] +"_"+ evasion_name +"."+ file_type
self.file_name = payload_name.split('.')[0] +"_"+ evasion_name +"."+ file_type
if padding != "None":
res = setPadding(payload_name, int(padding))
res.addPadding()
file_name = payload_name+"_pad"
if evasion_name != "None":
if padding != "None":
command_status = self.run_evasion("/tmp/"+payload_name+"_pad", file_type, evasion_name)
if padding == "None":
command_status = self.run_evasion("static/"+payload_name, file_type, evasion_name)
print "command status %s" % command_status
file_name = payload_name.split('.')[0] +"_"+ evasion_name +"."+ file_type
else:
if padding == "None":
os.system("cp static/%s /tmp/%s" % (payload_name, file_name))
command_status = "Done"
if characterSet != "None":
res = utf_encode("/tmp/"+file_name)
if characterSet == "utf7":
res.set_utf7()
if characterSet == "utf8bom":
res.set_utf8bom()
if characterSet == "utf16":
res.set_utf16()
if characterSet == "utf16le":
res.set_utf16le()
if characterSet == "utf16be":
res.set_utf16be()
if characterSet == "utf32":
res.set_utf32()
if characterSet == "utf32le":
res.set_utf32le()
if characterSet == "utf32be":
res.set_utf32be()
if characterSet == "base64":
self.setBase64(file_name)
else:
os.system("cp /tmp/%s /tmp/%s_%s" % (file_name, file_name, characterSet))
# Generate file /tmp/filename_utf32be
if compress != "None":
if compress == "deflate":
self.setDeflat(file_name + "_" + characterSet)
if compress == "gzip":
self.setGzip(file_name+"_"+characterSet)
else:
os.system("cp /tmp/%s_%s /tmp/%s_%s_%s" % (file_name, characterSet, file_name, characterSet, compress))
if command_status == "Done":
if chunked == "yes":
for chunk in self.chunks(''.join(open("/tmp/"+file_name+"_"+characterSet+"_"+compress, 'r').readlines()), 15):
chkn = len(chunk)
if chkn == 15:
chk_num = "f"
elif chkn == 14:
chk_num = "e"
elif chkn == 13:
chk_num = "d"
elif chkn == 12:
chk_num = "c"
elif chkn == 11:
chk_num = "b"
elif chkn == 10:
chk_num = "a"
else:
chk_num = chkn
self.wfile.write("%s\r\n" % chk_num)
self.wfile.write("%s\r\n" % chunk)
self.wfile.write('0\r\n\r\n')
else:
with open("/tmp/"+file_name+"_"+characterSet+"_"+compress) as data:
self.wfile.write(data.read())
self.wfile.write("Jayesh Patel")
else:
print "Error 404"
self.send_error(404, 'file not found')
os.system("rm -rf /tmp/%s*" % payload_name.split('.')[0])
print "remove file rm -rf /tmp/%s*" % payload_name.split('.')[0]
def setBase64(self, filename):
res = base64_encode("/tmp/"+filename)
res.set_base64()
# Generate New file in /tmp/filename_b64
def setDeflat(self, filename):
res = deflate_zip("/tmp/"+filename)
res.set_deflate()
# Generate New file with name filename_deflate
def setGzip(self, filename):
res = deflate_zip("/tmp/"+filename)
res.set_gzip()
# Generate New file filename_gzip
def do_HEAD(self):
self._set_headers()
def do_POST(self):
# Doesn't do anything with posted data
self._set_headers()
self.wfile.write("<html><body><h1>POST!</h1></body></html>")
def run(server_class=HTTPServer, handler_class=S, port=80):
server_address = ('', port)
httpd = server_class(server_address, handler_class)
print 'Starting httpd...'
httpd.serve_forever()
if __name__ == "__main__":
from sys import argv
if len(argv) == 2:
run(port=int(argv[1]))
else:
run()