吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 4879|回复: 6
收起左侧

[原创] Reversing x64Elf

[复制链接]
Sound 发表于 2016-12-29 00:52
本帖最后由 Sound 于 2016-12-29 00:53 编辑

描述:ReverseMe
这是一个 64bit elf,运行这个Elf文件 ,当程序进行参数执行的时候,输出以下信息
[Asm] 纯文本查看 复制代码
$ ./re
Enter the password: Sound
Incorrect password!

Main function Analysis
[Asm] 纯文本查看 复制代码
.text:00000000004007E8 ; int __cdecl main(int, char **, char **)
.text:00000000004007E8 main            proc near               ; DATA XREF: start+1Do
.text:00000000004007E8
.text:00000000004007E8 s               = byte ptr -110h
.text:00000000004007E8 var_8           = qword ptr -8
.text:00000000004007E8
.text:00000000004007E8                 push    rbp
.text:00000000004007E9                 mov     rbp, rsp
.text:00000000004007EC                 sub     rsp, 110h
.text:00000000004007F3                 mov     rax, fs:28h
.text:00000000004007FC                 mov     [rbp+var_8], rax
.text:0000000000400800                 xor     eax, eax
.text:0000000000400802                 mov     edi, offset format ; "Enter the password: "
.text:0000000000400807                 mov     eax, 0
.text:000000000040080C                 call    _printf
.text:0000000000400811                 mov     rdx, cs:stdin   ; stream
.text:0000000000400818                 lea     rax, [rbp+s]
.text:000000000040081F                 mov     esi, 0FFh       ; n
.text:0000000000400824                 mov     rdi, rax        ; s
.text:0000000000400827                 call    _fgets
.text:000000000040082C                 test    rax, rax
.text:000000000040082F                 jz      short loc_400866
.text:0000000000400831                 lea     rax, [rbp+s]
.text:0000000000400838                 mov     rdi, rax
.text:000000000040083B                 call    sub_4006FD
.text:0000000000400840                 test    eax, eax
.text:0000000000400842                 jnz     short loc_400855
.text:0000000000400844                 mov     edi, offset s   ; "Nice!"
.text:0000000000400849                 call    _puts
.text:000000000040084E                 mov     eax, 0
.text:0000000000400853                 jmp     short loc_40086B
.text:0000000000400855 ; ---------------------------------------------------------------------------
.text:0000000000400855
.text:0000000000400855 loc_400855:                             ; CODE XREF: main+5Aj
.text:0000000000400855                 mov     edi, offset aIncorrectPassw ; "Incorrect password!"
.text:000000000040085A                 call    _puts
.text:000000000040085F                 mov     eax, 1
.text:0000000000400864                 jmp     short loc_40086B
.text:0000000000400866 ; ---------------------------------------------------------------------------
.text:0000000000400866
.text:0000000000400866 loc_400866:                             ; CODE XREF: main+47j
.text:0000000000400866                 mov     eax, 0

在0x400827处,开始询问用户输入的密码(调用_fgets)并传递到0x40083B处的sub_4006FD 函数
2.png
如果这个函数返回的值非零,则密码无效,程序将输出字符串“Incorrect password!”。 反之,它会显示Nice!
Analysis Sub_4006FD
[Asm] 纯文本查看 复制代码
.text:00000000004006FD Pw_Check        proc near               ; CODE XREF: main+53p
.text:00000000004006FD
.text:00000000004006FD var_38          = qword ptr -38h
.text:00000000004006FD var_24          = dword ptr -24h
.text:00000000004006FD var_20          = qword ptr -20h
.text:00000000004006FD var_18          = qword ptr -18h
.text:00000000004006FD var_10          = qword ptr -10h
.text:00000000004006FD
.text:00000000004006FD                 push    rbp
.text:00000000004006FE                 mov     rbp, rsp
.text:0000000000400701                 mov     [rbp+var_38], rdi
.text:0000000000400705                 mov     [rbp+var_24], 0
.text:000000000040070C                 mov     [rbp+var_20], offset aDufhbmf ; "Dufhbmf"
.text:0000000000400714                 mov     [rbp+var_18], offset aPgImos ; "pG`imos"
.text:000000000040071C                 mov     [rbp+var_10], offset aEwuglpt ; "ewUglpt"
.text:0000000000400724                 mov     [rbp+var_24], 0
.text:000000000040072B                 jmp     short loc_40079B
.text:000000000040072D ; ---------------------------------------------------------------------------
.text:000000000040072D
.text:000000000040072D loc_40072D:                             ; CODE XREF: Pw_Check+A2j
.text:000000000040072D                 mov     ecx, [rbp+var_24]
.text:0000000000400730                 mov     edx, 55555556h
.text:0000000000400735                 mov     eax, ecx
.text:0000000000400737                 imul    edx
.text:0000000000400739                 mov     eax, ecx
.text:000000000040073B                 sar     eax, 1Fh
.text:000000000040073E                 sub     edx, eax
.text:0000000000400740                 mov     eax, edx
.text:0000000000400742                 add     eax, eax
.text:0000000000400744                 add     eax, edx
.text:0000000000400746                 sub     ecx, eax
.text:0000000000400748                 mov     edx, ecx
.text:000000000040074A                 movsxd  rax, edx
.text:000000000040074D                 mov     rsi, [rbp+rax*8+var_20]
.text:0000000000400752                 mov     ecx, [rbp+var_24]
.text:0000000000400755                 mov     edx, 55555556h
.text:000000000040075A                 mov     eax, ecx
.text:000000000040075C                 imul    edx
.text:000000000040075E                 mov     eax, ecx
.text:0000000000400760                 sar     eax, 1Fh
.text:0000000000400763                 sub     edx, eax
.text:0000000000400765                 mov     eax, edx
.text:0000000000400767                 add     eax, eax
.text:0000000000400769                 cdqe
.text:000000000040076B                 add     rax, rsi
.text:000000000040076E                 movzx   eax, byte ptr [rax]
.text:0000000000400771                 movsx   edx, al
.text:0000000000400774                 mov     eax, [rbp+var_24]
.text:0000000000400777                 movsxd  rcx, eax
.text:000000000040077A                 mov     rax, [rbp+var_38]
.text:000000000040077E                 add     rax, rcx
.text:0000000000400781                 movzx   eax, byte ptr [rax]
.text:0000000000400784                 movsx   eax, al
.text:0000000000400787                 sub     edx, eax
.text:0000000000400789                 mov     eax, edx
.text:000000000040078B                 cmp     eax, 1
.text:000000000040078E                 jz      short loc_400797
.text:0000000000400790                 mov     eax, 1
.text:0000000000400795                 jmp     short loc_4007A6
.text:0000000000400797 ; ---------------------------------------------------------------------------
.text:0000000000400797
.text:0000000000400797 loc_400797:                             ; CODE XREF: Pw_Check+91j
.text:0000000000400797                 add     [rbp+var_24], 1
.text:000000000040079B
.text:000000000040079B loc_40079B:                             ; CODE XREF: Pw_Check+2Ej
.text:000000000040079B                 cmp     [rbp+var_24], 0Bh
.text:000000000040079F                 jle     short loc_40072D
.text:00000000004007A1                 mov     eax, 0
.text:00000000004007A6
.text:00000000004007A6 loc_4007A6:                             ; CODE XREF: Pw_Check+98j
.text:00000000004007A6                 pop     rbp
.text:00000000004007A7                 retn
.text:00000000004007A7 Pw_Check        endp

这个函数操作用户输入的密码,并将其与基于3个字符串 ("Dufhbmf"  "pG`imos"  "ewUglpt") 的计算的结果进行比较. 使用Pseudo-code Plugin (F5)
[Asm] 纯文本查看 复制代码
signed __int64 __fastcall sub_4006FD(__int64 a1)
{
  signed int i; // [sp+14h] [bp-24h]@1
  const char *v3; // [sp+18h] [bp-20h]@1
  const char *v4; // [sp+20h] [bp-18h]@1
  const char *v5; // [sp+28h] [bp-10h]@1

  v3 = "Dufhbmf";
  v4 = "pG`imos";
  v5 = "ewUglpt";
  for ( i = 0; i <= 11; ++i )
  {
    if ( (&v3)[8 * (i % 3)][2 * (i / 3)] - *(_BYTE *)(i + a1) != 1 )
      return 1LL;
  }
  return 0LL;
}

现在可以很直观的了解函数的流程,在3个字符串的字符之间轮流(模数计数器),然后来计算ELF预设的密码字符。
Done:
先对3个字符串进行ASCII hex转换,
Dufhbmf0x44, 0x75, 0x66, 0x68, 0x62, 0x6D, 0x66
pG`imos 0x70, 0x47, 0x60, 0x69, 0x6D, 0x6F, 0x73
ewUglpt 0x65, 0x77, 0x55, 0x67, 0x6C, 0x70, 0x74    code python scr
[Asm] 纯文本查看 复制代码
#!/usr/bin/env python3
s = [[0x44, 0x75, 0x66, 0x68, 0x62, 0x6D, 0x66],
    [0x70, 0x47, 0x60, 0x69, 0x6D, 0x6F, 0x73],
    [0x65, 0x77, 0x55, 0x67, 0x6C, 0x70, 0x74]]
flag = []
for i in range(12):
    flag.append(s[i%3][2*(i//3)]-1)
print(''.join([chr(i) for i in flag]))

输出 Flag:Code_Talkers
[Asm] 纯文本查看 复制代码
$ ./rr
Enter the password: Code_Talkers
Nice!

re.7z

1.96 KB, 下载次数: 11, 下载积分: 吾爱币 -1 CB

免费评分

参与人数 5威望 +2 热心值 +5 收起 理由
yufan1123 + 1 热心回复!
Hmily + 2 + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!
wcj1997 + 1 已答复!
palard + 1 欢迎分析讨论交流,吾爱破解论坛有你更精彩!
Anonyomus + 1 感谢发布原创作品,吾爱破解论坛因你更精彩!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

palard 发表于 2016-12-29 01:13
前排围观。
小锤子起钉儿 发表于 2016-12-29 01:32
jason_tingna 发表于 2016-12-29 03:22 来自手机
tianlang4999 发表于 2016-12-29 09:28
我这小白表示看不懂
快乐的小飞侠 发表于 2016-12-29 13:50
小白看不懂啊
Hmily 发表于 2016-12-29 17:38
Tutorial-Reversing x64Elf
http://www.52pojie.cn/thread-568767-1-1.html
(出处: 吾爱破解论坛)


对应的是这个视频教程?
旧忆如梦 发表于 2016-12-29 17:45
表示完全看不懂,支持一下
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2024-11-17 10:44

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表