def main(args):
    """Run the manual library identifier script.

    Args:
        args (list): list of command line arguments
    """
    global disas_cmd

    # argument parser
    parser = argparse.ArgumentParser(description='Enables the user to manually identify the versions of located but unknown libraries, later to be used by %s\'s Matcher.' % (LIBRARY_NAME))
    parser.add_argument('bin', metavar='bin', type=str,
                        help='path to the disassembler\'s database for the wanted binary')
    parser.add_argument('-D', '--debug', action='store_true', help='set logging level to logging.DEBUG')

    # parse the args
    args = parser.parse_args(args)
    bin_path = args.bin
    is_debug = args.debug

    # open the log
    prompter = Prompter(min_log_level=logging.INFO if not is_debug else logging.DEBUG)
    prompter.info('Starting the Script')

    # always init the utils before we start
    initUtils(prompter, None, invoked_before=True)

    # Load the existing knowledge config, if exists
    prompter.debug('Opening knowledge configuration file from path: %s', accumulatedKnowledgePath(bin_path))
    prompter.addIndent()
    knowledge_config = loadKnowledge(bin_path)
    if knowledge_config is None:
        prompter.debug('Failed to find an existing configuration file')
        knowledge_config = {}
    prompter.removeIndent()

    # receive all of the couples from the user
    knowledge_config = recordManualVersions(knowledge_config, prompter)
    prompter.info('Storing the data to the knowledge configuration file')
    storeKnowledge(knowledge_config, bin_path)

    # finished
    prompter.info('Finished Successfully')
Пример #2
0
def main(args):
    """Run the manual anchors script.

    Args:
        args (list): list of command line arguments
    """
    global disas_cmd

    # argument parser
    parser = argparse.ArgumentParser(description=f"Enables the user to manually defined matches, acting as manual anchors, later to be used by {LIBRARY_NAME}'s Matcher.")
    parser.add_argument("bin", metavar="bin", type=str,
                        help="path to the disassembler's database for the wanted binary")
    parser.add_argument("name", metavar="lib-name", type=str,
                        help="name (case sensitive) of the relevant open source library")
    parser.add_argument("version", metavar="lib-version", type=str,
                        help="version string (case sensitive) as used by the identifier")
    parser.add_argument("config", metavar="configs", type=str,
                        help="path to the *.json \"configs\" directory")
    parser.add_argument("-D", "--debug", action="store_true", help="set logging level to logging.DEBUG")
    parser.add_argument("-W", "--windows", action="store_true", help="signals that the binary was compiled for Windows")

    # parse the args
    args = parser.parse_args(args)
    library_name    = args.name
    library_version = args.version
    bin_path        = args.bin
    config_path     = args.config
    is_debug        = args.debug
    is_windows      = args.windows

    # open the log
    prompter = Prompter(min_log_level=logging.INFO if not is_debug else logging.DEBUG)
    prompter.info("Starting the Script")

    # use the user supplied flag
    if is_windows:
        setWindowsMode()

    # always init the utils before we start
    initUtils(prompter, None, invoked_before=True)
    # register our contexts
    registerContexts(SourceContext, BinaryContext, IslandContext)

    # Load the information from the relevant library
    lib_config_file = constructConfigPath(library_name, library_version)
    prompter.debug(f"Loading the configuration file for library: {library_name}")
    prompter.addIndent()
    cur_config_path = os.path.join(config_path, lib_config_file)
    if not os.path.exists(cur_config_path):
        prompter.error(f"Missing configuration file ({lib_config_file}) for \"{library_name}\" Version: \"{library_version}\"")
        return
    # Load the configuration file
    fd = open(cur_config_path, "r")
    library_config = json.load(fd)
    fd.close()
    prompter.removeIndent()

    # Load the existing knowledge config, if exists
    prompter.debug(f"Opening knowledge configuration file from path: {accumulatedKnowledgePath(bin_path)}")
    prompter.addIndent()
    knowledge_config = loadKnowledge(bin_path)
    if knowledge_config is None:
        prompter.debug("Failed to find an existing configuration file")
        knowledge_config = {}
    prompter.removeIndent()

    # receive all of the couples from the user
    knowledge_config = recordManualAnchors(library_config, knowledge_config, library_name, prompter)
    prompter.info("Storing the data to the knowledge configuration file")
    storeKnowledge(knowledge_config, bin_path)

    # finished
    prompter.info("Finished Successfully")
Пример #3
0
def main(args):
    """Run the manual anchors script.

    Args:
        args (list): list of command line arguments
    """
    global disas_cmd

    # argument parser
    parser = argparse.ArgumentParser(description='Enables the user to manually defined matches, acting as manual anchors, later to be used by %s\'s Matcher.' % (LIBRARY_NAME))
    parser.add_argument('bin', metavar='bin', type=str,
                        help='path to the disassembler\'s database for the wanted binary')
    parser.add_argument('name', metavar='lib-name', type=str,
                        help='name (case sensitive) of the relevant open source library')
    parser.add_argument('version', metavar='lib-version', type=str,
                        help='version string (case sensitive) as used by the identifier')
    parser.add_argument('config', metavar='configs', type=str,
                        help='path to the *.json "configs" directory')
    parser.add_argument('-D', '--debug', action='store_true', help='set logging level to logging.DEBUG')
    parser.add_argument('-W', '--windows', action='store_true', help='signals that the binary was compiled for Windows')

    # parse the args
    args = parser.parse_args(args)
    library_name    = args.name
    library_version = args.version
    bin_path        = args.bin
    config_path     = args.config
    is_debug        = args.debug
    is_windows      = args.windows

    # open the log
    prompter = Prompter(min_log_level=logging.INFO if not is_debug else logging.DEBUG)
    prompter.info('Starting the Script')

    # use the user supplied flag
    if is_windows:
        setWindowsMode()

    # always init the utils before we start
    initUtils(prompter, None, invoked_before=True)
    # register our contexts
    registerContexts(SourceContext, BinaryContext, IslandContext)

    # Load the information from the relevant library
    lib_config_file = constructConfigPath(library_name, library_version)
    prompter.debug('Loading the configuration file for library: %s', library_name)
    prompter.addIndent()
    cur_config_path = os.path.join(config_path, lib_config_file)
    if not os.path.exists(cur_config_path):
        prompter.error('Missing configuration file (%s) for \"%s\" Version: \"%s\"', lib_config_file, library_name, library_version)
        return
    # Load the configuration file
    fd = open(cur_config_path, 'r')
    library_config = json.load(fd, object_pairs_hook=collections.OrderedDict)
    fd.close()
    prompter.removeIndent()

    # Load the existing knowledge config, if exists
    prompter.debug('Opening knowledge configuration file from path: %s', accumulatedKnowledgePath(bin_path))
    prompter.addIndent()
    knowledge_config = loadKnowledge(bin_path)
    if knowledge_config is None:
        prompter.debug('Failed to find an existing configuration file')
        knowledge_config = {}
    prompter.removeIndent()

    # receive all of the couples from the user
    knowledge_config = recordManualAnchors(library_config, knowledge_config, library_name, prompter)
    prompter.info('Storing the data to the knowledge configuration file')
    storeKnowledge(knowledge_config, bin_path)

    # finished
    prompter.info('Finished Successfully')
Пример #4
0
from elementals import Prompter
from elementals import createAnchor
from elementals import hexDump

import time
import logging

TOOL_NAME = "Extractor"

createAnchor(".", "Output %s", move_inside=True)

prompt = Prompter("test", [('action_log.txt', 'w', logging.DEBUG)])
prompt.debug("The name should be \"test\"")
prompt.info("Started the script")
prompt.info("Phase #1 - collecting the data")
prompt.addIndent()
prompt.info("Searching for the tool")

s = StatusBar('Searching for the ELF\'s start',
              30,
              time_format="Elapsed %M:%S -")
s.start()
for i in range(100):
    s.update()
    time.sleep(0.1)
s.finish()

prompt.warning("The tool only supports 32 bit")

prompt.info("Activating tool %s", TOOL_NAME)