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: OPTIXShellDialogue.cpp 1410 2007-10-12 13:07:23Z common $ */
29
30 #include "vuln-optix.hpp"
31 #include "OPTIXShellDialogue.hpp"
32
33 #include "SocketManager.hpp"
34 #include "Message.hpp"
35 #include "DownloadManager.hpp"
36 #include "LogManager.hpp"
37
38 #include "Buffer.hpp"
39 #include "Buffer.cpp"
40 #include "Utilities.hpp"
41
42 #include "DialogueFactoryManager.hpp"
43
44 #ifdef STDTAGS
45 #undef STDTAGS
46 #endif
47 #define STDTAGS l_mod
48
49 using namespace nepenthes;
50
51 /**
52 * Dialogue::Dialogue(Socket *)
53 * construktor for the OPTIXShellDialogue, creates a new OPTIXShellDialogue
54 *
55 * replies some crap to the socket
56 *
57 * @param socket the Socket the Dialogue has to use
58 */
OPTIXShellDialogue(Socket * socket)59 OPTIXShellDialogue::OPTIXShellDialogue(Socket *socket)
60 {
61 m_Socket = socket;
62 m_DialogueName = "OPTIXShellDialogue";
63 m_DialogueDescription = "Optix Shell Dialogue";
64
65 m_ConsumeLevel = CL_ASSIGN;
66
67 // m_Socket->doRespond("Welcome to dong Shell\n",strlen("Welcome to dong Shell\n"));
68
69 m_Buffer = new Buffer(256);
70 m_State = OPTIX_CONNECTED;
71 }
72
~OPTIXShellDialogue()73 OPTIXShellDialogue::~OPTIXShellDialogue()
74 {
75 delete m_Buffer;
76 }
77
78 /**
79 * Dialogue::incomingData(Message *)
80 *
81 * @param msg the Message the Socker received.
82 *
83 *
84 * @return CL_ASSIGN
85 */
incomingData(Message * msg)86 ConsumeLevel OPTIXShellDialogue::incomingData(Message *msg)
87 {
88 m_Buffer->add(msg->getMsg(),msg->getSize());
89
90 switch(m_State)
91 {
92 case OPTIX_CONNECTED:
93 if (m_Buffer->getSize() > 4)
94 {
95 // we could do this with pcre ...
96 if (memcmp(m_Buffer->getData(),"022�",4) == 0)
97 {
98 m_State = OPTIX_AUTHED;
99
100 // dont know what exactly the optix replies
101 msg->getResponder()->doRespond("001� YOhoo your mum\r\n",strlen("001� YOhoo your mum\r\n"));
102 m_Buffer->clear();
103 }
104 }
105 break;
106
107 case OPTIX_AUTHED:
108 if (m_Buffer->getSize() >= 6)
109 {
110 // g_Nepenthes->getUtilities()->hexdump((byte *)m_Buffer->getData(),m_Buffer->getSize());
111 // we could do this with pcre ...
112 if (memcmp(m_Buffer->getData(),"019�\r\n",6) == 0)
113 {
114 msg->getResponder()->doRespond("020�\r\n",strlen("020�\r\n"));
115 m_Buffer->clear();
116
117 // this will just open the optix downloadmanagers bind socket it its closed
118
119 g_Nepenthes->getDownloadMgr()->downloadUrl(msg->getLocalHost(),(char *)"optix://localhost:500/file",msg->getRemoteHost(),(char *)"optix foobar",0);
120 }
121 }
122 break;
123
124 }
125
126 return CL_ASSIGN;
127 }
128
129 /**
130 * Dialogue::outgoingData(Message *)
131 * as we are not interested in these socket actions
132 * we simply return CL_DROP to show the socket
133 *
134 * @param msg
135 *
136 * @return CL_DROP
137 */
outgoingData(Message * msg)138 ConsumeLevel OPTIXShellDialogue::outgoingData(Message *msg)
139 {
140 return m_ConsumeLevel;
141 }
142
143 /**
144 * Dialogue::handleTimeout(Message *)
145 * as we are not interested in these socket actions
146 * we simply return CL_DROP to show the socket
147 *
148 * @param msg
149 *
150 * @return CL_DROP
151 */
handleTimeout(Message * msg)152 ConsumeLevel OPTIXShellDialogue::handleTimeout(Message *msg)
153 {
154 return CL_DROP;
155 }
156
157 /**
158 * Dialogue::connectionLost(Message *)
159 * as we are not interested in these socket actions
160 * we simply return CL_DROP to show the socket
161 *
162 * @param msg
163 *
164 * @return CL_DROP
165 */
connectionLost(Message * msg)166 ConsumeLevel OPTIXShellDialogue::connectionLost(Message *msg)
167 {
168 return CL_DROP;
169 }
170
171 /**
172 * Dialogue::connectionShutdown(Message *)
173 * as we are not interested in these socket actions
174 * we simply return CL_DROP to show the socket
175 *
176 * @param msg
177 *
178 * @return CL_DROP
179 */
connectionShutdown(Message * msg)180 ConsumeLevel OPTIXShellDialogue::connectionShutdown(Message *msg)
181 {
182 return CL_DROP;
183 }
184
185