
接着上一篇的总结,ONDragon的第二课。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80
| #define _CRT_SECURE_NO_WARNINGS #include <windows.h> #include <stdio.h> #include "resource.h" char name[1024] = "ONDragon"; //设置用户名、密码 char pass[1024] = "666"; BOOL check(char userName[], char passWord[]) //检测判断用户名和密码是否和设置一样 { if (userName == NULL || passWord == NULL) { return FALSE; } else { if (*userName == *name) { if (*passWord == *pass) { return TRUE; } else { return FALSE; } } else { return FALSE; } } } BOOL CALLBACK MainDlgProc(HWND hDlg, UINT uMsg, WPARAM wParam, LPARAM lParam) { BOOL bRet = FALSE; switch (uMsg) { case WM_CLOSE: { EndDialog(hDlg, 0); break; } case WM_INITDIALOG: { SetWindowPos(hDlg, HWND_NOTOPMOST, 400, 300, 410, 180, SWP_SHOWWINDOW); break; } case WM_COMMAND: switch (LOWORD(wParam)) { case IDC_BUTTON_LOGIN: { char userName[1024]; char passWord[1024]; GetDlgItemText(hDlg, IDC_EDIT_USER, userName, 1024); GetDlgItemText(hDlg, IDC_EDIT_PASS, passWord, 1024); if (check(userName,passWord)) { MessageBox(hDlg, "Login Successful", "Congratulation", MB_OK); //登录成功 } else { MessageBox(hDlg, "Login Failed", "Sorry", MB_OK); //登录失败 } return TRUE; }
} break; }
return bRet; } int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow) { DialogBox(hInstance, MAKEINTRESOURCE(IDD_DIALOG_MAIN), NULL, MainDlgProc); return 0; }
|
这次依旧是登录小程序
本次编译的是 release版本

未破解的

破解后的

载入Ollydebug
这里我们载入OD

和上篇一样,我这里依旧使用的是查找字符串

在这里只能短短的看到 登录失败和登录成功几个字,我们双击其中一个字符串,进行跟踪


我们来简单看下。

1. 简单思考与分析
这两条指令 (cmp)将 ss:[ebp-0x404]的值和0x4F做比较,两个值相减为0,(ZF ,零标志,标明结果为0。真置1,假置0。)
反汇编窗口
这里也就是将第一个字节 与4F 做判断是否非为0。第一个cmp指的是用户名的字符串

那么这里我们不能让下条指令跳转到,登录失败。 第二个cmp指的是密码的字符串

这里同样也是将第一个字节 与4F 做判断是否非为0。

寄存器窗口

2.修改
我们如何不能让他跳转到登录失败呢
这里我们下个断点,在第一个cmp处。也就是判断用户名是否正确的地方。(按F2设置断点)

并且运行程序

键入用户名和密码后,已断在断点处。

选中第一个cmp处,查看内存地址对应键入用户名的字符串 (右键->数据窗口中跟随->内存地址)

我们在数据窗口中可以看到,我们键入的用户名为demon ,第一个字节d 对应的则为64 十六进制 (在ASCLL码表即可找到相应的,其他依次类推)由于在cmp 设置的为bype 一个字节,后门判断 4F也为一个字节,cmp需将其判断为0,则我们也可以将其cmp处的代码 中的0x4F,改为0x64


或将数据窗口的 64 改成4F即可。

第二处 cmp以此类推。
修改完两处之后,我们运行看看,可以成功得到login successful 的弹窗!

3.NOP大法
还有另一种修改方案则是NOP大法。
在cmp处下断点,并将两处cmp 将其NOP掉。
双击CMP 汇编代码 ,将其代码填写为nop

填充nop

nop后

运行后,一样提示得到login successful 的弹窗!

4.修改跳转指令
先上几张跳转指令基础知识图


今天就先看这几个跳转指令,与ZF标志位相关

这里我们依旧还是在cmp处下断点,并运行,执行到断点处

两处jnz 改为 jz 或者je (改成jz 或自动填写je)

以下是debug版本的IDA载入图,破解方法和之前的类似,这里就不再重复多说了,工具和课程视频咋即刻安全网盘即可下载。
