【逆向工具】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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM