【问题标题】:Please Explain the Missing Lines of my Assembly Shellcode. What are the EXECVE Parameters?请解释我的汇编 Shellcode 中缺少的行。什么是 EXECVE 参数?
【发布时间】:2014-01-12 22:33:02
【问题描述】:

我知道它的作用,但我真的很想解释为什么?

SECTION .data
        global _start
_start:
        jmp j ;jump to 'j' label
r:
        pop ebx ;Pop the address of 'shell' into EBX. Parameter is Filename
        xor eax, eax ; clear EAX register
        mov BYTE[ebx+7], al ;push one NUL byte to end any string reading
        mov DWORD[ebx+8], ebx ;mov address of EBX into the content EBX (offset of 8)
        mov DWORD[ebx+12], eax ;mov 4 NUL bytes at EBX (offset of 12)
        mov al, 11d ;execve system call
        lea ecx, [ebx+8] ; HELP
        lea edx, [ebx+12] ; HELP
        int 80h ;Kernel call
j:      call r ;call r... pushes 'shell' address onto the stack
shell:  db "/bin/sh" ;file name

具体来说,我想知道:
1) execve 的 3 个参数是什么(我看过 man 2 execve 并没有帮助)
2) 在这种情况下,LEA 究竟做了什么?

【问题讨论】:

    标签: assembly linux-kernel nasm shellcode


    【解决方案1】:

    mov DWORD[ebx+8], ebxmov DWORD[ebx+12], eax 的 cmets 是错误的,或者至少是误导性的。

    标签“shell”处的字节是“/bin/sh”,占 7 个字节,mov BYTE[ebx+7], al 以空字节结束此字符串。

    下一条语句mov DWORD[ebx+8], ebx 将 ebx 的内容(指向 shell 的指针)移动到 shell 后面的 4 个字节。

    之后,mov DWORD[ebx+12], eax 将零移动到接下来的 4 个字节。所以我们有如下的内存布局,其中bxbxbxbx是这个内存块的起始地址:

      bx                                 value=bx, points to /bin/sh
      |                                ___________
      v                               /           \
    +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
    | / | b | i | n | / | s | h |\0 |bx |bx |bx |bx | 0 | 0 | 0 | 0 |   
    +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
    

    两条 LEA 指令分别将 (bx+8) 和 (bx+12) 的地址移动到 cx 和 dx。您可以将它们替换为MOV CX, BX; ADD CX, 8; MOV DX, BX; ADD DX,12

      bx
      |
      v
    +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
    | / | b | i | n | / | s | h |\0 |bx |bx |bx |bx | 0 | 0 | 0 | 0 |   
    +---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+---+
                                      ^               ^
                                      cx              dx
    

    现在如果你看一下 execvp:

    bx 中的第一个参数是一个指向包含要执行的文件名的字符串的指针。那是/bin/sh。 第二个参数,在 cx 中,是一个指向字符串数组的指针,该数组要传递给要作为 argv 执行的程序。在这里,它由一个指向“/b​​in/sh”的指针和一个 NULL 指针组成。 NULL 指针用作数组终止符(请参阅 execve 文档),因为没有明确的数组长度。 第三个参数,在 dx 中,是指向新进程环境的指针——因为它是一个指向 NULL 指针的指针,所以新进程不会从你那里继承任何环境变量。

    【讨论】:

      猜你喜欢
      • 2019-02-09
      • 1970-01-01
      • 1970-01-01
      • 2013-11-01
      • 2015-08-13
      • 1970-01-01
      • 1970-01-01
      • 2014-04-29
      • 1970-01-01
      相关资源
      最近更新 更多