我正在使用 ubuntu 14.04、64 位。我正在学习 shellcode 编写。因此,为了生成一个 shell,我编写了以下程序
segment .text
global _start:
_start:
jmp short GotoCall
shellcode:
pop esi
xor eax, eax
mov byte [esi + 7], al #here i get Error
lea ebx, [esi]
mov long [esi + 8], ebx
mov long [esi + 12], eax
mov byte al, 0x0b
mov ebx, esi
lea ecx, [esi + 8]
lea edx, [esi + 12]
int 80h
GotoCall:
call shellcode
Db '/bin/shJAAAABBBB'
已编译 -> nasm -ggdb -f elf Shellcode_Execve.asm
链接 -> ld -m elf_i386 -ggdb -o Shellcode_Execve Shellcode_Execve.o
当我在 GDB 中运行它时,我发现在下面的指令中我得到了错误,
mov byte [esi + 7], al
我发现,这是因为 DEP(数据执行预防)。所以我尝试了“-fno-stack-protector -z execstack”来编译和链接,如下所示,
$ nasm -ggdb -f elf32 -z execstack Shellcode_Execve.asm
nasm: error: unrecognised option `-z'
nasm: error: more than one input file specified
type `nasm -h' for help
$ nasm -ggdb -f elf32 -z execstack -o shell Shellcode_Execve.asm
nasm: error: unrecognised option `-z'
nasm: error: more than one input file specified
type `nasm -h' for help
$ nasm -ggdb -z execstack -f elf32 -o shell Shellcode_Execve.asm
nasm: error: unrecognised option `-z'
nasm: error: more than one input file specified
type `nasm -h' for help
$ nasm -ggdb -fno-stack-protector -z execstack -z execstack -f elf32 -o shell Shellcode_Execve.asm
nasm: fatal: unrecognised output format `no-stack-protector' - use -hf for a list
type `nasm -h' for help
$ nasm -ggdb -f elf32 Shellcode_Execve.asm
$ gcc -ggdb -m32 -fno-stack-protector -z execstack -o Shellcode_Execve Shellcode_Execve.o
Shellcode_Execve.o:Shellcode_Execve.asm:5: multiple definition of `_start'
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib32/crt1.o:(.text+0x0): first defined here
/usr/lib/gcc/x86_64-linux-gnu/4.8/../../../../lib32/crt1.o: In function `_start':
(.text+0x18): undefined reference to `main'
collect2: error: ld returned 1 exit status
$ nasm -ggdb -f elf32 Shellcode_Execve.asm
$ gcc -ggdb -m32 -fno-stack-protector -z execstack -o Shellcode_Execve Shellcode_Execve.o
$ ./Shellcode_Execve
Segmentation fault (core dumped)
$ nasm -ggdb -f elf32 Shellcode_Execve.asm
$ ld -m elf_i386 -ggdb -z execstack -o Shellcode_Execve Shellcode_Execve.o
$ ./Shellcode_Execve
Segmentation fault (core dumped)
像上面一样,我尝试了所有使用 GCC 和 ld 禁用 DEP 的方法。但没有任何效果。那么如何禁用 DEP?并使我的代码工作?(请确保问题出在 DEP 上)