首页
社区
课程
招聘
[原创]CTF2018-第二题-半加器
2018-12-4 17:06 2563

[原创]CTF2018-第二题-半加器

2018-12-4 17:06
2563
一、分析工具
     IDA、OD

二、分析过程
       1、双击运行,发现有个输入序列号的提示: "Please Input:"
       2、打开IDA,把exe拖进去shift+F12查看字符串,根据字符串的交叉引用定位到提示输入系列号的地址在:0x004A19D8
           
.text:004A19D8                 push    offset aPleaseInput ; "Please Input:"
.text:004A19DD                 push    offset unk_5F31E0
.text:004A19E2                 call    sub_48CD46
.text:004A19E7                 add     esp, 8
.text:004A19EA                 push    1Eh
.text:004A19EC                 push    offset unk_5F3068
.text:004A19F1                 push    offset aS       ; "%s"
.text:004A19F6                 call    sub_48C0EE
.text:004A19FB                 add     esp, 0Ch
.text:004A19FE                 push    offset unk_5F3068
.text:004A1A03                 call    j_strlen_
.text:004A1A08                 add     esp, 4
.text:004A1A0B                 mov     [ebp+var_8], eax
.text:004A1A0E                 cmp     [ebp+var_8], 1Eh
.text:004A1A12                 jg      short loc_4A1A1A;序列号的长度大于0x1E,输入错误
.text:004A1A14                 cmp     [ebp+var_8], 0Ah
.text:004A1A18                 jge     short loc_4A1A30;序列号的长度大于等于0x0A,继续

       3、根据第二步的长度判断,符合长度限定之后来到地址:0x4A1A30,并找到序列号生成算法的函数在sub_48D3A4
.text:004A1A30 loc_4A1A30:                             ; CODE XREF: main+68j
.text:004A1A30                 push    offset unk_5F3068
.text:004A1A35                 push    1Eh
.text:004A1A37                 mov     eax, dword_5F3088
.text:004A1A3C                 push    eax
.text:004A1A3D                 call    sub_48E5BF;拷贝序列号到地址0x5F3068
.text:004A1A42                 add     esp, 0Ch
.text:004A1A45                 mov     eax, 1
.text:004A1A4A                 imul    ecx, eax, 7
.text:004A1A4D                 mov     edx, dword_5F3088
.text:004A1A53                 movsx   eax, byte ptr [edx+ecx]
.text:004A1A57                 cmp     eax, 41h
.text:004A1A5A                 jz      short loc_4A1A70;判断序号的第8位是不是'A',如果不是则失败
.text:004A1A5C                 push    offset unk_5B25CC
.text:004A1A61                 call    sub_48A6DB
.text:004A1A66                 add     esp, 4
.text:004A1A69                 push    0
.text:004A1A6B                 call    sub_48C274
.text:004A1A70
.text:004A1A70 loc_4A1A70:                             ; CODE XREF: main+AAj
.text:004A1A70                 mov     eax, dword_5F3088
.text:004A1A75                 push    eax
.text:004A1A76                 call    sub_48D3A4;序列号生成算法
.text:004A1A7B                 add     esp, 4
.text:004A1A7E
.text:004A1A7E loc_4A1A7E:                             ; CODE XREF: main+7Ej
.text:004A1A7E                 xor     eax, eax

        4、分析序列号生成算法 : sub_48D3A4 ,这个算法分两个步骤
              1)、把序列号的第8位‘A’替换成'#'
              2)、把替换好的序列号逐位与0x1F异或,生成新的序列号
.text:0049DBD0 serial_generate proc near               ; CODE XREF: j_serial_generatej
.text:0049DBD0
.text:0049DBD0 var_CC          = byte ptr -0CCh
.text:0049DBD0 var_8           = dword ptr -8
.text:0049DBD0 arg_0           = dword ptr  8
.text:0049DBD0
.text:0049DBD0                 push    ebp
.text:0049DBD1                 mov     ebp, esp
.text:0049DBD3                 sub     esp, 0CCh
.text:0049DBD9                 push    ebx
.text:0049DBDA                 push    esi
.text:0049DBDB                 push    edi
.text:0049DBDC                 lea     edi, [ebp+var_CC]
.text:0049DBE2                 mov     ecx, 33h
.text:0049DBE7                 mov     eax, 0CCCCCCCCh
.text:0049DBEC                 rep stosd
.text:0049DBEE                 mov     ecx, offset unk_5F6007
.text:0049DBF3                 call    sub_48D7B4
.text:0049DBF8                 mov     eax, 1
.text:0049DBFD                 imul    ecx, eax, 7
.text:0049DC00                 mov     edx, [ebp+arg_0]
.text:0049DC03                 mov     byte ptr [edx+ecx], 23h;把序列号的第8位'A'替换成'#'
.text:0049DC07                 mov     [ebp+var_8], 0
.text:0049DC0E                 jmp     short loc_49DC19
.text:0049DC10 ; ---------------------------------------------------------------------------
.text:0049DC10
.text:0049DC10 loc_49DC10:                             ; CODE XREF: serial_generate+6Ej
.text:0049DC10                 mov     eax, [ebp+var_8]
.text:0049DC13                 add     eax, 1
.text:0049DC16                 mov     [ebp+var_8], eax
.text:0049DC19
.text:0049DC19 loc_49DC19:                             ;这是一个循环,把序列号的每一位与0x1F异或
.text:0049DC19                 mov     eax, [ebp+arg_0]
.text:0049DC1C                 push    eax
.text:0049DC1D                 call    j_strlen_
.text:0049DC22                 add     esp, 4
.text:0049DC25                 cmp     [ebp+var_8], eax
.text:0049DC28                 jnb     short loc_49DC40
.text:0049DC2A                 mov     eax, [ebp+arg_0]
.text:0049DC2D                 add     eax, [ebp+var_8]
.text:0049DC30                 movsx   ecx, byte ptr [eax]
.text:0049DC33                 xor     ecx, 1Fh
.text:0049DC36                 mov     edx, [ebp+arg_0]
.text:0049DC39                 add     edx, [ebp+var_8]
.text:0049DC3C                 mov     [edx], cl
.text:0049DC3E                 jmp     short loc_49DC10
.text:0049DC40 ; ---------------------------------------------------------------------------
.text:0049DC40
.text:0049DC40 loc_49DC40:                             ; CODE XREF: serial_generate+58j
.text:0049DC40                 mov     eax, [ebp+arg_0]
.text:0049DC43                 pop     edi
.text:0049DC44                 pop     esi
.text:0049DC45                 pop     ebx
.text:0049DC46                 add     esp, 0CCh
.text:0049DC4C                 cmp     ebp, esp
.text:0049DC4E                 call    sub_48D935
.text:0049DC53                 mov     esp, ebp
.text:0049DC55                 pop     ebp
.text:0049DC56                 retn
.text:0049DC56 serial_generate endp
      
       5、根据上一步异或产生的序列号,在首地址处下一个内存访问的硬件访问断点,定位到序列号比较函数
.text:00547DE0 compare_serial  proc near               ; CODE XREF: j_compare_serialj
.text:00547DE0
.text:00547DE0 arg_0           = dword ptr  4
.text:00547DE0 arg_4           = dword ptr  8
.text:00547DE0
.text:00547DE0                 mov     edx, [esp+arg_0]
.text:00547DE4                 mov     ecx, [esp+arg_4]
.text:00547DE8                 test    edx, 3
.text:00547DEE                 jnz     short loc_547E30
.text:00547DF0
.text:00547DF0 loc_547DF0:                             ; CODE XREF: compare_serial+3Cj
.text:00547DF0                                         ; compare_serial+6Ej ...
.text:00547DF0                 mov     eax, [edx]
.text:00547DF2                 cmp     al, [ecx]
.text:00547DF4                 jnz     short loc_547E28
.text:00547DF6                 test    al, al
.text:00547DF8                 jz      short loc_547E20
.text:00547DFA                 cmp     ah, [ecx+1]
.text:00547DFD                 jnz     short loc_547E28
.text:00547DFF                 test    ah, ah
.text:00547E01                 jz      short loc_547E20
.text:00547E03                 shr     eax, 10h
.text:00547E06                 cmp     al, [ecx+2]
.text:00547E09                 jnz     short loc_547E28
.text:00547E0B                 test    al, al
.text:00547E0D                 jz      short loc_547E20
.text:00547E0F                 cmp     ah, [ecx+3]
.text:00547E12                 jnz     short loc_547E28
.text:00547E14                 add     ecx, 4
.text:00547E17                 add     edx, 4
.text:00547E1A                 test    ah, ah
.text:00547E1C                 jnz     short loc_547DF0
.text:00547E1E                 mov     edi, edi
.text:00547E20
.text:00547E20 loc_547E20:                             ; CODE XREF: compare_serial+18j
.text:00547E20                                         ; compare_serial+21j ...
.text:00547E20                 xor     eax, eax
.text:00547E22                 retn
.text:00547E23 ; ---------------------------------------------------------------------------
.text:00547E23                 jmp     short loc_547E28
.text:00547E23 ; ---------------------------------------------------------------------------
.text:00547E25                 align 4
.text:00547E28
.text:00547E28 loc_547E28:                             ; CODE XREF: compare_serial+14j
.text:00547E28                                         ; compare_serial+1Dj ...
.text:00547E28                 sbb     eax, eax
.text:00547E2A                 or      eax, 1
.text:00547E2D                 retn
.text:00547E2D ; ---------------------------------------------------------------------------
.text:00547E2E                 align 10h
.text:00547E30
.text:00547E30 loc_547E30:                             ; CODE XREF: compare_serial+Ej
.text:00547E30                 test    edx, 1
.text:00547E36                 jz      short loc_547E50
.text:00547E38                 mov     al, [edx]
.text:00547E3A                 add     edx, 1
.text:00547E3D                 cmp     al, [ecx]
.text:00547E3F                 jnz     short loc_547E28
.text:00547E41                 add     ecx, 1
.text:00547E44                 test    al, al
.text:00547E46                 jz      short loc_547E20
.text:00547E48                 test    edx, 2
.text:00547E4E                 jz      short loc_547DF0
.text:00547E50
.text:00547E50 loc_547E50:                             ; CODE XREF: compare_serial+56j
.text:00547E50                 mov     ax, [edx]
.text:00547E53                 add     edx, 2
.text:00547E56                 cmp     al, [ecx]
.text:00547E58                 jnz     short loc_547E28
.text:00547E5A                 test    al, al
.text:00547E5C                 jz      short loc_547E20
.text:00547E5E                 cmp     ah, [ecx+1]
.text:00547E61                 jnz     short loc_547E28
.text:00547E63                 test    ah, ah
.text:00547E65                 jz      short loc_547E20
.text:00547E67                 add     ecx, 2
.text:00547E6A                 jmp     short loc_547DF0
.text:00547E6A compare_serial  endp
      发现是异或之后的结果跟字符串 urj}pux<}n{iqyrh 比较,相同则ok
      所以只需要把 urj}pux<}n{iqyrh 与0x17异或,然后把第8个序列号改成‘A’即是最终的序列号:jmubojgAbqdvnfmw



[培训]内核驱动高级班,冲击BAT一流互联网大厂工作,每周日13:00-18:00直播授课

最后于 2018-12-4 20:46 被MTRush编辑 ,原因:
收藏
点赞1
打赏
分享
最新回复 (0)
游客
登录 | 注册 方可回帖
返回