Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # -*- coding: utf-8 -*-
- 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, traceback
- #Lists
- tempid=[]
- 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']
- wusers=[]
- userdb=[]
- bots=[]
- #Admin
- admin="Nikon" #You
- adminpass = "7c289fa791749a55127b06da1a65cdbccfe8775603b7f425ea08884183a0305fb4a326a17461f2cb11004701f3b6cf30160535115a21c7d5c1d1809f1e295c98" #This is for if Mech can't identify you. Replace this with a sha512 of a sha512 of your password
- ##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 mech_Client(irc.IRCClient):
- #Nick
- nickname = "Mech"
- #Real name
- realname = "mech"
- #Username
- username = "mech"
- #CTCP replies
- versionName = "IRC Mech"
- sourceURL = None
- #Globals
- global tempid
- global admin
- global adminpass
- global userdb
- global bopmList
- global bots
- #Definitions
- def signedOn(self):
- self.sendLine("MODE Mech +TpBR")
- self.msg("ircd","oper [youroperid] [operpass]")
- self.join(self.factory.channel)
- self.msg(self.factory.channel, "\xe2\x9a\x9d Mech online.")
- 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):
- user = user.split('!', 1)[0]
- ## IDENTIFICATION ##
- if msg.startswith(">login"):
- if len(msg.split())>=1:
- if hashlib.sha512(hashlib.sha512(msg.split()[1]).hexdigest()).hexdigest() == adminpass:
- if user not in tempid:
- tempid.append(user)
- self.notice(user, "\xee\x80\x91 You are now authenticated " + user + "\x0F.")
- else:
- self.notice(user, "\xee\x80\x91 You have already authenticated " + user)
- else:
- self.notice(user, "\xee\x80\x91 Authentication failed.")
- else:
- if user in tempid:
- self.notice(user, "\xee\x80\x91 You have already authenticated " + user)
- else:
- self.msg("NickServ", "STATUS " + user)
- if user == "NickServ" and msg.startswith("STATUS"):
- status = msg.split()
- if status[2] == '3':
- tempid.append(status[1])
- self.notice(self.factory.channel, "\xee\x80\x91 You are now authenticated " + status[1] + ".")
- else:
- self.notice(status[1], "\xee\x80\x91 Authentication failed. You must be registered with NickServ.")
- ## GENERAL / STATISTICAL COMMANDS ##
- #Help
- if msg.startswith (">help"):
- self.notice(user, "Admin commands: >shutdown, >restart >dump >raw >scan >analyze >engage_drones >engage_bopm >logflag")
- self.notice(user, "General commands: >help, >login")
- self.notice(user, "Statistical commands: >hosts, >idle, >signon")
- #Shutdown Bot
- if msg.startswith (">shutdown") and reg(user) and user == admin:
- shutdown()
- #Restart Bot
- if msg.startswith (">restart") and reg(user) and user == admin:
- restart()
- #Raw
- if msg.startswith(">raw ") and reg(user) and user == admin:
- self.sendLine(msg.replace(">raw ",""))
- #Dump
- if msg.startswith(">dump") and reg(user) and user == admin:
- self.msg(channel,"\xee\x80\x91 Length of UserDB: " + str(len(userdb)))
- for x in userdb:
- self.msg(user,x)
- print bots
- #Host frequency
- if msg.startswith(">hosts") and reg(user):
- self.msg(channel,"\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(user,"The\x035 " + x[0] + " \x0Fhostmask has " + str(x[1]) + " known clone(s) including the user(s):\x035 " + "\x0F,\x035 ".join([ d['NICK'] for d in userdb if d['HOSTMASK'] == x[0] ]))
- #Idle frequency
- if msg.startswith(">idle") and reg(user):
- self.msg(channel,"\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(user,"Idle:\x035 " + str(x[0]) + "\x0F second(s) | " + str(x[1]) + " User(s):\x035 " + "\x0F,\x035 ".join([ d['NICK'] for d in userdb if d['IDLE'] == x[0] ]))
- #Sign-on frequency
- if msg.startswith(">signon") and reg(user):
- self.msg(channel,"\xee\x80\x91 Dumping sign-on frequency..")
- signons=list(x['SIGNON'] for x in userdb if x != None)
- print signons
- d=defaultdict(int)
- for x in signons:
- d[x]+=1
- for x in d.items():
- if x[0] != None:
- self.msg(user,"Signon:\x035 " + time.ctime(float(x[0])) + "\x0F | " + str(x[1]) + " User(s):\x035 " + "\x0F,\x035 ".join([ d['NICK'] for d in userdb if d['SIGNON'] == x[0] ]))
- else:
- pass
- #Analyze
- if msg.startswith(">analyze") and reg(user) and user == admin:
- if len(msg.split())>=1:
- usr=msg.split()[1]
- if usr in wusers:
- self.notice(admin,"User cannot be analyzed (umode +W)")
- else:
- self.notice(admin,"\xee\x80\x91 Analyzing "+usr)
- usr_ip=list(z['IP'] for z in userdb if (z['NICK'] == usr))[0]
- usr_signon=list(z['SIGNON'] for z in userdb if (z['NICK'] == usr))[0]
- usr_ident=list(z['IDENT'] for z in userdb if (z['NICK'] == usr))[0]
- usr_hostmask=list(z['HOSTMASK'] for z in userdb if (z['NICK'] == usr))[0]
- usr_channels=list(z['CHANNELS'] for z in userdb if (z['NICK'] == usr))[0]
- usr_idle=list(z['IDLE'] for z in userdb if (z['NICK'] == usr))[0]
- self.notice(admin,"Nick:\x035 "+usr)
- self.notice(admin,"IP:\x035 "+usr_ip)
- self.notice(admin,"Hostmask:\x035 "+usr_ident+"@"+usr_hostmask)
- self.notice(admin,"Signon:\x035 "+time.ctime(float(usr_signon)))
- self.notice(admin,"Idle:\x035 "+usr_idle+" \x0Fsecond(s)")
- self.notice(admin,"Channels:\x035 "+"\x0F,\x035 ".join(usr_channels))
- else:
- self.notice(admin,"\xee\x80\x91 You must specify a user to analyze")
- ## DEFENSE ##
- #Scan
- if msg.startswith(">scan") and reg(user) and user == admin:
- 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 "+str(len(bots))+" \x0Fbot(s) on the network.")
- self.msg(channel,"Nicks:\x035 "+"\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.")
- #Logflag
- if msg.startswith(">logflag") and reg(user) and user == admin:
- 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)
- 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(x+"\n")
- file.closed
- self.msg(channel,"\xee\x80\x91 Success.")
- except:
- self.msg(channel,"\xee\x80\x91 You must scan for active drones first (>scan).")
- #EngageDRONES
- if msg.startswith(">engage_drones") and reg(user) and user == admin:
- try:
- self.msg(channel,"\xee\x80\x91 \x035Engaging all drones..")
- for x in bots:
- self.sendLine("KILL "+x+" :\x035Drone\x0F")
- except:
- self.msg(channel,"\xee\x80\x91 You must scan for active drones first (>scan).")
- #EngageBOPM
- if msg.startswith(">engage_bopm") and reg(user) and user == admin:
- 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 :\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.")
- ## OTHER HANDLERS ##
- def userLeft(self, user, channel):
- if user in tempid:
- tempid.remove(user)
- else:
- pass
- def userQuit(self, user, quitMessage):
- if user in tempid:
- tempid.remove(user)
- else:
- pass
- def userKicked(self, kickee, channel, kicker, message):
- if kickee in tempid:
- tempid.remove(kickee)
- else:
- pass
- def userRenamed(self, oldname, newname):
- if oldname in tempid:
- tempid.remove(oldname)
- else:
- pass
- 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 "+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 mech_Protocol(protocol.ClientFactory):
- protocol = mech_Client
- def __init__(self, channel):
- self.channel = channel
- def clientConnectionLost(self, connector, reason):
- connector.connect()
- def clientConnectionFailed(self, connector, reason):
- print "connection failed:", reason
- reactor.stop()
- if __name__ == '__main__':
- f = mech_Protocol("#thegibson")
- reactor.connectTCP("niggers.skidsr.us", 6667, f)
- try:
- reactor.run()
- except:
- traceback.print_exc()
- #TODO:
- #Network regex kill command
- #Monitor SENDQ buffer
- #Make it first look for control char instead of looking for many different messages per privmsg
- #Condense analyze
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement