#include <iostream>
#include <windows.h>
#include <string>
#include "hacker.h"
using namespace std;
#define WIDTH 60
#define HIEGHT 30
void terminal(void) {
char print[68];
sprintf(print, "mode con cols=%d lines=%d", WIDTH, HIEGHT);
system(print);
}
void Initialize_the(void) {
string name;
string password;
while (1) {
system("cls");
cout << "请输入账号:";
cin >> name;
cout << "请输入密码:";
cin >> password;
if( name =="dandan" && password =="123456") {
break;
} else {
cout << "账号或密码错误!!!" << endl;
cout << "请重新输入。。。" << endl;
system("pause");
}
}
}
void print_theme(string print) {
int blank= (WIDTH - print.length()) / 2;
for(int i=0; i<blank; ++i) {
printf(" ");
}
cout << print << endl;
}
void The_menu(void) {
string print[] ={
"1。404攻击",
"2.篡改攻击",
"3.攻击恢复",
"4.攻击查看",
"5.退出",
"请选择:",
};
system("cls");
print_theme("---黑客攻击系统---");
int print_unit = sizeof(print) / sizeof(print[0]);
int print_and =0;
for(int i=0; i<print_unit; ++i) {
if(print[i].length() > print_and) {
print_and = print[i].length();
}
}
int print_empty = (WIDTH - print_and) / 2;
for(int i=0; i<print_unit; ++i) {
for(int i=0; i<print_empty; ++i) {HHHH
printf(" ");
}
cout << print[i] << endl;
}
}
int Menu_options(void) {
int n = 0;
while (1) {
cin >> n;
if (cin.fail()) {
cin.clear();
cin.clear();
cout << "无效输入. 请重新输入." << endl;
system("pause");
} else {
break;
}
}
return n;
}
void The_menu1(void) {
char id[36];
char result[MAXSIZE];
system("cls");
print_theme("404攻击");
cout << "请输入网站id: ";
scanf_s("%s", id, sizeof(id));
cout << "正在404攻击!!!" << endl;
hk_404(id, result);
string retstr= UTF8ToGBK(result);
cout << retstr << endl;
system("pause");
}
void The_menu2(void) {
system("cls");
char id[36];
char result[MAXSIZE];
string str;
string para;
print_theme("篡改攻击");
cout << "请输入篡改网站id:";
scanf_s("%s", id, sizeof(id));
cout << "正在攻击" << endl;
cout << "请输入嵌入的内容:";
cin >> para;
GBKToUTF8(para);
hk_tamper(id, (char*)(para.c_str()), result);
string retstr= UTF8ToGBK(result);
cout << retstr << endl;
system("pause");
}
void The_menu3(void) {
char id[36];
char result[MAXSIZE];
system("cls");
print_theme("攻击恢复");
cout << "请输入恢复网站id:";
scanf_s("%s", id, sizeof(id));
hk_restore(id, result);
string retstr= UTF8ToGBK(result);
cout << retstr << endl;
system("pause");
}
void The_menu4(void) {
char id[36];
char result[MAXSIZE];
system("cls");
print_theme("查看攻击记录");
cout << "请输入查看网站id:";
scanf_s("%s", id, sizeof(id));
hk_record(id, result);
string retstr= UTF8ToGBK(result);
cout << retstr << endl;
system("pause");
}
void The_menu6(void) {
system("cls");
cout << "输入错误请重新输入..;...." << endl;
system("pause");
}
int main(void) {
terminal();
Initialize_the();
while(1) {
The_menu();
int p = Menu_options();
switch (p) {
case 1:
The_menu1();
break;
case 2:
The_menu2();
break;
case 3:
The_menu3();
break;
case 4:
The_menu4();
break;
case 5:
return 0;
break;
default:
The_menu6();
break;
}
}
system("pause");
return 0;
}
项目优化4
隐藏密码输入
#include<conio.h>
void input_pwd(char pwd[], int max_len) {
char c;
int i = 0;
while (1) {
c = getch();
if (c == '\r' || i >= max_len) {
pwd[i] = 0;
break;
}
pwd[i++] = c;
printf("*", c);
}
printf("\n");
}
void login(void) {
string name;
char pwd[16];
while (1) {
system("cls");
std::cout << "请输入账号:";
std::cin >> name;
std::cout << "请输入密码:";
input_pwd(pwd, sizeof(pwd));
if (name == "54hk" && !strcmp(pwd, "123456")) {
return;
} else {
cout << "用户名或密码错误!" << endl;
system("pause");
}
}
}