暴力破解

用控制台写一个登录页面,密码为6位数字,再写一个暴力破解的程序

// client.cpp
#include <iostream>
#include <Windows.h>
#include <string>

using namespace std;

int main()
{
    string pwd;
    while (1)
    {
        cout << "请输入密码:";
        cin >> pwd;
        if (pwd == "000123")
        {
            cout << "登录成功" << endl;
            break;
        }
        cout << "密码错误" << endl;
    }

    cout << endl;
    cout << "          1.注册 " << endl;
    cout << "          2.管理 " << endl;
    cout << "          3.查询 " << endl;
    cout << "          4.删除 " << endl;
    cout << endl;

    system("pause");
    return 0;
}

image

// crack.cpp
#include <iostream>
#include <Windows.h>
#include <string>

using namespace std;

int main()
{
    int pwdDict[10] = { '0','1','2','3','4','5','6','7','8','9' };  // 密码字典
    char pwd[7] = { 0 };

    for (int p1 = 0; p1 < 10; p1++)
    {
        for (int p2 = 0; p2 < 10; p2++)
        {
            for (int p3 = 0; p3 < 10; p3++)
            {
                for (int p4 = 0; p4 < 10; p4++)
                {
                    for (int p5 = 0; p5 < 10; p5++)
                    {
                        for (int p6 = 0; p6 < 10; p6++)
                        {
                            pwd[0] = pwdDict[p1];
                            pwd[1] = pwdDict[p2];
                            pwd[2] = pwdDict[p3];
                            pwd[3] = pwdDict[p4];
                            pwd[4] = pwdDict[p5];
                            pwd[5] = pwdDict[p6];
                            pwd[6] = '\0';

                            cout << pwd << endl;
                        }
                    }
                }
            }
        }
    }

    system("pause");
    return 0;
}

image
这里一直在循环输出

我们把两个exe放到同一个目录下
image

用命令行进入这两个exe所在的目录下,输入crack.exe | client.exe
image
image

如果页面中文显示不出来,可以用chcp查看一下当前代码页的编码,如果不是936可以用chcp 936改成936就能显示中文了
image

posted @ 2022-04-08 12:13  荒年、  阅读(71)  评论(0编辑  收藏  举报