【问题标题】:How to discover a password in a binary file如何在二进制文件中发现密码
【发布时间】:2017-03-26 14:13:35
【问题描述】:

我最近收到了一个包含二进制可执行文件的谜题,该谜题的目的是发现隐藏在二进制文件的十六进制转储中的密码。我试图关注this guideline,但我没有想法继续我已经达到的点。这是具有逻辑的代码部分:

#h begins the printf "password: "

4006dc: bf 14 08 40 00          mov    $0x400814,%edi
4006e1: b8 00 00 00 00          mov    $0x0,%eax
#h sets %eax to NULL

4006e6: e8 a5 fe ff ff          callq  400590 <printf@plt>
4006eb: 48 8b 15 6e 09 20 00    mov    0x20096e(%rip),%rdx        # 601060 <stdin@@GLIBC_2.2.5>
4006f2: 48 8d 45 b0             lea    -0x50(%rbp),%rax
#h probably the address of the string "password: "

4006f6: be 32 00 00 00          mov    $0x32,%esi
4006fb: 48 89 c7                mov    %rax,%rdi
4006fe: e8 ad fe ff ff          callq  4005b0 <fgets@plt>
#h calling the fgets function, so here we know which register is being used for storing the input

400703: c7 45 ac 00 00 00 00    movl   $0x0,-0x54(%rbp)
#h makes mem[rbp-84] = NULL

40070a: c7 45 a8 00 00 00 00    movl   $0x0,-0x58(%rbp)
#h makes mem[rpb-88] = NULL

400711: eb 27                   jmp    40073a <__gmon_start__@plt+0x17a>
#h jumps unconditionally to the pc address 40073a

400713: 8b 45 a8                mov    -0x58(%rbp),%eax
400716: 48 98                   cltq
400718: 0f b6 44 05 b0          movzbl -0x50(%rbp,%rax,1),%eax
40071d: 0f be d0                movsbl %al,%edx
400720: 8b 45 a8                mov    -0x58(%rbp),%eax
400723: 48 98                   cltq
400725: 0f b6 44 05 b0          movzbl -0x50(%rbp,%rax,1),%eax
40072a: 0f be c0                movsbl %al,%eax
40072d: 89 c1                   mov    %eax,%ecx
#h ecx loop counter

40072f: d3 e2                   shl    %cl,%edx
400731: 89 d0                   mov    %edx,%eax
#h moves edx to eax

400733: 31 45 ac                xor    %eax,-0x54(%rbp)
#h do a xor between eax and -0x54(rbp)

400736: 83 45 a8 01             addl   $0x1,-0x58(%rbp)

#h pc address 40073a is below here
40073a: 8b 45 a8                mov    -0x58(%rbp),%eax
40073d: 48 63 d8                movslq %eax,%rbx
400740: 48 8d 45 b0             lea    -0x50(%rbp),%rax
#h register rax receives the mem[rbp-80] (first local variable)

400744: 48 89 c7                mov    %rax,%rdi
400747: e8 24 fe ff ff          callq  400570 <strlen@plt>
40074c: 48 39 c3                cmp    %rax,%rbx
40074f: 72 c2                   jb     400713 <__gmon_start__@plt+0x153>
#h if %rax < %rdi, jump to pc = 400713

400751: 81 7d ac 62 02 49 0d    cmpl   $0xd490262,-0x54(%rbp)
#here it compares the 0xd490262 memory address with mem[rbp-84], so I guess that the -0x54(%rbp) contains the string we want, but where???

400758: 75 0c                   jne    400766 <__gmon_start__@plt+0x1a6>
#h here it does the jump if not equal, so the contents we want is on $0xd490262

#h WELL DONE!
40075a: bf 1f 08 40 00          mov    $0x40081f,%edi
40075f: e8 fc fd ff ff          callq  400560 <puts@plt>
400764: eb 0a                   jmp    400770 <__gmon_start__@plt+0x1b0>
#h wrong password
400766: bf 2b 08 40 00          mov    $0x40082b,%edi
40076b: e8 f0 fd ff ff          callq  400560 <puts@plt>
400770: 48 8b 4d e8             mov    -0x18(%rbp),%rcx
400774: 64 48 33 0c 25 28 00    xor    %fs:0x28,%rcx
40077b: 00 00

注意:我不知道我所有的 cmets 是否正确,所以请不要相信 100%。

所以,我分析了这个文件 2 天试图得到一个想法,但我认为我走到了死胡同。

以防万一,二进制执行:

$./binary
$password: (fgets function in here)
$wrong password!

谁能给我一个提示?

【问题讨论】:

  • 尝试编写与您的汇编代码执行相同操作的 C 代码。
  • @FUZxxl 我已经尝试过这样做,但我认为二进制文件的作者使用了与我完全不同的逻辑。二进制可执行文件的 hexdump 甚至无法接近 :(
  • 您编写的近似此代码的 C 代码不太可能产生相同的程序集。行为应该匹配,而不是程序集。

标签: assembly passwords x86-64 reverse-engineering elf


【解决方案1】:

由于这是某种crackme,可能某些部分只是诱饵或红鲱鱼,所以最好学习如何有效地使用调试器,例如使用断点、搜索内存地址范围等。

从获取您的字符串并将其保存到应用程序缓冲区的部分开始跟踪,跟踪哪些指令正在操作您的输入字符串,找到如何将您的输入与正确密码进行比较的方法。

从外观上看,我猜密码是常量 $0xd490262,因为它与 [rbp-0x54] 中的值进行比较,所以如果 [rbp-0x54] 包含 $0xd490262,那么比较后的 jne 将不会跳转.从而打印好男孩的消息。

【讨论】:

  • 当您说“密码是常量 $0xd490262”时,您的意思是字符串“$0xd490262”或它的十进制数 222888546?
  • 我的意思是,密码是一个硬编码值,其十六进制值为 0d490262h,因此来自用户的输入值必须以该值结尾或具有该 4 字节值,以便它可以通过,但这些值不是“可键入”字符?,所以我猜测某些东西正在操纵输入值,在反汇编中很难破译,使用调试器在运行时检查它以进一步分析正在发生的事情。
猜你喜欢
  • 1970-01-01
  • 2015-08-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-01-16
  • 1970-01-01
  • 2018-10-30
  • 1970-01-01
相关资源
最近更新 更多