IDA Python安装与使用
1、IDA Pyhon介绍
IDA Python是IDA6.8后自带插件,可以使用Python做很多的辅助操作,非常方便的感觉。
2、IDA Python安装
从github上IDAPython项目获取跟自己电脑IDA、Python对应的版本。
项目地址:https://github.com/idapython
IDA Python手册:https://www.hex-rays.com/products/ida/support/idapython_docs/
我的IDA是6.8,Python是2.7版本。
IDA Python安装的说明:
1. Install 2.6 or 2.7 from http://www.python.org/
2. Copy the whole "python" directory to %IDADIR%
3. Copy the contents of the "plugins" directory to the %IDADIR%\plugins\
4. Copy "python.cfg" to %IDADIR%\cfg
翻译:
1、从http://www.python.org/安装Python 2.7版本。
2、复制安装包内的python目录到%IDADIR%(IDA)目录,%IDADIR%\python
3、复制安装包内的plugins目录到%IDADIR%(IDA)目录,%IDADIR%\plugins
4、复制安装包内的"python.cfg" 到 %IDADIR%\cfg内
3、使用方法
3.1、快捷键使用
- 运行IDA脚本文件: (Alt-F7)
- 单行执行Python (Ctrl-F3)
- 查看现有的IDA脚本文件 (Alt+F9)
3.2、测试代码
网上找到的Python代码是拿printf做的测试,可是我这边好像没有能解析printf函数,所以我用了IsProcessorFeaturePresent函数做示例。
单个函数测试:
#coding:utf-8
from idaapi import *
danger_funcs = ["IsProcessorFeaturePresent"]  # 需要寻找的函数名
for func in danger_funcs:
    addr = LocByName( func ) 
    if addr != BADADDR:
       #找到交叉引用的地址
        cross_refs = CodeRefsTo( addr, 0 )
        print "Cross References to %s" % func 
        print "-------------------------------"
        for ref in cross_refs: 
            print "%08x" % ref
             # 函数的颜色为红色
            SetColor( ref, CIC_ITEM, 0x0000ff)
多个函数需要识别的时候就可以把代码写得更加规范一些。
#
## another way to search all not safe functions
#
#coding:utf-8
from idaapi import *
# 设置颜色
def judgeAduit(addr):
    '''
    not safe function handler
    '''
    MakeComm(addr,"### AUDIT HERE ###")
    SetColor(addr,CIC_ITEM,0x0000ff)  #set backgroud to red
    pass
# 函数标识	
def flagCalls(danger_funcs):
    '''
    not safe function finder
    '''
    count = 0
    for func in danger_funcs:      
        faddr = LocByName( func )     
        if faddr != BADADDR: 
            # Grab the cross-references to this address         
            cross_refs = CodeRefsTo( faddr, 0 )                       
            for addr in cross_refs:
                count += 1 
                Message("%s[%d] calls 0x%08x\n"%(func,count,addr))  
                judgeAduit(addr)
                    
if __name__ == '__main__':
    '''
    handle all not safe functions
    '''
    print "-------------------------------"
	# 列表存储需要识别的函数
    danger_funcs = ["strcpy","sprintf","strncpy"] 
    flagCalls(danger_funcs)
    print "-------------------------------"
	
4、测试效果

5、参考链接
- IDAPython安装 | All Right
http://spd.dropsec.xyz/2016/10/05/IDAPython安装/
- IDAPython脚本之收集函数的调用信息 | All Right
http://spd.dropsec.xyz/2016/10/16/IDAPython脚本之收集函数的调用信息/
- IDAPython学习(一)
http://www.cnblogs.com/blacksunny/p/7214645.html
- 11 IDAPYTHON --- IDA 脚本
https://wizardforcel.gitbooks.io/grey-hat-python/content/44.html

 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号