我正在尝试将 Enrique Nissim 的脚本从他的演示文稿“KMDF 驱动程序上的逆向工程和错误搜索”移植到 IDA 7.4。他的原始脚本可以在以下位置找到:
https://github.com/IOActive/kmdf_re/tree/master/code
我的更新版本可以在以下位置找到:https : //github.com/MrSynAckSter/kmdf_re/blob/master/code/kmdf_re.py
虽然我已经消除了大部分错误,但我注意到在我尝试过的所有驱动程序上,有些常量无法添加到 IDA 数据库中。
运行脚本时会传播这些错误:
(1, '_GUID')
(2, 'GUID')
(3, 'RUNTIME_FUNCTION')
(4, 'UNWIND_INFO_HDR')
(5, 'UNWIND_CODE')
(6, '_UNICODE_STRING')
(7, 'USHORT')
(8, 'PWSTR')
(9, 'WCHAR')
(10, 'wchar_t')
(11, 'FILE')
(12, '_iobuf')
(13, '_MAJOR_FUNCTIONS')
(14, 'MAJOR_FUNCTIONS')
MAJOR_FUNCTIONS: failed to add constant DispatchCreate=0 (0x0)
MAJOR_FUNCTIONS: failed to add constant DispatchCreateNamedPipe=1 (0x1)
MAJOR_FUNCTIONS: failed to add constant DispatchCLose=2 (0x2)
MAJOR_FUNCTIONS: failed to add constant DispatchRead=3 (0x3)
MAJOR_FUNCTIONS: failed to add constant DispatchWrite=4 (0x4)
MAJOR_FUNCTIONS: failed to add constant DispatchQueryInformation=5 (0x5)
MAJOR_FUNCTIONS: failed to add constant DispatchSetInformation=6 (0x6)
MAJOR_FUNCTIONS: failed to add constant DispatchQueryEA=7 (0x7)
MAJOR_FUNCTIONS: failed to add constant DispatchSetEA=8 (0x8)
MAJOR_FUNCTIONS: failed to add constant DispatchFlushBuffers=9 (0x9)
MAJOR_FUNCTIONS: failed to add constant DispatchQueryVolumeInformation=10 (0xA)
MAJOR_FUNCTIONS: failed to add constant DispatchSetVolumeInformation=11 (0xB)
MAJOR_FUNCTIONS: failed to add constant DispatchDirectoryControl=12 (0xC)
MAJOR_FUNCTIONS: failed to add constant DispatchFileSystemControl=13 (0xD)
MAJOR_FUNCTIONS: failed to add constant DispatchDeviceIOControl=14 (0xE)
MAJOR_FUNCTIONS: failed to add constant DispatchInternalDeviceControl=15 (0xF)
MAJOR_FUNCTIONS: failed to add constant DispatchShutdown=16 (0x10)
MAJOR_FUNCTIONS: failed to add constant DispatchLockControl=17 (0x11)
MAJOR_FUNCTIONS: failed to add constant DispatchCleanup=18 (0x12)
MAJOR_FUNCTIONS: failed to add constant DispatchCreateMailslot=19 (0x13)
MAJOR_FUNCTIONS: failed to add constant DispatchQuerySecurity=20 (0x14)
MAJOR_FUNCTIONS: failed to add constant DispatchSetSecurity=21 (0x15)
MAJOR_FUNCTIONS: failed to add constant DispatchPower=22 (0x16)
MAJOR_FUNCTIONS: failed to add constant DispatchSystemControl=23 (0x17)
MAJOR_FUNCTIONS: failed to add constant DispatchDeviceChange=24 (0x18)
MAJOR_FUNCTIONS: failed to add constant DispatchQueryQuota=25 (0x19)
MAJOR_FUNCTIONS: failed to add constant DispatchSetQuota=26 (0x1A)
MAJOR_FUNCTIONS: failed to add constant DispatchPNP=27 (0x1B)
我已经将它们的起源缩小到第 439 行脚本的这一部分:
def load_kmdf_types_into_idb():
header_path = idautils.GetIdbDir()
idaapi.idc_parse_types("".join([header_path, "WDFStructs.h"]), idc.PT_FILE)
for idx in range(1, idc.get_ordinal_qty
()):
#Fails to add some of the types
print((idx, idc.get_numbered_type_name(idx)))
idc.import_type(idx, idc.get_numbered_type_name(idx))
然而,IDA 文档在破译“未能添加常量”错误方面并没有多大帮助。
https://www.hex-rays.com/products/ida/support/idapython_docs/ida_typeinf-module.html#import_type
import_type(til, idx, name, flags=0)
Copy a named type from til to idb.
Parameters:
til - type library (C++: const til_t *)
idx - the position of the new type in the list of types (structures or enums). -1 means at the end of the list (C++: int)
name - the type name (C++: const char *)
flags - combination of Import type flags (C++: int)
Returns: tid_t
BADNODE on error
对我来说最大的问题是为什么这种类型的导入会失败?是因为类型已经存在,还是这里有一些微妙的语法错误?这里的标志参数是强制性的吗?错误和文档使得很难准确地说出这里发生了什么。
我关心的原因是我相信失败的导入导致驱动程序无法找到 IoControlls、驱动程序主要功能和其他用于逆向工程 KMDF 驱动程序的重要结构。
以下是我为什么会发生这种情况的主要理论:
不知何故,import_type 的行为与原始脚本中的原始 Til2Idb 方法的工作不够紧密。
由于调情签名或其他原因,这些类型以某种方式已经以某种冲突的方式存在于数据库中。我尝试手动查找它们,但我没有看到它们被添加到我使用脚本尝试过的任何驱动程序中。
这是 IDA 告诉我无法添加常量,因为它们不存在于数据库中,并且脚本或多或少地按预期运行。如果是这种情况,我希望 IDA 文档能给我一些关于这种行为的指示。
我希望这能让问题清晰,伙计们。我希望你能帮忙!
更新:作为一个额外的问题,当我手动导入头文件时,解析 IDA 不会产生任何错误。