Beispiel #1
0
def main(args):
    # Check the arguments (None for now)
    if len(args) != 1 + 0:
        print(f'Wrong amount of arguments, got {len(args) - 1}, expected 0')
        printUsage(args)

    # Create the logger
    prompter = Prompter()

    # Compile the user scout
    compileScout(prompter)

    prompter.info('Finished Successfully')
Beispiel #2
0
def main(args):
    # Check the arguments (None for now)
    if len(args) != 1 + 0:
        print 'Wrong amount of arguments, got %d, expected %d' % (len(args) - 1, 0)
        printUsage(args)

    # Create the logger
    prompter = Prompter()

    # Compile the scout's loader (TCP server)
    compileScoutLoader(prompter)
    # Compile the full scout
    compileScout(prompter)

    prompter.info("Finished Successfully")
Beispiel #3
0
def main(args):
    # Check the arguments
    if len(args) not in [1 + 1, 1 + 2]:
        print(f'Wrong amount of arguments, got {len(args) - 1}, expected 1/2')
        printUsage(args)

    # parse the args
    server_ip = args[1]

    # open the log
    prompter = Prompter('Scout Manager',
                        [('scout_log.txt', 'a', logging.DEBUG)])

    # Check if we need to load the full scout before connecting to it
    if len(args) == 1 + 2:
        scout_path = args[2]
        full_scout = open(scout_path, "rb").read()
        remoteLoadServer(server_ip, full_scout, prompter)
        prompter.info("Waiting for Scout to fully load")
        time.sleep(2)

    # connect to the server
    prompter.info("Connecting to the fully loaded scout")
    sock_fd = socket.create_connection((server_ip, SCOUT_PORT))

    # configure the scout
    setBitness32()

    # start the managing session
    startManage(sock_fd, prompter)

    prompter.info('Finished Successfully')
Beispiel #4
0
def main(args):
    # Check the arguments
    if len(args) != 1 + 1:
        print 'Wrong amount of arguments, got %d, expected %d' % (len(args) - 1, 1)
        printUsage( args )
        
    # parse the args
    server_ip = args[1]

    # open the log
    prompter = Prompter("Scout Manager", [("proxy_log.txt", "a", logging.DEBUG)])

    # connect to the server
    sock_fd = socket.create_connection((server_ip, SCOUT_PORT))

    # configure the scout
    setBitness64()
    
    # start the managing session
    startManage(sock_fd, prompter)

    prompter.info('Finished Successfully')
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')
Beispiel #6
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")
Beispiel #7
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')
Beispiel #8
0
def main(args):
    """Create a .json configuration for the open source library version.

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

    # argument parser
    parser = argparse.ArgumentParser(
        description=
        'Compiles a *.json configuration file for a specific version of an open source library, later to be used by %s\'s Matcher.'
        % (LIBRARY_NAME))
    parser.add_argument(
        'name',
        metavar='lib-name',
        type=str,
        help='name (case sensitive) of the 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(
        'couples',
        metavar='dir archive',
        type=str,
        nargs='+',
        help=
        'directory with the compiled *.o / *.obj files + path to the matching *.a / *.lib file (if didn\'t use "--no-archive")'
    )
    parser.add_argument('-D',
                        '--debug',
                        action='store_true',
                        help='set logging level to logging.DEBUG')
    parser.add_argument(
        '-N',
        '--no-archive',
        action='store_false',
        help='extract data from all *.o / *.obj files in the directory')
    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
    is_debug = args.debug
    is_windows = args.windows
    using_archives = args.no_archive
    couples = args.couples

    bin_dirs = []
    archive_paths = []
    if using_archives:
        if len(couples) % 2 != 0:
            parser.error(
                "Odd length in list of dir,archive couples, should be: [(directory, archive name), ...]"
            )
        for i in xrange(0, len(couples), 2):
            bin_dirs.append(couples[i])
            archive_paths.append(couples[i + 1])
    else:
        bin_dirs = couples

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

    # requesting the path to the chosen disassembler
    setDisassemblerPath(prompter)
    disas_cmd = identifyDisassemblerHandler(getDisasPath(), prompter)
    if disas_cmd is None:
        return

    # register our contexts
    registerContexts(SourceContext, BinaryContext, IslandContext)

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

    # Check if launched from the src directory
    if not os.path.exists(SCRIPT_PATH):
        prompter.error(
            'The script should be executed from Karta\'s src directory!')
        prompter.error('Exiting')
        return

    # analyze the open source library
    analyzeLibrary(constructConfigPath(library_name, library_version),
                   bin_dirs, archive_paths, prompter)

    # finished
    prompter.info('Finished Successfully')
Beispiel #9
0
from elementals import ProgressBar
from elementals import StatusBar
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")