Changeset 572

Show
Ignore:
Timestamp:
06/22/06 19:55:04 (3 years ago)
Author:
common
Message:

nepenthes
- module-honeytrap

  • fix modulename
  • add credits
  • set timeouts on pcap & ipq listeners
Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • nepenthes/trunk/modules/module-honeytrap/module-honeytrap.cpp

    r569 r572  
    6161 
    6262 
     63/* 
     64 * This module is derived from honeytrap (honeytrap.sf.net) by Werner Tillmann 
     65 * 
     66 * The idea is really good, and it as it was easy to make a nepenthes module of it, we stole it 
     67 * 
     68 */  
     69 
     70 
     71 
     72 
    6373/** 
    6474 * as we may need a global pointer to our Nepenthes in our modules, 
     
    7181/** 
    7282 * The Constructor 
    73  * creates a new X2 Module,  
    74  * X2 is an example for binding a socket & setting up the Dialogue & DialogueFactory 
    75  *  
    76  *  
    77  * it can be used as a shell emu to allow trigger commands  
    78  *  
    79  *  
    80  * sets the following values: 
    81  * - m_DialogueFactoryName 
    82  * - m_DialogueFactoryDescription 
     83 * creates a new ModuleHoneyTrap Module,  
    8384 *  
    8485 * @param nepenthes the pointer to our Nepenthes 
    8586 */ 
    86 X2::X2(Nepenthes *nepenthes) 
    87 { 
    88         m_ModuleName        = "x-2"; 
    89         m_ModuleDescription = "eXample Module 2 -binding sockets & setting up a dialogue example-"; 
     87ModuleHoneyTrap::ModuleHoneyTrap(Nepenthes *nepenthes) 
     88{ 
     89        m_ModuleName        = "module-honeytrap"; 
     90        m_ModuleDescription = "open closed ports to accept connections - idea from http://honeytrap.sf.net "; 
    9091        m_ModuleRevision    = "$Rev$"; 
    9192        m_Nepenthes = nepenthes; 
    9293 
    9394        g_Nepenthes = nepenthes; 
     95 
     96#ifdef HAVE_PCAP 
    9497        m_RawListener = NULL; 
    95  
     98#endif 
     99 
     100#ifdef HAVE_IPQ 
    96101        m_IPQHandle = NULL; 
     102#endif  
    97103 
    98104        m_HTType = HT_IPQ; 
    99105} 
    100106 
    101 X2::~X2() 
     107ModuleHoneyTrap::~ModuleHoneyTrap() 
    102108{ 
    103109 
     
    108114 * Module::Init() 
    109115 *  
    110  * binds the port, adds the DialogueFactory to the Socket 
    111116 *  
    112117 * @return returns true if everything was fine, else false 
    113118 *         false indicates a fatal error 
    114119 */ 
    115 bool X2::Init() 
    116 
    117  
     120bool ModuleHoneyTrap::Init() 
     121
     122        string isupport = ""; 
     123 
     124#ifdef HAVE_PCAP 
     125        isupport += "pcap,"; 
     126#endif 
     127 
     128#ifdef HAVE_IPQ 
     129        isupport += "ipq"; 
     130#endif 
     131 
     132        logInfo("ModuleHoneyTrap compiled with support for %s\n",isupport.c_str()); 
    118133 
    119134        if ( m_Config == NULL ) 
     
    137152        { 
    138153                m_HTType = HT_PCAP; 
     154                 
    139155        }else 
    140156        if (mode == "ipq") 
     
    143159        }else 
    144160        { 
    145                 logCrit("Invlaid mode %s for module-honeytrap\n",mode.c_str()); 
    146                 return false; 
    147         } 
     161                logCrit("Invalid mode %s for module-honeytrap\n",mode.c_str()); 
     162                return false; 
     163        } 
     164 
     165        logInfo("ModuleHoneyTrap mode %s\n",mode.c_str()); 
    148166 
    149167        bool retval = false; 
     
    172190} 
    173191 
    174 bool X2::Init_IPQ() 
     192bool ModuleHoneyTrap::Init_IPQ() 
    175193{ 
    176194#ifdef HAVE_IPQ 
     
    192210} 
    193211 
    194 bool X2::Init_PCAP() 
     212bool ModuleHoneyTrap::Init_PCAP() 
    195213{ 
    196214 
     
    248266} 
    249267 
    250 bool X2::Exit() 
     268bool ModuleHoneyTrap::Exit() 
    251269{ 
    252270        bool retval = false; 
     
    264282} 
    265283 
    266 bool X2::Exit_PCAP() 
     284bool ModuleHoneyTrap::Exit_PCAP() 
    267285{ 
    268286#ifdef HAVE_PCAP 
     
    292310} 
    293311 
    294 bool X2::Exit_IPQ() 
     312bool ModuleHoneyTrap::Exit_IPQ() 
    295313{ 
    296314#ifdef HAVE_IPQ 
     
    306324 
    307325 
    308 bool X2::wantSend() 
     326bool ModuleHoneyTrap::wantSend() 
    309327{ 
    310328 
     
    312330} 
    313331 
    314 int32_t X2::doSend() 
     332int32_t ModuleHoneyTrap::doSend() 
    315333{ 
    316334 
     
    318336} 
    319337 
    320 int32_t X2::doRecv() 
     338int32_t ModuleHoneyTrap::doRecv() 
    321339{ 
    322340 
     
    335353} 
    336354 
    337 int32_t X2::doRecv_PCAP() 
     355int32_t ModuleHoneyTrap::doRecv_PCAP() 
    338356{ 
    339357 
     
    358376                logInfo("Got RST packet from localhost:%i %i\n",ntohs(tcp->th_sport),tcp->th_sport); 
    359377 
    360                 Socket *sock = g_Nepenthes->getSocketMgr()->bindTCPSocket(INADDR_ANY,ntohs(tcp->th_sport),0,60); 
     378                Socket *sock = g_Nepenthes->getSocketMgr()->bindTCPSocket(INADDR_ANY,ntohs(tcp->th_sport),600,60); 
    361379                if ( sock != NULL ) 
    362380                { 
     
    381399} 
    382400 
    383 int32_t X2::doRecv_IPQ() 
     401int32_t ModuleHoneyTrap::doRecv_IPQ() 
    384402{ 
    385403        logPF(); 
     
    472490                                                logInfo("Connection to unbound port %i requested, binding port\n",ntohs(tcp->th_dport)); 
    473491 
    474                                                 Socket *sock = g_Nepenthes->getSocketMgr()->bindTCPSocket(INADDR_ANY,ntohs(tcp->th_dport),0,60); 
     492                                                Socket *sock = g_Nepenthes->getSocketMgr()->bindTCPSocket(INADDR_ANY,ntohs(tcp->th_dport),60,60); 
    475493                                                if ( sock != NULL ) 
    476494                                                { 
     
    504522} 
    505523 
    506 int32_t X2::getSocket() 
     524int32_t ModuleHoneyTrap::getSocket() 
    507525{ 
    508526        switch ( m_HTType ) 
     
    523541} 
    524542 
    525 int32_t X2::getsockOpt(int32_t level, int32_t optname,void *optval,socklen_t *optlen) 
     543int32_t ModuleHoneyTrap::getsockOpt(int32_t level, int32_t optname,void *optval,socklen_t *optlen) 
    526544{ 
    527545        return getsockopt(getSocket(), level, optname, optval, optlen); 
     
    529547 
    530548 
    531 bool X2::isPortListening(uint16_t localport, uint32_t localhost) 
     549bool ModuleHoneyTrap::isPortListening(uint16_t localport, uint32_t localhost) 
    532550{ 
    533551        logSpam("looking for %s:%i\n",inet_ntoa(*(struct in_addr *)&localhost),localport); 
     
    537555        char line[512]; 
    538556        struct sockaddr_in localaddr; //, remaddr; 
     557 
     558        /* 
     559         * parsing logic basically taken from netstat.c tcp_do_one() in net-tools  
     560         * 
     561         */ 
    539562 
    540563        FILE *fp; 
     
    590613        if ( version == MODULE_IFACE_VERSION ) 
    591614        { 
    592                 *module = new X2(nepenthes); 
     615                *module = new ModuleHoneyTrap(nepenthes); 
    593616                return 1; 
    594617        } 
     
    598621        } 
    599622} 
     623 
  • nepenthes/trunk/modules/module-honeytrap/module-honeytrap.hpp

    r569 r572  
    142142        } honeytrap_type; 
    143143 
    144         class X2 : public Module, public POLLSocket //, public DialogueFactory 
     144        class ModuleHoneyTrap : public Module, public POLLSocket //, public DialogueFactory 
    145145        { 
    146146        public: 
    147                 X2(Nepenthes *); 
    148                 ~X2(); 
     147                ModuleHoneyTrap(Nepenthes *); 
     148                ~ModuleHoneyTrap(); 
    149149//              Dialogue *createDialogue(Socket *socket); 
    150150                bool Init(); 
     
    170170 
    171171        protected: 
     172#ifdef HAVE_PCAP 
    172173                pcap_t  *m_RawListener; 
     174#endif 
     175  
     176#ifdef HAVE_IPQ 
     177                struct ipq_handle *m_IPQHandle; 
     178#endif 
     179 
    173180                Nepenthes *m_Nepenthes; 
    174                 struct ipq_handle *m_IPQHandle; 
    175  
    176181                honeytrap_type m_HTType; 
    177  
    178182        }; 
    179183