Skip to content

Commit 8b31ae6

Browse files
committed
Layers: Make the low-stub method less brittle
1 parent ea232f5 commit 8b31ae6

File tree

1 file changed

+34
-30
lines changed

1 file changed

+34
-30
lines changed

volatility3/framework/automagic/pdbscan.py

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -392,38 +392,42 @@ def method_low_stub_offset(
392392
# Try locating kernel base via x64 Low Stub in lower 1MB starting from second page (4KB)
393393
# If "Discard Low Memory" setting is disabled in BIOS, the Low Stub may be at the third/fourth or further pages
394394
for offset in range(0x1000, 0x100000, 0x1000):
395-
jmp_and_completion_values = int.from_bytes(
396-
physical_layer.read(offset, 0x8), "little"
397-
)
398-
if (
399-
0xFFFFFFFFFFFF00FF & jmp_and_completion_values
400-
!= constants.windows.JMP_AND_COMPLETION_SIGNATURE
401-
):
402-
continue
403-
cr3_value = int.from_bytes(
404-
physical_layer.read(
405-
offset + constants.windows.PROCESSOR_START_BLOCK_CR3_OFFSET, 0x8
406-
),
407-
"little",
408-
)
395+
try:
396+
jmp_and_completion_values = int.from_bytes(
397+
physical_layer.read(offset, 0x8), "little"
398+
)
399+
if (
400+
0xFFFFFFFFFFFF00FF & jmp_and_completion_values
401+
!= constants.windows.JMP_AND_COMPLETION_SIGNATURE
402+
):
403+
continue
404+
cr3_value = int.from_bytes(
405+
physical_layer.read(
406+
offset + constants.windows.PROCESSOR_START_BLOCK_CR3_OFFSET, 0x8
407+
),
408+
"little",
409+
)
409410

410-
# Compare previously observed valid page table address that's stored in vlayer._initial_entry
411-
# with PROCESSOR_START_BLOCK->ProcessorState->SpecialRegisters->Cr3
412-
# which was observed to be an invalid page address, so add 1 (to make it valid too)
413-
if (cr3_value + 1) != vlayer._initial_entry:
414-
continue
415-
potential_kernel_hint = int.from_bytes(
416-
physical_layer.read(
417-
offset + constants.windows.PROCESSOR_START_BLOCK_LM_TARGET_OFFSET,
418-
0x8,
419-
),
420-
"little",
421-
)
422-
if 0x3 & potential_kernel_hint:
411+
# Compare previously observed valid page table address that's stored in vlayer._initial_entry
412+
# with PROCESSOR_START_BLOCK->ProcessorState->SpecialRegisters->Cr3
413+
# which was observed to be an invalid page address, so add 1 (to make it valid too)
414+
if (cr3_value + 1) != vlayer._initial_entry:
415+
continue
416+
potential_kernel_hint = int.from_bytes(
417+
physical_layer.read(
418+
offset
419+
+ constants.windows.PROCESSOR_START_BLOCK_LM_TARGET_OFFSET,
420+
0x8,
421+
),
422+
"little",
423+
)
424+
if 0x3 & potential_kernel_hint:
425+
continue
426+
kernel_hint = potential_kernel_hint & 0xFFFFFFFFFFFF
427+
kernel_base = kernel_hint & (~0x1FFFFF) & 0xFFFFFFFFFFFF
428+
break
429+
except exceptions.InvalidAddressException:
423430
continue
424-
kernel_hint = potential_kernel_hint & 0xFFFFFFFFFFFF
425-
kernel_base = kernel_hint & (~0x1FFFFF) & 0xFFFFFFFFFFFF
426-
break
427431

428432
if kernel_base:
429433
# Scanning 32mb in 2mb chunks for the 'ntoskrnl' base address

0 commit comments

Comments
 (0)