Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: UTF-8 -*-
- # ,-----.
- # |M3Ch2|
- # ,--|NiKoN|-.
- # __,----| | | |
- # ,;:: | `_____' |
- # `._______| i^i |
- # `----| |---'| .
- # ,-------._| |== ||//
- # | |_|P`. /'/
- # `-------' 'Y Y/'/'
- # .== /_
- # / /'| `i
- # /' / | |
- # /' / | `i
- # ___,;`----'.___L_,-'`__
- # i_____;----.____i""____
- #
- # TODO:
- # - Analyze doesnt check if the user exists/is a network service
- # - Userdb regex kill command (ie >regex ident hardbot)
- # - Autoscan for bots
- #
- # General config
- server="niggers.skidsr.us"
- port=6667
- channels=["#mech","#help"]
- # SHA512 of a SHA512
- adminpass="110b77dd590f299dcdaac438bd9d6e119464a82fe625d34fa89c4083695f62627774a39d4baedf582f33d97897fda95037ed7b55929e43d59679d980543d46a2"
- # NickServ pass
- nspass="lolno"
- # O-Line is required
- oper="OPER Nikon notthiseither"
- # Don't edit past here unless you know what you're doing
- from twisted.words.protocols import irc
- from twisted.internet import reactor, protocol, defer
- from twisted.names.client import lookupAddress
- from twisted.internet.task import LoopingCall
- from twisted.python import log
- from collections import defaultdict
- import re, os, sys, hashlib, time
- # Lists
- verifiedadmins=[]
- tempid=[]
- wusers=[]
- userdb=[]
- bopmList = ['rbl.efnet.org', 'tor.efnet.org', 'tor.dnsbl.sectoor.de', 'xbl.spamhaus.org', 'sbl.spamhaus.org', 'tor.ahbl.org', 'ircbl.ahbl.org', 'dnsbl.njabl.org', 'cbl.abuseat.org']
- bots=[]
- ## PREDEFINED FUNCTIONS ##
- def shutdown():
- reactor.stop()
- def restart():
- python = sys.executable
- os.execl(python, python, * sys.argv)
- def reg(user):
- if user in tempid:
- return True
- else:
- return False
- def group(list,range):
- try:
- list.sort()
- out = []
- new_list = []
- out.append(new_list)
- app = new_list.append
- prev = list.pop(0)
- app(prev)
- while list:
- cur = list.pop(0)
- if cur-prev > range:
- new_list = []
- app = new_list.append
- out.append(new_list)
- app(cur)
- prev = cur
- return out
- except:
- pass
- ## IRC CLIENT ##
- class IRCClient(irc.IRCClient):
- nickname = 'Mech'
- username = 'mech'
- realname = '\xf0\x9d\x97\xa0\xf0\x9d\x97\xb2\xf0\x9d\x97\xb0\xf0\x9d\x97\xb5 \xf0\x9d\x9f\xae \xf0\x9d\x97\x94\xf0\x9d\x97\xbb\xf0\x9d\x98\x81\xf0\x9d\x97\xb6\xf0\x9d\x97\xaf\xf0\x9d\x97\xbc\xf0\x9d\x98\x81'
- password = nspass
- versionName = ":: \xf0\x9d\x97\xa0\xf0\x9d\x97\xb2\xf0\x9d\x97\xb0\xf0\x9d\x97\xb5 \xf0\x9d\x9f\xae \xf0\x9d\x97\x94\xf0\x9d\x97\xbb\xf0\x9d\x98\x81\xf0\x9d\x97\xb6\xf0\x9d\x97\xaf\xf0\x9d\x97\xbc\xf0\x9d\x98\x81 \x02|\x02 \xf0\x9d\x97\xa1\xf0\x9d\x97\xb6\xf0\x9d\x97\xb8\xf0\x9d\x97\xbc\xf0\x9d\x97\xbb "
- sourceURL = None
- def signedOn(self):
- print "[*] Connected to %s" % server
- self.sendLine("MODE Mech +TpBR")
- self.sendLine(oper)
- for channel in self.factory.channels:
- self.join(channel)
- self.msg(channel,"\xee\x80\x91 \xf0\x9d\x97\xa0\xf0\x9d\x97\xb2\xf0\x9d\x97\xb0\xf0\x9d\x97\xb5 \xf0\x9d\x97\xbc\xf0\x9d\x97\xbb\xf0\x9d\x97\xb9\xf0\x9d\x97\xb6\xf0\x9d\x97\xbb\xf0\x9d\x97\xb2.")
- def update():
- global userdb
- userdb=[]
- self.sendLine("WHO")
- self.sendLine("LIST")
- try:
- repeater.stop()
- repeater.start(15)
- except:
- repeater = LoopingCall(update)
- repeater.start(15)
- def privmsg(self, user, channel, msg):
- nickname = user[:user.find('!')]
- if nickname == "NickServ" and msg.startswith("STATUS"):
- status = msg.split()
- if status[2] == '3':
- tempid.append(status[1])
- self.notice(status[1], "\xee\x80\x91 You are now authenticated %s\x0f." % status[1])
- else:
- self.notice(status[1], "\xee\x80\x91 Authentication failed. You must be registered with NickServ.")
- try:
- params = msg.split()
- cmd = params[0]
- if cmd.startswith('>'):
- cb = getattr(self, 'CMD_%s' % cmd[1:].lower(), None)
- if cb is not None:
- cb(nickname, channel, msg, params)
- except IndexError:
- pass
- except Exception, e:
- print e
- # Commands #
- ## IDENTIFICATION ##
- def CMD_login(self, nickname, channel, msg, params):
- if len(params)==2:
- if hashlib.sha512(hashlib.sha512(params[1]).hexdigest()).hexdigest()==adminpass:
- if nickname not in tempid:
- tempid.append(nickname)
- verifiedadmins.append(nickname)
- self.notice(nickname,"\xee\x80\x91 You are now authenticated %s\x0F." % nickname)
- else:
- self.notice(nickname,"\xee\x80\x91 You have already authenticated %s." % nickname)
- else:
- self.notice(nickname,"\xee\x80\x91 Authentication failed.")
- else:
- if nickname in tempid:
- self.notice(nickname,"\xee\x80\x91 You have already authenticated %s." % nickname)
- else:
- self.msg("NickServ","STATUS %s" % nickname)
- ## GENERAL / STATISTICAL COMMANDS ##
- # Help
- def CMD_help(self, nickname, channel, line, params):
- self.notice(nickname,"\xee\x80\x91 \xf0\x9d\x97\xa0\xf0\x9d\x97\xb2\xf0\x9d\x97\xb0\xf0\x9d\x97\xb5 \xf0\x9d\x9f\xae \xf0\x9d\x97\x94\xf0\x9d\x97\xbb\xf0\x9d\x98\x81\xf0\x9d\x97\xb6\xf0\x9d\x97\xaf\xf0\x9d\x97\xbc\xf0\x9d\x98\x81")
- self.notice(nickname,"General commands: >help, >login")
- self.notice(nickname,"Statistical commands: >hosts, >idle, >signon")
- self.notice(nickname,"Admin commands: >shutdown, >restart, >dump, >raw, >scan, >analyze, >engage_drones, >engage_bopm, >logflag")
- # Shutdown
- def CMD_shutdown(self, nickname, channel, line, params):
- if nickname in verifiedadmins:
- shutdown()
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- # Restart
- def CMD_restart(self, nickname, channel, line, params):
- if nickname in verifiedadmins:
- restart()
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- # Raw
- def CMD_raw(self, nickname, channel, line, params):
- if nickname in verifiedadmins:
- self.sendLine(line.replace(">raw ",""))
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- # Dump
- def CMD_dump(self, nickname, channel, line, params):
- if nickname in verifiedadmins:
- self.notice(nickname,"\xee\x80\x91 Length of UserDB: %s" % str(len(userdb)))
- for x in userdb:
- self.msg(nickname,x)
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- # Host frequency
- def CMD_hosts(self, nickname, channel, line, params):
- if nickname in tempid:
- self.notice(nickname,"\xee\x80\x91 Dumping host frequency (clones)..")
- hosts=list(x['HOSTMASK'] for x in userdb)
- d=defaultdict(int)
- for x in hosts:
- d[x]+=1
- for x in d.items():
- self.msg(nickname,"The\x035 %s \x0Fhostmask has %s known clone(s) including the user(s):\x035 %s" % (x[0], x[1], "\x0F,\x035 ".join([ d['NICK'] for d in userdb if d['HOSTMASK'] == x[0] ])))
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- # Idle frequency
- def CMD_idle(self, nickname, channel, line, params):
- if nickname in tempid:
- self.notice(nickname,"\xee\x80\x91 Dumping idle frequency..")
- times=list(x['IDLE'] for x in userdb)
- d=defaultdict(int)
- for x in times:
- d[x]+=1
- for x in d.items():
- self.msg(nickname,"Idle:\x035 %s\x0F second(s) | %s User(s):\x035 %s" % (x[0],x[1],"\x0F,\x035 ".join([ d['NICK'] for d in userdb if d['IDLE'] == x[0] ])))
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- # Sign-on frequency
- def CMD_signon(self, nickname, channel, line, params):
- if nickname in tempid:
- self.notice(nickname,"\xee\x80\x91 Dumping sign-on frequency..")
- signons=list(x['SIGNON'] for x in userdb if x != None)
- d=defaultdict(int)
- for x in signons:
- d[x]+=1
- for x in d.items():
- if x[0] != None:
- self.msg(nickname,"Signon:\x035 %s\x0F | %s User(s):\x035 %s" % (time.ctime(float(x[0])),x[1],"\x0F,\x035 ".join([ d['NICK'] for d in userdb if d['SIGNON'] == x[0] ])))
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- # Analyze
- def CMD_analyze(self, nickname, channel, line, params):
- if nickname in verifiedadmins:
- if len(params)==2:
- usr=params[1]
- if usr in wusers:
- self.notice(nickname,"User cannot be analyzed (umode +W)")
- else:
- self.notice(nickname,"\xee\x80\x91 Analyzing %s" % usr)
- self.notice(nickname,"Nick:\x035 %s " % usr)
- self.notice(nickname,"IP:\x035 %s" % list(z['IP'] for z in userdb if (z['NICK']==usr))[0])
- self.notice(nickname,"Hostmask:\x035 %s@%s" % (list(z['IDENT'] for z in userdb if (z['NICK'] == usr))[0],list(z['HOSTMASK'] for z in userdb if (z['NICK'] == usr))[0]))
- self.notice(nickname,"Signon:\x035 %s" % time.ctime(float(list(z['SIGNON'] for z in userdb if (z['NICK']==usr))[0])))
- self.notice(nickname,"Idle:\x035 %s \x0Fsecond(s)" % list(z['IDLE'] for z in userdb if (z['NICK'] == usr))[0])
- self.notice(nickname,"Channels:\x035 %s" % "\x0F,\x035 ".join(list(z['CHANNELS'] for z in userdb if (z['NICK'] == usr))[0]))
- else:
- self.notice(nickname,"\xee\x80\x91 Usage: >analyze [user]")
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- ## DEFENSE ##
- # Scan
- def CMD_scan(self, nickname, channel, line, params):
- if nickname in verifiedadmins:
- signons=list(int(x['SIGNON']) for x in userdb if (x['SIGNON'] is not None) and (x['IP'] is not None))
- idles=list(int(x['IDLE']) for x in userdb if (x['IDLE'] is not None) and (x['IP'] is not None))
- signons_grouped=group(signons,2)
- idles_grouped=group(idles,1)
- signons_elim=[]
- idles_elim=[]
- for x in signons_grouped:
- if len(x)>=5:
- for y in x:
- signons_elim.append(str(y))
- for x in idles_grouped:
- if len(x)>=5:
- for y in x:
- idles_elim.append(str(y))
- idleset=set(idles_elim)
- signonset=set(signons_elim)
- botlist1=[]
- botlist2=[]
- for x in idleset:
- for y in list(z['NICK'] for z in userdb if (z['IDLE'] == x)):
- botlist1.append(y)
- for x in signonset:
- for y in list(z['NICK'] for z in userdb if (z['SIGNON'] == x)):
- botlist2.append(y)
- bots=set(botlist1)&set(botlist2)
- global bots
- if len(bots)>0:
- self.msg(channel,"\xee\x80\x91 There are\x035 %s \x0Fbot(s) on the network." % len(bots))
- self.msg(channel,"Nicks:\x035 %s" % "\x0F,\x035 ".join(bots))
- elif len(bots)==0:
- self.msg(channel,"\xee\x80\x91 There are no bots on the network.")
- else:
- self.msg(channel,"\xee\x80\x91 \x035Error.")
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- # Logflag
- def CMD_logflag(self, nickname, channel, line, params):
- if nickname in verifiedadmins:
- try:
- self.msg(channel,"\xee\x8e\xaa Adding all detected drones to local DroneBL")
- ips=[]
- for x in bots:
- for y in list(z['IP'] for z in userdb if (z['NICK'] == x)):
- ips.append(y)
- ips_elim=set(ips)
- try:
- file=open('dronebl.txt','r+')
- except IOError:
- print "[*] DroneBL file not found, creating one.."
- file=open('dronebl.txt','w+')
- file.write("DroneBL file created on %s\n" % time.ctime())
- file.closed
- file=open('dronebl.txt','r+')
- dronelist=file.readlines()
- file.closed
- file=open('dronebl.txt','w+')
- for x in dronelist:
- if x in ips_elim:
- pass
- else:
- file.write(x)
- file.closed
- file=open('dronebl.txt','a+')
- for x in ips_elim:
- file.write("%s\n" % x)
- file.closed
- self.msg(channel,"\xee\x80\x91 Success.")
- except:
- self.notice(nickname,"\xee\x80\x91 You must scan for active drones first (>scan).")
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- # Engage drones
- def CMD_engage_drones(self, nickname, channel, line, params):
- if nickname in verifiedadmins:
- try:
- self.msg(channel,"\xee\x80\x91 \x035Engaging all drones..")
- for x in bots:
- self.sendLine("GLINE %s 1800 :\x035Drone\x0F" % x)
- except:
- self.notice(nickname,"\xee\x80\x91 You must scan for active drones first (>scan).")
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- # Engage BOPM
- def CMD_engage_bopm(self, nickname, channel, line, params):
- if nickname in verifiedadmins:
- self.msg(channel,"\xee\x80\x91 \x035Engaging all listed proxies..")
- try:
- for y in set(x['IP'] for x in userdb if x['IP'] is not None):
- name, original = '.'.join(y.split('.')[::-1]), y
- hit=[lookupAddress('%s.%s' % (name, bopm)) for bopm in bopmList]
- d = defer.DeferredList(hit, fireOnOneCallback=1, consumeErrors=1)
- def result(h, ip):
- h = list(h)
- if h[0][0] is False:
- pass
- else:
- for z in [u['NICK'] for u in userdb if u['IP']==ip]:
- self.sendLine("GLINE +%s 1800 :\x035Listed in %s\x0F" % (z,'.'.join(h[0][0][0].name.name.split('.')[4:])))
- d.addCallback(result, original)
- except:
- self.msg(channel,"\xee\x80\x91 \x035Error.")
- else:
- self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
- ## OTHER HANDLERS ##
- def userLeft(self, user, channel):
- if user in tempid:
- tempid.remove(user)
- if user in verifiedadmins:
- verifiedadmins.remove(user)
- def userQuit(self, user, quitMessage):
- if user in tempid:
- tempid.remove(user)
- if user in verifiedadmins:
- verifiedadmins.remove(user)
- def userKicked(self, kickee, channel, kicker, message):
- if kickee in tempid:
- tempid.remove(kickee)
- if kickee in verifiedadmins:
- verifiedadmins.remove(kickee)
- def userRenamed(self, oldname, newname):
- if oldname in tempid:
- tempid.remove(oldname)
- if oldname in verifiedadmins:
- verifiedadmins.remove(oldname)
- def kickedFrom(self, channel, kicker, message):
- self.join(channel)
- tempid=[]
- def irc_unknown(self, prefix, command, params):
- #print prefix,command,params
- if command == "379":
- if "W" in params[2].split("+")[1][:-1]:
- wusers.append(params[1])
- if command == "378":
- for d in userdb:
- if d["NICK"] == params[1]:
- try:
- d["IP"] = params[2].split()[4]
- except:
- pass
- if command == "RPL_WHOISIDLE":
- for d in userdb:
- if d["NICK"] == params[1]:
- d["SIGNON"] = params[3]
- d["IDLE"] = params[2]
- if command == "RPL_WHOISCHANNELS":
- for d in userdb:
- if d["NICK"] == params[1]:
- d["CHANNELS"] = params[2].split()
- if command == "RPL_WHOREPLY":
- userdb.append({"NICK":params[5],"IDENT":params[2],"HOSTMASK":params[3],"SIGNON":None,"CHANNELS":None,"IDLE":None,"IP":None})
- if params[5] not in wusers:
- self.sendLine("WHOIS %s %s" % (params[5],params[5]))
- if command == "RPL_LIST":
- if (int(params[2]) >= 5) and ("L" not in str(re.findall("\[(.*?)\]", params[3]))[0]):
- self.join(params[1])
- class IRCFactory(protocol.ClientFactory):
- protocol = IRCClient
- def __init__(self, channels):
- self.channels = channels
- reactor.connectTCP(server, port, IRCFactory(channels))
- reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement