好友
阅读权限 40
听众
最后登录 1970-1-1
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 函数
如果这个函数返回的值非零,则密码无效,程序将输出字符串“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转换,
Dufhbmf 0x44, 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
免费评分
查看全部评分