Ejemplo n.º 1
0
 def testRender(self):
     scout = ApiScout()
     results = {
         'test_1': [(16, 0x1032, 'test32.dll', 'TestApi32', 32),
                    (40, 0x1064, 'test64.dll', 'TestApi64', 64)]
     }
     expected_hits = [
         'Results for API DB: test_1',
         'idx: offset    ; VA                ; DLL                           ; API',
         '  1: 0x00000010;         0x00001032; test32.dll (32bit)            ; TestApi32',
         '---------------------------------------------------------------------------------------------------------------------------------',
         '  2: 0x00000028; 0x0000000000001064; test64.dll (64bit)            ; TestApi64',
         'DLLs: 2, APIs: 2'
     ]
     rendered = scout.render(results)
     for hit in expected_hits:
         self.assertTrue(hit in rendered)
     expected_no_result = "No results for API map: test_2\n"
     self.assertEqual(expected_no_result, scout.render({"test_2": []}))
Ejemplo n.º 2
0
def main():
    parser = argparse.ArgumentParser(
        description=
        'Demo: Use apiscout with a prepared api database (created using DatabaseBuilder.py) to crawl a dump for imports and render the results.'
    )
    parser.add_argument(
        '-f',
        '--filter',
        type=int,
        default=0,
        help='Filter out APIs that do not have a neighbour within N bytes.')
    parser.add_argument(
        '-i',
        '--ignore_aslr',
        action='store_true',
        help=
        'Do not apply the per-module ASLR offset potentially contained in a API DB file.'
    )
    parser.add_argument('binary_path',
                        type=str,
                        default='',
                        help='Path to the memory dump to crawl.')
    parser.add_argument(
        'db_path',
        type=str,
        nargs='*',
        help=
        'Path to the DB(s). If no argument is given, use all files found in "./dbs"'
    )

    args = parser.parse_args()
    if args.binary_path:
        binary = ""
        if os.path.isfile(args.binary_path):
            with open(args.binary_path, "rb") as f_binary:
                binary = f_binary.read()
        if not args.db_path:
            args.db_path = get_all_db_files()
        scout = ApiScout()
        # override potential ASLR offsets that are stored in the API DB files.
        scout.ignoreAslrOffsets(args.ignore_aslr)
        # load DB file
        for db_path in args.db_path:
            scout.loadDbFile(db_path)
        print("Using '{}' to analyze '{}.".format(args.db_path,
                                                  args.binary_path))
        num_apis_loaded = scout.getNumApisLoaded()
        filter_info = " - neighbour filter: 0x%x" % args.filter if args.filter else ""
        print("Buffer size is {} bytes, {} APIs loaded{}.\n".format(
            len(binary), num_apis_loaded, filter_info))
        results = scout.crawl(binary)
        filtered_results = scout.filter(results, 0, 0, args.filter)
        print(scout.render(filtered_results))
    else:
        parser.print_help()
Ejemplo n.º 3
0
def main():
    parser = argparse.ArgumentParser(description='Demo: Use apiscout with a prepared api database (created using DatabaseBuilder.py) to crawl a dump for imports and render the results.')
    parser.add_argument('-f', '--filter', type=int, default=0, help='Filter out APIs that do not have a neighbour within N bytes.')
    parser.add_argument('-i', '--ignore_aslr', action='store_true', help='Do not apply the per-module ASLR offset potentially contained in a API DB file.')
    parser.add_argument('-c', '--collection_file', type=str, default='', help='Optionally match the output against a WinApi1024 vector collection file.')
    parser.add_argument('-b', '--base_addr', type=str, default='', help='Set base address to given value (int or 0x-hex format).')
    parser.add_argument('-t', '--import_table_only', action='store_true', help='Do not crawl for API references but only parse the import table instead - assumes an unmapped PE file as input.')
    parser.add_argument('binary_path', type=str, default='', help='Path to the memory dump to crawl.')
    parser.add_argument('db_path', type=str, nargs='*', help='Path to the DB(s). If no argument is given, use all files found in "./dbs"')

    args = parser.parse_args()
    if args.binary_path:
        binary = ""
        if os.path.isfile(args.binary_path):
            with open(args.binary_path, "rb") as f_binary:
                binary = f_binary.read()
        scout = ApiScout()
        base_addr = get_base_addr(args)
        print("Using base adress 0x{:x} to infer reference counts.".format(base_addr))
        scout.setBaseAddress(base_addr)
        # override potential ASLR offsets that are stored in the API DB files.
        scout.ignoreAslrOffsets(args.ignore_aslr)
        # load DB file
        db_paths = []
        if args.db_path:
            db_paths = args.db_path
        elif not args.import_table_only:
            db_paths = get_all_db_files()
        for db_path in db_paths:
            scout.loadDbFile(db_path)
        # load WinApi1024 vector
        scout.loadWinApi1024(get_winapi1024_path())
        # scout the binary
        results = {}
        if args.import_table_only:
            print("Parsing Import Table for\n  {}.".format(args.binary_path))
            results = scout.evaluateImportTable(binary, is_unmapped=True)
        else:
            print("Using \n  {}\nto analyze\n  {}.".format("\n  ".join(db_paths), args.binary_path))
            num_apis_loaded = scout.getNumApisLoaded()
            filter_info = " - neighbour filter: 0x%x" % args.filter if args.filter else ""
            print("Buffer size is {} bytes, {} APIs loaded{}.\n".format(len(binary), num_apis_loaded, filter_info))
            results = scout.crawl(binary)
        filtered_results = scout.filter(results, 0, 0, args.filter)
        print(scout.render(filtered_results))
        print(scout.renderVectorResults(filtered_results))
        if args.collection_file:
            print(scout.renderResultsVsCollection(filtered_results, args.collection_file))
    else:
        parser.print_help()