Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 14.71 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3.  
  4. from twisted.words.protocols import irc
  5. from twisted.internet import reactor, protocol, defer
  6. from twisted.names.client import lookupAddress
  7. from twisted.internet.task import LoopingCall
  8. from twisted.python import log
  9. from collections import defaultdict
  10. import re, os, sys, hashlib, time, traceback
  11.  
  12. #Lists
  13. tempid=[]
  14. 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']
  15. wusers=[]
  16. userdb=[]
  17. bots=[]
  18.  
  19. #Admin
  20. admin="Nikon" #You
  21. adminpass = "7c289fa791749a55127b06da1a65cdbccfe8775603b7f425ea08884183a0305fb4a326a17461f2cb11004701f3b6cf30160535115a21c7d5c1d1809f1e295c98" #This is for if Mech can't identify you. Replace this with a sha512 of a sha512 of your password
  22.  
  23. ##PREDEFINED FUNCTIONS##
  24. def shutdown():
  25. reactor.stop()
  26. def restart():
  27. python = sys.executable
  28. os.execl(python, python, * sys.argv)
  29. def reg(user):
  30. if user in tempid:
  31. return True
  32. else:
  33. return False
  34. def group(list,range):
  35. try:
  36. list.sort()
  37. out = []
  38. new_list = []
  39. out.append(new_list)
  40. app = new_list.append
  41. prev = list.pop(0)
  42. app(prev)
  43. while list:
  44. cur = list.pop(0)
  45. if cur-prev > range:
  46. new_list = []
  47. app = new_list.append
  48. out.append(new_list)
  49. app(cur)
  50. prev = cur
  51. return out
  52. except:
  53. pass
  54.  
  55. ##IRC CLIENT##
  56. class mech_Client(irc.IRCClient):
  57. #Nick
  58. nickname = "Mech"
  59. #Real name
  60. realname = "mech"
  61. #Username
  62. username = "mech"
  63. #CTCP replies
  64. versionName = "IRC Mech"
  65. sourceURL = None
  66. #Globals
  67. global tempid
  68. global admin
  69. global adminpass
  70. global userdb
  71. global bopmList
  72. global bots
  73. #Definitions
  74. def signedOn(self):
  75. self.sendLine("MODE Mech +TpBR")
  76. self.msg("ircd","oper [youroperid] [operpass]")
  77. self.join(self.factory.channel)
  78. self.msg(self.factory.channel, "\xe2\x9a\x9d Mech online.")
  79. def update():
  80. global userdb
  81. userdb=[]
  82. self.sendLine("WHO")
  83. self.sendLine("LIST")
  84. try:
  85. repeater.stop()
  86. repeater.start(15)
  87. except:
  88. repeater = LoopingCall(update)
  89. repeater.start(15)
  90. def privmsg(self, user, channel, msg):
  91. user = user.split('!', 1)[0]
  92. ## IDENTIFICATION ##
  93. if msg.startswith(">login"):
  94. if len(msg.split())>=1:
  95. if hashlib.sha512(hashlib.sha512(msg.split()[1]).hexdigest()).hexdigest() == adminpass:
  96. if user not in tempid:
  97. tempid.append(user)
  98. self.notice(user, "\xee\x80\x91 You are now authenticated " + user + "\x0F.")
  99. else:
  100. self.notice(user, "\xee\x80\x91 You have already authenticated " + user)
  101. else:
  102. self.notice(user, "\xee\x80\x91 Authentication failed.")
  103. else:
  104. if user in tempid:
  105. self.notice(user, "\xee\x80\x91 You have already authenticated " + user)
  106. else:
  107. self.msg("NickServ", "STATUS " + user)
  108. if user == "NickServ" and msg.startswith("STATUS"):
  109. status = msg.split()
  110. if status[2] == '3':
  111. tempid.append(status[1])
  112. self.notice(self.factory.channel, "\xee\x80\x91 You are now authenticated " + status[1] + ".")
  113. else:
  114. self.notice(status[1], "\xee\x80\x91 Authentication failed. You must be registered with NickServ.")
  115. ## GENERAL / STATISTICAL COMMANDS ##
  116. #Help
  117. if msg.startswith (">help"):
  118. self.notice(user, "Admin commands: >shutdown, >restart >dump >raw >scan >analyze >engage_drones >engage_bopm >logflag")
  119. self.notice(user, "General commands: >help, >login")
  120. self.notice(user, "Statistical commands: >hosts, >idle, >signon")
  121. #Shutdown Bot
  122. if msg.startswith (">shutdown") and reg(user) and user == admin:
  123. shutdown()
  124. #Restart Bot
  125. if msg.startswith (">restart") and reg(user) and user == admin:
  126. restart()
  127. #Raw
  128. if msg.startswith(">raw ") and reg(user) and user == admin:
  129. self.sendLine(msg.replace(">raw ",""))
  130. #Dump
  131. if msg.startswith(">dump") and reg(user) and user == admin:
  132. self.msg(channel,"\xee\x80\x91 Length of UserDB: " + str(len(userdb)))
  133. for x in userdb:
  134. self.msg(user,x)
  135. print bots
  136. #Host frequency
  137. if msg.startswith(">hosts") and reg(user):
  138. self.msg(channel,"\xee\x80\x91 Dumping host frequency (clones)..")
  139. hosts=list(x['HOSTMASK'] for x in userdb)
  140. d=defaultdict(int)
  141. for x in hosts:
  142. d[x]+=1
  143. for x in d.items():
  144. 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] ]))
  145. #Idle frequency
  146. if msg.startswith(">idle") and reg(user):
  147. self.msg(channel,"\xee\x80\x91 Dumping idle frequency..")
  148. times=list(x['IDLE'] for x in userdb)
  149. d=defaultdict(int)
  150. for x in times:
  151. d[x]+=1
  152. for x in d.items():
  153. 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] ]))
  154. #Sign-on frequency
  155. if msg.startswith(">signon") and reg(user):
  156. self.msg(channel,"\xee\x80\x91 Dumping sign-on frequency..")
  157. signons=list(x['SIGNON'] for x in userdb if x != None)
  158. print signons
  159. d=defaultdict(int)
  160. for x in signons:
  161. d[x]+=1
  162. for x in d.items():
  163. if x[0] != None:
  164. 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] ]))
  165. else:
  166. pass
  167. #Analyze
  168. if msg.startswith(">analyze") and reg(user) and user == admin:
  169. if len(msg.split())>=1:
  170. usr=msg.split()[1]
  171. if usr in wusers:
  172. self.notice(admin,"User cannot be analyzed (umode +W)")
  173. else:
  174. self.notice(admin,"\xee\x80\x91 Analyzing "+usr)
  175. usr_ip=list(z['IP'] for z in userdb if (z['NICK'] == usr))[0]
  176. usr_signon=list(z['SIGNON'] for z in userdb if (z['NICK'] == usr))[0]
  177. usr_ident=list(z['IDENT'] for z in userdb if (z['NICK'] == usr))[0]
  178. usr_hostmask=list(z['HOSTMASK'] for z in userdb if (z['NICK'] == usr))[0]
  179. usr_channels=list(z['CHANNELS'] for z in userdb if (z['NICK'] == usr))[0]
  180. usr_idle=list(z['IDLE'] for z in userdb if (z['NICK'] == usr))[0]
  181. self.notice(admin,"Nick:\x035 "+usr)
  182. self.notice(admin,"IP:\x035 "+usr_ip)
  183. self.notice(admin,"Hostmask:\x035 "+usr_ident+"@"+usr_hostmask)
  184. self.notice(admin,"Signon:\x035 "+time.ctime(float(usr_signon)))
  185. self.notice(admin,"Idle:\x035 "+usr_idle+" \x0Fsecond(s)")
  186. self.notice(admin,"Channels:\x035 "+"\x0F,\x035 ".join(usr_channels))
  187. else:
  188. self.notice(admin,"\xee\x80\x91 You must specify a user to analyze")
  189. ## DEFENSE ##
  190. #Scan
  191. if msg.startswith(">scan") and reg(user) and user == admin:
  192. signons=list(int(x['SIGNON']) for x in userdb if (x['SIGNON'] is not None) and (x['IP'] is not None))
  193. idles=list(int(x['IDLE']) for x in userdb if (x['IDLE'] is not None) and (x['IP'] is not None))
  194. signons_grouped=group(signons,2)
  195. idles_grouped=group(idles,1)
  196. signons_elim=[]
  197. idles_elim=[]
  198. for x in signons_grouped:
  199. if len(x)>=5:
  200. for y in x:
  201. signons_elim.append(str(y))
  202. for x in idles_grouped:
  203. if len(x)>=5:
  204. for y in x:
  205. idles_elim.append(str(y))
  206. idleset=set(idles_elim)
  207. signonset=set(signons_elim)
  208. botlist1=[]
  209. botlist2=[]
  210. for x in idleset:
  211. for y in list(z['NICK'] for z in userdb if (z['IDLE'] == x)):
  212. botlist1.append(y)
  213. for x in signonset:
  214. for y in list(z['NICK'] for z in userdb if (z['SIGNON'] == x)):
  215. botlist2.append(y)
  216. bots=set(botlist1)&set(botlist2)
  217. global bots
  218. if len(bots)>0:
  219. self.msg(channel,"\xee\x80\x91 There are\x035 "+str(len(bots))+" \x0Fbot(s) on the network.")
  220. self.msg(channel,"Nicks:\x035 "+"\x0F,\x035 ".join(bots))
  221. elif len(bots)==0:
  222. self.msg(channel,"\xee\x80\x91 There are no bots on the network.")
  223. else:
  224. self.msg(channel,"\xee\x80\x91 \x035Error.")
  225. #Logflag
  226. if msg.startswith(">logflag") and reg(user) and user == admin:
  227. try:
  228. self.msg(channel,"\xee\x8e\xaa Adding all detected drones to local DroneBL")
  229. ips=[]
  230. for x in bots:
  231. for y in list(z['IP'] for z in userdb if (z['NICK'] == x)):
  232. ips.append(y)
  233. ips_elim=set(ips)
  234. file=open('dronebl.txt','r+')
  235. dronelist=file.readlines()
  236. file.closed
  237. file=open('dronebl.txt','w+')
  238. for x in dronelist:
  239. if x in ips_elim:
  240. pass
  241. else:
  242. file.write(x)
  243. file.closed
  244. file=open('dronebl.txt','a+')
  245. for x in ips_elim:
  246. file.write(x+"\n")
  247. file.closed
  248. self.msg(channel,"\xee\x80\x91 Success.")
  249. except:
  250. self.msg(channel,"\xee\x80\x91 You must scan for active drones first (>scan).")
  251. #EngageDRONES
  252. if msg.startswith(">engage_drones") and reg(user) and user == admin:
  253. try:
  254. self.msg(channel,"\xee\x80\x91 \x035Engaging all drones..")
  255. for x in bots:
  256. self.sendLine("KILL "+x+" :\x035Drone\x0F")
  257. except:
  258. self.msg(channel,"\xee\x80\x91 You must scan for active drones first (>scan).")
  259. #EngageBOPM
  260. if msg.startswith(">engage_bopm") and reg(user) and user == admin:
  261. self.msg(channel,"\xee\x80\x91 \x035Engaging all listed proxies..")
  262. try:
  263. for y in set(x['IP'] for x in userdb if x['IP'] is not None):
  264. name, original = '.'.join(y.split('.')[::-1]), y
  265. hit=[lookupAddress('%s.%s' % (name, bopm)) for bopm in bopmList]
  266. d = defer.DeferredList(hit, fireOnOneCallback=1, consumeErrors=1)
  267. def result(h, ip):
  268. h = list(h)
  269. if h[0][0] is False:
  270. pass
  271. else:
  272. for z in [u['NICK'] for u in userdb if u['IP']==ip]:
  273. self.sendLine("GLINE +%s :\x035Listed in %s\x0F" % (z,'.'.join(h[0][0][0].name.name.split('.')[4:])))
  274. d.addCallback(result, original)
  275. except:
  276. self.msg(channel,"\xee\x80\x91 \x035Error.")
  277. ## OTHER HANDLERS ##
  278. def userLeft(self, user, channel):
  279. if user in tempid:
  280. tempid.remove(user)
  281. else:
  282. pass
  283. def userQuit(self, user, quitMessage):
  284. if user in tempid:
  285. tempid.remove(user)
  286. else:
  287. pass
  288. def userKicked(self, kickee, channel, kicker, message):
  289. if kickee in tempid:
  290. tempid.remove(kickee)
  291. else:
  292. pass
  293. def userRenamed(self, oldname, newname):
  294. if oldname in tempid:
  295. tempid.remove(oldname)
  296. else:
  297. pass
  298. def kickedFrom(self, channel, kicker, message):
  299. self.join(channel)
  300. tempid=[]
  301. def irc_unknown(self, prefix, command, params):
  302. #print prefix,command,params
  303. if command == "379":
  304. if "W" in params[2].split("+")[1][:-1]:
  305. wusers.append(params[1])
  306. if command == "378":
  307. for d in userdb:
  308. if d["NICK"] == params[1]:
  309. try:
  310. d["IP"] = params[2].split()[4]
  311. except:
  312. pass
  313. if command == "RPL_WHOISIDLE":
  314. for d in userdb:
  315. if d["NICK"] == params[1]:
  316. d["SIGNON"] = params[3]
  317. d["IDLE"] = params[2]
  318. if command == "RPL_WHOISCHANNELS":
  319. for d in userdb:
  320. if d["NICK"] == params[1]:
  321. d["CHANNELS"] = params[2].split()
  322. if command == "RPL_WHOREPLY":
  323. userdb.append({"NICK":params[5],"IDENT":params[2],"HOSTMASK":params[3],"SIGNON":None,"CHANNELS":None,"IDLE":None,"IP":None})
  324. if params[5] not in wusers:
  325. self.sendLine("WHOIS "+params[5]+" "+params[5])
  326. if command == "RPL_LIST":
  327. if (int(params[2]) >= 5) and ("L" not in str(re.findall("\[(.*?)\]", params[3]))[0]):
  328. self.join(params[1])
  329. class mech_Protocol(protocol.ClientFactory):
  330. protocol = mech_Client
  331. def __init__(self, channel):
  332. self.channel = channel
  333. def clientConnectionLost(self, connector, reason):
  334. connector.connect()
  335. def clientConnectionFailed(self, connector, reason):
  336. print "connection failed:", reason
  337. reactor.stop()
  338. if __name__ == '__main__':
  339. f = mech_Protocol("#thegibson")
  340. reactor.connectTCP("niggers.skidsr.us", 6667, f)
  341. try:
  342. reactor.run()
  343. except:
  344. traceback.print_exc()
  345.  
  346. #TODO:
  347. #Network regex kill command
  348. #Monitor SENDQ buffer
  349. #Make it first look for control char instead of looking for many different messages per privmsg
  350. #Condense analyze
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement