能看懂的都是大神
#include <stdio.h>
#include <WinSock2.h>
#include <stdlib.h>
#include <memory.h>
#include <iostream>
#include <string.h>
#include "hacker.h"
#pragma comment(lib, "ws2_32.lib")
#define SERVER_IP "118.126.117.125"
#define PORT 8000
#define CONNECT_FAIL "connect server failed"
#define ATTACK_SUCCESS "攻击成功"
#define ATTACK_FAIL "攻击失败"
#define ATTACK_RECORD_SUCCESS "["
using namespace std;
int send_cmd(char *cmd, char *response) {
int ret;
strcat(cmd, " check:13243879166");
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD(1, 1);
err = WSAStartup(wVersionRequested, &wsaData);
if (err != 0)
{
return -1;
}
if (LOBYTE(wsaData.wVersion) != 1 || HIBYTE(wsaData.wVersion) != 1)
{
WSACleanup();
return -1;
}
SOCKET sockClient = socket(AF_INET, SOCK_STREAM, 0);
SOCKADDR_IN addrSrv;
addrSrv.sin_addr.S_un.S_addr = inet_addr(SERVER_IP);
addrSrv.sin_family = AF_INET;
addrSrv.sin_port = htons(PORT);
ret = connect(sockClient, (SOCKADDR*)&addrSrv, sizeof(SOCKADDR));
if (ret < 0) {
strcpy(response, "connect server failed.");
return -1;
}
//printf("sending.....\n");
ret = send(sockClient, cmd, strlen(cmd) + 1, 0);
if (ret <= 0) {
printf(response, "send cmd failed.");
return -1;
}
//printf("send ended. waiting for server\n");
//printf("receiving.....\n");
ret = recv(sockClient, response, MAXSIZE, 0);
if (ret <= 0) {
printf(response, "receive response failed.");
return -1;
}
closesocket(sockClient);
WSACleanup();
return 0;
}
int hk_404(char *id, char *response) {
char buff[128];
sprintf(buff, "cmd:attack_404 para:null id:%s", id);
return send_cmd(buff, response);
}
int hk_restore(char *id, char *response) {
char buff[128];
sprintf(buff, "cmd:attack_restore para:null id:%s", id);
return send_cmd(buff, response);
}
int hk_tamper(char *id, char *para, char *response) {
char buff[128];
sprintf(buff, "cmd:attack_tamper para:%s id:%s", para, id);
return send_cmd(buff, response);
}
int hk_record(char *id, char *response) {
char buff[128];
sprintf(buff, "cmd:attack_record para:null id:%s", id);
return send_cmd(buff, response);
}
std::string UTF8ToGBK(const char* strUTF8)
{
int len = MultiByteToWideChar(CP_UTF8, 0, strUTF8, -1, NULL, 0);
wchar_t* wszGBK = new wchar_t[len+1];
memset(wszGBK, 0, len*2+2);
MultiByteToWideChar(CP_UTF8, 0, strUTF8, -1, wszGBK, len);
len = WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, NULL, 0, NULL, NULL);
char* szGBK = new char[len+1];
memset(szGBK, 0, len+1);
WideCharToMultiByte(CP_ACP, 0, wszGBK, -1, szGBK, len, NULL, NULL);
std::string strTemp(szGBK);
if(wszGBK) delete[] wszGBK;
if(szGBK) delete[] szGBK;
return strTemp;
}
void GBKToUTF8(string &strGBK)
{
int len=MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, NULL,0);
wchar_t * wszUtf8 = new wchar_t [len];
memset(wszUtf8, 0, len);
MultiByteToWideChar(CP_ACP, 0, strGBK.c_str(), -1, wszUtf8, len);
len = WideCharToMultiByte(CP_UTF8, 0, wszUtf8, -1, NULL, 0, NULL, NULL);
char *szUtf8=new char[len + 1];
memset(szUtf8, 0, len + 1);
WideCharToMultiByte (CP_UTF8, 0, wszUtf8, -1, szUtf8, len, NULL,NULL);
strGBK = szUtf8;
delete[] szUtf8;
delete[] wszUtf8;
}
bool check_response(const char *response) {
if (!strncmp(response, ATTACK_SUCCESS, strlen(ATTACK_SUCCESS)) ||
!strncmp(response, ATTACK_RECORD_SUCCESS, strlen(ATTACK_RECORD_SUCCESS))){
return true;
}
return false;
}
#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;
}
/**
system("cls");
//登录菜单
cout << "---黑客攻击系统---" << endl;
cout << "1.404攻击" << endl;
cout << "2.篡改攻击" << endl;
cout << "3.攻击修复" << endl;
cout << "4.查看攻击记录" << endl;
cout << "5.退出" << endl;
cout << "请选择:";
**/
}
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) {
//int hk_404(char *id, char *response) ;
char id[36]; //网站的id
char result[MAXSIZE]; //攻击服务器的返回结果
system("cls");
//居中打印
print_theme("404攻击");
cout << "请输入网站id: ";
scanf_s("%s", id, sizeof(id));
//攻击时打印提示信息
cout << "正在404攻击!!!" << endl;
//发起攻击
hk_404(id, result);
//攻击完打印返回结果 为GBK编码
//把攻击result编码 转换成jbk编码 保存到retstr里面 并打印输出
string retstr= UTF8ToGBK(result);
cout << retstr << endl;
system("pause");
/**
system("cls");
cout << "404攻击" << endl;
cout << "待实现。。。" << endl;
system("pause");
**/
}
void The_menu2(void) {
system("cls");
//cout << "篡改攻击" << endl;
//cout << "待实现。。。" << endl;
//system("pause");
char id[36]; //网站的id
char result[MAXSIZE]; //攻击服务器的返回结果
string str;
string para; //打印篡改信息
//居中打印
print_theme("篡改攻击");
cout << "请输入篡改网站id:";
scanf_s("%s", id, sizeof(id));
//攻击是打印提示信息
cout << "正在攻击" << endl;
cout << "请输入嵌入的内容:";
cin >> para;
GBKToUTF8(para); //gbk转换
//发起攻击
hk_tamper(id, (char*)(para.c_str()), result);
//攻击完打印返回结果 为GBK编码
//把攻击result编码 转换成jbk编码 保存到retstr里面 并打印输出
string retstr= UTF8ToGBK(result);
cout << retstr << endl;
system("pause");
}
void The_menu3(void) {
char id[36]; //网站的id
char result[MAXSIZE]; //攻击服务器的返回结果
system("cls");
//居中打印
print_theme("攻击恢复");
cout << "请输入恢复网站id:";
scanf_s("%s", id, sizeof(id));
//恢复网站
hk_restore(id, result);
//攻击完打印返回结果 为GBK编码
//把攻击result编码 转换成jbk编码 保存到retstr里面 并打印输出
string retstr= UTF8ToGBK(result);
cout << retstr << endl;
system("pause");
/**
system("cls");
cout << "攻击修复" << endl;
cout << "待实现。。。" << endl;
system("pause");
**/
}
void The_menu4(void) {
char id[36]; //网站的id
char result[MAXSIZE]; //攻击服务器的返回结果
system("cls");
//居中打印
print_theme("查看攻击记录");
cout << "请输入查看网站id:";
scanf_s("%s", id, sizeof(id));
hk_record(id, result);
//攻击完打印返回结果 为GBK编码
//把攻击result编码 转换成jbk编码 保存到retstr里面 并打印输出
string retstr= UTF8ToGBK(result);
cout << retstr << endl;
system("pause");
/**
system("cls");
cout << "查看攻击记录" << endl;
cout << "待实现。。。" << 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;
}
void attack404(void) {
char response[MAXSIZE] ;
char id[64];
memset(response, 0, sizeof(response));
system("cls");
printInMiddle("---网站404攻击---");
cout << "请输入准备攻击的网站ID:";
scanf_s("%s", id, sizeof(id));
cout << "正在执行404攻击..." << endl;
hk_404(id, response);
string retStr = UTF8ToGBK(response);
cout << retStr << endl;
system("pause");
}
void siteEdit(void) {
char response[MAXSIZE];
char id[16];
std::string str;
string attackText;
system("cls");
printInMiddle("---网站篡改攻击---");
cout << "请输入准备攻击的网站ID:";
scanf_s("%s", id, sizeof(id));
cout << "请输入嵌入的内容:";
cin >> attackText;
GBKToUTF8(attackText);
hk_tamper(id, (char*)(attackText.c_str()), response);
string retStr = UTF8ToGBK(response);
cout << retStr << endl;
system("pause");
}
void siteRepair(void) {
char response[MAXSIZE];
char id[16];
std::string str;
string attackText;
system("cls");
printInMiddle("---网站攻击修复---");
cout << "请输入准备查询的网站ID:";
scanf_s("%s", id, sizeof(id));
hk_restore(id, response);
string retStr = UTF8ToGBK(response);
cout << retStr << endl;
system("pause");
}
void attckRecord(void) {
char response[MAXSIZE] ;
char id[64];
system("cls");
printInMiddle("---攻击记录获取---");
cout << "请输入准备攻击的网站ID:";
scanf_s("%s", id, sizeof(id));
hk_record(id, response);
string retStr = UTF8ToGBK(response);
cout << retStr;
system("pause");
}