gpt4 book ai didi

ubuntu - 如何在ubuntu中禁用数据执行保护(DEP)以执行shellcode

转载 作者:太空宇宙 更新时间:2023-11-03 16:52:13 24 4
gpt4 key购买 nike

我正在使用 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的问题)

最佳答案

我稍微修改了我的 NASM 代码,现在它看起来像下面这样,

section .mytext progbits alloc exec write align=16  ; CHANGED HERE
global _start:
_start:
jmp short GotoCall

shellcode:
pop esi
xor eax, eax
mov byte [esi + 7], al
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'

默认情况下,.text 部分是不可写的。只是将第一行更改为

"section .mytext progbits alloc exec write align=16 "

for details about progbits alloc exec write,please click here.

并且链接器有一些默认覆盖,因此它会忽略可写的 .text,即使您要求它也是如此。但它不在乎它是否有不同的名称。

现在编译并链接它,

nasm -f elf32 Shellcode_Execve.asm
ld -m elf_i386 -o Shellcode_Execve Shellcode_Execve.o

现在可以了:)

关于ubuntu - 如何在ubuntu中禁用数据执行保护(DEP)以执行shellcode,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24515720/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com