Changeset 490
- Timestamp:
- 04/07/06 10:19:35 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
library/trunk/modules/service-gotek/service-gotek.cpp
r480 r490 163 163 m_ConsumeLevel = CL_ASSIGN; 164 164 165 m_LastQuery = NULL; 166 167 m_State = GCS_VIRGIN; 165 m_State = GCS_VIRGIN; 168 166 169 167 char szHandshake[4] = … … 187 185 ServiceGotekDialogue::~ServiceGotekDialogue() 188 186 { 189 if (m_LastQuery != NULL)187 while (m_QueryQueue.size() > 0) 190 188 { 191 m_LastQuery->cancelCallback(); 189 m_QueryQueue.front()->cancelCallback(); 190 m_QueryQueue.pop_front(); 192 191 } 193 192 } … … 227 226 return CL_DROP; 228 227 229 string query = "SELECT \" binaryKey\" FROM \"users\".\"accounts\" WHERE username = '";228 string query = "SELECT \"authkey\" FROM \"users-dp\".\"users\" WHERE username = '"; 230 229 query += m_Username.c_str(); 231 230 query += "';"; 232 231 233 232 SQLQuery *sqlquery = g_Library->getSQLMgr()->addQuery(&query,this,NULL); 234 m_ LastQuery = sqlquery;233 m_QueryQueue.push_back(sqlquery); 235 234 } 236 235 break; … … 284 283 } 285 284 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='"; 289 288 query += filehash; 290 289 query += "';"; 291 290 292 291 SQLQuery *sqlquery = g_Library->getSQLMgr()->addQuery(&query,this,NULL); 293 m_ LastQuery = sqlquery;292 m_QueryQueue.push_back(sqlquery); 294 293 m_Buffer.erase(0, 64 + 8); 295 294 … … 326 325 string md5hash = g_Library->getUtilities()->md5sum((char *)m_Buffer.data() + 12 ,filesize); 327 326 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); 332 339 333 340 logSpam("Successfully received %u bytes over a data connection.", ntohl(* ((unsigned int *) (m_Buffer.data() + 8)))); … … 405 412 406 413 407 if (m_ LastQuery != NULL)414 if (m_QueryQueue.size() == 0) 408 415 { 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; 410 419 } 411 420 … … 418 427 if (result.size() == 1) 419 428 { 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()); 422 430 bkey.append((char *)&m_SessionKey,8); 423 431 … … 432 440 char cAckByte = 0xAA; 433 441 m_Socket->doWrite(&cAckByte,1); 434 return true;435 436 442 } 437 443 438 } 439 m_Socket->setStatus(SS_CLOSED); 444 }else 445 { 446 m_Socket->setStatus(SS_CLOSED); 447 } 440 448 break; 441 449 … … 443 451 if (result.size() == 1) 444 452 { 445 char cValue = atoi(result[0]["count"].c_str()) > 0 ? 0x55 : 0xAA; 453 logSpam("%s %i\n",__FILE__,__LINE__); 454 char cValue = 0x55; 446 455 m_Socket->doWrite(&cValue,1); 447 456 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__); 452 471 } 453 472 break; … … 457 476 logInfo("state %i, query %s\n",m_State,sqlresult->getQuery().c_str()); 458 477 } 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 482 bool ServiceGotekDialogue::sqlFailure(SQLResult *sqlresult) 483 { 484 logPF(); 485 486 if (m_QueryQueue.size() == 0) 468 487 { 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()); 496 489 m_Socket->setStatus(SS_CLOSED); 490 return false; 497 491 } 498 492 … … 504 498 break; 505 499 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()); 507 501 } 502 503 m_QueryQueue.pop_front(); 508 504 509 505 return true; library/trunk/modules/service-gotek/service-gotek.hpp
r480 r490 91 91 protected: 92 92 string m_Buffer; 93 SQLQuery *m_LastQuery;93 list<SQLQuery *> m_QueryQueue; 94 94 95 95 GotekClientState m_State;
