Advertisement
irenicus09

Gen2k [Automated Word List Generator]

May 19th, 2013
3,543
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 7.87 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. __author__    = 'irenicus09'
  4. __email__     = 'irenicus09[at]gmail[dot]com'
  5. __license__   = 'BSD'
  6. __version__   = 'BETA'
  7. __date__      = '18/05/2013'
  8.  
  9. import sys
  10.  
  11.  
  12. """
  13. ##############################  GEN2K  ####################################
  14.  
  15.                    Automated Word List Generator
  16.  
  17. > Generates passwords combinations by combining words from wordlist.
  18. > Covers frequently used number patterns used along with words.
  19. > Generates passwords combinations using year/date combo.
  20. > Generates custom user defined value(s) combination with word list.
  21. > Option to auto convert words to upper/lowercase & capitalisation.
  22. > WPA/WPA2 password validation check.
  23. > No external dependencies.
  24.  
  25. ---------------------------------------------------------------------------
  26.  
  27.                            HINTS:
  28.  
  29.  * DO NOT USE A GENERAL PURPOSE WORDLIST
  30.  * SUPPLIED WORDLIST MUST ONLY CONTAIN KNOWN FACTS ABOUT TARGET
  31.    E.G NAMES, ADDRESS, FAVORITE ARTIST, PLACE, EVENT, ETC.
  32.  * TRY TO KEEP WORDLIST AT A MINIMUM, DON'T INCLUDE TOO MUCH DETAILS
  33.  * THE FINAL GENERATED WORD LIST CAN GET EXTREMELY LARGE!
  34.  
  35. ###########################################################################
  36. """
  37.  
  38.  
  39. def help():
  40.     print """
  41.  
  42.  
  43.         ######   ######## ##    ##  #######  ##    ##
  44.        ##    ##  ##       ###   ## ##     ## ##   ##
  45.        ##        ##       ####  ##        ## ##  ##
  46.        ##   #### ######   ## ## ##  #######  #####
  47.        ##    ##  ##       ##  #### ##        ##  ##
  48.        ##    ##  ##       ##   ### ##        ##   ##
  49.         ######   ######## ##    ## ######### ##    ##  %s
  50.  
  51.         ======= Automated Word List Generator =======
  52.  
  53.                Copyright (C) irenicus09 2013
  54.  
  55.  
  56.    USAGE: ./gen2k.py -w <wordlist> -o <output> [options]
  57.  
  58.    [ -c ] Enable word combination among the words in wordlist.
  59.  
  60.    [ -d ] Custom comma separated values to combine with wordlist.
  61.  
  62.    [ -e ] Enable wpa/wpa2 fitness check for generated passwords.
  63.  
  64.    [ -h ] Prints this help.
  65.  
  66.    [ -n ] Enable frequently used number combination with wordlist.
  67.  
  68.    [ -o ] Output filename.
  69.  
  70.    [ -w ] Path to word list file.
  71.           Wordlist must contain info related to Target.
  72.  
  73.    [ -y ] Enable year combination with wordlist.
  74.  
  75.    [ -z ] Enable conversion of words to upper & lower case letters.
  76.  
  77.           Note: Conversion to upper/lowercase & capitalisation
  78.           takes place before other modes are applied to the original list.
  79.  
  80.    """ % __version__
  81.  
  82.  
  83.  
  84.  
  85. def main():
  86.  
  87.     if exist('-h'):
  88.         help()
  89.         sys.exit(0)
  90.  
  91.     if not (exist('-w') or exist('-o')):
  92.         help()
  93.         sys.exit(1)
  94.  
  95.     master_list = load_words(find('-w')) # List supplied by user
  96.  
  97.     data = [] # Final wordlist
  98.     temp = [] # Temporary wordlist
  99.  
  100.     if exist('-z'):
  101.         master_list = gen_case(master_list)
  102.         data = master_list
  103.  
  104.     if exist('-c'):
  105.         temp = gen_word_combo(master_list)
  106.         data = list(set(temp+data))
  107.  
  108.     if exist('-n'):
  109.         temp = gen_numbers(master_list)
  110.         data = list(set(temp+data))
  111.  
  112.     if exist('-y'):
  113.         temp = gen_year(master_list)
  114.         data = list(set(temp+data))
  115.  
  116.     if exist('-d'):
  117.         try:
  118.             custom_values = find('-d').split(',')
  119.         except (AttributeError):
  120.             print '[!] Are you kidding me with no values?'
  121.             sys.exit(1)
  122.  
  123.         temp = gen_custom(master_list, custom_values)
  124.         data = list(set(temp+data))
  125.  
  126.     if exist('-e'):
  127.         data = wpa_validation_check(data)
  128.  
  129.     write_file(find('-o'), data)
  130.  
  131.     print '[*] Total words generated: %d' % (len(data))
  132.  
  133.     sys.exit(0)
  134.  
  135.  
  136. def merge_list(temp_list=[], final_list=[]):
  137.     """
  138.    Merges contents from temp_list (1st param) with final_list (2nd param)
  139.    """
  140.     for word in temp_list:
  141.         if word not in final_list:
  142.             final_list.append(word)
  143.  
  144.  
  145. def load_words(path_to_file):
  146.     """
  147.    Function to fetch all possible words.
  148.    """
  149.     data = []
  150.  
  151.     try:
  152.         handle = open(path_to_file, 'r')
  153.         temp_list = handle.readlines()
  154.         handle.close()
  155.  
  156.     except(BaseException):
  157.         print '[!] Error occured while reading wordlist.'
  158.         sys.exit(1)
  159.  
  160.     for word in temp_list:
  161.         word = word.strip()
  162.         if word != '':
  163.             data.append(word)
  164.  
  165.     return data
  166.  
  167.  
  168.  
  169. def write_file(path_to_file, data=[]):
  170.     """
  171.    Writing to specified file.
  172.    """
  173.     try:
  174.         handle = open(path_to_file, 'wb+')
  175.  
  176.         for word in data:
  177.             handle.write(word+'\n')
  178.  
  179.         handle.close()
  180.     except(BaseException):
  181.         print '[!] Error occured while writing to file.'
  182.         sys.exit(1)
  183.  
  184.  
  185.  
  186. def gen_case(words=[]):
  187.     """
  188.    Function to change words to Upper & Lower case.
  189.    """
  190.     custom_list = []
  191.  
  192.     for x in words:
  193.         custom_list.append(x.lower())
  194.         custom_list.append(x.capitalize())
  195.         custom_list.append(x.upper())
  196.  
  197.     return list(set(custom_list))
  198.  
  199.  
  200.  
  201. def gen_numbers(words=[]):
  202.     """
  203.    Function to mix words with commonly used numbers patterns.
  204.    """
  205.     word_list = []
  206.  
  207.     if len(words) <= 0:
  208.         return word_list
  209.  
  210.     num_list = ['0', '01', '012', '0123', '01234', '012345', '0123456', '01234567', '012345678', '0123456789',
  211.     '1', '12', '123', '1234','12345', '123456','1234567','12345678','123456789', '1234567890', '9876543210',
  212.     '987654321', '87654321', '7654321', '654321', '54321', '4321', '321', '21']
  213.  
  214.     for word in words:
  215.         for num in num_list:
  216.             word_list.append((word+num))
  217.             word_list.append((num+word))
  218.  
  219.     return word_list
  220.  
  221.  
  222.  
  223.  
  224. def gen_year(words=[]):
  225.     """
  226.    Function to mix auto generated year with words from wordlist.
  227.  
  228.    Hint: Date of birth & special dates are often
  229.          combined with certain words to form
  230.          passwords.
  231.    """
  232.     word_list = []
  233.  
  234.     if len(words) <= 0:
  235.         return word_list
  236.  
  237.     # Double digit dates
  238.     start = 1
  239.     while(start <= 99):
  240.         for word in words:
  241.             word_list.append(word + str("%02d") % (start))
  242.             word_list.append(str("%02d") % start + word)
  243.         start += 1
  244.  
  245.     # Four digit dates
  246.     start = 1900
  247.     while (start <= 2020):
  248.         for word in words:
  249.             word_list.append(word+str(start))
  250.             word_list.append(str(start)+word)
  251.         start += 1
  252.  
  253.     return word_list
  254.  
  255.  
  256.  
  257.  
  258. def gen_word_combo(words=[]):
  259.     """
  260.    Function to mix multiple words from given list.
  261.    """
  262.     word_list = []
  263.  
  264.     if len(words) <= 1:
  265.         return word_list
  266.  
  267.     for word in words:
  268.         for second_word in words:
  269.             if word != second_word:
  270.                 word_list.append(second_word+word)
  271.  
  272.     return word_list
  273.  
  274.  
  275.  
  276.  
  277. def gen_custom(words=[], data=[]):
  278.     """
  279.    Funtion to combine user defined input with wordlist.
  280.  
  281.    > Takes a comma separated list via cmdline as values.
  282.    """
  283.     word_list = []
  284.  
  285.     if (len(words) <= 0 or len(data) <= 0):
  286.         return word_list
  287.  
  288.     for item in data:
  289.         for word in words:
  290.             word_list.append(item+word)
  291.             word_list.append(word+item)
  292.  
  293.     return word_list
  294.  
  295.  
  296.  
  297. def wpa_validation_check(words=[]):
  298.     """
  299.    Function to optimise wordlist for wpa cracking
  300.  
  301.    > Removes Duplicates.
  302.    > Removes passwords < 8 or > 63 characters in length.
  303.    """
  304.     custom_list =  list(set(words))
  305.     custom_list = [x for x in custom_list if not (len(x) < 8 or len(x) > 63)]
  306.  
  307.     return custom_list
  308.  
  309.  
  310. # S3my0n's argument parsers, thx brah :)
  311. def find(flag):
  312.     try:
  313.         a = sys.argv[sys.argv.index(flag)+1]
  314.     except (IndexError, ValueError):
  315.         return None
  316.     else:
  317.         return a
  318.  
  319. def exist(flag):
  320.     if flag in sys.argv[1:]:
  321.         return True
  322.     else:
  323.         return False
  324.  
  325.  
  326.  
  327.  
  328.  
  329.  
  330.  
  331.  
  332. if __name__ == '__main__':
  333.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement