黑客管理系统

#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <stdio.h>
#include <string>
#include <Windows.h>
#include <conio.h>
#include "hacker.h"

#define WIDTH 40
#define HEIGHT 15
using namespace std;
void showMenu();

// 输入密码
void inputPwd(char pwd[], int size)
{
    char c = 0;
    int i = 0;

    while (1)
    {
        c = _getch();
        if (c == '\r' || i >= size)
        {
            break;
        }
        pwd[i++] = c;
        cout << '*';
    }
    pwd[i] = '\0';

    cout << endl;
}

// 登录
void login()
{
    string name;
    char pwd[32] = { 0 };

    while (1)
    {
        cout << "账号:";
        cin >> name;
        cout << "密码:";
        //cin >> pwd;
        inputPwd(pwd, sizeof(pwd));

        if (name == "admin" && !strcmp(pwd, "123456"))
        {
            // 显示菜单
            showMenu();
            break;
        }
        else
        {
            system("cls");
            cout << "账号或密码错误,请重新输入" << endl;
        }
    }
}

// 居中显示
void printInMiddle(string str)
{
    // 计算打印空格数
    int leftSpace = (WIDTH - str.length()) / 2;
    for (int i = 0; i < leftSpace; i++)
    {
        cout << " ";
    }
    cout << str << endl;
}

// 显示菜单
void showMenu()
{
    int maxMenu = 0;
    string menu[] = {
        "1.网站404攻击",
        "2.网站篡改攻击",
        "3.网站攻击修复",
        "4.查看攻击记录",
        "5.退出"
    };

    // 计算菜单最大长度
    int menuCount = sizeof(menu) / sizeof(menu[0]);
    for (int i = 0; i < menuCount; i++)
    {
        if (maxMenu < menu[i].length())
        {
            maxMenu = menu[i].length();
        }
    }

    // 计算打印空格数量
    int leftSpace = (WIDTH - maxMenu) / 2;

    // 打印菜单
    printInMiddle("菜单");
    for (int i = 0; i < menuCount; i++)
    {
        for (int j = 0; j < leftSpace; j++)
        {
            cout << " ";
        }
        cout << menu[i] << endl;
    }
}

// 选择菜单功能
int menuChoise()
{
    int index;
    cout << "请输入功能序号:";
    while (1)
    {
        cin >> index;
        if (cin.fail())
        {
            cin.clear();
            cin.ignore();
            system("cls");
            showMenu();
            cout << "无效输入,请重新输入:";
        }
        else if (index < 1 || index >5)
        {
            system("cls");
            showMenu();
            cout << "无效输入,请重新输入:";
        }
        else
        {
            return index;
        }
    }
}

// 初始化
void init()
{
    // 把控制台初始化为固定长度
    char cmd[128] = { 0 };
    sprintf(cmd, "mode con cols=%d lines=%d", WIDTH, HEIGHT);
    system(cmd);
}

// 网站404攻击
void attack404()
{
    char id[64] = { 0 };           // 网站id
    char response[1024] = { 0 };   // 攻击返回结果

    cout << "请输入你要404攻击的网站id:";
    scanf("%s", id);

    cout << "正在进行404攻击..." << endl;
    hk_404(id, response);
    string strRet = UTF8ToGBK(response);
    cout << strRet << endl;
}

// 网站篡改攻击
void falsifyAttack()
{
    char id[64] = { 0 };           // 网站id
    char response[1024] = { 0 };   // 攻击返回结果
    string attackText;

    cout << "请输入你要篡改的网站id:";
    scanf("%s", id);
    cout << "请输入你要篡改的内容:";
    cin >> attackText;

    cout << "正在进行网站篡改攻击..." << endl;
    GBKToUTF8(attackText);
    hk_tamper(id, (char*)attackText.c_str(), response);

    string strRet = UTF8ToGBK(response);
    cout << strRet << endl;
}

// 网站攻击修复
void attackRestore()
{
    char id[64] = { 0 };           // 网站id
    char response[1024] = { 0 };   // 攻击返回结果

    cout << "请输入你要修复的网站id:";
    scanf("%s", id);

    cout << "正在进行网站修复..." << endl;
    hk_restore(id, response);
    string strRet = UTF8ToGBK(response);
    cout << strRet << endl;
}

// 网站攻击记录
void attackRecord()
{
    char id[64] = { 0 };           // 网站id
    char response[1024] = { 0 };   // 攻击返回结果

    cout << "请输入你查看攻击记录的网站id:";
    scanf("%s", id);

    cout << "正在进行查看攻击记录..." << endl;
    hk_record(id, response);
    string strRet = UTF8ToGBK(response);
    cout << strRet << endl;
}

int main()
{
    init();
    login();
    while (1)
    {
        system("cls");
        showMenu();
        switch (menuChoise())
        {
        case 1:
            attack404();
            system("pause");
            break;
        case 2:
            falsifyAttack();
            system("pause");
            break;
        case 3:
            attackRestore();
            system("pause");
            break;
        case 4:
            attackRecord();
            system("pause");
            break;
        case 5:
            return 0;
        default:
            break;
        }

    }

    return 0;
}

posted @ 2022-04-15 04:41  荒年、  阅读(98)  评论(0编辑  收藏  举报