修改值以通过跳转并使用 Radare2 打印消息

逆向工程 雷达2
2021-07-02 02:30:45

我的理解有问题,为什么在修改变量var_4h并通过 jne at 积极传递0x000006c3我仍然看不到消息。我使用radare2

在调试模式下,就在 cmp 之前,我使用: wv \0x5 @rbp-0x4

 52: main ();
│           ; var uint32_t var_4h @ rbp-0x4
│           0x000006b0      55             push rbp
│           0x000006b1      4889e5         mov rbp, rsp
│           0x000006b4      4883ec10       sub rsp, 0x10
│           0x000006b8      c745fc040000.  mov dword [var_4h], 4
│           0x000006bf      837dfc05       cmp dword [var_4h], 5
│       ┌─< 0x000006c3      7518           jne 0x6dd
│       │   0x000006c5      488d35980000.  lea rsi, qword str.You_win  ; 0x764 ; "You win!"
│       │   0x000006cc      488d3d9a0000.  lea rdi, qword [0x0000076d] ; "%s"
│       │   0x000006d3      b800000000     mov eax, 0
│       │   0x000006d8      e883feffff     call sym.imp.printf
│       │   ; CODE XREF from main @ 0x6c3
│       └─> 0x000006dd      b800000000     mov eax, 0
│           0x000006e2      c9             leave
└           0x000006e3      c3             ret

有人可以帮我弄这个吗?我只是想不出我做错了什么。

1个回答

为了复制您的问题,我创建了一个简单的程序:

#include <stdio.h>

int main()
{
  int x = 4;
  if (x == 5)
    printf("You win!\n");
  return 0;
}

接着:

[0x7fb00d000c30]> aaa
[x] Analyze all flags starting with sym. and entry0 (aa)
[x] Analyze function calls (aac)
[x] Analyze len bytes of instructions for references (aar)
[x] Check for objc references
[x] Check for vtables
[TOFIX: aaft can't run in debugger mode.ions (aaft)
[x] Type matching analysis for all functions (aaft)
[x] Propagate noreturn information
[x] Use -AA or aaaa to perform additional experimental analysis.
[0x7fb00d000c30]> dcu main
Continue until 0x004004b2 using 1 bpsize
hit breakpoint at: 4004b2
[0x004004b2]> pdf
            ; DATA XREF from entry0 @ 0x4003fd
            ;-- rax:
            ;-- rip:
┌ 38: int main (int argc, char **argv, char **envp);
│           ; var int64_t var_4h @ rbp-0x4
│           0x004004b2      55             push rbp
│           0x004004b3      4889e5         mov rbp, rsp
│           0x004004b6      4883ec10       sub rsp, 0x10
│           0x004004ba      c745fc040000.  mov dword [var_4h], 4
│           0x004004c1      837dfc05       cmp dword [var_4h], 5
│       ┌─< 0x004004c5      750a           jne 0x4004d1
│       │   0x004004c7      bf64054000     mov edi, str.You_win        ; 0x400564 ; "You win!"
│       │   0x004004cc      e8dffeffff     call sym.imp.puts           ; int puts(const char *s)
│       └─> 0x004004d1      b800000000     mov eax, 0
│           0x004004d6      c9             leave
└           0x004004d7      c3             ret
[0x004004b2]> dcu 0x004004c1
Continue until 0x004004c1 using 1 bpsize
hit breakpoint at: 4004c1
[0x004004c1]> pf d @ rbp-0x4
0x7ffff4c0021c = 4
[0x004004c1]> wv 5 @rbp-0x4
[0x004004c1]> pf d @ rbp-0x4
0x7ffff4c0021c = 5
[0x004004c1]> dc
You win!

需要注意的几点:

  1. 检查你的 write - wv 命令
  2. 还要注意的是,输出显示不出来(在我的情况),如果我不使用\n"you win!\n"字符串(虽然我不知道为什么会这样的确切原因)
  3. 如果您无权访问源代码,请编辑字符串并添加您\n自己。
>iz
nth paddr      vaddr      len size section type  string
―――――――――――――――――――――――――――――――――――――――――――――――――――――――
0   0x00000564 0x00400564 9   9    .rodata ascii You win!
>w You win!\n @0x00400564

(在写入模式下-w)这不是最优雅的方式,但在我的情况下有效。

如果您解决此问题,那么您的程序应该可以正常工作。