Skip to content

Instantly share code, notes, and snippets.

@Phillip-C
Created September 3, 2017 17:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Phillip-C/666b6c7ca2cc52331e280318e76d2f2b to your computer and use it in GitHub Desktop.
Save Phillip-C/666b6c7ca2cc52331e280318e76d2f2b to your computer and use it in GitHub Desktop.
Brute-Force Password Generator
#!/usr/bin/python
################################################################################
# tool: PaGen - Brute-Force Password Generator
# version: 0.2
# email: mrh@bushisecurity.com
# www: bushisecurity.com/pagen/
################################################################################
# MIT License
# Copyright (c) 2017 Phillip Aaron
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal#
# in the Software without restriction, including without limitation the rights#
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell#
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import argparse, sys
from itertools import chain, product
# Iterable Method for brute-forcing a character set and length
def bruteforce(charset, maxlength, minlength):
return (''.join(candidate)
for candidate in chain.from_iterable(product(charset, repeat=i)
for i in range(minlength, maxlength + 1)))
def main(args):
for pwd in bruteforce(args.charset, int(args.length),int(args.minlength)):
if args.prefix:
pwd = str(args.prefix) + pwd
if args.postfix:
pwd += str(args.postfix)
print pwd
if __name__ == "__main__":
# Declare an argparse variable to handle application command line arguments
parser = argparse.ArgumentParser()
parser.add_argument("charset", action="store", help="Characters Set")
parser.add_argument("-l", "--length", action="store",
nargs='?', default=8, const=8, help="Password Length")
parser.add_argument("-m","--minlength", action="store",
nargs='?', default=1, const=1, help="Minimum password length")
parser.add_argument("-r","--prefix", action="store", help="Prefix each password")
parser.add_argument("-o","--postfix", action="store", help="Postfix each password")
# Show help if required arg not included
if len(sys.argv[1:])==0:
parser.print_help()
parser.exit()
args = parser.parse_args()
if args.minlength > args.length:
print "\n** Argument Logic Error **"
print "Minimum password length [-m "+str(args.minlength)+"] is greater than Password length [-l "+str(args.length)+"]\n"
parser.print_help()
parser.exit()
main(args)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment