Advertisement
Guest User

Untitled

a guest
Jul 7th, 2017
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 17.89 KB | None | 0 0
  1. #!/usr/bin/env python
  2. # -*- coding: UTF-8 -*-
  3. # ,-----.
  4. # |M3Ch2|
  5. # ,--|NiKoN|-.
  6. # __,----| | | |
  7. # ,;:: | `_____' |
  8. # `._______| i^i |
  9. # `----| |---'| .
  10. # ,-------._| |== ||//
  11. # | |_|P`. /'/
  12. # `-------' 'Y Y/'/'
  13. # .== /_
  14. # / /'| `i
  15. # /' / | |
  16. # /' / | `i
  17. # ___,;`----'.___L_,-'`__
  18. # i_____;----.____i""____
  19. #
  20. # TODO:
  21. # - Analyze doesnt check if the user exists/is a network service
  22. # - Userdb regex kill command (ie >regex ident hardbot)
  23. # - Autoscan for bots
  24. #
  25. # General config
  26. server="niggers.skidsr.us"
  27. port=6667
  28. channels=["#mech","#help"]
  29. # SHA512 of a SHA512
  30. adminpass="110b77dd590f299dcdaac438bd9d6e119464a82fe625d34fa89c4083695f62627774a39d4baedf582f33d97897fda95037ed7b55929e43d59679d980543d46a2"
  31. # NickServ pass
  32. nspass="lolno"
  33. # O-Line is required
  34. oper="OPER Nikon notthiseither"
  35. # Don't edit past here unless you know what you're doing
  36. from twisted.words.protocols import irc
  37. from twisted.internet import reactor, protocol, defer
  38. from twisted.names.client import lookupAddress
  39. from twisted.internet.task import LoopingCall
  40. from twisted.python import log
  41. from collections import defaultdict
  42. import re, os, sys, hashlib, time
  43. # Lists
  44. verifiedadmins=[]
  45. tempid=[]
  46. wusers=[]
  47. userdb=[]
  48. 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']
  49. bots=[]
  50. ## PREDEFINED FUNCTIONS ##
  51. def shutdown():
  52. reactor.stop()
  53. def restart():
  54. python = sys.executable
  55. os.execl(python, python, * sys.argv)
  56. def reg(user):
  57. if user in tempid:
  58. return True
  59. else:
  60. return False
  61. def group(list,range):
  62. try:
  63. list.sort()
  64. out = []
  65. new_list = []
  66. out.append(new_list)
  67. app = new_list.append
  68. prev = list.pop(0)
  69. app(prev)
  70. while list:
  71. cur = list.pop(0)
  72. if cur-prev > range:
  73. new_list = []
  74. app = new_list.append
  75. out.append(new_list)
  76. app(cur)
  77. prev = cur
  78. return out
  79. except:
  80. pass
  81. ## IRC CLIENT ##
  82. class IRCClient(irc.IRCClient):
  83. nickname = 'Mech'
  84. username = 'mech'
  85. 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'
  86. password = nspass
  87. 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 "
  88. sourceURL = None
  89. def signedOn(self):
  90. print "[*] Connected to %s" % server
  91. self.sendLine("MODE Mech +TpBR")
  92. self.sendLine(oper)
  93. for channel in self.factory.channels:
  94. self.join(channel)
  95. 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.")
  96. def update():
  97. global userdb
  98. userdb=[]
  99. self.sendLine("WHO")
  100. self.sendLine("LIST")
  101. try:
  102. repeater.stop()
  103. repeater.start(15)
  104. except:
  105. repeater = LoopingCall(update)
  106. repeater.start(15)
  107. def privmsg(self, user, channel, msg):
  108. nickname = user[:user.find('!')]
  109. if nickname == "NickServ" and msg.startswith("STATUS"):
  110. status = msg.split()
  111. if status[2] == '3':
  112. tempid.append(status[1])
  113. self.notice(status[1], "\xee\x80\x91 You are now authenticated %s\x0f." % status[1])
  114. else:
  115. self.notice(status[1], "\xee\x80\x91 Authentication failed. You must be registered with NickServ.")
  116. try:
  117. params = msg.split()
  118. cmd = params[0]
  119. if cmd.startswith('>'):
  120. cb = getattr(self, 'CMD_%s' % cmd[1:].lower(), None)
  121. if cb is not None:
  122. cb(nickname, channel, msg, params)
  123. except IndexError:
  124. pass
  125. except Exception, e:
  126. print e
  127. # Commands #
  128. ## IDENTIFICATION ##
  129. def CMD_login(self, nickname, channel, msg, params):
  130. if len(params)==2:
  131. if hashlib.sha512(hashlib.sha512(params[1]).hexdigest()).hexdigest()==adminpass:
  132. if nickname not in tempid:
  133. tempid.append(nickname)
  134. verifiedadmins.append(nickname)
  135. self.notice(nickname,"\xee\x80\x91 You are now authenticated %s\x0F." % nickname)
  136. else:
  137. self.notice(nickname,"\xee\x80\x91 You have already authenticated %s." % nickname)
  138. else:
  139. self.notice(nickname,"\xee\x80\x91 Authentication failed.")
  140. else:
  141. if nickname in tempid:
  142. self.notice(nickname,"\xee\x80\x91 You have already authenticated %s." % nickname)
  143. else:
  144. self.msg("NickServ","STATUS %s" % nickname)
  145. ## GENERAL / STATISTICAL COMMANDS ##
  146. # Help
  147. def CMD_help(self, nickname, channel, line, params):
  148. 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")
  149. self.notice(nickname,"General commands: >help, >login")
  150. self.notice(nickname,"Statistical commands: >hosts, >idle, >signon")
  151. self.notice(nickname,"Admin commands: >shutdown, >restart, >dump, >raw, >scan, >analyze, >engage_drones, >engage_bopm, >logflag")
  152. # Shutdown
  153. def CMD_shutdown(self, nickname, channel, line, params):
  154. if nickname in verifiedadmins:
  155. shutdown()
  156. else:
  157. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  158. # Restart
  159. def CMD_restart(self, nickname, channel, line, params):
  160. if nickname in verifiedadmins:
  161. restart()
  162. else:
  163. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  164. # Raw
  165. def CMD_raw(self, nickname, channel, line, params):
  166. if nickname in verifiedadmins:
  167. self.sendLine(line.replace(">raw ",""))
  168. else:
  169. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  170. # Dump
  171. def CMD_dump(self, nickname, channel, line, params):
  172. if nickname in verifiedadmins:
  173. self.notice(nickname,"\xee\x80\x91 Length of UserDB: %s" % str(len(userdb)))
  174. for x in userdb:
  175. self.msg(nickname,x)
  176. else:
  177. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  178. # Host frequency
  179. def CMD_hosts(self, nickname, channel, line, params):
  180. if nickname in tempid:
  181. self.notice(nickname,"\xee\x80\x91 Dumping host frequency (clones)..")
  182. hosts=list(x['HOSTMASK'] for x in userdb)
  183. d=defaultdict(int)
  184. for x in hosts:
  185. d[x]+=1
  186. for x in d.items():
  187. 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] ])))
  188. else:
  189. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  190. # Idle frequency
  191. def CMD_idle(self, nickname, channel, line, params):
  192. if nickname in tempid:
  193. self.notice(nickname,"\xee\x80\x91 Dumping idle frequency..")
  194. times=list(x['IDLE'] for x in userdb)
  195. d=defaultdict(int)
  196. for x in times:
  197. d[x]+=1
  198. for x in d.items():
  199. 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] ])))
  200. else:
  201. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  202. # Sign-on frequency
  203. def CMD_signon(self, nickname, channel, line, params):
  204. if nickname in tempid:
  205. self.notice(nickname,"\xee\x80\x91 Dumping sign-on frequency..")
  206. signons=list(x['SIGNON'] for x in userdb if x != None)
  207. d=defaultdict(int)
  208. for x in signons:
  209. d[x]+=1
  210. for x in d.items():
  211. if x[0] != None:
  212. 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] ])))
  213. else:
  214. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  215. # Analyze
  216. def CMD_analyze(self, nickname, channel, line, params):
  217. if nickname in verifiedadmins:
  218. if len(params)==2:
  219. usr=params[1]
  220. if usr in wusers:
  221. self.notice(nickname,"User cannot be analyzed (umode +W)")
  222. else:
  223. self.notice(nickname,"\xee\x80\x91 Analyzing %s" % usr)
  224. self.notice(nickname,"Nick:\x035 %s " % usr)
  225. self.notice(nickname,"IP:\x035 %s" % list(z['IP'] for z in userdb if (z['NICK']==usr))[0])
  226. 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]))
  227. self.notice(nickname,"Signon:\x035 %s" % time.ctime(float(list(z['SIGNON'] for z in userdb if (z['NICK']==usr))[0])))
  228. self.notice(nickname,"Idle:\x035 %s \x0Fsecond(s)" % list(z['IDLE'] for z in userdb if (z['NICK'] == usr))[0])
  229. self.notice(nickname,"Channels:\x035 %s" % "\x0F,\x035 ".join(list(z['CHANNELS'] for z in userdb if (z['NICK'] == usr))[0]))
  230. else:
  231. self.notice(nickname,"\xee\x80\x91 Usage: >analyze [user]")
  232. else:
  233. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  234. ## DEFENSE ##
  235. # Scan
  236. def CMD_scan(self, nickname, channel, line, params):
  237. if nickname in verifiedadmins:
  238. signons=list(int(x['SIGNON']) for x in userdb if (x['SIGNON'] is not None) and (x['IP'] is not None))
  239. idles=list(int(x['IDLE']) for x in userdb if (x['IDLE'] is not None) and (x['IP'] is not None))
  240. signons_grouped=group(signons,2)
  241. idles_grouped=group(idles,1)
  242. signons_elim=[]
  243. idles_elim=[]
  244. for x in signons_grouped:
  245. if len(x)>=5:
  246. for y in x:
  247. signons_elim.append(str(y))
  248. for x in idles_grouped:
  249. if len(x)>=5:
  250. for y in x:
  251. idles_elim.append(str(y))
  252. idleset=set(idles_elim)
  253. signonset=set(signons_elim)
  254. botlist1=[]
  255. botlist2=[]
  256. for x in idleset:
  257. for y in list(z['NICK'] for z in userdb if (z['IDLE'] == x)):
  258. botlist1.append(y)
  259. for x in signonset:
  260. for y in list(z['NICK'] for z in userdb if (z['SIGNON'] == x)):
  261. botlist2.append(y)
  262. bots=set(botlist1)&set(botlist2)
  263. global bots
  264. if len(bots)>0:
  265. self.msg(channel,"\xee\x80\x91 There are\x035 %s \x0Fbot(s) on the network." % len(bots))
  266. self.msg(channel,"Nicks:\x035 %s" % "\x0F,\x035 ".join(bots))
  267. elif len(bots)==0:
  268. self.msg(channel,"\xee\x80\x91 There are no bots on the network.")
  269. else:
  270. self.msg(channel,"\xee\x80\x91 \x035Error.")
  271. else:
  272. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  273. # Logflag
  274. def CMD_logflag(self, nickname, channel, line, params):
  275. if nickname in verifiedadmins:
  276. try:
  277. self.msg(channel,"\xee\x8e\xaa Adding all detected drones to local DroneBL")
  278. ips=[]
  279. for x in bots:
  280. for y in list(z['IP'] for z in userdb if (z['NICK'] == x)):
  281. ips.append(y)
  282. ips_elim=set(ips)
  283. try:
  284. file=open('dronebl.txt','r+')
  285. except IOError:
  286. print "[*] DroneBL file not found, creating one.."
  287. file=open('dronebl.txt','w+')
  288. file.write("DroneBL file created on %s\n" % time.ctime())
  289. file.closed
  290. file=open('dronebl.txt','r+')
  291. dronelist=file.readlines()
  292. file.closed
  293. file=open('dronebl.txt','w+')
  294. for x in dronelist:
  295. if x in ips_elim:
  296. pass
  297. else:
  298. file.write(x)
  299. file.closed
  300. file=open('dronebl.txt','a+')
  301. for x in ips_elim:
  302. file.write("%s\n" % x)
  303. file.closed
  304. self.msg(channel,"\xee\x80\x91 Success.")
  305. except:
  306. self.notice(nickname,"\xee\x80\x91 You must scan for active drones first (>scan).")
  307. else:
  308. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  309. # Engage drones
  310. def CMD_engage_drones(self, nickname, channel, line, params):
  311. if nickname in verifiedadmins:
  312. try:
  313. self.msg(channel,"\xee\x80\x91 \x035Engaging all drones..")
  314. for x in bots:
  315. self.sendLine("GLINE %s 1800 :\x035Drone\x0F" % x)
  316. except:
  317. self.notice(nickname,"\xee\x80\x91 You must scan for active drones first (>scan).")
  318. else:
  319. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  320. # Engage BOPM
  321. def CMD_engage_bopm(self, nickname, channel, line, params):
  322. if nickname in verifiedadmins:
  323. self.msg(channel,"\xee\x80\x91 \x035Engaging all listed proxies..")
  324. try:
  325. for y in set(x['IP'] for x in userdb if x['IP'] is not None):
  326. name, original = '.'.join(y.split('.')[::-1]), y
  327. hit=[lookupAddress('%s.%s' % (name, bopm)) for bopm in bopmList]
  328. d = defer.DeferredList(hit, fireOnOneCallback=1, consumeErrors=1)
  329. def result(h, ip):
  330. h = list(h)
  331. if h[0][0] is False:
  332. pass
  333. else:
  334. for z in [u['NICK'] for u in userdb if u['IP']==ip]:
  335. self.sendLine("GLINE +%s 1800 :\x035Listed in %s\x0F" % (z,'.'.join(h[0][0][0].name.name.split('.')[4:])))
  336. d.addCallback(result, original)
  337. except:
  338. self.msg(channel,"\xee\x80\x91 \x035Error.")
  339. else:
  340. self.notice(nickname,"\xee\x80\x91 You must be authenticated to use this command")
  341. ## OTHER HANDLERS ##
  342. def userLeft(self, user, channel):
  343. if user in tempid:
  344. tempid.remove(user)
  345. if user in verifiedadmins:
  346. verifiedadmins.remove(user)
  347. def userQuit(self, user, quitMessage):
  348. if user in tempid:
  349. tempid.remove(user)
  350. if user in verifiedadmins:
  351. verifiedadmins.remove(user)
  352. def userKicked(self, kickee, channel, kicker, message):
  353. if kickee in tempid:
  354. tempid.remove(kickee)
  355. if kickee in verifiedadmins:
  356. verifiedadmins.remove(kickee)
  357. def userRenamed(self, oldname, newname):
  358. if oldname in tempid:
  359. tempid.remove(oldname)
  360. if oldname in verifiedadmins:
  361. verifiedadmins.remove(oldname)
  362. def kickedFrom(self, channel, kicker, message):
  363. self.join(channel)
  364. tempid=[]
  365. def irc_unknown(self, prefix, command, params):
  366. #print prefix,command,params
  367. if command == "379":
  368. if "W" in params[2].split("+")[1][:-1]:
  369. wusers.append(params[1])
  370. if command == "378":
  371. for d in userdb:
  372. if d["NICK"] == params[1]:
  373. try:
  374. d["IP"] = params[2].split()[4]
  375. except:
  376. pass
  377. if command == "RPL_WHOISIDLE":
  378. for d in userdb:
  379. if d["NICK"] == params[1]:
  380. d["SIGNON"] = params[3]
  381. d["IDLE"] = params[2]
  382. if command == "RPL_WHOISCHANNELS":
  383. for d in userdb:
  384. if d["NICK"] == params[1]:
  385. d["CHANNELS"] = params[2].split()
  386. if command == "RPL_WHOREPLY":
  387. userdb.append({"NICK":params[5],"IDENT":params[2],"HOSTMASK":params[3],"SIGNON":None,"CHANNELS":None,"IDLE":None,"IP":None})
  388. if params[5] not in wusers:
  389. self.sendLine("WHOIS %s %s" % (params[5],params[5]))
  390. if command == "RPL_LIST":
  391. if (int(params[2]) >= 5) and ("L" not in str(re.findall("\[(.*?)\]", params[3]))[0]):
  392. self.join(params[1])
  393. class IRCFactory(protocol.ClientFactory):
  394. protocol = IRCClient
  395. def __init__(self, channels):
  396. self.channels = channels
  397. reactor.connectTCP(server, port, IRCFactory(channels))
  398. reactor.run()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement