Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,12 @@ past roughly six lines it belongs in the PR the entry links.
### Removed

### Fixed
- **(labels)** Apply the per-DLL `aslr_offset` of an ApiScout DB in `WinApiResolver`, as ApiScout does. The
offset was ignored, so a DB built with ASLR offsets mapped every rebased DLL to its file ImageBase, where most
64-bit system DLLs collide at `0x180000000`. *Measured on apiscout's `win10_prof_1803_example.json` (`668c981`):*
5,706 of 86,703 resolver addresses matched ApiScout's before, all 97,516 after. Cost: none, DBs without offsets
(the bundled Win7 and XP ones) load bit-identical. *Not bundled; the behaviour is covered by
`test_win_api_resolver_applies_aslr_offsets_of_the_database`.*

### Security

Expand Down
2 changes: 1 addition & 1 deletion src/smda/common/labelprovider/WinApiResolver.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ def _loadDbFile(self, os_name, db_filepath):
dll = api_db["dlls"][dll_entry]
dll_name = "_".join(dll_entry.split("_")[2:])
has_64bit |= dll["bitness"] == 64
base_address = dll["base_address"]
base_address = dll["base_address"] - dll.get("aslr_offset", 0)
for export in dll["exports"]:
num_apis_loaded += 1
api_name = str(export["name"])
Expand Down
39 changes: 39 additions & 0 deletions tests/testPeSymbolProvider.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,45 @@ def test_win_api_resolver_defers_parsing_uncached_databases(self):
self.assertEqual(resolver._os_name, "testos")
self.assertIsNone(resolver._deferred_dbs)

def test_win_api_resolver_applies_aslr_offsets_of_the_database(self):
api_db = {
"os_name": "testos",
"aslr_offsets": True,
"dlls": {
"64_10.0.17134.1_first.dll_0x180000000": {
"bitness": 64,
"base_address": 0x180000000,
"aslr_offset": 0x180000000 - 0x7FF8D5930000,
"exports": [{"name": "FirstApi", "address": 0x1000, "ordinal": 1}],
},
"64_10.0.17134.1_second.dll_0x180000000": {
"bitness": 64,
"base_address": 0x180000000,
"aslr_offset": 0x180000000 - 0x7FF8D7520000,
"exports": [{"name": "SecondApi", "address": 0x1000, "ordinal": 1}],
},
"64_10.0.17134.1_unrebased.dll_0x10000000": {
"bitness": 64,
"base_address": 0x10000000,
"aslr_offset": 0,
"exports": [{"name": "UnrebasedApi", "address": 0x1000, "ordinal": 1}],
},
},
}
with tempfile.TemporaryDirectory() as tmp_dir:
db_path = os.path.join(tmp_dir, "apiscout_aslr.json")
with open(db_path, "w", encoding="utf-8") as f_json:
json.dump(api_db, f_json)
config = SimpleNamespace(API_COLLECTION_FILES={"testos": db_path})
with mock.patch.object(WinApiResolver, "_db_cache", {}):
resolver = WinApiResolver(config)
resolver.update(SimpleNamespace(is_buffer=True))

self.assertEqual(resolver.getApi(0, 0x7FF8D5931000), ("first.dll_0x180000000", "FirstApi"))
self.assertEqual(resolver.getApi(0, 0x7FF8D7521000), ("second.dll_0x180000000", "SecondApi"))
self.assertEqual(resolver.getApi(0, 0x10001000), ("unrebased.dll_0x10000000", "UnrebasedApi"))
self.assertEqual(resolver.getApi(0, 0x180001000), (None, None))

def test_win_api_resolver_keeps_an_explicit_os_name_across_deferred_loading(self):
api_db = {
"os_name": "present",
Expand Down
Loading