Changeset 550
- Timestamp:
- 05/04/06 12:25:35 (3 years ago)
- Files:
-
- nepenthes/trunk/conf/nepenthes.conf.dist (modified) (1 diff)
- nepenthes/trunk/modules/dnsresolve-adns/dnsresolve-adns.cpp (modified) (1 diff)
- nepenthes/trunk/modules/download-creceive/CReceiveDialogue.cpp (modified) (1 diff)
- nepenthes/trunk/modules/download-csend/CSendDownloadHandler.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/download-curl/download-curl.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/download-ftp/CTRLDialogue.cpp (modified) (9 diffs)
- nepenthes/trunk/modules/download-ftp/FILEDialogue.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/download-ftp/download-ftp.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/download-http/HTTPDialogue.cpp (modified) (1 diff)
- nepenthes/trunk/modules/download-link/LinkDialogue.cpp (modified) (1 diff)
- nepenthes/trunk/modules/download-link/download-link.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/download-rcp/RCPDialogue.cpp (modified) (3 diffs)
- nepenthes/trunk/modules/download-rcp/download-rcp.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/download-tftp/TFTPDialogue.cpp (modified) (1 diff)
- nepenthes/trunk/modules/download-tftp/TFTPDownloadHandler.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/log-download/log-download.cpp (modified) (3 diffs)
- nepenthes/trunk/modules/log-irc/IrcDialogue.cpp (modified) (11 diffs)
- nepenthes/trunk/modules/log-irc/IrcDialogue.hpp (modified) (3 diffs)
- nepenthes/trunk/modules/log-irc/log-irc.conf.dist (modified) (2 diffs)
- nepenthes/trunk/modules/log-irc/log-irc.cpp (modified) (5 diffs)
- nepenthes/trunk/modules/log-irc/log-irc.hpp (modified) (5 diffs)
- nepenthes/trunk/modules/log-prelude/log-prelude.cpp (modified) (8 diffs)
- nepenthes/trunk/modules/log-surfnet/log-surfnet.cpp (modified) (5 diffs)
- nepenthes/trunk/modules/module-bridge/module-bridge.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/module-portwatch/module-portwatch.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/shellcode-generic/sch_generic_bielefeld_connect.cpp (modified) (1 diff)
- nepenthes/trunk/modules/shellcode-generic/sch_generic_bind.cpp (modified) (3 diffs)
- nepenthes/trunk/modules/shellcode-generic/sch_generic_cmd.cpp (modified) (1 diff)
- nepenthes/trunk/modules/shellcode-generic/sch_generic_connect.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/shellcode-generic/sch_generic_connect_trans.cpp (modified) (1 diff)
- nepenthes/trunk/modules/shellcode-generic/sch_generic_createprocess.cpp (modified) (1 diff)
- nepenthes/trunk/modules/shellcode-generic/sch_generic_mainz_bind.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/shellcode-generic/sch_generic_wget.cpp (modified) (1 diff)
- nepenthes/trunk/modules/shellcode-generic/sch_generic_winexec.cpp (modified) (1 diff)
- nepenthes/trunk/modules/shellcode-generic/sch_generic_xor.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/shellcode-generic/shellcode-generic.cpp (modified) (1 diff)
- nepenthes/trunk/modules/shellcode-signatures/sch_namespace_bindshell.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/shellcode-signatures/sch_namespace_connectbackshell.cpp (modified) (1 diff)
- nepenthes/trunk/modules/shellcode-signatures/sch_namespace_execute.cpp (modified) (1 diff)
- nepenthes/trunk/modules/shellemu-winnt/VFSCommandFTP.cpp (modified) (4 diffs)
- nepenthes/trunk/modules/shellemu-winnt/VFSCommandRCP.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/shellemu-winnt/VFSCommandREDIR.cpp (modified) (1 diff)
- nepenthes/trunk/modules/shellemu-winnt/VFSCommandRREDIR.cpp (modified) (1 diff)
- nepenthes/trunk/modules/submit-file/submit-file.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/submit-gotek/gotekCTRLDialogue.cpp (modified) (3 diffs)
- nepenthes/trunk/modules/submit-gotek/submit-gotek.cpp (modified) (6 diffs)
- nepenthes/trunk/modules/submit-norman/submit-norman.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-asn1/SMBDialogue.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-asn1/vuln-asn1.cpp (modified) (1 diff)
- nepenthes/trunk/modules/vuln-bagle/vuln-bagle.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-dameware/vuln-dameware.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-dcom/DCOMDialogue.cpp (modified) (3 diffs)
- nepenthes/trunk/modules/vuln-dcom/vuln-dcom.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-ftpd/vuln-ftpd.cpp (modified) (8 diffs)
- nepenthes/trunk/modules/vuln-iis/vuln-iis.cpp (modified) (1 diff)
- nepenthes/trunk/modules/vuln-kuang2/Kuang2Dialogue.cpp (modified) (1 diff)
- nepenthes/trunk/modules/vuln-kuang2/vuln-kuang2.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-lsass/vuln-lsass.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-msdtc/vuln-msdtc.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-msmq/vuln-msmq.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-mssql/MSSQLDialogue.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-mssql/vuln-mssql.cpp (modified) (1 diff)
- nepenthes/trunk/modules/vuln-mydoom/vuln-mydoom.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-netbiosname/vuln-netbiosname.cpp (modified) (1 diff)
- nepenthes/trunk/modules/vuln-netdde/vuln-netdde.cpp (modified) (1 diff)
- nepenthes/trunk/modules/vuln-optix/vuln-optix.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-pnp/vuln-pnp.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-sasserftpd/vuln-sasserftpd.cpp (modified) (1 diff)
- nepenthes/trunk/modules/vuln-ssh/SSHSocket.cpp (modified) (5 diffs)
- nepenthes/trunk/modules/vuln-ssh/vuln-ssh.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-sub7/vuln-sub7.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/vuln-upnp/vuln-upnp.cpp (modified) (1 diff)
- nepenthes/trunk/modules/vuln-veritas/vuln-veritas.cpp (modified) (1 diff)
- nepenthes/trunk/modules/vuln-wins/vuln-wins.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/x-2/x-2.cpp (modified) (2 diffs)
- nepenthes/trunk/modules/x-5/x-5.cpp (modified) (1 diff)
- nepenthes/trunk/nepenthes-core/include/LogManager.hpp (modified) (1 diff)
- nepenthes/trunk/nepenthes-core/include/Nepenthes.hpp (modified) (1 diff)
- nepenthes/trunk/nepenthes-core/src/DNSManager.cpp (modified) (2 diffs)
- nepenthes/trunk/nepenthes-core/src/DialogueFactoryManager.cpp (modified) (1 diff)
- nepenthes/trunk/nepenthes-core/src/ModuleManager.cpp (modified) (4 diffs)
- nepenthes/trunk/nepenthes-core/src/Nepenthes.cpp (modified) (6 diffs)
- nepenthes/trunk/nepenthes-core/src/SocketManager.cpp (modified) (2 diffs)
- nepenthes/trunk/nepenthes-core/src/SubmitManager.cpp (modified) (8 diffs)
- nepenthes/trunk/nepenthes-core/src/TCPSocket.cpp (modified) (1 diff)
- nepenthes/trunk/nepenthes-core/src/UDPSocket.cpp (modified) (2 diffs)
- nepenthes/trunk/nepenthes-core/src/Utilities.cpp (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
nepenthes/trunk/conf/nepenthes.conf.dist
r442 r550 30 30 "downloadtftp.so", "download-tftp.conf", "" 31 31 "downloadrcp.so", "" "" 32 33 // upload handler for various? protocols34 "uploadhttp.so", "", ""35 32 36 33 // submission handler nepenthes/trunk/modules/dnsresolve-adns/dnsresolve-adns.cpp
r408 r550 88 88 g_Nepenthes->getDNSMgr()->registerDNSHandler(this); 89 89 REG_EVENT_HANDLER(this); 90 logDebug(" %s","adns_init() Success\n");90 logDebug("adns_init() Success\n"); 91 91 92 92 return true; nepenthes/trunk/modules/download-creceive/CReceiveDialogue.cpp
r332 r550 106 106 logSpam("... DATA ... FIXME %i bytes \n",msg->getSize()); 107 107 m_Download->getDownloadBuffer()->addData(msg->getMsg(),msg->getSize()); 108 109 if (m_Download->getDownloadBuffer()->getSize() > 1024 * 1024 * 4) // hardcoded 4mb limit for now (tm) 110 return CL_DROP; 111 108 112 return CL_ASSIGN; 109 113 } nepenthes/trunk/modules/download-csend/CSendDownloadHandler.cpp
r332 r550 80 80 if (m_Config == NULL) 81 81 { 82 logCrit(" %s","I need a config\n");82 logCrit("I need a config\n"); 83 83 return false; 84 84 } … … 90 90 catch(...) 91 91 { 92 logCrit(" %s","Error setting needed vars, check your config\n");92 logCrit("Error setting needed vars, check your config\n"); 93 93 return false; 94 94 } nepenthes/trunk/modules/download-curl/download-curl.cpp
r408 r550 81 81 if ( m_Config == NULL ) 82 82 { 83 logCrit(" %s","I need a config\n");83 logCrit("I need a config\n"); 84 84 return false; 85 85 } … … 92 92 } catch ( ... ) 93 93 { 94 logCrit(" %s","Error setting needed vars, check your config\n");94 logCrit("Error setting needed vars, check your config\n"); 95 95 return false; 96 96 } nepenthes/trunk/modules/download-ftp/CTRLDialogue.cpp
r343 r550 115 115 if (m_Download == NULL && m_State < FTP_RETR) 116 116 { 117 logWarn(" %s","broken ftp daemon \n");117 logWarn("broken ftp daemon \n"); 118 118 return CL_DROP; 119 119 } … … 207 207 if (strncmp((char *)m_Buffer->getData() + iStart,"150 ",4) == 0) 208 208 { 209 logDebug(" %s","RETR accepted\n");209 logDebug("RETR accepted\n"); 210 210 }else 211 211 if (strncmp((char *)m_Buffer->getData() + iStart,"226 ",4) == 0) 212 212 { 213 logDebug(" %s","Transferr finished\n");213 logDebug("Transferr finished\n"); 214 214 sendQuit(); 215 215 m_State = FTP_QUIT; … … 353 353 if (strncmp(msg,"230 ",4) == 0) 354 354 { 355 logDebug(" %s","Pass accepted, logged in \n");355 logDebug("Pass accepted, logged in \n"); 356 356 return true; 357 357 }else … … 376 376 if (strncmp(msg,"200 ",4) == 0) 377 377 { 378 logDebug(" %s","Type accepted \n");378 logDebug("Type accepted \n"); 379 379 return true; 380 380 }else … … 388 388 void CTRLDialogue::sendPort() 389 389 { 390 logDebug(" %s","System ... \n");390 logDebug("System ... \n"); 391 391 392 392 uint32_t ip; … … 468 468 if (strncmp(msg,"200 ",4) == 0) 469 469 { 470 logDebug(" %s","Port accepted\n");470 logDebug("Port accepted\n"); 471 471 return true; 472 472 }else … … 492 492 if (strncmp(msg,"150 ",4) == 0) 493 493 { 494 logDebug(" %s","Retr accepted\n");494 logDebug("Retr accepted\n"); 495 495 return true; 496 496 }else … … 514 514 if (strncmp(msg,"221 ",4) == 0) 515 515 { 516 logDebug(" %s","Quit accepted\n");516 logDebug("Quit accepted\n"); 517 517 return true; 518 518 }else … … 535 535 if (strncmp(msg,"250 ",4) == 0) 536 536 { 537 logDebug(" %s","CWD accepted\n");538 return true; 539 }else 540 { 541 return false; 542 } 543 } 544 537 logDebug("CWD accepted\n"); 538 return true; 539 }else 540 { 541 return false; 542 } 543 } 544 nepenthes/trunk/modules/download-ftp/FILEDialogue.cpp
r332 r550 94 94 if (m_Download == NULL) 95 95 { 96 logWarn(" %s","broken ftp server connected 2 times, dropping second connection\n");96 logWarn("broken ftp server connected 2 times, dropping second connection\n"); 97 97 return CL_DROP; 98 98 } … … 100 100 // logSpam("Got %i bytes data\n",msg->getSize()); 101 101 m_Download->getDownloadBuffer()->addData(msg->getMsg(),msg->getSize()); 102 103 if (m_Download->getDownloadBuffer()->getSize() > 1024 * 1024 * 4) // hardcoded 4mb limit for now (tm) 104 return CL_DROP; 105 102 106 return CL_ASSIGN; 103 107 } nepenthes/trunk/modules/download-ftp/download-ftp.cpp
r343 r550 123 123 if ( m_Config == NULL ) 124 124 { 125 logCrit(" %s","I need a config\n");125 logCrit("I need a config\n"); 126 126 return false; 127 127 } … … 148 148 } catch ( ... ) 149 149 { 150 logCrit(" %s","Error setting needed vars, check your config\n");150 logCrit("Error setting needed vars, check your config\n"); 151 151 return false; 152 152 } nepenthes/trunk/modules/download-http/HTTPDialogue.cpp
r503 r550 93 93 // g_Nepenthes->getUtilities()->hexdump((byte *)msg->getMsg(),msg->getSize()); 94 94 m_Download->getDownloadBuffer()->addData(msg->getMsg(),msg->getSize()); 95 96 if (m_Download->getDownloadBuffer()->getSize() > 1024 * 1024 * 4) // hardcoded 4mb limit for now (tm) 97 return CL_DROP; 98 95 99 return CL_ASSIGN; 96 100 } nepenthes/trunk/modules/download-link/LinkDialogue.cpp
r341 r550 132 132 case LINK_FILE: 133 133 m_Download->getDownloadBuffer()->addData(msg->getMsg(),msg->getSize()); 134 if( m_Download->getDownloadBuffer()->getSize() > 1024 * 1024 * 4 ) // hardcoded 4mb filesize limit for now (tm) 135 return CL_DROP; 134 136 break; 135 137 } nepenthes/trunk/modules/download-link/download-link.cpp
r332 r550 78 78 if (m_Config == NULL) 79 79 { 80 logCrit(" %s","I need a config\n");80 logCrit("I need a config\n"); 81 81 return false; 82 82 } … … 88 88 catch(...) 89 89 { 90 logCrit(" %s","Error setting needed vars, check your config\n");90 logCrit("Error setting needed vars, check your config\n"); 91 91 return false; 92 92 } nepenthes/trunk/modules/download-rcp/RCPDialogue.cpp
r341 r550 123 123 { 124 124 case RCP_STATE_REQUEST: 125 logSpam(" %s","RCP STATE_REQUEST\n");125 logSpam("RCP STATE_REQUEST\n"); 126 126 m_Buffer->add(msg->getMsg(),msg->getSize()); 127 127 if (m_Buffer->getSize() == 1 && *(char *)m_Buffer->getData() == 0) … … 140 140 case RCP_STATE_FILESTATS: 141 141 m_Buffer->add(msg->getMsg(),msg->getSize()); 142 logSpam(" %s","RCP STATE_FILESTATS\n");142 logSpam("RCP STATE_FILESTATS\n"); 143 143 { 144 144 // "C0644 98 7819 foo.exe\n" … … 203 203 { 204 204 m_Download->getDownloadBuffer()->addData(msg->getMsg(),msg->getSize()); 205 if ( m_Download->getDownloadBuffer()->getSize() > 1024 * 1024 * 4) // hardcoded 4mb limit for now (tm) 206 { 207 return CL_DROP; 208 } 205 209 } 206 210 break; nepenthes/trunk/modules/download-rcp/download-rcp.cpp
r341 r550 80 80 if (m_Config == NULL) 81 81 { 82 logCrit(" %s","I need a config\n");82 logCrit("I need a config\n"); 83 83 return false; 84 84 } … … 90 90 catch(...) 91 91 { 92 logCrit(" %s","Error setting needed vars, check your config\n");92 logCrit("Error setting needed vars, check your config\n"); 93 93 return false; 94 94 } nepenthes/trunk/modules/download-tftp/TFTPDialogue.cpp
r341 r550 161 161 msg->getSocket()->getNepenthes()->getSubmitMgr()->addSubmission(m_Download); 162 162 m_Socket->setStatus(SS_CLOSED); 163 }else 164 { 165 if( m_Download->getDownloadBuffer()->getSize() > 1024 * 1024 * 4 ) // hardcoded 4mb limit for now (tm) 166 { 167 return CL_DROP; 168 } 163 169 } 164 170 } nepenthes/trunk/modules/download-tftp/TFTPDownloadHandler.cpp
r332 r550 85 85 if ( m_Config == NULL ) 86 86 { 87 logCrit(" %s","I need a config\n");87 logCrit("I need a config\n"); 88 88 return false; 89 89 } … … 95 95 } catch ( ... ) 96 96 { 97 logCrit(" %s","Error setting needed vars, check your config\n");97 logCrit("Error setting needed vars, check your config\n"); 98 98 return false; 99 99 } nepenthes/trunk/modules/log-download/log-download.cpp
r321 r550 107 107 if ( m_Config == NULL ) 108 108 { 109 logCrit(" %s","I need a config\n");109 logCrit("I need a config\n"); 110 110 return false; 111 111 } … … 130 130 } catch ( ... ) 131 131 { 132 logCrit(" %s","Error setting needed vars, check your config\n");132 logCrit("Error setting needed vars, check your config\n"); 133 133 return false; 134 134 } … … 220 220 221 221 default: 222 logWarn(" %s","this should not happen\n");222 logWarn("this should not happen\n"); 223 223 } 224 224 return 0; nepenthes/trunk/modules/log-irc/IrcDialogue.cpp
r378 r550 6 6 * 7 7 * Copyright (C) 2005 Paul Baecher & Markus Koetter 8 * Copyright (C) 2006 Georg Wicherski 8 9 * 9 10 * This program is free software; you can redistribute it and/or … … 30 31 #include <ctype.h> 31 32 #include <string> 33 #include <string.h> 32 34 #include <vector> 33 35 … … 62 64 63 65 64 65 66 /**67 * Dialogue::Dialogue(Socket *)68 * construktor for the IrcDialogue, creates a new IrcDialogue69 *70 * replies some crap to the socket71 *72 * @param socket the Socket the Dialogue has to use73 */74 66 IrcDialogue::IrcDialogue(Socket *socket, LogIrc * logirc) 75 67 { 76 68 m_Socket = socket; 77 m_DialogueName = "IrcDialogue";78 m_DialogueDescription = " eXample Dialogue";69 m_DialogueName = "IrcDialogue"; 70 m_DialogueDescription = "IRC logging client"; 79 71 80 72 m_ConsumeLevel = CL_ASSIGN; 81 73 m_LogIrc = logirc; 74 m_LoggedOn = false; 82 75 83 76 m_State = IRCDIA_REQUEST_SEND; … … 85 78 if ( m_LogIrc->useTor() == true ) 86 79 { 87 socks4_header_t s4hHeader; 88 memset(&s4hHeader,0,sizeof(socks4_header_t)); 89 90 s4hHeader.ucVersion = 4; 91 s4hHeader.ucCommand = 1; // connect request 92 s4hHeader.usDestPort = htons(m_LogIrc->getIrcPort()); 93 s4hHeader.ulDestAddr = m_LogIrc->getIrcIP(); 94 95 m_Socket->doRespond((char *) &s4hHeader,8+ strlen(s4hHeader.szUser)+1 ); 96 } else 80 SocksHeader torHeader; 81 memset(&torHeader, 0, sizeof(torHeader)); 82 83 torHeader.version = 4; 84 torHeader.command = 1; // connect request 85 torHeader.destPort = htons(m_LogIrc->getIrcPort()); 86 torHeader.destAddress = m_LogIrc->getIrcIP(); 87 88 m_Socket->doRespond((char *) &torHeader,8+strlen(torHeader.user)+1); 89 } 90 else 97 91 { 98 92 m_State = IRCDIA_CONNECTED; … … 116 110 } 117 111 118 /**119 * Dialogue::incomingData(Message *)120 *121 * a small and ugly shell where we can use122 * "download protocol://localction:port/path/to/file123 * to trigger a download124 *125 * @param msg the Message the Socker received.126 *127 *128 * @return CL_ASSIGN129 */130 112 ConsumeLevel IrcDialogue::incomingData(Message *msg) 131 113 { 132 133 114 switch (m_State) 134 115 { 135 116 case IRCDIA_REQUEST_SEND: 136 if ( ((socks4_header_t *)msg->getMsg())->ucCommand == 90 )137 { 138 logInfo(" %s","connected to ircd via tor\n");117 if( ((SocksHeader *) msg->getMsg())->command == 90 ) 118 { 119 logInfo("Connected to IRC server \"%s\" through TOR proxy \"%s\"\n", m_LogIrc->getIrcServer().c_str(), m_LogIrc->getTorServer().c_str()); 139 120 m_State = IRCDIA_CONNECTED; 140 121 … … 143 124 sendUser(); 144 125 145 } else 146 { 147 logWarn("%s","tor did not accept our connection \n"); 126 } 127 else 128 { 129 logInfo("Relaying to IRC server \"%s\" denied by TOR proxy \"%s\"\n", m_LogIrc->getIrcServer().c_str(), m_LogIrc->getTorServer().c_str()); 148 130 return CL_DROP; 149 131 } 132 150 133 break; 134 151 135 case IRCDIA_CONNECTED: 152 { 153 m_Buffer->add(msg->getMsg(),msg->getSize()); 154 processBuffer(); 155 } 136 m_Buffer->add(msg->getMsg(),msg->getSize()); 137 processBuffer(); 138 156 139 break; 157 140 158 141 } 142 159 143 return CL_ASSIGN; 160 144 } 161 145 162 146 //! oxff: slightly faster and definitely better readable than old implementation 163 147 void IrcDialogue::processBuffer() 164 148 { 165 logPF(); 166 unsigned char *linestart = (unsigned char *)m_Buffer->getData(); 167 unsigned char *linestopp = (unsigned char *)m_Buffer->getData(); 168 169 uint32_t i=0; 170 while (i < m_Buffer->getSize()) 171 { 172 173 if ( linestopp[i] == '\n') 174 { 175 i++; 176 // printf("IRCLINE len %i \n'%.*s'\n",(int32_t)(linestopp+i-linestart),(int32_t)(linestopp+i-linestart),linestart); 177 string line((char *)m_Buffer->getData(),(int32_t)(linestopp+i - linestart)); 178 if (line[line.size()-1] == '\n') 149 uint32_t bufferLength = m_Buffer->getSize(); 150 uint32_t lineLength, processedLength; 151 const char *look, *lineStart; 152 153 if(bufferLength < 2) 154 return; 155 156 processedLength = 0; 157 look = (char *) m_Buffer->getData(); 158 159 lineStart = look; 160 lineLength = 1; 161 ++look; 162 163 for(uint32_t i = 0; i < bufferLength; ++i, ++look) 164 { 165 if(* look == '\n' && * (look - 1) == '\r') 166 { 167 // -1 cuts the already processed '\r' 168 processLine(lineStart, lineLength - 1); 169 170 // + 1 includes the trailing '\n' 171 processedLength += lineLength + 1; 172 lineLength = 0; 173 lineStart = look + 1; 174 } 175 else 176 ++lineLength; 177 } 178 179 m_Buffer->cut(processedLength); 180 } 181 182 //! oxff: again slightly faster and definitely better readable 183 //! oxff: now splits into IRC RFC elements, not words (leaving PRIVMSG lines) 184 void IrcDialogue::processLine(const char *line, uint32_t lineLength) 185 { 186 vector<string> lineElements; 187 188 { 189 const char *look = line; 190 string element; 191 192 if(* line == ':') 193 { 194 if(!--lineLength) 195 return; 196 197 ++look; 198 } 199 200 //! oxff: this is a pre-condition to the parsing loop 201 if(* look == ':') 202 { 203 logWarn("IRC Server \"%s\" sent line beginning with two colons\n", m_LogIrc->getIrcServer().c_str()); 204 return; 205 } 206 207 for(uint32_t i = 0; i < lineLength; ++i, ++look) 208 { 209 if(* look == ' ') 179 210 { 180 line[line.size()-1] = '\0'; 211 lineElements.push_back(element); 212 element.erase(); 181 213 } 182 if (line[line.size()-2] == '\r') 183 { 184 line[line.size()-2] = '\0'; 214 else if(* look == ':' && * (look - 1) == ' ') // look behind allowed due to pre-condition 215 { 216 element = string(look + 1, lineLength - i - 1); 217 lineElements.push_back(element); 218 element.erase(); 219 220 break; 185 221 } 186 printf("test '%s'\n",line.c_str()); 187 processLine(&line); 188 m_Buffer->cut(i); 189 i=0; 190 linestart = linestopp+i; 191 }else 192 { 193 i++; 194 } 195 } 196 } 197 198 void IrcDialogue::processLine(string *line) 199 { 200 vector<string> words; 201 202 uint32_t i=0; 203 bool haschar = false; 204 uint32_t wordstart=0; 205 uint32_t wordstopp=0; 206 207 while ( i<=line->size() ) 208 { 209 if ( ( ( (*line)[i] == ' ' || (*line)[i] == '\0') && haschar == true) ) 210 { 211 wordstopp = i; 212 string word = line->substr(wordstart,wordstopp-wordstart); 213 // logInfo("Word is %i %i '%s' \n",wordstart,wordstopp,word.c_str()); 214 words.push_back(word); 215 haschar = false; 216 } else 217 if ( isgraph((*line)[i]) && haschar == false ) 218 { 219 haschar = true; 220 wordstart = i; 221 } 222 i++; 223 } 224 225 /* 226 for (i=0;i<words.size();i++) 227 { 228 logSpam("word is '%s'\n",words[i].c_str()); 229 } 230 */ 231 232 if (words[0] == "PING" ) 233 { 234 string reply = "PONG "; 235 reply += words[1]; 236 reply += "\r\n"; 237 m_Socket->doRespond((char *)reply.c_str(),reply.size()); 238 239 }else 240 if ( words[1] == "376" || words[1] == "422" ) 241 { 242 string reply = "JOIN "; 243 reply += m_LogIrc->getIrcChannel(); 244 reply += " "; 245 reply += m_LogIrc->getIrcChannelPass(); 246 reply += "\r\n"; 247 m_Socket->doRespond((char *)reply.c_str(),reply.size()); 248 m_LogIrc->setDialogue(this); 249 }else 250 if (words[1] == "PONG" ) 251 { 222 else 223 element.push_back(* look); 224 } 225 226 if(element.size()) 227 lineElements.push_back(element); 228 } 229 230 if(lineElements.empty()) 231 return; 232 233 234 if(lineElements.size() >= 1 && lineElements[1] == "433") 235 sendNick(true); 236 if(lineElements[0] == "PING" && lineElements.size() == 2) 237 { 238 string reply = "PONG " + lineElements[1] + "\r\n"; 239 240 m_Socket->doRespond((char *) reply.data(), reply.size()); 241 } 242 else if(lineElements[0] == "PONG") 252 243 m_Pinged = false; 253 }else 254 if ( words[1] == "433" ) 255 { 256 sendNick(true); 257 }else 258 if ( words.size() >= 4 && words[1] == "PRIVMSG" && words[3] == ":!version") 259 { 260 char *reply; 261 asprintf(&reply,"PRIVMSG %s :Nepenthes Version %s - Compiled on %s %s with %s %s \n",words[2].c_str(),VERSION,__DATE__, __TIME__,MY_COMPILER,__VERSION__); 262 m_Socket->doRespond((char *)reply,strlen(reply)); 263 free(reply); 264 } 265 return; 266 267 } 268 269 /** 270 * Dialogue::outgoingData(Message *) 271 * as we are not interested in these socket actions 272 * we simply return CL_DROP to show the socket 273 * 274 * @param msg 275 * 276 * @return CL_DROP 277 */ 244 else if(lineElements.size() >= 2 && (lineElements[1] == "003" ||lineElements[1] == "004" || lineElements[1] == "005" || lineElements[1] == "376" || lineElements[1] == "422")) 245 loggedOn(); 246 else if(lineElements.size() >= 4 && (lineElements[1] == "PRIVMSG" || lineElements[1] == "NOTICE")) 247 processMessage(lineElements[0].c_str(), lineElements[2].c_str(), lineElements[3].c_str());&nb
