Advertisement
th3j35t3r

Ancient (2011) version of Mech

Feb 6th, 2014
1,003
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 29.09 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. # old m3
  4. # re-released because fuck hann
  5. # "You sit here locking away other lifeforms
  6. # like some kind of king! That's nobody's
  7. # limitation but your own!" -Simon, TTGL
  8. # ,-----.
  9. # |M3Ch3|
  10. # ,--| XiX |-.
  11. # __,----| | | |
  12. # ,;:: | `_____' |
  13. # `._______| i^i |
  14. # `----| |---'| .
  15. # ,-------._| |== ||//
  16. # | |_|P`. /'/
  17. # `-------' 'Y Y/'/'
  18. # .== /_
  19. # / /'| `i
  20. # /' / | |
  21. # /' / | `i
  22. # ___,;`----'.___L_,-'`__
  23. # i_____;----.____i""____
  24. #
  25. # DEV:
  26. # - XiX : Dev
  27. # - e : Grouping implementation, BOPM scan
  28. # - venuism : Core distribution, testing
  29. # - Xero : Testing
  30. #
  31. # TODO:
  32. # - [4] Fix BOPM scan
  33. # - [4] Multiserver support
  34. # - [4] Protect vs bruting admin pass
  35. # - [4] User object instead of dictionary
  36. # - [4] On a connection to the network privmsg question to recieve ProtectedUser status
  37. # - [4] Regex engage using WHO
  38. # - [4] Error logging
  39. # - [5] Additional scanning methods, reorganize code for structured scan types, modular, interface
  40. # - [?] Mech 'forgets' admin (???) need more information on this
  41. #
  42. # LICENSE:
  43. # This program is free software; you can redistribute it and/or modify
  44. # it under the terms of the GNU General Public License as published by
  45. # the Free Software Foundation; either version 1, or (at your option)
  46. # any later version.
  47. #
  48. # This program is distributed in the hope that it will be useful,
  49. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  50. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  51. # GNU General Public License for more details.
  52. #
  53. # You should have received a copy of the GNU General Public License
  54. # along with this program; if not, write to the Free Software
  55. # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  56. #
  57. # General config
  58. server="IRC.NIGGERS.COM"
  59. port=6667
  60. channels=["#CHANNEL"]
  61. # SHA512 of a SHA512
  62. adminpass="cf83e1357eefb8bdf1542850d66d8007d620e4050b5715dc83f4a921d36ce9ce47d0d13c5d85f2b0ff8318d2877eec2f63b931bd47417a81a538327af927da3e"
  63. # NickServ pass (optional)
  64. nspass=""
  65. # O-Line is required
  66. oper="OPER user oper"
  67. # Don't edit past here unless you know what you're doing
  68. from twisted.words.protocols import irc
  69. from twisted.internet import reactor, protocol, defer
  70. from twisted.names.client import lookupAddress
  71. from twisted.internet.task import LoopingCall
  72. from collections import defaultdict
  73. import re, os, sys, hashlib, time, random
  74. # Lists
  75. verifiedadmins=[]
  76. tempid=[]
  77. wusers=[]
  78. userdb=[]
  79. corelist=[]
  80. 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']
  81. bopmusers=[]
  82. bots=[]
  83. protectedusers=["Mech"]
  84. corebots=[]
  85. # Vars
  86. corelevel=0
  87. removecore=0
  88. autoscan_enabled=False
  89. autoscan_bopm_enabled=False
  90. autoengage_drones_enabled=False
  91. autoengage_bopm_enabled=False
  92. ## PREDEFINED FUNCTIONS ##
  93. def shutdown():
  94. reactor.stop()
  95. def restart():
  96. python = sys.executable
  97. os.execl(python, python, * sys.argv)
  98. def reg(user):
  99. if user in tempid:
  100. return True
  101. else:
  102. return False
  103. def group(iterable, range):
  104. iterable.sort()
  105. next = iter(iterable)
  106. def iterate():
  107. prev = next.next()
  108. new_list = [prev]
  109. append = new_list.append
  110. for cur in next:
  111. if cur-prev > range:
  112. yield new_list
  113. new_list = []
  114. append = new_list.append
  115. append(cur)
  116. prev = cur
  117. yield new_list
  118. return list(iterate())
  119. ## IRC CLIENT ##
  120. class IRCClient(irc.IRCClient):
  121. nickname = 'Mech'
  122. username = 'mech'
  123. realname = '\xf0\x9d\x97\xa0\xf0\x9d\x97\xb2\xf0\x9d\x97\xb0\xf0\x9d\x97\xb5 \xf0\x9d\x9f\xaf \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'
  124. password = nspass
  125. versionName = ":: \xf0\x9d\x97\xa0\xf0\x9d\x97\xb2\xf0\x9d\x97\xb0\xf0\x9d\x97\xb5 \xf0\x9d\x9f\xaf \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\xab\xf0\x9d\x97\xb6\xf0\x9d\x97\xab "
  126. sourceURL = "http://mech.pastebay.org/131442"
  127. lineRate = 0.05
  128. def signedOn(self):
  129. print "[*] Mech connected to %s" % server
  130. self.sendLine("MODE Mech +TpBRiwx-s")
  131. self.sendLine(oper)
  132. for channel in self.factory.channels:
  133. self.join(channel)
  134. 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.")
  135. def update():
  136. global userdb
  137. userdb=[]
  138. self.sendLine("LUSERS")
  139. self.sendLine("WHO")
  140. self.sendLine("LIST")
  141. try:
  142. repeater.stop()
  143. repeater.start(15, now=False)
  144. except:
  145. repeater = LoopingCall(update)
  146. repeater.start(15, now=False)
  147. def privmsg(self, user, channel, msg):
  148. nickname = user[:user.find('!')]
  149. if nickname == "NickServ" and msg.startswith("STATUS"):
  150. status = msg.split()
  151. if status[2] == '3':
  152. tempid.append(status[1])
  153. self.notice(status[1], "\xee\x80\x91 You are now authenticated %s\x0f." % status[1])
  154. else:
  155. self.notice(status[1], "\xee\x80\x91 Authentication failed. You must be registered with NickServ.")
  156. try:
  157. params = msg.split()
  158. cmd = params[0]
  159. if cmd.startswith('>'):
  160. cb = getattr(self, 'CMD_%s' % cmd[1:].lower(), None)
  161. if cb is not None:
  162. cb(nickname, channel, msg, params)
  163. except IndexError:
  164. pass
  165. except Exception, e:
  166. print e
  167. # Commands #
  168. ## IDENTIFICATION ##
  169. def CMD_login(self, nickname, channel, msg, params):
  170. if len(params)==2:
  171. if hashlib.sha512(hashlib.sha512(params[1]).hexdigest()).hexdigest()==adminpass:
  172. if nickname not in tempid:
  173. tempid.append(nickname)
  174. verifiedadmins.append(nickname)
  175. self.notice(nickname,"\xee\x80\x91 You are now authenticated %s\x0F." % nickname)
  176. else:
  177. self.notice(nickname,"\xee\x80\x91 You have already authenticated %s." % nickname)
  178. else:
  179. self.notice(nickname,"\xee\x80\x91 Authentication failed.")
  180. print "[*] Authentication failure for user '%s' using password '%s'" % (nickname,params[1])
  181. else:
  182. if nickname in tempid:
  183. self.notice(nickname,"\xee\x80\x91 You have already authenticated %s." % nickname)
  184. else:
  185. self.msg("NickServ","STATUS %s" % nickname)
  186. ## GENERAL / STATISTICAL COMMANDS ##
  187. # Help
  188. def CMD_help(self, nickname, channel, line, params):
  189. 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\xaf \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")
  190. self.notice(nickname,"General commands: >help, >login")
  191. self.notice(nickname,"Statistical commands: >hosts, >idle, >signon")
  192. self.notice(nickname,"Admin commands: >shutdown, >restart, >dump, >raw, >analyze, >scan, >scan_bopm, >autoscan, >autoscan_bopm, >engage_drones, >engage_bopm, >autoengage_drones, >autoengage_bopm, >logflag")
  193. # Shutdown
  194. def CMD_shutdown(self, nickname, channel, line, params):
  195. if nickname in verifiedadmins:
  196. shutdown()
  197. else:
  198. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  199. # Restart
  200. def CMD_restart(self, nickname, channel, line, params):
  201. if nickname in verifiedadmins:
  202. restart()
  203. else:
  204. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  205. # Raw
  206. def CMD_raw(self, nickname, channel, line, params):
  207. if nickname in verifiedadmins:
  208. self.sendLine(line.replace(">raw ",""))
  209. else:
  210. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  211. # Dump
  212. def CMD_dump(self, nickname, channel, line, params):
  213. if nickname in verifiedadmins:
  214. self.notice(nickname,"\xee\x80\x91 Length of UserDB: %i" % len(userdb))
  215. for x in userdb:
  216. self.msg(nickname,x)
  217. else:
  218. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  219. # Host frequency
  220. def CMD_hosts(self, nickname, channel, line, params):
  221. if nickname in tempid:
  222. self.notice(nickname,"\xee\x80\x91 Dumping host frequency (clones)..")
  223. hosts=list(x['HOSTMASK'] for x in userdb)
  224. d=defaultdict(int)
  225. for x in hosts:
  226. d[x]+=1
  227. for x in d.items():
  228. 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] ])))
  229. else:
  230. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  231. # Idle frequency
  232. def CMD_idle(self, nickname, channel, line, params):
  233. if nickname in tempid:
  234. self.notice(nickname,"\xee\x80\x91 Dumping idle frequency..")
  235. times=list(x['IDLE'] for x in userdb if x != None)
  236. d=defaultdict(int)
  237. for x in times:
  238. d[x]+=1
  239. for x in d.items():
  240. 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] ])))
  241. else:
  242. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  243. # Sign-on frequency
  244. def CMD_signon(self, nickname, channel, line, params):
  245. if nickname in tempid:
  246. self.notice(nickname,"\xee\x80\x91 Dumping sign-on frequency..")
  247. signons=list(x['SIGNON'] for x in userdb if x != None)
  248. d=defaultdict(int)
  249. for x in signons:
  250. d[x]+=1
  251. for x in d.items():
  252. if x[0] != None:
  253. 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] ])))
  254. else:
  255. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  256. # Analyze
  257. def CMD_analyze(self, nickname, channel, line, params):
  258. if nickname in verifiedadmins:
  259. if len(params)==2:
  260. usr=params[1]
  261. if usr in wusers:
  262. self.notice(nickname,"User cannot be analyzed (umode +W)")
  263. elif usr in list(x['NICK'] for x in userdb):
  264. self.notice(nickname,"\xee\x80\x91 Analyzing %s" % usr)
  265. self.notice(nickname,"Nick:\x035 %s " % usr)
  266. self.notice(nickname,"IP:\x035 %s" % list(z['IP'] for z in userdb if (z['NICK']==usr))[0])
  267. 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]))
  268. self.notice(nickname,"Signon:\x035 %s" % time.ctime(float(list(z['SIGNON'] for z in userdb if (z['NICK']==usr))[0])))
  269. self.notice(nickname,"Idle:\x035 %s \x0Fsecond(s)" % list(z['IDLE'] for z in userdb if (z['NICK'] == usr))[0])
  270. self.notice(nickname,"Channels:\x035 %s" % "\x0F,\x035 ".join(list(z['CHANNELS'] for z in userdb if (z['NICK'] == usr))[0]))
  271. else:
  272. self.notice(nickname,"User does not exist in the database")
  273. else:
  274. self.notice(nickname,"\xee\x80\x91 Usage: >analyze [user]")
  275. else:
  276. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  277. ## DEFENSE ##
  278. # Scan function
  279. def scan(self):
  280. signons=list(int(x['SIGNON']) for x in userdb if (x['SIGNON'] is not None) and (x['IP'] is not None))
  281. idles=list(int(x['IDLE']) for x in userdb if (x['IDLE'] is not None) and (x['IP'] is not None))
  282. signons_grouped=group(signons,4)
  283. idles_grouped=group(idles,4)
  284. signons_elim=[]
  285. idles_elim=[]
  286. for x in signons_grouped:
  287. if len(x)>=5:
  288. for y in x:
  289. signons_elim.append(str(y))
  290. for x in idles_grouped:
  291. if len(x)>=5:
  292. for y in x:
  293. idles_elim.append(str(y))
  294. idleset=set(idles_elim)
  295. signonset=set(signons_elim)
  296. botlist1=[]
  297. botlist2=[]
  298. for x in idleset:
  299. for y in list(z['NICK'] for z in userdb if (z['IDLE'] == x)):
  300. botlist1.append(y)
  301. for x in signonset:
  302. for y in list(z['NICK'] for z in userdb if (z['SIGNON'] == x)):
  303. botlist2.append(y)
  304. global bots
  305. bots=set(botlist1)&set(botlist2)
  306. # Scan
  307. def CMD_scan(self, nickname, channel, line, params):
  308. if nickname in verifiedadmins:
  309. self.scan()
  310. if len(bots)>0:
  311. self.msg(channel,"\xee\x80\x91 There are\x035 %i \x0Fbot(s) on the network." % len(bots))
  312. self.msg(channel,"Nicks:\x035 %s\x0F.." % "\x0F,\x035 ".join(list(bots)[0:10]))
  313. elif len(bots)==0:
  314. self.msg(channel,"\xee\x80\x91 There are no bots on the network.")
  315. else:
  316. self.msg(channel,"\xee\x80\x91 \x035Error.")
  317. else:
  318. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  319. # Autoscan function
  320. def autoscan_update(self, channel):
  321. self.scan()
  322. if len(bots)>0:
  323. print "[*] Autoscan report: %i bot(s) detected" % len(bots)
  324. self.msg(channel,"\xee\x80\x91 Notice:\x035 %i \x0Fbot(s) detected on the network" % len(bots))
  325. self.msg(channel,"Nicks:\x035 %s\x0F.." % "\x0F,\x035 ".join(list(bots)[0:10]))
  326. else:
  327. print "[*] Autoscan report: No bots detected"
  328. # Autoscan
  329. def CMD_autoscan(self, nickname, channel, line, params):
  330. global autoscan_enabled
  331. global autoscanloop
  332. if "autoscanloop" not in globals():
  333. autoscanloop = LoopingCall(self.autoscan_update, channel)
  334. if nickname in verifiedadmins:
  335. if autoscan_enabled is False:
  336. autoscanloop.start(15, channel)
  337. autoscan_enabled=True
  338. self.msg(channel,"\xee\x80\x91 Autoscan active")
  339. elif autoscan_enabled is True:
  340. autoscanloop.stop()
  341. autoscan_enabled=False
  342. self.msg(channel,"\xee\x80\x91 \x035Autoscan disabled")
  343. else:
  344. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  345. # Logflag
  346. def CMD_logflag(self, nickname, channel, line, params):
  347. if nickname in verifiedadmins:
  348. try:
  349. self.msg(channel,"\xee\x8e\xaa Adding all detected drones to local DroneBL")
  350. ips=[]
  351. for x in bots:
  352. for y in list(z['IP'] for z in userdb if (z['NICK'] == x)):
  353. ips.append(y)
  354. ips_elim=set(ips)
  355. try:
  356. file=open('dronebl.txt','r+')
  357. except IOError:
  358. print "[*] DroneBL file not found, creating one.."
  359. file=open('dronebl.txt','w+')
  360. file.write("DroneBL file created on %s\n" % time.ctime())
  361. file.closed
  362. file=open('dronebl.txt','r+')
  363. dronelist=file.readlines()
  364. file.closed
  365. file=open('dronebl.txt','w+')
  366. for x in dronelist:
  367. if x in ips_elim:
  368. pass
  369. else:
  370. file.write(x)
  371. file.closed
  372. file=open('dronebl.txt','a+')
  373. for x in ips_elim:
  374. file.write("%s\n" % x)
  375. file.closed
  376. self.msg(channel,"\xee\x80\x91 Success.")
  377. except:
  378. self.notice(nickname,"\xee\x80\x91 You must scan for active drones first (>scan).")
  379. else:
  380. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  381. # Engage drones
  382. def CMD_engage_drones(self, nickname, channel, line, params):
  383. if nickname in verifiedadmins:
  384. try:
  385. self.msg(channel,"\xee\x80\x91 \x035Engaging all drones..")
  386. for y in set(x['IP'] for x in userdb if (x['NICK'] in bots and x['NICK'] not in verifiedadmins and x['NICK'] not in protectedusers and x['NICK'] not in corebots and x['NICK'] not in wusers)):
  387. self.sendLine("GLINE +*@%s 1800 :\x035Drone\x0F" % y)
  388. except:
  389. self.notice(nickname,"\xee\x80\x91 You must scan for active drones first (>scan).")
  390. else:
  391. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  392. # BOPM function
  393. def bopm(self):
  394. global bopmusers
  395. bopmusers=[]
  396. for y in set(x['IP'] for x in userdb if x['IP'] is not None):
  397. name, original = '.'.join(y.split('.')[::-1]), y
  398. hit=[lookupAddress('%s.%s' % (name, bopm)) for bopm in bopmList]
  399. d = defer.DeferredList(hit, fireOnOneCallback=1, consumeErrors=1)
  400. def result(h, ip):
  401. h = list(h)
  402. if h[0][0] is False:
  403. pass
  404. else:
  405. for z in [u['NICK'] for u in userdb if u['IP']==ip]:
  406. bopmusers.append(z)
  407. d.addCallback(result, original)
  408. # BOPM Scan
  409. def CMD_scan_bopm(self, nickname, channel, line, params):
  410. if nickname in verifiedadmins:
  411. self.bopm()
  412. if len(bopmusers)>0:
  413. self.msg(channel,"\xee\x80\x91 There are\x035 %i \x0Fuser(s) listed in drone banlists." % len(bots))
  414. self.msg(channel,"Nicks:\x035 %s\x0F.." % "\x0F,\x035 ".join(list(bots)[0:10]))
  415. elif len(bopmusers)==0:
  416. self.msg(channel,"\xee\x80\x91 There are no users listed in drone banlists.")
  417. else:
  418. self.msg(channel,"\xee\x80\x91 \x035Error.")
  419. else:
  420. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  421. # Autoscan BOPM function
  422. def autoscan_bopm_update(self, channel):
  423. self.bopm()
  424. if len(bopmusers)>0:
  425. print "[*] BOPM Autoscan report: %i user(s) listed in drone banlists" % len(bopmusers)
  426. self.msg(channel,"\xee\x80\x91 Notice:\x035 %i \x0Fuser(s) detected in drone banlists" % len(bopmusers))
  427. self.msg(channel,"Nicks:\x035 %s\x0F.." % "\x0F,\x035 ".join(bopmusers[0:10]))
  428. else:
  429. print "[*] BOPM Autoscan report: No users listed in drone banlists"
  430. # Autoscan BOPM
  431. def CMD_autoscan_bopm(self, nickname, channel, line, params):
  432. global autoscan_bopm_enabled
  433. global autoscan_bopmloop
  434. if "autoscan_bopmloop" not in globals():
  435. autoscan_bopmloop = LoopingCall(self.autoscan_bopm_update, channel)
  436. if nickname in verifiedadmins:
  437. if autoscan_bopm_enabled is False:
  438. autoscan_bopmloop.start(15, channel)
  439. autoscan_bopm_enabled=True
  440. self.msg(channel,"\xee\x80\x91 BOPM Autoscan active")
  441. elif autoscan_bopm_enabled is True:
  442. autoscan_bopmloop.stop()
  443. autoscan_bopm_enabled=False
  444. self.msg(channel,"\xee\x80\x91 \x035BOPM Autoscan disabled")
  445. else:
  446. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  447. # Engage BOPM
  448. def CMD_engage_bopm(self, nickname, channel, line, params):
  449. if nickname in verifiedadmins:
  450. self.msg(channel,"\xee\x80\x91 \x035Engaging all listed proxies..")
  451. try:
  452. for y in set(x['IP'] for x in userdb if (x['NICK'] in bopmusers and x['NICK'] not in verifiedadmins and x['NICK'] not in protectedusers and x['NICK'] not in corebots and x['NICK'] not in wusers)):
  453. self.sendLine("GLINE +*@%s 1800 :\x035Listed in drone banlists\x0F" % y)
  454. except:
  455. self.msg(channel,"\xee\x80\x91 You must scan for active BOPM users first (>scan_bopm).")
  456. else:
  457. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  458. # Autoengage Drones function
  459. def autoengage_drones_update(self, channel):
  460. self.scan()
  461. if len(bots)>0:
  462. for y in set(x['IP'] for x in userdb if (x['NICK'] in bots and x['NICK'] not in verifiedadmins and x['NICK'] not in protectedusers and x['NICK'] not in corebots and x['NICK'] not in wusers)):
  463. self.sendLine("GLINE +*@%s 1800 :\x035Drone\x0F" % y)
  464. # Autoengage Drones
  465. def CMD_autoengage_drones(self, nickname, channel, line, params):
  466. global autoengage_drones_enabled
  467. global autoengage_dronesloop
  468. if "autoengage_dronesloop" not in globals():
  469. autoengage_dronesloop = LoopingCall(self.autoengage_drones_update, channel)
  470. if nickname in verifiedadmins:
  471. if autoengage_drones_enabled is False:
  472. autoengage_dronesloop.start(15, channel)
  473. autoengage_drones_enabled=True
  474. self.msg(channel,"\xee\x80\x91 \x035DRONE AUTOENGAGE ACTIVE")
  475. elif autoengage_drones_enabled is True:
  476. autoengage_dronesloop.stop()
  477. autoengage_drones_enabled=False
  478. self.msg(channel,"\xee\x80\x91 \x035DRONE AUTOENGAGE DISABLED")
  479. else:
  480. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  481. # Autoengage BOPM function
  482. def autoengage_bopm_update(self, channel):
  483. self.bopm()
  484. if len(bopmusers)>0:
  485. for y in set(x['IP'] for x in userdb if (x['NICK'] in bopmusers and x['NICK'] not in verifiedadmins and x['NICK'] not in protectedusers and x['NICK'] not in corebots and x['NICK'] not in wusers)):
  486. self.sendLine("GLINE +*@%s 1800 :\x035Listed in drone banlists\x0F" % y)
  487. # Autoengage BOPM
  488. def CMD_autoengage_bopm(self, nickname, channel, line, params):
  489. global autoengage_bopm_enabled
  490. global autoengage_bopmloop
  491. if "autoengage_bopmloop" not in globals():
  492. autoengage_bopmloop = LoopingCall(self.autoengage_bopm_update, channel)
  493. if nickname in verifiedadmins:
  494. if autoengage_bopm_enabled is False:
  495. autoengage_bopmloop.start(15, channel)
  496. autoengage_bopm_enabled=True
  497. self.msg(channel,"\xee\x80\x91 \x035BOPM AUTOENGAGE ACTIVE")
  498. elif autoengage_bopm_enabled is True:
  499. autoengage_bopmloop.stop()
  500. autoengage_bopm_enabled=False
  501. self.msg(channel,"\xee\x80\x91 \x035BOPM AUTOENGAGE DISABLED")
  502. else:
  503. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  504. ## OTHER HANDLERS ##
  505. def userLeft(self, user, channel):
  506. if user in tempid:
  507. tempid.remove(user)
  508. if user in verifiedadmins:
  509. verifiedadmins.remove(user)
  510. def userQuit(self, user, quitMessage):
  511. if user in tempid:
  512. tempid.remove(user)
  513. if user in verifiedadmins:
  514. verifiedadmins.remove(user)
  515. def userKicked(self, kickee, channel, kicker, message):
  516. if kickee in tempid:
  517. tempid.remove(kickee)
  518. if kickee in verifiedadmins:
  519. verifiedadmins.remove(kickee)
  520. def userRenamed(self, oldname, newname):
  521. if oldname in tempid:
  522. tempid.remove(oldname)
  523. if oldname in verifiedadmins:
  524. verifiedadmins.remove(oldname)
  525. def kickedFrom(self, channel, kicker, message):
  526. self.join(channel)
  527. tempid=[]
  528. def irc_unknown(self, prefix, command, params):
  529. global corelevel
  530. global removecore
  531. #print prefix,command,params
  532. if command == "266":
  533. print params[1].split()
  534. globalusers=int(params[1].split()[0])
  535. if globalusers > corelevel:
  536. if corelevel == 0:
  537. print "[*] Spawning initial core"
  538. reactor.connectTCP(server, port, IRCCoreFactory())
  539. corelevel+=200
  540. else:
  541. factor=((globalusers+200)-corelevel)/200
  542. print "[*] Core(s) overloaded, adding %i core(s)" % factor
  543. for x in range(factor):
  544. reactor.connectTCP(server, port, IRCCoreFactory())
  545. corelevel+=200
  546. if corelevel > globalusers+200:
  547. factor=(corelevel-globalusers)/200
  548. if factor >= 1:
  549. print "[*] Core(s) underloaded, removing %i core(s)" % factor
  550. for x in range(factor):
  551. removecore+=1
  552. corelevel-=200
  553. if command == "RPL_WHOREPLY":
  554. userdb.append({"NICK":params[5],"IDENT":params[2],"HOSTMASK":params[3],"SIGNON":None,"CHANNELS":None,"IDLE":None,"IP":None})
  555. if params[5] not in wusers:
  556. corelist.append(params[5])
  557. if command == "RPL_LIST":
  558. if (int(params[2]) >= 5) and ("L" not in str(re.findall("\[(.*?)\]", params[3]))[0]):
  559. self.join(params[1])
  560. class IRCCore(irc.IRCClient):
  561. def _get_nickname(self):
  562. return self.factory.nickname
  563. nickname = property(_get_nickname)
  564. username = 'mech'
  565. realname = '\xf0\x9d\x97\xa0\xf0\x9d\x97\xb2\xf0\x9d\x97\xb0\xf0\x9d\x97\xb5 \xf0\x9d\x97\x96\xf0\x9d\x97\xbc\xf0\x9d\x97\xbf\xf0\x9d\x97\xb2'
  566. versionName = ":: \xf0\x9d\x97\xa0\xf0\x9d\x97\xb2\xf0\x9d\x97\xb0\xf0\x9d\x97\xb5 \xf0\x9d\x9f\xaf \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 \xf0\x9d\x97\x96\xf0\x9d\x97\xbc\xf0\x9d\x97\xbf\xf0\x9d\x97\xb2"
  567. sourceURL = "http://mech.pastebay.org/131442"
  568. def signedOn(self):
  569. corename=self.factory.nickname
  570. print "[*] Core connected to %s" % server
  571. corebots.append(corename)
  572. self.sendLine("MODE %s +TpBRiwx-s" % corename)
  573. self.sendLine(oper)
  574. def update(corename):
  575. global removecore
  576. if removecore > 0:
  577. removecore-=1
  578. corebots.remove(corename)
  579. self.transport.loseConnection()
  580. if len(corelist) > 0:
  581. whoisusr=corelist[0]
  582. corelist.remove(whoisusr)
  583. self.sendLine("WHOIS %s %s" % (whoisusr,whoisusr))
  584. try:
  585. repeater.stop()
  586. repeater.start(0.01)
  587. except:
  588. repeater = LoopingCall(update,corename)
  589. repeater.start(0.01)
  590. def irc_unknown(self, prefix, command, params):
  591. if command == "379":
  592. if "W" in params[2].split("+")[1][:-1]:
  593. wusers.append(params[1])
  594. if command == "378":
  595. for d in userdb:
  596. if d["NICK"] == params[1]:
  597. try:
  598. d["IP"] = params[2].split()[4]
  599. except:
  600. pass
  601. if command == "RPL_WHOISIDLE":
  602. for d in userdb:
  603. if d["NICK"] == params[1]:
  604. d["SIGNON"] = params[3]
  605. d["IDLE"] = params[2]
  606. if command == "RPL_WHOISCHANNELS":
  607. for d in userdb:
  608. if d["NICK"] == params[1]:
  609. d["CHANNELS"] = params[2].split()
  610. class IRCCoreFactory(protocol.ClientFactory):
  611. protocol = IRCCore
  612. def __init__(self):
  613. self.nickname = 'Mech_CORE[%i]' % random.randint(1,99)
  614. def clientConnectionFailed(self, connector, reason):
  615. print "[*] Core connection failed:", reason
  616. print "[*] Retrying.."
  617. connector.connect()
  618. class IRCFactory(protocol.ClientFactory):
  619. protocol = IRCClient
  620. def __init__(self, channels):
  621. self.channels = channels
  622. def clientConnectionLost(self, connector, reason):
  623. connector.connect()
  624. def clientConnectionFailed(self, connector, reason):
  625. print "[*] Connection failed:", reason
  626. reactor.stop()
  627. reactor.connectTCP(server, port, IRCFactory(channels))
  628. reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement