execve shellcode编写分段错误

时间:2012-12-08 12:22:41

标签: assembly x86 segmentation-fault shellcode execve

我正在尝试研究execve shellcode,

操作系统:Linux bt 2.6.39.4

root @ bt:〜/ exploit#cat gshell.s

.globl _start

_start:

    nop
    jmp MyString

    shell:

            popl %esi
            xorl %eax,%eax

            movl %al,9(%esi)
            movl %esi,10(%esi)
            movl %eax,14(%esi)

            movb $11,%al
            movl %esi, %ebx
            leal 0xa(%esi),%ecx
            leal 0xe(%esi),%edx
            int $0x80



            movl $1,%eax
            movl $0,%ebx
            int $0x80


    MyString:
            call shell
            shellvar:
                    .ascii "/bin/bashADDDDCCCC"

root @ bt:〜/ exploit#as -gstabs -o gshell.o gshell.s

root @ bt:〜/ exploit #ld -o gshell gshell.o

root @ bt:〜/ exploit#。/ themhell 分段故障(核心转储) 根@ BT:〜/利用#

GDB:

(gdb)break * _start 断点1位于0x8048054:文件gshell.s,第6行。

(gdb)r 启动程序:/ root / exploit / gshell

编程接收信号SIGSEGV,分段故障。 shell()at gshell.s:14 14 movb%al,9(%esi)

(gdb)print / x $ esi $ 1 = 0x804807a (gdb)x / 16cb $ esi 0x804807a:47'/ '98'b'105'i'110'n'47'/ '98'b'97'a'115'' 0x8048082:104'h'65'A'68'D'68'D'68'D'68'D'67'C'67'C' (GDB)

从上面输出似乎我已经成功地将/ bin / sh地址写入ESI寄存器 但是当我尝试将0移到9(%esi)时 - >它会导致分段错误。 甚至试图修改这个程序:movl $ 0到$ esi。 想知道是否限制写入0x804807a地址?导致这个错误? 以及如何继续成功运行此shellcode

谢谢, littlejack

1 个答案:

答案 0 :(得分:4)

正如Bo在评论中所说,.text部分在当前系统上默认是只读的。要使此代码有效,您必须使其可写。例如,您可以在源文件中使用指令,如下所示:

.section wtext, "awx", @progbits

等效的nasm指令是:

section wtext exec write

或者,也可以将-N开关传递给链接器。

请注意,此类shell代码通常用于堆栈执行,这是当前操作系统中通常禁用的另一件事。如果您想在堆栈上尝试此操作,则可能需要-z execstack链接器选项。

相关问题