1 /********************************************************************************
2  *                              Nepenthes
3  *                        - finest collection -
4  *
5  *
6  *
7  * Copyright (C) 2005  Paul Baecher & Markus Koetter
8  *
9  * This program is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU General Public License
11  * as published by the Free Software Foundation; either version 2
12  * of the License, or (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
22  *
23  *
24  *             contact nepenthesdev@users.sourceforge.net
25  *
26  *******************************************************************************/
27 
28  /* $Id: vuln-sub7.cpp 550 2006-05-04 10:25:35Z common $ */
29 
30 #include <cctype>
31 #include <cstdlib>
32 
33 #include "vuln-sub7.hpp"
34 #include "SUB7Dialogue.hpp"
35 
36 #include "SocketManager.hpp"
37 #include "Message.hpp"
38 #include "DownloadManager.hpp"
39 #include "LogManager.hpp"
40 
41 #include "Config.hpp"
42 
43 #ifdef STDTAGS
44 #undef STDTAGS
45 #endif
46 #define STDTAGS l_mod
47 
48 using namespace nepenthes;
49 
50 /**
51  * as we may need a global pointer to our Nepenthes in our modules,
52  * and cant access the cores global pointer to nepenthes
53  * we have to use a own global pointer to nepenthes per module
54  * we need this pointer for logInfo() etc
55  */
56 Nepenthes *g_Nepenthes;
57 
58 /**
59  * The Constructor
60  * creates a new SUB7Vuln Module,
61  * SUB7Vuln is an example for binding a socket & setting up the Dialogue & DialogueFactory
62  *
63  *
64  * it can be used as a shell emu to allow trigger commands
65  *
66  *
67  * sets the following values:
68  * - m_DialogueFactoryName
69  * - m_DialogueFactoryDescription
70  *
71  * @param nepenthes the pointer to our Nepenthes
72  */
SUB7Vuln(Nepenthes * nepenthes)73 SUB7Vuln::SUB7Vuln(Nepenthes *nepenthes)
74 {
75 	m_ModuleName        = "vuln-sub7";
76 	m_ModuleDescription = "emulate the sub7 backdoor";
77 	m_ModuleRevision    = "$Rev: 550 $";
78 	m_Nepenthes = nepenthes;
79 
80 	m_DialogueFactoryName = "SUB7DialogueFactory";
81 	m_DialogueFactoryDescription = "creates Sub7 Dialogues";
82 
83 	g_Nepenthes = nepenthes;
84 }
85 
~SUB7Vuln()86 SUB7Vuln::~SUB7Vuln()
87 {
88 
89 }
90 
91 
92 /**
93  * Module::Init()
94  *
95  * binds the port, adds the DialogueFactory to the Socket
96  *
97  * @return returns true if everything was fine, else false
98  *         false indicates a fatal error
99  */
Init()100 bool SUB7Vuln::Init()
101 {
102    logPF();
103 	if ( m_Config == NULL )
104 	{
105 		logCrit("I need a config\n");
106 		return false;
107 	}
108 
109 	StringList sList;
110 	int32_t timeout;
111 	try
112 	{
113 		sList = *m_Config->getValStringList("vuln-sub7.ports");
114 		timeout = m_Config->getValInt("vuln-sub7.accepttimeout");
115 	} catch ( ... )
116 	{
117 		logCrit("Error setting needed vars, check your config\n");
118 		return false;
119 	}
120 
121 	uint32_t i = 0;
122 	while (i < sList.size())
123 	{
124 		m_Nepenthes->getSocketMgr()->bindTCPSocket(0,atoi(sList[i]),0,timeout,this);
125 		i++;
126 	}
127 
128 	m_ModuleManager = m_Nepenthes->getModuleMgr();
129 
130 	return true;
131 }
132 
Exit()133 bool SUB7Vuln::Exit()
134 {
135 	return true;
136 }
137 
138 /**
139  * DialogueFactory::createDialogue(Socket *)
140  *
141  * creates a new SUB7VulnDialogue
142  *
143  * @param socket the socket the DIalogue has to use, can be NULL if the Dialogue can handle it
144  *
145  * @return returns the new created dialogue
146  */
createDialogue(Socket * socket)147 Dialogue *SUB7Vuln::createDialogue(Socket *socket)
148 {
149 	return new SUB7Dialogue(socket);
150 }
151 
152 
153 
module_init(int32_t version,Module ** module,Nepenthes * nepenthes)154 extern "C" int32_t module_init(int32_t version, Module **module, Nepenthes *nepenthes)
155 {
156 	if (version == MODULE_IFACE_VERSION) {
157         *module = new SUB7Vuln(nepenthes);
158         return 1;
159     } else {
160         return 0;
161     }
162 }
163 
164