__author_info = "Antonio Ospite"
+# returns a tuple: (num_passwords, passwords)
+# where passwords is an iterable type
def generate_passwords(password_pattern, dry_run=False):
- passwords = list(exrex.generate(password_pattern))
+ num_passwords = exrex.count(password_pattern)
+ passwords = exrex.generate(password_pattern)
if dry_run:
- print "Generated %d passwords." % len(passwords)
+ print "Generated %d passwords." % num_passwords
for p in passwords:
print p
- return []
+ return (0, iter([]))
- return passwords
+ return (num_passwords, passwords)
+# the passwords parameter is a tuple: (n, L)
+# where L is an iterable type and n is the number of elements in L
def crackpop(host, port, ssl, user, passwords):
if ssl:
pop3_connect = poplib.POP3_SSL
else:
pop3_connect = poplib.POP3
- print "Testing %d passwords." % len(passwords)
- for p in passwords:
+ print "Testing %d passwords." % passwords[0]
+ for p in passwords[1]:
# TODO maybe the same connection can be reused for more than one try,
# but some logic needs to be added to detect the maximum allowed
# authentication attempts or a disconnection from the server.
parser.add_argument(
'-P', '--port', metavar="<port>",
- dest='port', default=110,
+ dest='port', default=None,
help='the port the pop3 server is listening on')
parser.add_argument(
dest='ssl', action='store_const', const=True,
help='use SSL to connect to the pop3 server')
- parser.add_argument(
- '-S', '--ssl-port', metavar="<ssl_port>",
- dest='ssl_port', default=995,
- help='the port the SSL pop3 server is listening on')
-
return parser
parser = option_parser()
args = parser.parse_args()
- if args.ssl:
- port = args.ssl_port
+ if args.port is None:
+ if args.ssl:
+ port = poplib.POP3_SSL_PORT
+ else:
+ port = poplib.POP3_PORT
else:
port = args.port