部分漏洞利用代码只有在关闭某种保护模式后才能利用成功。在此之前,需要知道程序启用了哪种保护模式。验证的方法其实有很多。原理是读取PE文件的头结构,找到OPTIONAL_HEADER.DllCharacteristics结构,通过不同的操作数和运算得到。LyScript插件可以完全实现这个验证功能,而且实现起来也很简单。插件地址:https://github.com/lyshark/Ly...验证PE保护方式:验证自身保护方式,不遍历加载的模块,读入DllCharacteristics,依次对操作数进行运算,获得保护主程序的方法。fromLyScript32importMyDebugimportpefileif__name__=="__main__":#初始化dbg=MyDebug()dbg.connect()#根据文本段获取程序首地址base=dbg.get_base_from_address(dbg.get_local_base())byte_array=bytearray()forindexinrange(0,4096):read_byte=dbg.read_memory_byte(base+index)byte_array.append(read_byte)oPE=pefile.PE(data=byte_array)#随机基地址=>hex(pe.OPTIONAL_HEADER.DllCharacteristics)&0x40==0x40if((oPE.OPTIONAL_HEADER.DllCharacteristics&64)==64):print("Baseaddressrandomization:True")else:print("Baseaddressrandomization:False")#数据是不可执行DEP=>hex(pe.OPTIONAL_HEADER.DllCharacteristics)&0x100==0x100if((oPE.OPTIONAL_HEADER.DllCharacteristics&256)==256):print("DEPProtectionStatus:True")else:print("DEPProtectionStatus:False")#Mandatoryintegrity=>hex(pe.OPTIONAL_HEADER.DllCharacteristics)&0x80==0x80if((oPE.OPTIONAL_HEADER.DllCharacteristics&128)==128):print("EnforceIntegrity:True")else:print("EnforceIntegrity:False")if((oPE.OPTIONAL_HEADER.DllCharacteristics&1024)==1024):print("SEHexceptionprotection:True")else:print("SEHexceptionprotection:False")运行后可以输出dbg.close()程序,当前主程序开启了哪种保护模式:如果需要验证当前程序加载所有模块,可以通过dbg.get_all_module()遍历加载的模块,依次读入DllCharacteristics和操作数,得到保护模式fromLyScript32importMyDebugimportpefileif__name__=="__main__":#初始化dbg=MyDebug()dbg.connect()#获取所有加载的模块module_list=dbg.get_all_module()print("-"*100)print("模块名称\t\t\t基地址随机化\t\tDEP保护\t\t强制完整性\t\tSEH异常保护\t\t")print("-"*100)formodule_indexinmodule_list:print("{:15}\t\t".format(module_index.get("name")),end="")#读入程序加载的模块byte_array=bytearray()forindexinrange(0,4096):read_byte=dbg.read_memory_byte(module_index.get("base")+index)byte_array.append(read_byte)oPE=pefile.PE(data=byte_array)#随机基地址=>hex(pe.OPTIONAL_HEADER.DllCharacteristics)&0x40==0x40if((oPE.OPTIONAL_HEADER.DllCharacteristics&64)==64):print("True\t\t\t",end="")else:print("False\t\t\t",end="")#数据不可执行DEP=>hex(pe.OPTIONAL_HEADER.DllCharacteristics)&0x100==0x100if((oPE.OPTIONAL_HEADER.DllCharacteristics&256)==256):print("True\t\t\t",end="")else:print("False\t\t\t",end="")#强制完整性=>hex(pe.OPTIONAL_HEADER.DllCharacteristics)&0x80==0x80if((oPE.OPTIONAL_HEADER.DllCharacteristics&128)==128):print("True\t\t\t",end="")else:print("False\t\t\t",end="")if((oPE.OPTIONAL_HEADER.DllCharacteristics&1024)==1024):print("True\t\t\t",end="")else:print("False\t\t\t",end="")print()dbg.close()验证后得到的保护放入列表如下:得到程序打开保护模式后,可以对症下药,提前判断漏洞攻击是否可以反弹
