【问题标题】:EggHunter not finding the egg, causing infinite loopEggHunter 找不到彩蛋,导致死循环
【发布时间】:2015-09-02 21:21:00
【问题描述】:

EggHunter 找不到彩蛋(32 位),导致无限循环 我有 1 个例子,打印出 We found the egg!哪个有效,另一个打印Hello egg!这不起作用。

两者都使用同一个鸡蛋 0x90f890f9

我认为问题可能出在: cmp dword [ecx], 0x90f890f9 ;标记

这里是c代码:

#include <stdio.h>
#include <string.h>
#include <stdlib.h>

unsigned char egghunter[21];

void main()
{

/* works OK (We found the egg!)

"\x90\xf9\x90\xf8\x90\x68\x21\x0a\x0a\x0a\x68\x20\x65\x67\x67\x68\x20\x74\x68"
"\x65\x68\x6f\x75\x6e\x64\x68\x57\x65\x20\x66\x31\xc9\xb1\x12\x51\xb8"
"\x11\x11\x51\x08\x50\x31\xc0\x50\x54\x51\x89\xe6\x83\xc6\x14\x03\x74"
"\x24\x10\x2b\x34\x24\x56\x89\xf1\xeb\x1c\xeb\x0c\x59\x59\xe2\xe8\x31"
"\xdb\x31\xc0\xb0\x01\xcd\x80\x31\xc0\xb0\xa2\x8d\x5c\x24\x0c\x31\xc9"
"\xcd\x80\xeb\xe6\x31\xd2\xb2\x01\x31\xdb\xb3\x01\x31\xc0\xb0\x04\xcd"
"\x80\xeb\xd4";

*/

/* gives an infinite loop (suppose to print Hello egg!)

"\x90\xf9\x90\xf8\x90\xeb\x17\x31\xc0\xb0\x04\x31\xdb\xb3\x01\x59\x31\xd2\xb2\x0b\xcd\x80"
"\x31\xc0\xb0\x01\x31\xdb\xcd\x80\xe8\xe4\xff\xff\xff\x48\x65\x6c\x6c"
"\x6f\x20\x65\x67\x67\x21\x0a";

*/

unsigned char shellcode[256] = \
"\x90\xf9\x90\xf8\x90\xeb\x17\x31\xc0\xb0\x04\x31\xdb\xb3\x01\x59\x31\xd2\xb2\x0b\xcd\x80"
"\x31\xc0\xb0\x01\x31\xdb\xcd\x80\xe8\xe4\xff\xff\xff\x48\x65\x6c\x6c"
"\x6f\x20\x65\x67\x67\x21\x0a";


printf("Shellcode: %d bytes\n", strlen(shellcode));

strcpy(egghunter,"\xeb\x0e\x59\x83\xe9\x17\x81\x39\xf9\x90\xf8\x90\xe0\xf8\xff\xe1\xe8\xed\xff\xff\xff");

printf("Egghunter: %d bytes\n", strlen(egghunter));

int (*ret)() = (int(*)())egghunter;

ret();
}

这是猎蛋者代码:

global _start
section .text
_start:
  jmp     call_egghunter
egghunter:
  pop     ecx                 ; save addr ptr
  sub     ecx, 23             ; move addr ptr back
next:
  cmp     dword [ecx], 0x90f890f9  ; marker
  loopnz  next                ; dec ecx, jump
  jmp ecx                     ; jump to shellcode
call_egghunter:
  call    egghunter

不起作用的 hello egg 代码是: 全局_start

section .text

_start:

    jmp short call_shellcode 


shellcode: 

    ; print hello world on the screen

    xor eax, eax
    mov al, 0x4

    xor ebx, ebx
    mov bl, 0x1

    pop ecx

    xor edx, edx
    mov dl, 11

    int 0x80


    ; exit the program gracefully

    xor eax, eax
    mov al, 0x1

    xor ebx, ebx

    int 0x80

call_shellcode:

    call shellcode
    message: db "Hello egg!", 0xA

【问题讨论】:

    标签: c assembly nasm


    【解决方案1】:

    您的egghunter 是一个位于数据部分的全局变量。您的 shellcode 是一个存在于堆栈中的局部变量。您从egghunter 向下搜索标记,但是Linux 上的通常布局(由于int 0x80,我假设您使用它)将堆栈置于数据部分之上。因此,您的搜索方向是错误的,无论您找到什么都不是您的shellcode。实际上,它是执行strcpy(egghunter, literal) 的代码的一部分:

       0x80494fe:   movl   $0x90f890f9,0x80497d0
       0x8049508:   movl   $0xe1fff8e0,0x80497d4
       0x8049512:   movl   $0xffffede8,0x80497d8
       0x804951c:   movw   $0xff,0x80497dc
       0x8049525:   movl   $0x80497c8,(%esp)
    

    学习使用调试器,这样您就可以单步调试代码并查看它在做什么。

    【讨论】:

    • 我在gdb中看,我在看ecx,但这似乎并没有说明什么我在gdb中还应该看什么?
    • 你的shellcode的地址,所以你可以看到它在看错地方。
    猜你喜欢
    • 1970-01-01
    • 2021-05-06
    • 2021-03-14
    • 2015-06-08
    • 2021-09-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-13
    相关资源
    最近更新 更多