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: CReceiveDialogue.cpp 836 2007-02-06 15:16:50Z common $ */
29 
30 #include <cstdio>
31 
32 #include "CReceiveDialogue.hpp"
33 
34 #include "SocketManager.hpp"
35 
36 #include "DownloadManager.hpp"
37 #include "LogManager.hpp"
38 #include "DialogueFactoryManager.hpp"
39 
40 
41 #include "Buffer.hpp"
42 
43 #include "Message.hpp"
44 
45 #include "ShellcodeManager.hpp"
46 #include "Utilities.hpp"
47 
48 #include "Download.hpp"
49 #include "DownloadUrl.hpp"
50 #include "DownloadBuffer.hpp"
51 
52 #include "Download.cpp"
53 #include "DownloadUrl.cpp"
54 #include "DownloadBuffer.cpp"
55 
56 #include "SubmitManager.hpp"
57 
58 #ifdef STDTAGS
59 #undef STDTAGS
60 #endif
61 #define STDTAGS l_dl | l_dia | l_hlr
62 
63 using namespace nepenthes;
64 
65 
66 
67 /**
68  * Dialogue::Dialogue(Socket *)
69  * construktor for the CReceiveDialogue, creates a new CReceiveDialogue
70  *
71  * replies some crap to the socket
72  *
73  * @param socket the Socket the Dialogue has to use
74  */
CReceiveDialogue(Socket * socket)75 CReceiveDialogue::CReceiveDialogue(Socket *socket)//, Download *down)
76 {
77 	m_Socket = socket;
78     m_DialogueName = "CReceiveDialogue";
79 	m_DialogueDescription = "eXample Dialogue";
80 
81 	m_ConsumeLevel = CL_ASSIGN;
82 	char *url;
83 	uint32_t host = socket->getRemoteHost();
84 	uint16_t port = socket->getRemotePort();
85 	asprintf(&url,"creceive://%s:%i",inet_ntoa(*(in_addr *)&host),port);
86     m_Download = new Download(socket->getLocalHost(),url,socket->getRemoteHost(),url);
87 	free(url);
88 }
89 
~CReceiveDialogue()90 CReceiveDialogue::~CReceiveDialogue()
91 {
92 //	HEXDUMP(m_Socket,(byte *)m_Buffer->getData(),m_Buffer->getSize());
93 //	delete m_Buffer;
94 	delete m_Download;
95 }
96 
97 /**
98  * Dialogue::incomingData(Message *)
99  *
100  *
101  * @param msg the Message the Socker received.
102  *
103  *
104  * @return CL_ASSIGN
105  */
incomingData(Message * msg)106 ConsumeLevel CReceiveDialogue::incomingData(Message *msg)
107 {
108 	logSpam("... DATA ... FIXME %i bytes \n",msg->getSize());
109 	m_Download->getDownloadBuffer()->addData(msg->getMsg(),msg->getSize());
110 
111 	if (m_Download->getDownloadBuffer()->getSize() > 1024 * 1024 * 4)	// hardcoded 4mb limit for now (tm)
112 		return CL_DROP;
113 
114 	return CL_ASSIGN;
115 }
116 
117 /**
118  * Dialogue::outgoingData(Message *)
119  * as we are not interested in these socket actions
120  * we simply return CL_DROP to show the socket
121  *
122  * @param msg
123  *
124  * @return CL_DROP
125  */
outgoingData(Message * msg)126 ConsumeLevel CReceiveDialogue::outgoingData(Message *msg)
127 {
128 	return CL_ASSIGN;
129 }
130 
131 /**
132  * Dialogue::handleTimeout(Message *)
133  * as we are not interested in these socket actions
134  * we simply return CL_DROP to show the socket
135  *
136  * @param msg
137  *
138  * @return CL_DROP
139  */
handleTimeout(Message * msg)140 ConsumeLevel CReceiveDialogue::handleTimeout(Message *msg)
141 {
142 	return CL_DROP;
143 }
144 
145 /**
146  * Dialogue::connectionLost(Message *)
147  * as we are not interested in these socket actions
148  * we simply return CL_DROP to show the socket
149  *
150  * @param msg
151  *
152  * @return CL_DROP
153  */
connectionLost(Message * msg)154 ConsumeLevel CReceiveDialogue::connectionLost(Message *msg)
155 {
156 	return CL_DROP;
157 }
158 
159 /**
160  * Dialogue::connectionShutdown(Message *)
161  * as we are not interested in these socket actions
162  * we simply return CL_DROP to show the socket
163  *
164  * @param msg
165  *
166  * @return CL_DROP
167  */
connectionShutdown(Message * msg)168 ConsumeLevel CReceiveDialogue::connectionShutdown(Message *msg)
169 {
170 	g_Nepenthes->getSubmitMgr()->addSubmission(m_Download);
171 	return CL_DROP;
172 }
173 
174