Exemplo n.º 1
0
def main():
    
    management_vars = {
        ##--Information about this program--##
        'program_details':{
            'Program':'pcfg_manager.py',
            'Version': '3.3 Beta',
            'Author':'Matt Weir',
            'Contact':'*****@*****.**',
            'Source':'https://github.com/lakiw/pcfg_cracker'
        },
        ##--Runtime specific values, can be overriden via command line options
        'runtime_options':{
            'rule_name':'Default',
            #Debugging printouts of the queue behavior instead of generating cracking guesses
            'queue_info':False  
        }
    }  
    
    ##--Print out banner
    print_banner(management_vars['program_details'])
    
    ##--Parse the command line ---##
    if parse_command_line(management_vars['runtime_options']) != True:
        return
   
    ##--Specify where the rule file is located
    rule_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),'Rules', 
        management_vars['runtime_options']['rule_name'])   
   
    ##--Initialize the grammar--##
    grammar = []
    config_details = {}
    if load_grammar(rule_directory, grammar, config_details) != True:
        print ("Error loading the PCFG grammar, exiting",file=sys.stderr)
        print_error()
        return
 
    ##--Load the Markov stats file--##
    ##--Only do this on newer grammars to ensure backwards compatability--##
    if LooseVersion(config_details['version']) >= LooseVersion("3.3"):
        try:
            markov_cracker = MarkovCracker(rule_directory)
        except:
            print ("Error loading the Markov stats file for the ruleset, exiting",file=sys.stderr)
            print_error()
            return
    else:
        markov_cracker = MarkovCracker()
 
    pcfg = PcfgClass(grammar, markov_cracker)
    
    ##--Setup is done, now start generating rules
    print ("Starting to generate password guesses",file=sys.stderr)
    print ("Press [ENTER] to display a status output",file=sys.stderr)
    
    current_cracking_session = CrackingSession(pcfg = pcfg)
    current_cracking_session.run(print_queue_info = management_vars['runtime_options']['queue_info'])
Exemplo n.º 2
0
def main():

    ##--Information about this program--##
    program_details = {
        'Program': 'honeyword_gen.py',
        'Version': '3.1',
        'Author': 'Matt Weir',
        'Contact': '*****@*****.**',
        'Source': 'https://github.com/lakiw/pcfg_cracker'
    }

    ##--Print out banner
    print_banner(program_details)

    ##--Parse the command line ---##
    command_line_results = CommandLineVars()
    if parse_command_line(command_line_results) != RetType.STATUS_OK:
        return RetType.QUIT

    ##--Specify where the rule file is located
    rule_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),
                                  'Rules', command_line_results.rule_name)

    ##--Initialize the grammar--##
    grammar = []
    ret_value = load_grammar(rule_directory, grammar)
    if ret_value != RetType.STATUS_OK:
        print("Error loading the PCFG grammar, exiting", file=sys.stderr)
        print_error()
        return ret_value

    pcfg = PcfgClass(grammar)

    ##--Generate the honeywords--##
    print("Generating Honeywords", file=sys.stderr)
    print("--------------------------------", file=sys.stderr)
    # First find the start index
    start_index = pcfg.start_index()
    if start_index == -1:
        print("Error with the grammar, could not find the start index",
              file=sys.stderr)
        return RetType.ERROR_QUIT
    for i in range(0, command_line_results.num_honeywords):
        ##--Perform a weighted random walk of the grammar to get the parse tree
        parse_tree = pcfg.random_grammar_walk(start_index)

        ##--get all terminals generated by this parse tree
        ##--This could be improved to select a random terminal in the grammar, but I didn't feel the performance
        ##--improvement was worth the extra code
        honeyword = pcfg.gen_random_terminal(parse_tree)

        ##--Print the results
        print(str(honeyword))

    return RetType.STATUS_OK
Exemplo n.º 3
0
def main():

    ##--Information about this program--##
    program_details = {
        "Program": "honeyword_gen.py",
        "Version": "3.1",
        "Author": "Matt Weir",
        "Contact": "*****@*****.**",
        "Source": "https://github.com/lakiw/pcfg_cracker",
    }

    ##--Print out banner
    print_banner(program_details)

    ##--Parse the command line ---##
    command_line_results = CommandLineVars()
    if parse_command_line(command_line_results) != RetType.STATUS_OK:
        return RetType.QUIT

    ##--Specify where the rule file is located
    rule_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)), "Rules", command_line_results.rule_name)

    ##--Initialize the grammar--##
    grammar = []
    ret_value = load_grammar(rule_directory, grammar)
    if ret_value != RetType.STATUS_OK:
        print("Error loading the PCFG grammar, exiting", file=sys.stderr)
        print_error()
        return ret_value

    pcfg = PcfgClass(grammar)

    ##--Generate the honeywords--##
    print("Generating Honeywords", file=sys.stderr)
    print("--------------------------------", file=sys.stderr)
    # First find the start index
    start_index = pcfg.start_index()
    if start_index == -1:
        print("Error with the grammar, could not find the start index", file=sys.stderr)
        return RetType.ERROR_QUIT
    for i in range(0, command_line_results.num_honeywords):
        ##--Perform a weighted random walk of the grammar to get the parse tree
        parse_tree = pcfg.random_grammar_walk(start_index)

        ##--get all terminals generated by this parse tree
        ##--This could be improved to select a random terminal in the grammar, but I didn't feel the performance
        ##--improvement was worth the extra code
        honeyword = pcfg.gen_random_terminal(parse_tree)

        ##--Print the results
        print(str(honeyword))

    return RetType.STATUS_OK
Exemplo n.º 4
0
def main():
    
    ##--Information about this program--##
    program_details = {
        'Program':'pcfg_manager.py',
        'Version': '3.1 Alpha',
        'Author':'Matt Weir',
        'Contact':'*****@*****.**',
        'Source':'https://github.com/lakiw/pcfg_cracker'
    }
       
     ##--Print out banner
    print_banner(program_details)
    
    ##--Parse the command line ---##
    command_line_results = CommandLineVars()
    if parse_command_line(command_line_results) != RetType.STATUS_OK:
        return RetType.QUIT
   
    ##--Specify where the rule file is located
    rule_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),'Rules', command_line_results.rule_name)   
   
    ##--Initialize the grammar--##
    grammar = []
    ret_value = load_grammar(rule_directory, grammar)
    if ret_value != RetType.STATUS_OK:
        print ("Error loading the PCFG grammar, exiting",file=sys.stderr)
        print_error()
        return ret_value
 
    pcfg = PcfgClass(grammar)
    
    ##--Initialize the priority queue--##
    p_queue = PcfgQueue(verbose = command_line_results.verbose)
    ret_value = p_queue.initialize(pcfg)
    if ret_value != RetType.STATUS_OK:
        print ("Error initalizing the priority queue, exiting",file=sys.stderr)
        print_error()
        return ret_value 
    
    ##--Setup is done, now start generating rules
    print ("Starting to generate password guesses",file=sys.stderr)
    print ("Press [ENTER] to display a status output",file=sys.stderr)
    
    current_cracking_session = CrackingSession(pcfg = pcfg, p_queue = p_queue)
    current_cracking_session.run(print_queue_info = command_line_results.queue_info)
      
    return RetType.STATUS_OK
Exemplo n.º 5
0
def main():
    
    ##--Information about this program--##
    program_details = {
        'Program':'pcfg_manager.py',
        'Version': '3.1.3 Beta',
        'Author':'Matt Weir',
        'Contact':'*****@*****.**',
        'Source':'https://github.com/lakiw/pcfg_cracker'
    }
       
     ##--Print out banner
    print_banner(program_details)
    
    ##--Parse the command line ---##
    command_line_results = CommandLineVars()
    if parse_command_line(command_line_results) != RetType.STATUS_OK:
        return RetType.QUIT
   
    ##--Specify where the rule file is located
    rule_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),'Rules', command_line_results.rule_name)   
   
    ##--Initialize the grammar--##
    grammar = []
    ret_value = load_grammar(rule_directory, grammar)
    if ret_value != RetType.STATUS_OK:
        print ("Error loading the PCFG grammar, exiting",file=sys.stderr)
        print_error()
        return ret_value
 
    pcfg = PcfgClass(grammar)
    
    ##--Setup is done, now start generating rules
    print ("Starting to generate password guesses",file=sys.stderr)
    print ("Press [ENTER] to display a status output",file=sys.stderr)
    
    current_cracking_session = CrackingSession(pcfg = pcfg, verbose = command_line_results.verbose)
    current_cracking_session.run(print_queue_info = command_line_results.queue_info)
      
    return RetType.STATUS_OK
Exemplo n.º 6
0
def main():
    
    ##--Information about this program--##
    management_vars = {
        ##--Information about this program--##
        'program_details':{
            'Program':'honeyword_gen.py',
            ##--I know, I skipped a couple of versions but want to keep this synced with pcfg_manager
            'Version': '3.3 Beta',
            'Author':'Matt Weir',
            'Contact':'*****@*****.**',
            'Source':'https://github.com/lakiw/pcfg_cracker'
        },
        ##--Runtime specific values, can be overriden via command line options
        'runtime_options':{
            'rule_name':'Default',
            #Number of honeywords to generate
            'num_honeywords':1
        }
    }  
       
    ##--Print out banner
    print_banner(management_vars['program_details'])
    
    ##--Parse the command line ---##
    if parse_command_line(management_vars['runtime_options']) != True:
        return
   
    ##--Specify where the rule file is located
    rule_directory = os.path.join(os.path.dirname(os.path.realpath(__file__)),'Rules', 
        management_vars['runtime_options']['rule_name'])    
   
    ##--Initialize the grammar--##
    grammar = []
    config_details = {}
    if load_grammar(rule_directory, grammar, config_details) != True:
        print ("Error loading the PCFG grammar, exiting",file=sys.stderr)
        print_error()
        return
   
    ##--Load the Markov stats file--##
    ##--Only do this on newer grammars to ensure backwards compatability--##
    if LooseVersion(config_details['version']) >= LooseVersion("3.3"):
        try:
            markov_cracker = MarkovCracker(rule_directory)
        except:
            print ("Error loading the Markov stats file for the ruleset, exiting",file=sys.stderr)
            print_error()
            return
    else:
        markov_cracker = MarkovCracker()
 
    pcfg = PcfgClass(grammar, markov_cracker)

    ##--Generate the honeywords--##
    print("Generating Honeywords", file=sys.stderr)
    print("--------------------------------", file=sys.stderr)
    # First find the start index
    start_index = pcfg.start_index()
    if start_index == -1:
        print("Error with the grammar, could not find the start index", file=sys.stderr)
        return 
    
    ##--Number of honeywords left to generate
    ##--Errors can occur that prevent a honeyword from being displayed, (char encoding is a pain)
    ##--so this program needs to know that and then make more honeywords that can be displaced
    honeywords_left = management_vars['runtime_options']['num_honeywords']
    
    ##--If errrors occured, (used for debugging and warning users of this tool)
    errors_occured = 0
    
    ##--Generate each honeyword
    while honeywords_left >= 0:
        
        try:
            ##--Perform a weighted random walk of the grammar to get the parse tree
            parse_tree = pcfg.random_grammar_walk(start_index)
            honeyword = pcfg.gen_random_terminal(parse_tree)

            ##--Print the results
            ##--Note, this may throw an exception if the terminal it is printing to
            ##--doesn't support the character type. For example if a Cyrillic character
            ##--is printed on an English language Windows Command shell
            print(str(honeyword))
            honeywords_left = honeywords_left - 1
            
        except Exception as msg:
            errors_occured += 1
    
    if errors_occured != 0:
        print()
        if errors_occured == 1:
            print("Warning: " + str(errors_occured) + " error occured when trying to generate your honeywords")
        else:
            print("Warning: " + str(errors_occured) + " errors occured when trying to generate your honeywords")
            
        print("This is usually caused by your terminal not supporting the character encoding of a specific honeyword")
        print("For example, the honeyword may have contained a letter in a language your terminal doesn't support")
   
    return
Exemplo n.º 7
0
def main():

    ##--Information about this program--##
    management_vars = {
        ##--Information about this program--##
        'program_details': {
            'Program': 'honeyword_gen.py',
            ##--I know, I skipped a couple of versions but want to keep this synced with pcfg_manager
            'Version': '3.3 Beta',
            'Author': 'Matt Weir',
            'Contact': '*****@*****.**',
            'Source': 'https://github.com/lakiw/pcfg_cracker'
        },
        ##--Runtime specific values, can be overriden via command line options
        'runtime_options': {
            'rule_name': 'Default',
            #Number of honeywords to generate
            'num_honeywords': 1
        }
    }

    ##--Print out banner
    print_banner(management_vars['program_details'])

    ##--Parse the command line ---##
    if parse_command_line(management_vars['runtime_options']) != True:
        return

    ##--Specify where the rule file is located
    rule_directory = os.path.join(
        os.path.dirname(os.path.realpath(__file__)), 'Rules',
        management_vars['runtime_options']['rule_name'])

    ##--Initialize the grammar--##
    grammar = []
    config_details = {}
    if load_grammar(rule_directory, grammar, config_details) != True:
        print("Error loading the PCFG grammar, exiting", file=sys.stderr)
        print_error()
        return

    ##--Load the Markov stats file--##
    ##--Only do this on newer grammars to ensure backwards compatability--##
    if LooseVersion(config_details['version']) >= LooseVersion("3.3"):
        try:
            markov_cracker = MarkovCracker(rule_directory)
        except:
            print(
                "Error loading the Markov stats file for the ruleset, exiting",
                file=sys.stderr)
            print_error()
            return
    else:
        markov_cracker = MarkovCracker()

    pcfg = PcfgClass(grammar, markov_cracker)

    ##--Generate the honeywords--##
    print("Generating Honeywords", file=sys.stderr)
    print("--------------------------------", file=sys.stderr)
    # First find the start index
    start_index = pcfg.start_index()
    if start_index == -1:
        print("Error with the grammar, could not find the start index",
              file=sys.stderr)
        return

    ##--Number of honeywords left to generate
    ##--Errors can occur that prevent a honeyword from being displayed, (char encoding is a pain)
    ##--so this program needs to know that and then make more honeywords that can be displaced
    honeywords_left = management_vars['runtime_options']['num_honeywords']

    ##--If errrors occured, (used for debugging and warning users of this tool)
    errors_occured = 0

    ##--Generate each honeyword
    while honeywords_left >= 0:

        try:
            ##--Perform a weighted random walk of the grammar to get the parse tree
            parse_tree = pcfg.random_grammar_walk(start_index)
            honeyword = pcfg.gen_random_terminal(parse_tree)

            ##--Print the results
            ##--Note, this may throw an exception if the terminal it is printing to
            ##--doesn't support the character type. For example if a Cyrillic character
            ##--is printed on an English language Windows Command shell
            print(str(honeyword))
            honeywords_left = honeywords_left - 1

        except Exception as msg:
            errors_occured += 1

    if errors_occured != 0:
        print()
        if errors_occured == 1:
            print("Warning: " + str(errors_occured) +
                  " error occured when trying to generate your honeywords")
        else:
            print("Warning: " + str(errors_occured) +
                  " errors occured when trying to generate your honeywords")

        print(
            "This is usually caused by your terminal not supporting the character encoding of a specific honeyword"
        )
        print(
            "For example, the honeyword may have contained a letter in a language your terminal doesn't support"
        )

    return