C/C++教程

C++ 黑客攻击系统

本文主要是介绍C++ 黑客攻击系统,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
#include <iostream>
#include <Windows.h>
#include <string>
#include <conio.h>  //getch使用
#include "hacker.h"
using namespace std;

#define WIDTH 40
#define HEIGHT 15

void inputPwd(char pwd[], int size) {
    char c;
    int i = 0;

    while (1)
    {
        c = getch();  //这个getch连回车符都吃!!!
        if (c == '\r') {
            pwd[i] = 0;
            break;
        }
        pwd[i++] = c;
        cout << "*" ;
    }
    cout << endl;
}
void init() {
    char cmd[128];
    sprintf_s(cmd, "mode con cols=%d lines=%d", WIDTH, HEIGHT);
    system(cmd);
}
void printInMiddle(string msg) {
    int space = (WIDTH - msg.length()) / 2;
    for (int i = 0; i < space; i++) {
        cout << " ";
    }
    cout << msg << endl;
}
void login(void) {
    string name;
    //string pwd;
    char pwd[32];

    while (1) {
        system("cls");

        std::cout << "请输入账号:";
        std::cin >> name;

        std::cout << "请输入密码:";
        //std::cin >> pwd;
        //实现密码的输入
        inputPwd(pwd, sizeof(pwd));

        if (name == "54hk" && !strcmp(pwd,"123456")) { //若比较结果是相等的就会等于0,非0为真
            //break;
            return;
        }
        else {
            cout << "用户名或密码错误!" << endl;
            system("pause");
        }
    }
}

void menuShow(void) {
    system("cls");
    string menu[] = {
        "1.网站404攻击",
        "2.网站篡改攻击",
        "3.网站攻击修复",
        "4.查看攻击记录",
        "5.退出"
    };

    system("cls");
    printInMiddle("---黑客攻击系统---");

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

    int leftSpace = (WIDTH - max) / 2;

    for (int i = 0; i < menuCount; i++) {
        for (int i = 0; i < leftSpace; i++) {
            printf(" ");

        }
        cout << menu[i] << endl;
    }
}

int menuChoise(void) {
    int n = 0;

    while (1) {
        cout << "请选择菜单项:";
        cin >> n;
        if (cin.fail()) {
            cin.clear();
            cin.sync();
            cout << "无效输入. 请重新输入." << endl;
            system("pause");
        }
        else {
            break;
        }
    }

    return n;
}

void attack404(void) {
    char id[64];
    char response[4096];

    system("cls");
    printInMiddle("---网站404攻击---");

    cout << "请输入准备攻击的网站ID:";
    cin >> id;

    cout << "正在执行404攻击..." << endl;

    hk_404(id, response);  //发起攻击
    //id指对应网站的端口号
    //服务器返回的结果是utf-8编码格式

    string retStr = UTF8ToGBK(response);
    cout << retStr << endl;

    // int hk_404(char *id, char *response) ;
    //cout << "404攻击..." << endl;   
    system("pause");
}

void siteEdit(void) {
    system("cls");
    char id[64];
    char response[4096];
    string attackText;
    //cout << "网站篡改攻击..." << endl;
    cout << "请输入准备攻击的网站ID:";
    scanf_s("%s",id, size(id));

    cout << "请输入你要写入的内容:";
    cin>> attackText;
    
    cout << "正在执行网站篡改攻击...\n";
    GBKToUTF8(attackText);
    hk_tamper(id, (char*)attackText.c_str(),response);

    string retStr = UTF8ToGBK(response);
    cout << retStr << endl;
    system("pause");
}

void siteRepair(void) {
    char id[64];
    char response[4096];

    system("cls");
    printInMiddle("---网站攻击修复---");

    cout << "请输入准备修复的网站ID:";
    cin >> id;

    cout << "正在执行攻击修复..." << endl;

    hk_restore(id, response);  //发起攻击
    //id指对应网站的端口号
    //服务器返回的结果是utf-8编码格式
    string retStr = UTF8ToGBK(response);
    cout << retStr << endl;
    system("pause");
}

void attckRecord(void) {
    char id[64];
    char response[4096];

    system("cls");
    printInMiddle("---网站攻击记录---");

    cout << "请输入需要查看记录的网站ID:";
    cin >> id;

    cout << "正在查看攻击记录..." << endl;

    hk_record(id, response);
    //id指对应网站的端口号
    //服务器返回的结果是utf-8编码格式
    string retStr = UTF8ToGBK(response);
    cout << retStr << endl;
    system("pause");
}

int main(void) {
    // 登录
    init();
    login();

    while (1) {
        menuShow();
        int n = menuChoise();
        switch (n) {
        case 1:
            attack404();
            break;
        case 2:
            siteEdit();
            break;
        case 3:
            siteRepair();
            break;
        case 4:
            attckRecord();
            break;
        case 5:
            //break;
            return 0;
        default:
            cout << "无效输入. 请重新输入." << endl;
            system("pause");
            break;
        }
    }
    system("pause");
    return 0;
}

 

这篇关于C++ 黑客攻击系统的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!