Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #InsoBot: An IRC bot that allows for basic file upload by an authorized
- #user via use of an IRC network of one's choice.
- import socket,os,string,sys,ftplib,hashlib
- import time
- #Define Variables that will be needed throughout the program.
- #Only change the variables in the box unless you've read the code
- #and understand what you're doing!
- ###############################################
- Host = "irc.example.com" #
- Port = 6667 #
- Filename = "" #
- chanpass = "" #
- FTPserver = "server.example.com" #
- #
- ftpuser="exampleuser" #
- ftppass="example_pass" #
- passhash = "example Hash" #
- ###############################################
- Auth = 0
- Filename = ""
- NICK="insobot"
- IDENT="insobot"
- REALNAME="insobot"
- readbuffer=""
- joined = 0
- perm = 0
- ############################
- #Define Essential Functions#
- ############################
- #Determines if user is allowed to perform an action.
- def getperm(pswd):
- global perm
- password = hashlib.md5()
- password.update(pswd)
- a = password.hexdigest()
- if a == passhash:
- user = line[0]
- perm = 1
- s.send("PRIVMSG %s \r\n" % "#insobot, You are authorized")
- else:
- s.send("PRIVMSG %s \r\n" % "#insobot, Wrong password")
- #Upload file to an FTP Server of your choice.
- def upfile(server,perm,name,ftpuser,ftppass,fname):
- if perm == 1:
- try:
- ftp=ftplib.FTP(server)
- ftp.login(ftpuser,ftppass)
- f = open(name,'rb')
- ftp.storbinary("STOR `Filename`",f)
- ftp.rename("`Filename`",fname)
- except ftplib.all_errors,e:
- ermsg = str(e)
- s.send("PRIVMSG %s \r\n" % "#insobot, There was an error with the FTP server")
- s.send("PRIVMSG %s \r\n" % "#insobot, Server Response: %(server_response)s" % {"server_response": ermsg})
- pass
- else:
- s.send("PRIVMSG %s \r\n" % "#insobot, You are not authorized")
- pass
- perm = 0
- #Connect to the Server
- global s
- s = socket.socket( )
- s.connect((Host,Port))
- s.send("NICK %s\r\n" % NICK)
- s.send("USER %s %s bla :%s\r\n" % (IDENT, Host, REALNAME))
- time.sleep(3)
- #Receive and Process data
- while 1:
- readbuffer=readbuffer+s.recv(1024)
- temp=string.split(readbuffer, "\n")
- readbuffer=temp.pop( )
- for line in temp:
- line=string.rstrip(line)
- print line
- line=string.split(line)
- try:
- #Tell the server we are still here if it asks.
- if(line[0]=="PING"):
- s.send("PONG %s\r\n" % line[1])
- #Join our channel.
- if joined == 0:
- s.send("JOIN %s\r\n" % "#insobot")
- s.send("MODE insobot +i %s \r\n")
- mode = "MODE #insobot +k " + chanpass + " %s \r\n"
- s.send(mode)
- joined == 1
- if (line[3]==":+login"):
- getperm(line[4])
- #Change Filename if no dangerous chars are present.
- if (line[3]==":+filename"):
- allow = 1
- for a in ["../","%","..","..\""]:
- if a in line[4]:
- s.send("PRIVMSG %s \r\n" % "#insobot, I don't think so.")
- allow = 0
- if allow == 1:
- Filename = "/home/patrick/Documents/" + line[4]
- s.send("PRIVMSG %s \r\n" % "#insobot, Filenamed changed.")
- print Filename
- ftpfname = line[4]
- else:
- pass
- if (line[3]==":+upload"):
- upfile(FTPserver,perm,Filename,ftpuser,ftppass,ftpfname)
- except IndexError:
- pass
Add Comment
Please, Sign In to add comment