Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/ssh/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在ubuntu中禁用数据执行保护(DEP)以执行外壳代码_Ubuntu_Nasm_Shellcode_Dep - Fatal编程技术网

如何在ubuntu中禁用数据执行保护(DEP)以执行外壳代码

如何在ubuntu中禁用数据执行保护(DEP)以执行外壳代码,ubuntu,nasm,shellcode,dep,Ubuntu,Nasm,Shellcode,Dep,我使用的是ubuntu 14.04,64位。 我正在学习外壳代码写作。为了生成一个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]

我使用的是ubuntu 14.04,64位。 我正在学习外壳代码写作。为了生成一个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外壳代码\u Execve.asm

链接->ld-m elf_i386-ggdb-o外壳代码\u Execve外壳代码\u 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)
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'
如上所述,我尝试了使用GCC和ld禁用DEP的所有方法。 但什么都不管用。那么如何禁用DEP?让我的代码正常工作?
(请确保问题出在DEP上)

我已经稍微更改了我的NASM代码,现在看起来如下所示

$ 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)
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”

而且链接器有一些默认覆盖,所以即使您要求,它也会忽略writable.text。但它不在乎它是否有不同的名字

现在编译并链接它

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

现在它工作了:)

我知道我真的迟到了,但我一直在与同样的代码和gcc堆栈保护作斗争。当使用objdump-d将其转换为外壳代码时,我得到了:

char shellcode[]="\xeb\x1a\x5e\x31\xc0\x88\x46\x07\x8d\x1e\x89\x5e\x08\x89\x46\x0c\xb0\x0b\x89\xf3\x8d\x4e\x08\x8d\x56\x0c\xcd\x80\xe8\xe1\xff\xff\xff\x2f\x62\x69\x6e\x2f\x73\x68";

int main()
{
    int *ret;
    ret = (int *)&ret + 2;
    (*ret) = (int)shellcode;
}
然后,在您的提示的帮助下,我能够编译并运行它:

~/Shellcode$gcc-fno stack protector-z execstack execShellSpawn.c-o execShellSpawn

如果没有-z execstack,我会得到一个Segfault。 如果没有-fno堆栈保护器,它将完成与退出(0)差不多的任务