Changeset 490

Show
Ignore:
Timestamp:
04/07/06 10:19:35 (2 years ago)
Author:
common
Message:

library
- service-gotek, we need to queue all queries with a callback, not only one
- using other sql layout it works now

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • library/trunk/modules/service-gotek/service-gotek.cpp

    r480 r490  
    163163        m_ConsumeLevel = CL_ASSIGN; 
    164164 
    165         m_LastQuery = NULL; 
    166  
    167         m_State = GCS_VIRGIN; 
     165    m_State = GCS_VIRGIN; 
    168166 
    169167    char szHandshake[4] =  
     
    187185ServiceGotekDialogue::~ServiceGotekDialogue() 
    188186{ 
    189         if (m_LastQuery != NULL
     187        while (m_QueryQueue.size() > 0
    190188        { 
    191                 m_LastQuery->cancelCallback(); 
     189                m_QueryQueue.front()->cancelCallback(); 
     190                m_QueryQueue.pop_front(); 
    192191        } 
    193192} 
     
    227226                                        return CL_DROP; 
    228227 
    229                         string query = "SELECT \"binaryKey\" FROM \"users\".\"accounts\" WHERE username = '"; 
     228                        string query = "SELECT \"authkey\" FROM \"users-dp\".\"users\" WHERE username = '"; 
    230229                        query  += m_Username.c_str(); 
    231230                        query  += "';"; 
    232231 
    233232                        SQLQuery *sqlquery = g_Library->getSQLMgr()->addQuery(&query,this,NULL); 
    234                         m_LastQuery = sqlquery
     233                        m_QueryQueue.push_back(sqlquery)
    235234                } 
    236235                break; 
     
    284283                                        } 
    285284 
    286                                        logSpam("Got Lookup request %s, enqueuing...\n",filehash.c_str()); 
    287  
    288                                         string query = "SELECT COUNT(*) FROM \"malware\".\"samples\" WHERE sha512_hash='"; 
     285//                                     logCrit("Got Lookup request %s, enqueuing...\n",filehash.c_str()); 
     286 
     287                                        string query = "SELECT \"sha512_hash\",\"count\" FROM \"users-dp\".\"malware\" WHERE sha512_hash='"; 
    289288                                        query  += filehash; 
    290289                                        query  += "';"; 
    291290 
    292291                                        SQLQuery *sqlquery = g_Library->getSQLMgr()->addQuery(&query,this,NULL); 
    293                                         m_LastQuery = sqlquery
     292                                        m_QueryQueue.push_back(sqlquery)
    294293                                        m_Buffer.erase(0, 64 + 8); 
    295294 
     
    326325                                string md5hash = g_Library->getUtilities()->md5sum((char *)m_Buffer.data() + 12 ,filesize); 
    327326 
    328                                 string query = "INSERT INTO \"malware\".\"samples\" (\"sha512_hash\",\"md5_hash\") VALUES ('" + sha512hash + "','" + md5hash + "')"; 
    329  
    330                                 SQLQuery *sqlquery = g_Library->getSQLMgr()->addQuery(&query,this,NULL); 
    331                                 m_LastQuery = sqlquery; 
     327                                string query =  
     328                                "INSERT INTO \"users-dp\".\"malware\" (\"sha512_hash\",\"md5_hash\",\"firstseen\",\"lastseen\",\"count\")" 
     329                                " VALUES ('" 
     330                                         + sha512hash + "','" + md5hash + "','10','11','1'" 
     331                                 + ")"; 
     332 
     333                g_Library->getSQLMgr()->addQuery(&query,NULL,NULL); 
     334 
     335                query = "INSERT INTO \"users-dp\".\"instances\" (\"sha512_hash\",\"time\",\"submitter\")" 
     336                                 " VALUES ('" + sha512hash + "','10','" + string(m_Username.c_str()) + "')"; 
     337 
     338                                g_Library->getSQLMgr()->addQuery(&query,NULL,NULL); 
    332339 
    333340                                logSpam("Successfully received %u bytes over a data connection.", ntohl(* ((unsigned int *) (m_Buffer.data() + 8)))); 
     
    405412 
    406413 
    407         if (m_LastQuery != NULL
     414        if (m_QueryQueue.size() == 0
    408415        { 
    409                 m_LastQuery = NULL; 
     416                logCrit("unexpected Query callback for query %s\n",sqlresult->getQuery().c_str()); 
     417                m_Socket->setStatus(SS_CLOSED); 
     418                return false; 
    410419        } 
    411420 
     
    418427                if (result.size() == 1) 
    419428                { 
    420                         printf("bkey is %i bytes\n",result[0]["binaryKey"].size()); 
    421                         string bkey(result[0]["binaryKey"].data(), result[0]["binaryKey"].size()); 
     429            string bkey(result[0]["authkey"].data(), result[0]["authkey"].size()); 
    422430                        bkey.append((char *)&m_SessionKey,8); 
    423431 
     
    432440                char cAckByte = 0xAA; 
    433441                m_Socket->doWrite(&cAckByte,1); 
    434                                 return true; 
    435  
    436442                        } 
    437443                         
    438                 } 
    439                 m_Socket->setStatus(SS_CLOSED); 
     444                }else 
     445                { 
     446                m_Socket->setStatus(SS_CLOSED); 
     447                } 
    440448                break; 
    441449 
     
    443451                if (result.size() == 1) 
    444452                { 
    445                         char cValue = atoi(result[0]["count"].c_str()) > 0 ? 0x55 : 0xAA; 
     453                        logSpam("%s %i\n",__FILE__,__LINE__); 
     454                        char cValue = 0x55; 
    446455                        m_Socket->doWrite(&cValue,1); 
    447456 
    448                         if (atoi(result[0]["count"].c_str()) > 0) 
    449                         { 
    450                                  
    451                         } 
     457                        string sha512hash = result[0]["sha512_hash"]; 
     458 
     459                        string query = "INSERT INTO \"users-dp\".\"instances\" (\"sha512_hash\",\"time\",\"submitter\")" 
     460                        " VALUES ('" + sha512hash + "','10','" + string(m_Username.c_str()) + "')"; 
     461                        g_Library->getSQLMgr()->addQuery(&query,NULL,NULL); 
     462 
     463                        query = "UPDATE \"users-dp\".\"malware\" SET count = count + 1 WHERE sha512_hash = '" + sha512hash + "'"; 
     464                        g_Library->getSQLMgr()->addQuery(&query,NULL,NULL); 
     465 
     466                }else 
     467                { 
     468                        char cValue = 0xAA; 
     469                        m_Socket->doWrite(&cValue,1); 
     470                        logSpam("%s %i\n",__FILE__,__LINE__); 
    452471                } 
    453472                break; 
     
    457476                logInfo("state %i, query %s\n",m_State,sqlresult->getQuery().c_str()); 
    458477        } 
    459  
    460 /* 
    461         vector< map<string,string> > result = *sqlresult->getResult(); 
    462  
    463         unsigned int i; 
    464         map<string,string>::iterator jt; 
    465  
    466         string reply = ""; 
    467         for (i=0;i<result.size();i++
     478        m_QueryQueue.pop_front(); 
     479        return true; 
     480
     481 
     482bool ServiceGotekDialogue::sqlFailure(SQLResult *sqlresult) 
     483
     484        logPF(); 
     485 
     486        if (m_QueryQueue.size() == 0
    468487        { 
    469                  
    470                  
    471                 for (jt=result[i].begin();jt!=result[i].end();jt++) 
    472                 { 
    473                         reply += " " + result[i][jt->first] + " |"; 
    474                 } 
    475                 reply += "\n"; 
    476 //              m_Socket->doWrite((char *)reply.c_str(),reply.size()); 
    477  
    478         } 
    479         reply += "\r\n"; 
    480         m_Socket->doWrite((char *)reply.c_str(),reply.size()); 
    481  
    482         m_Queries.pop_front(); 
    483 */       
    484         return true; 
    485 
    486  
    487 bool ServiceGotekDialogue::sqlFailure(SQLResult *sqlresult) 
    488 
    489         logPF(); 
    490         if ( m_LastQuery != NULL ) 
    491         { 
    492                 m_LastQuery = NULL; 
    493         } else 
    494         { 
    495                 logCrit("unexpected callback %s\n",sqlresult->getQuery().c_str()); 
     488                logCrit("unexpected Query callback for query %s\n",sqlresult->getQuery().c_str()); 
    496489                m_Socket->setStatus(SS_CLOSED); 
     490                return false; 
    497491        } 
    498492 
     
    504498                break; 
    505499        default: 
    506                 logInfo("state %s, query %s\n",m_State,sqlresult->getQuery().c_str()); 
     500                logInfo("state %i, query %s\n",m_State,sqlresult->getQuery().c_str()); 
    507501        } 
     502 
     503        m_QueryQueue.pop_front(); 
    508504 
    509505        return true; 
  • library/trunk/modules/service-gotek/service-gotek.hpp

    r480 r490  
    9191        protected: 
    9292                string          m_Buffer; 
    93                 SQLQuery       *m_LastQuery
     93                list<SQLQuery *>       m_QueryQueue
    9494 
    9595                GotekClientState        m_State;