OpenSDE Packages Database (without history before r20070)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

4595 lines
148 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../nepenthes/nepenthes-0.2.0-update-r1345.patch
  5. # Copyright (C) 2007 The OpenSDE Project
  6. #
  7. # More information can be found in the files COPYING and README.
  8. #
  9. # This patch file is dual-licensed. It is available under the license the
  10. # patched project is licensed under, as long as it is an OpenSource license
  11. # as defined at http://www.opensource.org/ (e.g. BSD, X11) or under the terms
  12. # of the GNU General Public License as published by the Free Software
  13. # Foundation; either version 2 of the License, or (at your option) any later
  14. # version.
  15. # --- SDE-COPYRIGHT-NOTE-END ---
  16. diff -ruN nepenthes-0.2.0/conf/nepenthes.conf.dist nepenthes-0.2.0-r1345/conf/nepenthes.conf.dist
  17. --- nepenthes-0.2.0/conf/nepenthes.conf.dist 2006-11-13 20:40:03.000000000 +0100
  18. +++ nepenthes-0.2.0-r1345/conf/nepenthes.conf.dist 2007-08-06 00:46:15.000000000 +0200
  19. @@ -35,10 +35,12 @@
  20. // "submitnorman.so", "submit-norman.conf", ""
  21. // "submitnepenthes.so", "submit-nepenthes.conf", "" // send to download-nepenthes in other nepenthes instances
  22. // "submitxmlrpc.so", "submit-xmlrpc.conf", "" // submit files to a xmlrpc server
  23. +// "submithttp.so", "submit-http.conf", "" // submit files to a web server
  24. // logging
  25. "logdownload.so", "log-download.conf", ""
  26. // "logirc.so", "log-irc.conf", "" // needs configuration
  27. +// "logprelude.so", "log-prelude.conf", ""
  28. // dumping and logging
  29. diff -ruN nepenthes-0.2.0/configure.ac nepenthes-0.2.0-r1345/configure.ac
  30. --- nepenthes-0.2.0/configure.ac 2006-11-13 20:50:47.000000000 +0100
  31. +++ nepenthes-0.2.0-r1345/configure.ac 2007-08-06 00:46:15.000000000 +0200
  32. @@ -201,6 +201,9 @@
  33. # libdl
  34. AC_SUBST([LIB_DL])
  35. +# libssh
  36. +AC_SUBST([LIB_SSH])
  37. +
  38. dnl **************************************************
  39. dnl * libdl linking flag *
  40. dnl **************************************************
  41. @@ -788,12 +791,11 @@
  42. AC_DEFINE(HAVE_LIBPRELUDE, 1,[Define if you want to use libprelude])
  43. PRELUDE_LDFLAGS=`$LIBPRELUDE_CONFIG --ldflags`
  44. PRELUDE_LIBS=`$LIBPRELUDE_CONFIG --libs`
  45. - PRELUDE_CPPFLAGS=`$LIBPRELUDE_CONFIG --cflags`
  46. + PRELUDE_CPPFLAGS=`$LIBPRELUDE_CONFIG --pthread-cflags`
  47. LIB_PRELUDE="$PRELUDE_LIBS"
  48. LDFLAG_PRELUDE="$PRELUDE_LDFLAGS"
  49. - CPPFLAG="$PRELUDE_CPPFLAGS"
  50. -
  51. + CPPFLAGS="$CPPFLAGS $PRELUDE_CPPFLAGS"
  52. fi
  53. fi
  54. @@ -913,6 +915,8 @@
  55. modules/submit-gotek/Makefile
  56. modules/submit-norman/Makefile
  57. modules/submit-postgres/Makefile
  58. + modules/submit-http/Makefile
  59. + modules/submit-mwserv/Makefile
  60. modules/vuln-asn1/Makefile
  61. modules/vuln-bagle/Makefile
  62. modules/vuln-dameware/Makefile
  63. @@ -931,6 +935,7 @@
  64. modules/vuln-pnp/Makefile
  65. modules/vuln-realvnc/Makefile
  66. modules/vuln-sasserftpd/Makefile
  67. + modules/vuln-sav/Makefile
  68. modules/vuln-ssh/Makefile
  69. modules/vuln-sub7/Makefile
  70. modules/vuln-upnp/Makefile
  71. diff -ruN nepenthes-0.2.0/modules/Makefile.am nepenthes-0.2.0-r1345/modules/Makefile.am
  72. --- nepenthes-0.2.0/modules/Makefile.am 2006-11-13 20:40:11.000000000 +0100
  73. +++ nepenthes-0.2.0-r1345/modules/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  74. @@ -4,11 +4,11 @@
  75. SUBDIRS = download-creceive download-csend download-curl download-ftp download-http download-link download-tftp download-rcp\
  76. log-download log-irc \
  77. - submit-file submit-gotek submit-norman submit-postgres\
  78. + submit-file submit-gotek submit-norman submit-postgres submit-http submit-mwserv \
  79. shellcode-generic shellemu-winnt \
  80. vuln-asn1 vuln-bagle vuln-dcom vuln-iis vuln-kuang2 vuln-lsass \
  81. vuln-msdtc vuln-msmq vuln-mssql vuln-mydoom \
  82. - vuln-netbiosname vuln-netdde vuln-optix vuln-pnp vuln-sasserftpd \
  83. + vuln-netbiosname vuln-netdde vuln-optix vuln-pnp vuln-sasserftpd vuln-sav \
  84. vuln-sub7 vuln-upnp vuln-veritas vuln-wins vuln-dameware vuln-ssh vuln-realvnc \
  85. module-portwatch module-honeytrap module-bridge module-peiros\
  86. dnsresolve-adns \
  87. diff -ruN nepenthes-0.2.0/modules/dnsresolve-adns/Makefile.am nepenthes-0.2.0-r1345/modules/dnsresolve-adns/Makefile.am
  88. --- nepenthes-0.2.0/modules/dnsresolve-adns/Makefile.am 2006-11-13 20:40:10.000000000 +0100
  89. +++ nepenthes-0.2.0-r1345/modules/dnsresolve-adns/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  90. @@ -12,4 +12,4 @@
  91. dnsresolveadns_la_SOURCES = dnsresolve-adns.cpp dnsresolve-adns.hpp
  92. -dnsresolveadns_la_LDFLAGS = -module -no-undefined -avoid-version
  93. +dnsresolveadns_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  94. diff -ruN nepenthes-0.2.0/modules/dnsresolve-adns/dnsresolve-adns.cpp nepenthes-0.2.0-r1345/modules/dnsresolve-adns/dnsresolve-adns.cpp
  95. --- nepenthes-0.2.0/modules/dnsresolve-adns/dnsresolve-adns.cpp 2006-11-13 20:40:10.000000000 +0100
  96. +++ nepenthes-0.2.0-r1345/modules/dnsresolve-adns/dnsresolve-adns.cpp 2007-08-06 00:46:15.000000000 +0200
  97. @@ -47,6 +47,7 @@
  98. #include "EventManager.hpp"
  99. +#include "Nepenthes.hpp"
  100. using namespace std;
  101. diff -ruN nepenthes-0.2.0/modules/download-creceive/CReceiveDialogue.cpp nepenthes-0.2.0-r1345/modules/download-creceive/CReceiveDialogue.cpp
  102. --- nepenthes-0.2.0/modules/download-creceive/CReceiveDialogue.cpp 2006-11-13 20:40:09.000000000 +0100
  103. +++ nepenthes-0.2.0-r1345/modules/download-creceive/CReceiveDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  104. @@ -87,7 +87,7 @@
  105. CReceiveDialogue::~CReceiveDialogue()
  106. {
  107. -// g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  108. +// HEXDUMP(m_Socket,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  109. // delete m_Buffer;
  110. delete m_Download;
  111. }
  112. diff -ruN nepenthes-0.2.0/modules/download-curl/Makefile.am nepenthes-0.2.0-r1345/modules/download-curl/Makefile.am
  113. --- nepenthes-0.2.0/modules/download-curl/Makefile.am 2006-11-13 20:40:06.000000000 +0100
  114. +++ nepenthes-0.2.0-r1345/modules/download-curl/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  115. @@ -12,4 +12,4 @@
  116. downloadcurl_la_SOURCES = download-curl.conf.dist download-curl.hpp download-curl.cpp
  117. -downloadcurl_la_LDFLAGS = -module -no-undefined -avoid-version
  118. +downloadcurl_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  119. diff -ruN nepenthes-0.2.0/modules/download-curl/download-curl.cpp nepenthes-0.2.0-r1345/modules/download-curl/download-curl.cpp
  120. --- nepenthes-0.2.0/modules/download-curl/download-curl.cpp 2006-11-13 20:40:06.000000000 +0100
  121. +++ nepenthes-0.2.0-r1345/modules/download-curl/download-curl.cpp 2007-08-06 00:46:15.000000000 +0200
  122. @@ -230,7 +230,9 @@
  123. down->getDownloadUrl()->getPort(),
  124. down->getDownloadUrl()->getPath().c_str());
  125. // string auth = down->getDownloadUrl()->getUser() + ":" + down->getDownloadUrl()->getPass();
  126. +#if LIBCURL_VERSION_NUM < 0x071000
  127. curl_easy_setopt(pCurlHandle, CURLOPT_SOURCE_USERPWD,(char *)down->getDownloadUrl()->getAuth().c_str());
  128. +#endif
  129. curl_easy_setopt(pCurlHandle, CURLOPT_USERPWD,(char *)down->getDownloadUrl()->getAuth().c_str());
  130. curl_easy_setopt(pCurlHandle, CURLOPT_URL , url);
  131. curl_easy_setopt(pCurlHandle, CURLOPT_FTP_RESPONSE_TIMEOUT, 120); // 2 min ftp timeout
  132. diff -ruN nepenthes-0.2.0/modules/download-http/HTTPDialogue.cpp nepenthes-0.2.0-r1345/modules/download-http/HTTPDialogue.cpp
  133. --- nepenthes-0.2.0/modules/download-http/HTTPDialogue.cpp 2006-11-13 20:40:04.000000000 +0100
  134. +++ nepenthes-0.2.0-r1345/modules/download-http/HTTPDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  135. @@ -178,7 +178,7 @@
  136. if ( end == NULL )
  137. {
  138. logWarn("HTTP ERROR header found %i\n", size);
  139. - g_Nepenthes->getUtilities()->hexdump((byte *)start,size);
  140. +// g_Nepenthes->getUtilities()->hexdump((byte *)start,size);
  141. return CL_DROP;
  142. }else
  143. if ( end != NULL )
  144. diff -ruN nepenthes-0.2.0/modules/download-link/LinkDialogue.cpp nepenthes-0.2.0-r1345/modules/download-link/LinkDialogue.cpp
  145. --- nepenthes-0.2.0/modules/download-link/LinkDialogue.cpp 2006-11-13 20:40:10.000000000 +0100
  146. +++ nepenthes-0.2.0-r1345/modules/download-link/LinkDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  147. @@ -122,7 +122,7 @@
  148. case LINK_NULL:
  149. {
  150. m_Buffer->add(msg->getMsg(),msg->getSize());
  151. -// g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  152. +// HEXDUMP(m_Socket,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  153. msg->getResponder()->doRespond((char *)&m_Challenge,4);
  154. m_State = LINK_FILE;
  155. diff -ruN nepenthes-0.2.0/modules/log-irc/log-irc.cpp nepenthes-0.2.0-r1345/modules/log-irc/log-irc.cpp
  156. --- nepenthes-0.2.0/modules/log-irc/log-irc.cpp 2006-11-13 20:40:09.000000000 +0100
  157. +++ nepenthes-0.2.0-r1345/modules/log-irc/log-irc.cpp 2007-08-06 00:46:15.000000000 +0200
  158. @@ -171,7 +171,7 @@
  159. }
  160. // m_Nepenthes->getSocketMgr()->bindTCPSocket(0,10002,0,45,this);
  161. - g_Nepenthes->getLogMgr()->addLogger(this,l_dl|l_sub);
  162. + g_Nepenthes->getLogMgr()->addLogger(this,l_all);
  163. return true;
  164. }
  165. diff -ruN nepenthes-0.2.0/modules/log-prelude/Makefile.am nepenthes-0.2.0-r1345/modules/log-prelude/Makefile.am
  166. --- nepenthes-0.2.0/modules/log-prelude/Makefile.am 2006-11-13 20:40:08.000000000 +0100
  167. +++ nepenthes-0.2.0-r1345/modules/log-prelude/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  168. @@ -4,7 +4,7 @@
  169. AUTOMAKE_OPTIONS = foreign
  170. -AM_CPPFLAGS = -I/usr/include/libprelude -I$(top_srcdir)/nepenthes-core/include -I$(top_srcdir)/nepenthes-core/src -pipe -D _GNU_SOURCE $(CPPFLAG_PRELUDE)
  171. +AM_CPPFLAGS = -I$(top_srcdir)/nepenthes-core/include -I$(top_srcdir)/nepenthes-core/src -pipe -D _GNU_SOURCE
  172. AM_CXXFLAGS = -Wall
  173. AM_LDFLAGS = $(LDFLAG_PRELUDE) ${LIB_PRELUDE}
  174. @@ -12,5 +12,5 @@
  175. logprelude_la_SOURCES = log-prelude.cpp log-prelude.hpp log-prelude.conf.dist
  176. -logprelude_la_LDFLAGS = -module -no-undefined -avoid-version
  177. +logprelude_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  178. diff -ruN nepenthes-0.2.0/modules/log-prelude/log-prelude.conf.dist nepenthes-0.2.0-r1345/modules/log-prelude/log-prelude.conf.dist
  179. --- nepenthes-0.2.0/modules/log-prelude/log-prelude.conf.dist 2006-11-13 20:40:08.000000000 +0100
  180. +++ nepenthes-0.2.0-r1345/modules/log-prelude/log-prelude.conf.dist 2007-08-06 00:46:15.000000000 +0200
  181. @@ -1,7 +1,9 @@
  182. log-prelude
  183. {
  184. - analyzerClass "NIDS";
  185. - analyzerModel "nepenthes";
  186. - analyzerName "nepenthes";
  187. -
  188. +
  189. + // Name of the Prelude analyzer to use (default is nepenthes).
  190. + // analyzerName "nepenthes";
  191. +
  192. + // Name of the Prelude profile to use (default is nepenthes).
  193. + // analyzerProfile "nepenthes";
  194. };
  195. diff -ruN nepenthes-0.2.0/modules/log-prelude/log-prelude.cpp nepenthes-0.2.0-r1345/modules/log-prelude/log-prelude.cpp
  196. --- nepenthes-0.2.0/modules/log-prelude/log-prelude.cpp 2006-11-13 20:40:08.000000000 +0100
  197. +++ nepenthes-0.2.0-r1345/modules/log-prelude/log-prelude.cpp 2007-08-06 00:48:07.000000000 +0200
  198. @@ -27,14 +27,6 @@
  199. /* $Id: log-prelude.cpp 550 2006-05-04 10:25:35Z common $ */
  200. -#ifdef HAVE_LIBPRELUDE
  201. -#include <prelude.h>
  202. -#include <libprelude/prelude-log.h>
  203. -#include <idmef-message-print.h>
  204. -#include <prelude-io.h>
  205. -#include <libprelude/prelude-timer.h>
  206. -#endif
  207. -
  208. #include <arpa/inet.h>
  209. #include "log-prelude.hpp"
  210. #include "Nepenthes.hpp"
  211. @@ -63,7 +55,11 @@
  212. #define STDTAGS l_mod | l_ev | l_hlr
  213. #define ANALYZER_MANUFACTURER "http://nepenthes.sf.net"
  214. -#define NEPENTHES_VERSION "$Rev: 550 $"
  215. +#define DEFAULT_ANALYZER_NAME "nepenthes"
  216. +#define DEFAULT_ANALYZER_PROFILE "nepenthes"
  217. +#define ANALYZER_MODEL "Nepenthes"
  218. +#define ANALYZER_CLASS "Honeypot"
  219. +#define ANALYZER_MANUFACTURER "http://nepenthes.mwcollect.org/"
  220. @@ -132,28 +128,21 @@
  221. #ifdef HAVE_LIBPRELUDE
  222. - if ( m_Config == NULL )
  223. - {
  224. - logCrit("I need a config\n");
  225. - return false;
  226. - }
  227. -
  228. - string analyzerClass;
  229. - string analyzerModel;
  230. string analyzerName;
  231. -
  232. - try
  233. - {
  234. - analyzerClass = (m_Config->getValString("log-prelude.analyzerClass"));
  235. - analyzerModel = m_Config->getValString("log-prelude.analyzerModel");
  236. - analyzerName = m_Config->getValString("log-prelude.analyzerName");
  237. -
  238. - } catch ( ... )
  239. - {
  240. - logCrit("Error setting needed vars, check your config\n");
  241. - return false;
  242. - }
  243. -
  244. + string analyzerProfile;
  245. +
  246. + try {
  247. + analyzerName = m_Config->getValString("log-prelude.analyzerName");
  248. + } catch ( ... ) {
  249. + analyzerName = DEFAULT_ANALYZER_NAME;
  250. + }
  251. +
  252. + try {
  253. + analyzerProfile = m_Config->getValString("log-prelude.analyzerProfile");
  254. + } catch ( ... ) {
  255. + analyzerProfile = DEFAULT_ANALYZER_PROFILE;
  256. + }
  257. +
  258. m_ModuleManager = m_Nepenthes->getModuleMgr();
  259. m_Events.set(EV_SOCK_TCP_ACCEPT);
  260. m_Events.set(EV_SOCK_TCP_CLOSE);
  261. @@ -163,44 +152,39 @@
  262. m_Events.set(EV_DOWNLOAD);
  263. m_Events.set(EV_SUBMISSION);
  264. -
  265. - const char *profile, *config;
  266. -
  267. - config = NULL;
  268. - profile = analyzerName.c_str();
  269. -
  270. -
  271. -
  272. -
  273. int32_t ret;
  274. // Initialize Prelude Library
  275. ret = prelude_init(NULL, NULL);
  276. - if ( ret < 0 )
  277. + if ( ret < 0 ) {
  278. logCrit("%s: Unable to initialize the Prelude library: %s.\n",
  279. prelude_strsource(ret),
  280. prelude_strerror(ret));
  281. + return false;
  282. + }
  283. // generate a new Prelude client
  284. - ret = prelude_client_new(&m_PreludeClient, profile);
  285. + ret = prelude_client_new(&m_PreludeClient, analyzerProfile.c_str());
  286. - if ( ret < 0 )
  287. + if ( ret < 0 ) {
  288. logCrit("%s: Unable to create a prelude client object: %s.\n",
  289. prelude_strsource(ret),
  290. prelude_strerror(ret));
  291. + return false;
  292. + }
  293. -
  294. +
  295. // set options in the analyzer-part of the client
  296. prelude_string_t *string;
  297. - ret = idmef_analyzer_new_model(prelude_client_get_analyzer(m_PreludeClient), &string);
  298. + ret = idmef_analyzer_new_class(prelude_client_get_analyzer(m_PreludeClient), &string);
  299. if ( ret < 0 )
  300. return false;
  301. - prelude_string_set_constant(string, analyzerModel.c_str());
  302. -
  303. - ret = idmef_analyzer_new_class(prelude_client_get_analyzer(m_PreludeClient), &string);
  304. + prelude_string_set_constant(string, ANALYZER_CLASS);
  305. +
  306. + ret = idmef_analyzer_new_model(prelude_client_get_analyzer(m_PreludeClient), &string);
  307. if ( ret < 0 )
  308. return false;
  309. - prelude_string_set_constant(string, analyzerClass.c_str());
  310. + prelude_string_set_constant(string, ANALYZER_MODEL);
  311. ret = idmef_analyzer_new_manufacturer(prelude_client_get_analyzer(m_PreludeClient), &string);
  312. if ( ret < 0 )
  313. @@ -209,28 +193,31 @@
  314. ret = idmef_analyzer_new_version(prelude_client_get_analyzer(m_PreludeClient), &string);
  315. if ( ret < 0 )
  316. - return false;
  317. -
  318. - prelude_string_set_constant(string, NEPENTHES_VERSION);
  319. + return false;
  320. + prelude_string_set_constant(string, VERSION);
  321. -// start the Prelude Client
  322. + ret = idmef_analyzer_new_name(prelude_client_get_analyzer(m_PreludeClient), &string);
  323. + if ( ret < 0 )
  324. + return false;
  325. + prelude_string_set_dup(string, analyzerName.c_str());
  326. +
  327. + // start the Prelude Client
  328. ret = prelude_client_start(m_PreludeClient);
  329. if ( ret < 0 )
  330. {
  331. - if ( prelude_client_is_setup_needed(ret) )
  332. - prelude_client_print_setup_error(m_PreludeClient);
  333. -
  334. logCrit("%s: Unable to initialize prelude client: %s.\n",
  335. prelude_strsource(ret), prelude_strerror(ret));
  336. + return false;
  337. }
  338. -// set async Prelude Flags for the client, makes the application multithreaded
  339. - ret = prelude_client_set_flags(m_PreludeClient, (prelude_client_flags_t) (PRELUDE_CLIENT_FLAGS_CONNECT | PRELUDE_CLIENT_FLAGS_ASYNC_SEND | PRELUDE_CLIENT_FLAGS_ASYNC_TIMER));
  340. - if ( ret < 0 )
  341. + // set async Prelude Flags for the client, makes the application multithreaded
  342. + ret = prelude_client_set_flags(m_PreludeClient, (prelude_client_flags_t) (PRELUDE_CLIENT_FLAGS_CONNECT | PRELUDE_CLIENT_FLAGS_ASYNC_SEND | PRELUDE_CLIENT_FLAGS_ASYNC_TIMER));
  343. + if ( ret < 0 ) {
  344. logCrit("%s: Unable to set asynchronous send and timer: %s.\n",
  345. prelude_strsource(ret),
  346. prelude_strerror(ret));
  347. -
  348. + return false;
  349. + }
  350. REG_EVENT_HANDLER(this);
  351. return true;
  352. @@ -274,7 +261,7 @@
  353. idmef_value_t *val;
  354. idmef_path_t *path;
  355. - ret = idmef_path_new(&path, object);
  356. + ret = idmef_path_new_fast(&path, object);
  357. if ( ret < 0 )
  358. {
  359. logWarn("imdef error #1 %s -> %s %i (%s) \n",object,value,ret, prelude_strerror(ret));
  360. @@ -376,7 +363,6 @@
  361. add_idmef_object(idmef, "alert.classification.text" ,"TCP Connection established");
  362. add_idmef_object(idmef, "alert.classification.ident", EV_SOCK_TCP_ACCEPT);
  363. -// add_idmef_object(idmef, "alert.classification.reference(0).origin" ,"vendor-specific" );
  364. add_idmef_object(idmef, "alert.source(0).Spoofed" ,"no");
  365. @@ -449,7 +435,6 @@
  366. add_idmef_object(idmef, "alert.classification.text" ,"TCP Connection closed");
  367. add_idmef_object(idmef, "alert.classification.ident", EV_SOCK_TCP_CLOSE);
  368. -// add_idmef_object(idmef, "alert.classification.reference(0).origin" ,"vendor-specific" );
  369. add_idmef_object(idmef, "alert.source(0).Service.protocol" ,"TCP");
  370. @@ -515,7 +500,6 @@
  371. // hl: added ident
  372. add_idmef_object(idmef, "alert.classification.ident", EV_SHELLCODE_DONE);
  373. - // add_idmef_object(idmef, "alert.classification.reference(0).origin" ,"vendor-specific" );
  374. add_idmef_object(idmef, "alert.source(0).Spoofed" ,"no");
  375. diff -ruN nepenthes-0.2.0/modules/log-prelude/log-prelude.cpp~ nepenthes-0.2.0-r1345/modules/log-prelude/log-prelude.cpp~
  376. --- nepenthes-0.2.0/modules/log-prelude/log-prelude.cpp~ 1970-01-01 01:00:00.000000000 +0100
  377. +++ nepenthes-0.2.0-r1345/modules/log-prelude/log-prelude.cpp~ 2006-11-13 20:40:08.000000000 +0100
  378. @@ -0,0 +1,857 @@
  379. +/********************************************************************************
  380. + * Nepenthes
  381. + * - finest collection -
  382. + *
  383. + *
  384. + *
  385. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  386. + *
  387. + * This program is free software; you can redistribute it and/or
  388. + * modify it under the terms of the GNU General Public License
  389. + * as published by the Free Software Foundation; either version 2
  390. + * of the License, or (at your option) any later version.
  391. + *
  392. + * This program is distributed in the hope that it will be useful,
  393. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  394. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  395. + * GNU General Public License for more details.
  396. + *
  397. + * You should have received a copy of the GNU General Public License
  398. + * along with this program; if not, write to the Free Software
  399. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  400. + *
  401. + *
  402. + * contact nepenthesdev@users.sourceforge.net
  403. + *
  404. + *******************************************************************************/
  405. +
  406. + /* $Id: log-prelude.cpp 550 2006-05-04 10:25:35Z common $ */
  407. +
  408. +#ifdef HAVE_LIBPRELUDE
  409. +#include <prelude.h>
  410. +#include <libprelude/prelude-log.h>
  411. +#include <idmef-message-print.h>
  412. +#include <prelude-io.h>
  413. +#include <libprelude/prelude-timer.h>
  414. +#endif
  415. +
  416. +#include <arpa/inet.h>
  417. +#include "log-prelude.hpp"
  418. +#include "Nepenthes.hpp"
  419. +#include "LogManager.hpp"
  420. +#include "EventManager.hpp"
  421. +#include "SubmitEvent.hpp"
  422. +
  423. +#include "Download.hpp"
  424. +#include "DownloadUrl.hpp"
  425. +#include "DownloadBuffer.hpp"
  426. +
  427. +#include "Socket.hpp"
  428. +#include "SocketEvent.hpp"
  429. +
  430. +#include "Message.hpp"
  431. +#include "Utilities.hpp"
  432. +#include "Config.hpp"
  433. +#include "ShellcodeHandler.hpp"
  434. +
  435. +
  436. +using namespace nepenthes;
  437. +
  438. +#ifdef STDTAGS
  439. +#undef STDTAGS
  440. +#endif
  441. +
  442. +#define STDTAGS l_mod | l_ev | l_hlr
  443. +#define ANALYZER_MANUFACTURER "http://nepenthes.sf.net"
  444. +#define NEPENTHES_VERSION "$Rev: 550 $"
  445. +
  446. +
  447. +
  448. +/**
  449. + * as we may need a global pointer to our Nepenthes in our modules,
  450. + * and cant access the cores global pointer to nepenthes
  451. + * we have to use a own global pointer to nepenthes per module
  452. + * we need this pointer for logInfo() etc
  453. + */
  454. +Nepenthes *g_Nepenthes;
  455. +
  456. +/**
  457. + * Constructor
  458. + * creates a new LogPrelude Module, where x% is public Module, public EventHandler
  459. + * - sets the ModuleName
  460. + * - sets the ModuleDescription
  461. + * - sets the EventHandlerName
  462. + * - sets the EventHandlerDescription
  463. + * - sets the EventHandlers Timeout
  464. + * - sets the Modules global pointer to the Nepenthes
  465. + *
  466. + * @param nepenthes pointer to our nepenthes master class
  467. + */
  468. +LogPrelude::LogPrelude(Nepenthes *nepenthes)
  469. +{
  470. + m_ModuleName = "log-prelude";
  471. + m_ModuleDescription = "event based prelude logger";
  472. + m_ModuleRevision = "$Rev: 550 $";
  473. + m_Nepenthes = nepenthes;
  474. +
  475. + m_EventHandlerName = "LogPreludeEventHandler";
  476. + m_EventHandlerDescription = "log events to a prelude database";
  477. +
  478. +// m_Timeout = time(NULL) + rand()%23;
  479. +
  480. + g_Nepenthes = nepenthes;
  481. +
  482. +#ifdef HAVE_LIBPRELUDE
  483. + m_PreludeClient = NULL;
  484. +#endif
  485. +}
  486. +
  487. +
  488. +/**
  489. + * exerything important happens in ::Exit() as we have a return value there
  490. + */
  491. +LogPrelude::~LogPrelude()
  492. +{
  493. +
  494. +}
  495. +
  496. +
  497. +
  498. +/**
  499. + * bool Module::Init()
  500. + * setup Module specific values
  501. + * here:
  502. + * - register as EventHandler
  503. + * - set wanted events
  504. + *
  505. + * @return returns true if everything was fine, else false
  506. + * returning false will showup errors in warning a module
  507. + */
  508. +bool LogPrelude::Init()
  509. +{
  510. +
  511. +#ifdef HAVE_LIBPRELUDE
  512. +
  513. + if ( m_Config == NULL )
  514. + {
  515. + logCrit("I need a config\n");
  516. + return false;
  517. + }
  518. +
  519. + string analyzerClass;
  520. + string analyzerModel;
  521. + string analyzerName;
  522. +
  523. + try
  524. + {
  525. + analyzerClass = (m_Config->getValString("log-prelude.analyzerClass"));
  526. + analyzerModel = m_Config->getValString("log-prelude.analyzerModel");
  527. + analyzerName = m_Config->getValString("log-prelude.analyzerName");
  528. +
  529. + } catch ( ... )
  530. + {
  531. + logCrit("Error setting needed vars, check your config\n");
  532. + return false;
  533. + }
  534. +
  535. + m_ModuleManager = m_Nepenthes->getModuleMgr();
  536. + m_Events.set(EV_SOCK_TCP_ACCEPT);
  537. + m_Events.set(EV_SOCK_TCP_CLOSE);
  538. + m_Events.set(EV_DIALOGUE_ASSIGN_AND_DONE);
  539. + m_Events.set(EV_SHELLCODE_DONE);
  540. +
  541. + m_Events.set(EV_DOWNLOAD);
  542. + m_Events.set(EV_SUBMISSION);
  543. +
  544. +
  545. + const char *profile, *config;
  546. +
  547. + config = NULL;
  548. + profile = analyzerName.c_str();
  549. +
  550. +
  551. +
  552. +
  553. + int32_t ret;
  554. +// Initialize Prelude Library
  555. + ret = prelude_init(NULL, NULL);
  556. + if ( ret < 0 )
  557. + logCrit("%s: Unable to initialize the Prelude library: %s.\n",
  558. + prelude_strsource(ret),
  559. + prelude_strerror(ret));
  560. +
  561. +// generate a new Prelude client
  562. + ret = prelude_client_new(&m_PreludeClient, profile);
  563. +
  564. + if ( ret < 0 )
  565. + logCrit("%s: Unable to create a prelude client object: %s.\n",
  566. + prelude_strsource(ret),
  567. + prelude_strerror(ret));
  568. +
  569. +
  570. + // set options in the analyzer-part of the client
  571. + prelude_string_t *string;
  572. +
  573. + ret = idmef_analyzer_new_model(prelude_client_get_analyzer(m_PreludeClient), &string);
  574. + if ( ret < 0 )
  575. + return false;
  576. + prelude_string_set_constant(string, analyzerModel.c_str());
  577. +
  578. + ret = idmef_analyzer_new_class(prelude_client_get_analyzer(m_PreludeClient), &string);
  579. + if ( ret < 0 )
  580. + return false;
  581. + prelude_string_set_constant(string, analyzerClass.c_str());
  582. +
  583. + ret = idmef_analyzer_new_manufacturer(prelude_client_get_analyzer(m_PreludeClient), &string);
  584. + if ( ret < 0 )
  585. + return false;
  586. + prelude_string_set_constant(string, ANALYZER_MANUFACTURER);
  587. +
  588. + ret = idmef_analyzer_new_version(prelude_client_get_analyzer(m_PreludeClient), &string);
  589. + if ( ret < 0 )
  590. + return false;
  591. +
  592. + prelude_string_set_constant(string, NEPENTHES_VERSION);
  593. +
  594. +// start the Prelude Client
  595. + ret = prelude_client_start(m_PreludeClient);
  596. + if ( ret < 0 )
  597. + {
  598. + if ( prelude_client_is_setup_needed(ret) )
  599. + prelude_client_print_setup_error(m_PreludeClient);
  600. +
  601. + logCrit("%s: Unable to initialize prelude client: %s.\n",
  602. + prelude_strsource(ret), prelude_strerror(ret));
  603. + }
  604. +
  605. +// set async Prelude Flags for the client, makes the application multithreaded
  606. + ret = prelude_client_set_flags(m_PreludeClient, (prelude_client_flags_t) (PRELUDE_CLIENT_FLAGS_CONNECT | PRELUDE_CLIENT_FLAGS_ASYNC_SEND | PRELUDE_CLIENT_FLAGS_ASYNC_TIMER));
  607. + if ( ret < 0 )
  608. + logCrit("%s: Unable to set asynchronous send and timer: %s.\n",
  609. + prelude_strsource(ret),
  610. + prelude_strerror(ret));
  611. +
  612. +
  613. + REG_EVENT_HANDLER(this);
  614. + return true;
  615. +#else
  616. + logCrit("Module log-prelude is compiled without libprelude, this wont work, reconfigure the whole source and recompile");
  617. + return false;
  618. +#endif
  619. +
  620. +}
  621. +
  622. +
  623. +/**
  624. + * unregister as EventHandler, destroy the Prelude Client
  625. + *
  626. + * @return returns true if everything was fine
  627. + */
  628. +bool LogPrelude::Exit()
  629. +{
  630. +#ifdef HAVE_LIBPRELUDE
  631. + if( m_PreludeClient != NULL)
  632. + {
  633. + prelude_client_destroy(m_PreludeClient, (prelude_client_exit_status_t)(PRELUDE_CLIENT_EXIT_STATUS_SUCCESS));
  634. + prelude_deinit();
  635. + }
  636. + // disabled by harald due to segfaults
  637. + //UNREG_EVENT_HANDLER(this);
  638. +#endif
  639. + return true;
  640. +}
  641. +
  642. +
  643. +
  644. +/**
  645. + * This function adds char * idmef values into an idmef message
  646. + *
  647. + */
  648. +#ifdef HAVE_LIBPRELUDE
  649. +int32_t add_idmef_object(idmef_message_t *message, const char *object, const char *value)
  650. +{
  651. + int32_t ret=0;
  652. + idmef_value_t *val;
  653. + idmef_path_t *path;
  654. +
  655. + ret = idmef_path_new(&path, object);
  656. + if ( ret < 0 )
  657. + {
  658. + logWarn("imdef error #1 %s -> %s %i (%s) \n",object,value,ret, prelude_strerror(ret));
  659. + return -1;
  660. + }
  661. +
  662. + ret = idmef_value_new_from_path(&val, path, value);
  663. + if ( ret < 0 )
  664. + {
  665. + idmef_path_destroy(path);
  666. + logWarn("imdef error #2 %s -> %s %i (%s) \n",object,value,ret, prelude_strerror(ret));
  667. + return -1;
  668. + }
  669. +
  670. + ret = idmef_path_set(path, message, val);
  671. +
  672. + idmef_value_destroy(val);
  673. + idmef_path_destroy(path);
  674. + return ret;
  675. +}
  676. +
  677. +
  678. +/**
  679. + *
  680. + * This function adds int32_t idmef values into an idmef message
  681. + */
  682. +int32_t add_idmef_object(idmef_message_t *message, const char *object, int32_t i)
  683. +{
  684. + char value[20];
  685. + memset(value,0,20);
  686. + snprintf(value,19,"%i",i);
  687. + return add_idmef_object(message,object,value);
  688. +}
  689. +
  690. +#endif
  691. +
  692. +
  693. +/**
  694. + * the handleEvent method is called whenever an event occurs
  695. + * the EventHandler wanted to have.
  696. + *
  697. + * @param event the Event
  698. + *
  699. + * @return return 0
  700. + */
  701. +uint32_t LogPrelude::handleEvent(Event *event)
  702. +{
  703. +// logPF();
  704. +// logInfo("Event %i\n",event->getType());
  705. + switch(event->getType())
  706. + {
  707. +
  708. + case EV_SOCK_TCP_ACCEPT:
  709. + handleTCPaccept(event);
  710. + break;
  711. +
  712. + case EV_SOCK_TCP_CLOSE:
  713. + handleTCPclose(event);
  714. + break;
  715. +
  716. + case EV_SUBMISSION:
  717. + handleSubmission(event);
  718. + break;
  719. +
  720. + case EV_DIALOGUE_ASSIGN_AND_DONE:
  721. + handleDialogueAssignAndDone(event);
  722. + break;
  723. +
  724. + case EV_SHELLCODE_DONE:
  725. + handleShellcodeDone(event);
  726. + break;
  727. +
  728. +
  729. + case EV_DOWNLOAD:
  730. + handleDownload(event);
  731. + break;
  732. +
  733. + default:
  734. + logWarn("this should not happen\n");
  735. + }
  736. + return 0;
  737. +}
  738. +
  739. +
  740. +void LogPrelude::handleTCPaccept(Event *event)
  741. +{
  742. +
  743. +
  744. + logInfo("LogPrelude EVENT EV_SOCK_TCP_ACCEPT\n");
  745. +
  746. +#ifdef HAVE_LIBPRELUDE
  747. + Socket *socket = ((SocketEvent *)event)->getSocket();
  748. +
  749. + idmef_message_t *idmef;
  750. +
  751. + int32_t ret = idmef_message_new(&idmef);
  752. + if ( ret < 0 )
  753. + return;
  754. +
  755. + add_idmef_object(idmef, "alert.classification.text" ,"TCP Connection established");
  756. + add_idmef_object(idmef, "alert.classification.ident", EV_SOCK_TCP_ACCEPT);
  757. +// add_idmef_object(idmef, "alert.classification.reference(0).origin" ,"vendor-specific" );
  758. +
  759. +
  760. + add_idmef_object(idmef, "alert.source(0).Spoofed" ,"no");
  761. + add_idmef_object(idmef, "alert.source(0).Service.protocol" ,"TCP");
  762. + add_idmef_object(idmef, "alert.source(0).Service.port" ,socket->getRemotePort());
  763. +
  764. + uint32_t addr = socket->getRemoteHost();
  765. + string address = inet_ntoa(*(in_addr *)&addr);
  766. + add_idmef_object(idmef, "alert.source(0).Node.Address(0).address" ,address.c_str());
  767. +
  768. +
  769. + add_idmef_object(idmef, "alert.target(0).Decoy" ,"yes");
  770. + add_idmef_object(idmef, "alert.target(0).Service.protocol" ,"TCP");
  771. + add_idmef_object(idmef, "alert.target(0).Service.port" ,socket->getLocalPort());
  772. +
  773. + addr = socket->getLocalHost();
  774. + address = inet_ntoa(*(in_addr *)&addr);
  775. + add_idmef_object(idmef, "alert.target(0).Node.Address(0).address" ,address.c_str());
  776. +
  777. +
  778. +
  779. +
  780. + idmef_time_t *time;
  781. +
  782. + ret = idmef_time_new_from_gettimeofday(&time);
  783. + idmef_alert_set_create_time(idmef_message_get_alert(idmef),
  784. + time);
  785. +
  786. +
  787. + // analyzer id
  788. + idmef_alert_set_analyzer(idmef_message_get_alert(idmef),
  789. + idmef_analyzer_ref(prelude_client_get_analyzer(m_PreludeClient)),
  790. + IDMEF_LIST_PREPEND);
  791. +
  792. +
  793. + prelude_client_send_idmef(m_PreludeClient, idmef);
  794. +
  795. + //prelude_string_t *field = idmef_alert_get_messageid(idmef_message_get_alert(idmef));
  796. + //const char *msgid = prelude_string_get_string(field);
  797. +
  798. + //logInfo("PreludeMessageID = %s \n",msgid);
  799. +
  800. + idmef_message_destroy(idmef);
  801. +#endif
  802. +}
  803. +
  804. +
  805. +
  806. +
  807. +void LogPrelude::handleTCPclose(Event *event)
  808. +{
  809. +
  810. + Socket *socket = ((SocketEvent *)event)->getSocket();
  811. +
  812. + if (! socket->isAccept())
  813. + {
  814. + return;
  815. + }
  816. +
  817. + logInfo("LogPrelude EVENT EV_SOCK_TCP_CLOSE\n");
  818. +
  819. +#ifdef HAVE_LIBPRELUDE
  820. +
  821. + idmef_message_t *idmef;
  822. +
  823. + int32_t ret = idmef_message_new(&idmef);
  824. + if ( ret < 0 )
  825. + return;
  826. +
  827. +
  828. + add_idmef_object(idmef, "alert.classification.text" ,"TCP Connection closed");
  829. + add_idmef_object(idmef, "alert.classification.ident", EV_SOCK_TCP_CLOSE);
  830. +// add_idmef_object(idmef, "alert.classification.reference(0).origin" ,"vendor-specific" );
  831. +
  832. +
  833. + add_idmef_object(idmef, "alert.source(0).Service.protocol" ,"TCP");
  834. + add_idmef_object(idmef, "alert.source(0).Service.port" ,socket->getRemotePort());
  835. +
  836. + uint32_t addr = socket->getRemoteHost();
  837. + string address = inet_ntoa(*(in_addr *)&addr);
  838. + add_idmef_object(idmef, "alert.source(0).Node.Address(0).address" ,address.c_str());
  839. +
  840. + add_idmef_object(idmef, "alert.target(0).Service.protocol" ,"TCP");
  841. + add_idmef_object(idmef, "alert.target(0).Service.port" ,socket->getLocalPort());
  842. +
  843. + addr = socket->getLocalHost();
  844. + address = inet_ntoa(*(in_addr *)&addr);
  845. + add_idmef_object(idmef, "alert.target(0).Node.Address(0).address",address.c_str());
  846. +
  847. + idmef_time_t *time;
  848. +
  849. + ret = idmef_time_new_from_gettimeofday(&time);
  850. + idmef_alert_set_create_time(idmef_message_get_alert(idmef),
  851. + time);
  852. +
  853. +
  854. + // analyzer id
  855. + idmef_alert_set_analyzer(idmef_message_get_alert(idmef),
  856. + idmef_analyzer_ref(prelude_client_get_analyzer(m_PreludeClient)),
  857. + IDMEF_LIST_PREPEND);
  858. +
  859. +
  860. + prelude_client_send_idmef(m_PreludeClient, idmef);
  861. +
  862. +// prelude_string_t *field = idmef_alert_get_messageid(idmef_message_get_alert(idmef));
  863. +// const char *msgid = prelude_string_get_string(field);
  864. +
  865. +// logInfo("CloseMessageID = %s \n",msgid);
  866. +
  867. + idmef_message_destroy(idmef);
  868. +
  869. +#endif
  870. +}
  871. +
  872. +
  873. +/**
  874. + * Send idmef message when finished with the Shellcode
  875. + *
  876. + */
  877. +void LogPrelude::handleShellcodeDone(Event *event)
  878. +{
  879. + logInfo("LogPrelude EVENT EV_SHELLCODE_DONE\n");
  880. +
  881. +#ifdef HAVE_LIBPRELUDE
  882. +
  883. + ShellcodeHandler *handler = ((ShellcodeEvent *)event)->getShellcodeHandler();
  884. + Socket *socket = ((ShellcodeEvent *)event)->getSocket();
  885. +
  886. + idmef_message_t *idmef;
  887. +
  888. + int32_t ret = idmef_message_new(&idmef);
  889. + if ( ret < 0 )
  890. + return;
  891. + string shellcodeText = "Shellcode detected: " + handler->getShellcodeHandlerName();
  892. + add_idmef_object(idmef, "alert.classification.text", shellcodeText.c_str());
  893. + // hl: added ident
  894. + add_idmef_object(idmef, "alert.classification.ident", EV_SHELLCODE_DONE);
  895. +
  896. + // add_idmef_object(idmef, "alert.classification.reference(0).origin" ,"vendor-specific" );
  897. +
  898. +
  899. + add_idmef_object(idmef, "alert.source(0).Spoofed" ,"no");
  900. + add_idmef_object(idmef, "alert.source(0).Service.protocol" ,"TCP");
  901. + add_idmef_object(idmef, "alert.source(0).Service.port" ,socket->getRemotePort());
  902. +
  903. + uint32_t addr = socket->getRemoteHost();
  904. + string address = inet_ntoa(*(in_addr *)&addr);
  905. + add_idmef_object(idmef, "alert.source(0).Node.Address(0).address" ,address.c_str());
  906. +
  907. +
  908. + add_idmef_object(idmef, "alert.target(0).Decoy" ,"yes");
  909. + add_idmef_object(idmef, "alert.target(0).Service.protocol" ,"TCP");
  910. + add_idmef_object(idmef, "alert.target(0).Service.port" ,socket->getLocalPort());
  911. +
  912. + addr = socket->getLocalHost();
  913. + address = inet_ntoa(*(in_addr *)&addr);
  914. + add_idmef_object(idmef, "alert.target(0).Node.Address(0).address" ,address.c_str());
  915. +
  916. +
  917. + add_idmef_object(idmef, "alert.assessment.impact.description" ,"possible Shellcode has been detected.");
  918. + add_idmef_object(idmef, "alert.assessment.impact.severity" ,"medium");
  919. +// add_idmef_object(idmef, "alert.assessment.impact.completion" ,"succeeded");
  920. + add_idmef_object(idmef, "alert.assessment.impact.type" ,"other");
  921. +
  922. +
  923. + // hl: added for additional information
  924. + add_idmef_object(idmef, "alert.additional_data(0).type", "string");
  925. + add_idmef_object(idmef, "alert.additional_data(0).meaning", "Shellcode");
  926. + add_idmef_object(idmef, "alert.additional_data(0).data", handler->getShellcodeHandlerName().c_str());
  927. +
  928. +
  929. + idmef_time_t *time;
  930. +
  931. + ret = idmef_time_new_from_gettimeofday(&time);
  932. + idmef_alert_set_create_time(idmef_message_get_alert(idmef),
  933. + time);
  934. +
  935. +
  936. + // analyzer id
  937. + idmef_alert_set_analyzer(idmef_message_get_alert(idmef),
  938. + idmef_analyzer_ref(prelude_client_get_analyzer(m_PreludeClient)),
  939. + IDMEF_LIST_PREPEND);
  940. +
  941. +
  942. + prelude_client_send_idmef(m_PreludeClient, idmef);
  943. +
  944. +// prelude_string_t *field = idmef_alert_get_messageid(idmef_message_get_alert(idmef));
  945. +// const char *msgid = prelude_string_get_string(field);
  946. +// logInfo("RecvMessageID = %s \n",msgid);
  947. +
  948. + idmef_message_destroy(idmef);
  949. +#endif
  950. +}
  951. +
  952. +
  953. +/**
  954. + *
  955. + * handle submitted files
  956. + */
  957. +void LogPrelude::handleSubmission(Event *event)
  958. +{
  959. + SubmitEvent *se = (SubmitEvent *)event;
  960. + Download *down = se->getDownload();
  961. +
  962. + logInfo("LogPrelude EVENT EV_SUBMISSION %s %s %i \n",down->getUrl().c_str(),
  963. + down->getMD5Sum().c_str(),
  964. + down->getDownloadBuffer()->getSize());
  965. +
  966. +#ifdef HAVE_LIBPRELUDE
  967. + idmef_message_t *idmef;
  968. +
  969. + int32_t ret = idmef_message_new(&idmef);
  970. + if ( ret < 0 )
  971. + return;
  972. +
  973. + // generic information
  974. + // hl: changed submited to submitted, added ident
  975. + add_idmef_object(idmef, "alert.classification.text" ,"Malware submitted");
  976. + add_idmef_object(idmef, "alert.classification.ident", EV_SUBMISSION);
  977. +
  978. + string url = "http://nepenthes.sf.net/wiki/submission/" + down->getMD5Sum();
  979. + add_idmef_object(idmef, "alert.classification.reference(0).origin" ,"vendor-specific" );
  980. + add_idmef_object(idmef, "alert.classification.reference(0).url" ,url.c_str() );
  981. +
  982. +
  983. + // file name and info
  984. + // hl: changed file tags because of DTD violation
  985. + add_idmef_object(idmef, "alert.target(0).file(0).name" ,down->getDownloadUrl()->getFile().c_str());
  986. + add_idmef_object(idmef, "alert.target(0).file(0).path" ,down->getUrl().c_str());
  987. + add_idmef_object(idmef, "alert.target(0).file(0).category" ,"current");
  988. + add_idmef_object(idmef, "alert.target(0).file(0).ident" ,down->getMD5Sum().c_str());
  989. + add_idmef_object(idmef, "alert.target(0).file(0).data_size" ,down->getDownloadBuffer()->getSize());
  990. +
  991. + //hl: some debug stuff, prelude-manager doesnt write the checksums into xml
  992. + ret = add_idmef_object(idmef, "alert.target(0).file(0).checksum(0).algorithm" ,"MD5");
  993. + //logInfo("LogPrelude DEBUG MD5 %i\n", ret);
  994. + ret = add_idmef_object(idmef, "alert.target(0).file(0).checksum(0).value" ,down->getMD5Sum().c_str());
  995. + //logInfo("LogPrelude DEBUG Hash %i\n", ret);
  996. + ret = add_idmef_object(idmef, "alert.target(0).file(0).checksum(1).algorithm" ,"SHA2-512");
  997. + //logInfo("LogPrelude DEBUG SHA %i\n", ret);
  998. + ret = add_idmef_object(idmef, "alert.target(0).file(0).checksum(1).value" ,down->getSHA512Sum().c_str());
  999. + //logInfo("LogPrelude DEBUG Hash %i\n", ret);
  1000. +
  1001. + uint32_t addr = down->getLocalHost();
  1002. + string address = inet_ntoa(*(in_addr *)&addr);
  1003. + add_idmef_object(idmef, "alert.target(0).Node.Address(0).address" ,address.c_str());
  1004. +
  1005. +
  1006. +
  1007. + // infection host
  1008. + addr = down->getRemoteHost();
  1009. + address = inet_ntoa(*(in_addr *)&addr);
  1010. + add_idmef_object(idmef, "alert.source(0).Node.Address(0).address" ,address.c_str());
  1011. +
  1012. +
  1013. + // download source
  1014. + add_idmef_object(idmef, "alert.source(0).Service.port", down->getDownloadUrl()->getPort());
  1015. +
  1016. + /* hl: previous dirty workaround -> commented
  1017. + string protocol;
  1018. + if (down->getDownloadUrl()->getProtocol() == "tftp" )
  1019. + protocol = "UDP";
  1020. + else
  1021. + protocol = "TCP";
  1022. +
  1023. + add_idmef_object(idmef, "alert.source(0).Service.protocol" ,protocol.c_str());
  1024. + */
  1025. +
  1026. + add_idmef_object(idmef, "alert.source(0).Service.web_service.url" ,down->getUrl().c_str());
  1027. + // hl: not needed
  1028. + //add_idmef_object(idmef, "alert.source(0).Service.web_service.http_method" ,"get");
  1029. +
  1030. + add_idmef_object(idmef, "alert.assessment.impact.description" ,"possible Malware stored for further analysis");
  1031. + add_idmef_object(idmef, "alert.assessment.impact.severity" ,"high");
  1032. +// add_idmef_object(idmef, "alert.assessment.impact.completion" ,"succeeded");
  1033. + add_idmef_object(idmef, "alert.assessment.impact.type" ,"other");
  1034. +
  1035. + // time
  1036. + idmef_time_t *time;
  1037. + ret = idmef_time_new_from_gettimeofday(&time);
  1038. + idmef_alert_set_create_time(idmef_message_get_alert(idmef),
  1039. + time);
  1040. +
  1041. +
  1042. + // analyzer id
  1043. + idmef_alert_set_analyzer(idmef_message_get_alert(idmef),
  1044. + idmef_analyzer_ref(prelude_client_get_analyzer(m_PreludeClient)),
  1045. + IDMEF_LIST_PREPEND);
  1046. +
  1047. +
  1048. + prelude_client_send_idmef(m_PreludeClient, idmef);
  1049. + idmef_message_destroy(idmef);
  1050. +
  1051. +#endif
  1052. +}
  1053. +
  1054. +
  1055. +
  1056. +/**
  1057. + *
  1058. + *
  1059. + *
  1060. + */
  1061. +void LogPrelude::handleDialogueAssignAndDone(Event *event)
  1062. +{
  1063. + logInfo("LogPrelude EVENT EV_ASSIGN_AND_DONE\n");
  1064. +
  1065. +#ifdef HAVE_LIBPRELUDE
  1066. +
  1067. + Dialogue *dia = ((DialogueEvent *)event)->getDialogue();
  1068. + Socket *socket = ((DialogueEvent *)event)->getSocket();
  1069. + idmef_message_t *idmef;
  1070. +
  1071. + int32_t ret = idmef_message_new(&idmef);
  1072. + if ( ret < 0 )
  1073. + return;
  1074. +
  1075. + string attack = "Exploit attempt: " + dia->getDialogueName();
  1076. +
  1077. + // generic information
  1078. + add_idmef_object(idmef, "alert.classification.text", attack.c_str());
  1079. + // hl: added ident field
  1080. + add_idmef_object(idmef, "alert.classification.ident", EV_DIALOGUE_ASSIGN_AND_DONE);
  1081. +
  1082. +// add_idmef_object(idmef, "alert.classification.reference(0).origin" ,"vendor-specific" );
  1083. +
  1084. +
  1085. + // attacker
  1086. + uint32_t addr = socket->getRemoteHost();
  1087. + string address = inet_ntoa(*(in_addr *)&addr);
  1088. + add_idmef_object(idmef, "alert.source(0).Node.Address(0).address", address.c_str());
  1089. +
  1090. + // target
  1091. + addr = socket->getLocalHost();
  1092. + address = inet_ntoa(*(in_addr *)&addr);
  1093. + add_idmef_object(idmef, "alert.target(0).Node.Address(0).address", address.c_str());
  1094. +
  1095. +// string protocol;
  1096. +// if (down->getDownloadUrl()->getProtocol() == "tftp" )
  1097. +// protocol = "UDP";
  1098. +// else
  1099. +// protocol = "TCP";
  1100. +//
  1101. +// add_idmef_object(idmef, "alert.source(0).Service.protocol" ,protocol.c_str());
  1102. +// add_idmef_object(idmef, "alert.source(0).Service.web_service.url" ,down->getUrl().c_str());
  1103. +// add_idmef_object(idmef, "alert.source(0).Service.web_service.http_method" ,"get");
  1104. +
  1105. + add_idmef_object(idmef, "alert.assessment.impact.description" ,"An exploit attempt is getting handled.");
  1106. + add_idmef_object(idmef, "alert.assessment.impact.severity" ,"low");
  1107. +// add_idmef_object(idmef, "alert.assessment.impact.completion" ,"succeeded");
  1108. + add_idmef_object(idmef, "alert.assessment.impact.type" ,"other");
  1109. +
  1110. +
  1111. + // hl: added
  1112. + add_idmef_object(idmef, "alert.additional_data(0).type", "string");
  1113. + add_idmef_object(idmef, "alert.additional_data(0).meaning", "Dialogue");
  1114. + add_idmef_object(idmef, "alert.additional_data(0).data", dia->getDialogueName().c_str());
  1115. +
  1116. + // time
  1117. + idmef_time_t *time;
  1118. + ret = idmef_time_new_from_gettimeofday(&time);
  1119. + idmef_alert_set_create_time(idmef_message_get_alert(idmef),
  1120. + time);
  1121. +
  1122. +
  1123. + // analyzer id
  1124. + idmef_alert_set_analyzer(idmef_message_get_alert(idmef),
  1125. + idmef_analyzer_ref(prelude_client_get_analyzer(m_PreludeClient)),
  1126. + IDMEF_LIST_PREPEND);
  1127. +
  1128. +
  1129. + prelude_client_send_idmef(m_PreludeClient, idmef);
  1130. +
  1131. +
  1132. + idmef_message_destroy(idmef);
  1133. +
  1134. +#endif
  1135. +}
  1136. +
  1137. +
  1138. +
  1139. +
  1140. +
  1141. +
  1142. +/**
  1143. + *
  1144. + *
  1145. + */
  1146. +void LogPrelude::handleDownload(Event *event)
  1147. +{
  1148. + SubmitEvent *se = (SubmitEvent *)event;
  1149. + Download *down = se->getDownload();
  1150. + string url = se->getDownload()->getUrl();
  1151. +
  1152. + se->getType();
  1153. + logInfo("LogPrelude EVENT EV_DOWNLOAD %s %s %i \n",down->getUrl().c_str(),
  1154. + down->getMD5Sum().c_str(),
  1155. + down->getDownloadBuffer()->getSize());
  1156. +
  1157. +#ifdef HAVE_LIBPRELUDE
  1158. +
  1159. + idmef_message_t *idmef;
  1160. +
  1161. + int32_t ret = idmef_message_new(&idmef);
  1162. + if ( ret < 0 )
  1163. + return;
  1164. +
  1165. + // generic information
  1166. + // hl: changed message
  1167. + string message = "possible Malware offered: " + down->getUrl();
  1168. +
  1169. + add_idmef_object(idmef, "alert.classification.text", message.c_str());
  1170. + // hl: changed to ident number
  1171. + add_idmef_object(idmef, "alert.classification.ident", EV_DOWNLOAD);
  1172. +
  1173. +// add_idmef_object(idmef, "alert.classification.reference(0).origin" ,"vendor-specific" );
  1174. +
  1175. +
  1176. + // infection host
  1177. + uint32_t addr = down->getRemoteHost();
  1178. + string address = inet_ntoa(*(in_addr *)&addr);
  1179. + add_idmef_object(idmef, "alert.source(0).Node.Address(0).address" ,address.c_str());
  1180. + //target host
  1181. + addr = down->getLocalHost();
  1182. + address = inet_ntoa(*(in_addr *)&addr);
  1183. + add_idmef_object(idmef, "alert.target(0).Node.Address(0).address" ,address.c_str());
  1184. +
  1185. +
  1186. + // download source
  1187. + // hl: removed protocol, added url
  1188. + /*
  1189. + string protocol;
  1190. + if (down->getDownloadUrl()->getProtocol() == "tftp" )
  1191. + protocol = "UDP";
  1192. + else
  1193. + protocol = "TCP";
  1194. + */
  1195. + add_idmef_object(idmef, "alert.source(0).Service.port" ,down->getDownloadUrl()->getPort());
  1196. + //add_idmef_object(idmef, "alert.source(0).Service.protocol" ,protocol.c_str());
  1197. + add_idmef_object(idmef, "alert.source(0).Service.web_service.url" ,down->getUrl().c_str());
  1198. +// add_idmef_object(idmef, "alert.source(0).Service.web_service.http_method" ,"get");
  1199. + add_idmef_object(idmef, "alert.assessment.impact.description" ,"Parsing the Shellcode has unrevealed a URL.");
  1200. + add_idmef_object(idmef, "alert.assessment.impact.severity" ,"medium");
  1201. +// add_idmef_object(idmef, "alert.assessment.impact.completion" ,"succeeded");
  1202. + add_idmef_object(idmef, "alert.assessment.impact.type" ,"other");
  1203. +
  1204. + // time
  1205. + idmef_time_t *time;
  1206. + ret = idmef_time_new_from_gettimeofday(&time);
  1207. + idmef_alert_set_create_time(idmef_message_get_alert(idmef),
  1208. + time);
  1209. +
  1210. +
  1211. + // analyzer id
  1212. + idmef_alert_set_analyzer(idmef_message_get_alert(idmef),
  1213. + idmef_analyzer_ref(prelude_client_get_analyzer(m_PreludeClient)),
  1214. + IDMEF_LIST_PREPEND);
  1215. +
  1216. +
  1217. + prelude_client_send_idmef(m_PreludeClient, idmef);
  1218. +
  1219. +
  1220. + idmef_message_destroy(idmef);
  1221. +#endif
  1222. +
  1223. +}
  1224. +
  1225. +
  1226. +
  1227. +extern "C" int32_t module_init(int32_t version, Module **module, Nepenthes *nepenthes)
  1228. +{
  1229. + if (version == MODULE_IFACE_VERSION) {
  1230. + *module = new LogPrelude(nepenthes);
  1231. + return 1;
  1232. + } else {
  1233. + return 0;
  1234. + }
  1235. +}
  1236. diff -ruN nepenthes-0.2.0/modules/log-prelude/log-prelude.hpp nepenthes-0.2.0-r1345/modules/log-prelude/log-prelude.hpp
  1237. --- nepenthes-0.2.0/modules/log-prelude/log-prelude.hpp 2006-11-13 20:40:08.000000000 +0100
  1238. +++ nepenthes-0.2.0-r1345/modules/log-prelude/log-prelude.hpp 2007-08-06 00:46:15.000000000 +0200
  1239. @@ -30,7 +30,7 @@
  1240. #include "config.h"
  1241. #ifdef HAVE_LIBPRELUDE
  1242. -#include <prelude.h>
  1243. +#include <libprelude/prelude.h>
  1244. #endif
  1245. #include <string>
  1246. diff -ruN nepenthes-0.2.0/modules/log-surfnet/Makefile.am nepenthes-0.2.0-r1345/modules/log-surfnet/Makefile.am
  1247. --- nepenthes-0.2.0/modules/log-surfnet/Makefile.am 2006-11-13 20:40:10.000000000 +0100
  1248. +++ nepenthes-0.2.0-r1345/modules/log-surfnet/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  1249. @@ -6,7 +6,6 @@
  1250. AM_CPPFLAGS = -I$(top_srcdir)/nepenthes-core/include -I$(top_srcdir)/nepenthes-core/src -I/usr/include/postgresql -pipe -D _GNU_SOURCE
  1251. AM_CXXFLAGS = -Wall -Werror
  1252. -AM_LDFLAGS = ${LIB_POSTGRES}
  1253. pkglib_LTLIBRARIES = logsurfnet.la
  1254. diff -ruN nepenthes-0.2.0/modules/log-surfnet/log-surfnet.conf.dist nepenthes-0.2.0-r1345/modules/log-surfnet/log-surfnet.conf.dist
  1255. --- nepenthes-0.2.0/modules/log-surfnet/log-surfnet.conf.dist 2006-11-13 20:40:10.000000000 +0100
  1256. +++ nepenthes-0.2.0-r1345/modules/log-surfnet/log-surfnet.conf.dist 2007-08-06 00:46:15.000000000 +0200
  1257. @@ -49,175 +49,3 @@
  1258. };
  1259. -
  1260. -/*
  1261. -
  1262. -don't forget to create these fn's in your surfnet ids database.
  1263. -
  1264. -
  1265. -CREATE PROCEDURAL LANGUAGE plpgsql;
  1266. -
  1267. -CREATE FUNCTION surfnet_attack_add(integer, inet, integer, inet, integer, macaddr, inet) RETURNS integer
  1268. - AS $_$DECLARE
  1269. - p_severity ALIAS FOR $1;
  1270. - p_attackerip ALIAS FOR $2;
  1271. - p_attackerport ALIAS FOR $3;
  1272. - p_decoyip ALIAS FOR $4;
  1273. - p_decoyport ALIAS FOR $5;
  1274. - p_hwa ALIAS FOR $6;
  1275. - p_localhost ALIAS FOR $7;
  1276. - m_attackid INTEGER;
  1277. - m_sensorid INTEGER;
  1278. -BEGIN
  1279. -
  1280. - SELECT INTO m_sensorid surfnet_sensorid_get(p_localhost);
  1281. - SELECT INTO m_attackid surfnet_attack_add_by_id(p_severity,
  1282. - p_attackerip, p_attackerport, p_decoyip,
  1283. - p_decoyport, p_hwa, m_sensorid);
  1284. -
  1285. - return m_attackid;
  1286. -END$_$
  1287. - LANGUAGE plpgsql;
  1288. -
  1289. -
  1290. -CREATE FUNCTION surfnet_attack_add_by_id(integer, inet, integer, inet, integer, macaddr, integer) RETURNS integer
  1291. - AS $_$DECLARE
  1292. - p_severity ALIAS FOR $1;
  1293. - p_attackerip ALIAS FOR $2;
  1294. - p_attackerport ALIAS FOR $3;
  1295. - p_decoyip ALIAS FOR $4;
  1296. - p_decoyport ALIAS FOR $5;
  1297. - p_hwa ALIAS FOR $6;
  1298. - p_sensorid ALIAS FOR $7;
  1299. - m_attackid INTEGER;
  1300. -BEGIN
  1301. - INSERT INTO attacks
  1302. - (severity,
  1303. - timestamp,
  1304. - dest,
  1305. - dport,
  1306. - source,
  1307. - sport,
  1308. - sensorid,
  1309. - src_mac)
  1310. - VALUES
  1311. - (p_severity,
  1312. - extract(epoch from current_timestamp(0))::integer,
  1313. - p_attackerip,
  1314. - p_attackerport,
  1315. - p_decoyip,
  1316. - p_decoyport,
  1317. - p_sensorid,
  1318. - p_hwa);
  1319. -
  1320. - SELECT INTO m_attackid currval('attacks_id_seq');
  1321. - return m_attackid;
  1322. -END$_$
  1323. - LANGUAGE plpgsql;
  1324. -
  1325. -
  1326. -
  1327. -CREATE FUNCTION surfnet_attack_update_severity(integer, integer) RETURNS void
  1328. - AS $_$DECLARE
  1329. - p_attackid ALIAS FOR $1;
  1330. - p_severity ALIAS FOR $2;
  1331. -BEGIN
  1332. - UPDATE attacks SET severity = p_severity WHERE id = p_attackid;
  1333. - return;
  1334. -END;$_$
  1335. - LANGUAGE plpgsql;
  1336. -
  1337. -
  1338. -CREATE FUNCTION surfnet_detail_add(integer, inet, integer, character varying) RETURNS void
  1339. - AS $_$DECLARE
  1340. - p_attackid ALIAS FOR $1;
  1341. - p_localhost ALIAS FOR $2;
  1342. - p_type ALIAS FOR $3;
  1343. - p_data ALIAS FOR $4;
  1344. -
  1345. - m_sensorid INTEGER;
  1346. -BEGIN
  1347. - SELECT INTO m_sensorid surfnet_sensorid_get(p_localhost);
  1348. -
  1349. - INSERT INTO details
  1350. - (attackid,sensorid,type,text)
  1351. - VALUES
  1352. - (p_attackid,m_sensorid,p_type,p_data);
  1353. -END$_$
  1354. - LANGUAGE plpgsql;
  1355. -
  1356. -
  1357. -CREATE FUNCTION surfnet_detail_add_by_id(integer, integer, integer, character varying) RETURNS void
  1358. - AS $_$DECLARE
  1359. - p_attackid ALIAS FOR $1;
  1360. - m_sensorid ALIAS FOR $2;
  1361. - p_type ALIAS FOR $3;
  1362. - p_data ALIAS FOR $4;
  1363. -BEGIN
  1364. - INSERT INTO details
  1365. - (attackid,sensorid,type,text)
  1366. - VALUES
  1367. - (p_attackid,m_sensorid,p_type,p_data);
  1368. -END$_$
  1369. - LANGUAGE plpgsql;
  1370. -
  1371. -
  1372. -CREATE FUNCTION surfnet_detail_add_download(inet, inet, character varying, character varying) RETURNS void
  1373. - AS $_$DECLARE
  1374. - p_remotehost ALIAS FOR $1;
  1375. - p_localhost ALIAS FOR $2;
  1376. - p_url ALIAS FOR $3;
  1377. - p_hash ALIAS FOR $4;
  1378. -
  1379. - m_sensorid INTEGER;
  1380. - m_attackid INTEGER;
  1381. -BEGIN
  1382. - SELECT INTO m_sensorid surfnet_sensorid_get(p_localhost);
  1383. - SELECT INTO m_attackid surfnet_attack_add_by_id(32,p_remotehost, 0,
  1384. - p_localhost, 0,
  1385. - NULL,m_sensorid);
  1386. -
  1387. - PERFORM surfnet_detail_add_by_id(m_attackid,
  1388. - m_sensorid,4,p_url);
  1389. - PERFORM surfnet_detail_add_by_id(m_attackid,
  1390. - m_sensorid,8,p_hash);
  1391. -
  1392. - return;
  1393. -END; $_$
  1394. - LANGUAGE plpgsql;
  1395. -
  1396. -
  1397. -CREATE FUNCTION surfnet_detail_add_offer(inet, inet, character varying) RETURNS void
  1398. - AS $_$DECLARE
  1399. - p_remotehost ALIAS FOR $1;
  1400. - p_localhost ALIAS FOR $2;
  1401. - p_url ALIAS FOR $3;
  1402. -
  1403. - m_sensorid INTEGER;
  1404. - m_attackid INTEGER;
  1405. -BEGIN
  1406. - SELECT INTO m_sensorid surfnet_sensorid_get(p_localhost);
  1407. - SELECT INTO m_attackid surfnet_attack_add_by_id(16,p_remotehost, 0,
  1408. - p_localhost, 0,
  1409. - NULL,m_sensorid);
  1410. -
  1411. - PERFORM surfnet_detail_add_by_id(m_attackid,
  1412. - m_sensorid,4,p_url);
  1413. - return;
  1414. -END; $_$
  1415. - LANGUAGE plpgsql;
  1416. -
  1417. -
  1418. -CREATE FUNCTION surfnet_sensorid_get(inet) RETURNS integer
  1419. - AS $_$DECLARE
  1420. - p_localhost ALIAS FOR $1;
  1421. - m_sensorid INTEGER;
  1422. -BEGIN
  1423. - SELECT INTO m_sensorid id FROM sensors WHERE tapip = p_localhost;
  1424. - return m_sensorid;
  1425. -END
  1426. -$_$
  1427. - LANGUAGE plpgsql;
  1428. -
  1429. -
  1430. -*/
  1431. diff -ruN nepenthes-0.2.0/modules/log-surfnet/log-surfnet.cpp nepenthes-0.2.0-r1345/modules/log-surfnet/log-surfnet.cpp
  1432. --- nepenthes-0.2.0/modules/log-surfnet/log-surfnet.cpp 2006-11-13 20:40:10.000000000 +0100
  1433. +++ nepenthes-0.2.0-r1345/modules/log-surfnet/log-surfnet.cpp 2007-08-06 00:46:15.000000000 +0200
  1434. @@ -76,7 +76,7 @@
  1435. m_attackID = 0;
  1436. m_closed = false;
  1437. - m_severity = 0;
  1438. + m_severity = -1;
  1439. }
  1440. @@ -471,7 +471,13 @@
  1441. (uint32_t) ((intptr_t)socket),
  1442. attackid);
  1443. - m_SocketTracker[(uintptr_t) socket].m_closed = true;
  1444. + if (m_SocketTracker[(uintptr_t) socket].m_Details.size() > 0)
  1445. + {
  1446. + m_SocketTracker[(uintptr_t) socket].m_closed = true;
  1447. + }else
  1448. + {
  1449. + m_SocketTracker.erase((uintptr_t)socket);
  1450. + }
  1451. }
  1452. void LogSurfNET::handleDialogueAssignAndDone(Socket *socket, Dialogue *dia, uint32_t attackid)
  1453. @@ -649,6 +655,19 @@
  1454. m_SocketTracker[(uintptr_t)s].m_Details.pop_front();
  1455. }
  1456. + if (m_SocketTracker[(uintptr_t)s].m_severity != -1)
  1457. + {
  1458. + string query;
  1459. +
  1460. + query = "SELECT surfnet_attack_update_severity('";
  1461. + query += itos(m_SocketTracker[(uintptr_t)s].m_attackID);
  1462. + query += "','";
  1463. + query += itos(m_SocketTracker[(uintptr_t)s].m_severity);
  1464. + query += "');";
  1465. +
  1466. + m_SQLHandler->addQuery(&query,NULL,NULL);
  1467. + }
  1468. +
  1469. if (m_SocketTracker[(uintptr_t)s].m_closed == true)
  1470. {
  1471. m_SocketTracker.erase((uintptr_t)s);
  1472. @@ -660,6 +679,11 @@
  1473. bool LogSurfNET::sqlFailure(SQLResult *result)
  1474. {
  1475. logPF();
  1476. +
  1477. + Socket *s;
  1478. + s = (Socket *)result->getObject();
  1479. + logCrit("Getting attackid for socket %x failed, dropping the whole attack, forgetting all details\n",(uintptr_t)s);
  1480. + m_SocketTracker.erase((uintptr_t)s);
  1481. return true;
  1482. }
  1483. diff -ruN nepenthes-0.2.0/modules/module-honeytrap/Makefile.am nepenthes-0.2.0-r1345/modules/module-honeytrap/Makefile.am
  1484. --- nepenthes-0.2.0/modules/module-honeytrap/Makefile.am 2006-11-13 20:40:09.000000000 +0100
  1485. +++ nepenthes-0.2.0-r1345/modules/module-honeytrap/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  1486. @@ -15,4 +15,4 @@
  1487. modulehoneytrap_la_SOURCES += TrapSocket.cpp TrapSocket.hpp
  1488. modulehoneytrap_la_SOURCES += module-honeytrap.conf.dist
  1489. -modulehoneytrap_la_LDFLAGS = -module -no-undefined -avoid-version
  1490. +modulehoneytrap_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  1491. diff -ruN nepenthes-0.2.0/modules/module-honeytrap/TrapSocket.cpp nepenthes-0.2.0-r1345/modules/module-honeytrap/TrapSocket.cpp
  1492. --- nepenthes-0.2.0/modules/module-honeytrap/TrapSocket.cpp 2006-11-13 20:40:09.000000000 +0100
  1493. +++ nepenthes-0.2.0-r1345/modules/module-honeytrap/TrapSocket.cpp 2007-08-06 00:46:15.000000000 +0200
  1494. @@ -782,11 +782,18 @@
  1495. {
  1496. printIPpacket(data,size);
  1497. + uint16_t port;
  1498. +
  1499. + if ( tcp->th_flags & TH_SYN && !(tcp->th_flags & TH_ACK) )
  1500. + port = ntohs(tcp->th_dport); // inline mode
  1501. + else
  1502. + port = ntohs(tcp->th_sport); // pcap mode
  1503. +
  1504. if (1)// isPortListening(ntohs(tcp->th_dport),*(uint32_t *)&(ip->ip_dst)) == false )
  1505. {
  1506. - logInfo("Connection to unbound port %i requested, binding port\n",ntohs(tcp->th_dport));
  1507. + logInfo("Connection to unbound port %i requested, binding port\n",port);
  1508. - Socket *sock = g_Nepenthes->getSocketMgr()->bindTCPSocket(INADDR_ANY,ntohs(tcp->th_dport),60,60);
  1509. + Socket *sock = g_Nepenthes->getSocketMgr()->bindTCPSocket(INADDR_ANY,port,60,60);
  1510. if ( sock != NULL && (sock->getDialogst()->size() == 0 && sock->getFactories()->size() == 0) )
  1511. {
  1512. diff -ruN nepenthes-0.2.0/modules/module-peiros/module-peiros.cpp nepenthes-0.2.0-r1345/modules/module-peiros/module-peiros.cpp
  1513. --- nepenthes-0.2.0/modules/module-peiros/module-peiros.cpp 2006-11-13 20:40:08.000000000 +0100
  1514. +++ nepenthes-0.2.0-r1345/modules/module-peiros/module-peiros.cpp 2007-08-06 00:46:15.000000000 +0200
  1515. @@ -29,6 +29,7 @@
  1516. #include <ctype.h>
  1517. #include <string.h>
  1518. +#include <sys/types.h>
  1519. #include <sys/socket.h>
  1520. #include <netinet/in.h>
  1521. #include <arpa/inet.h>
  1522. diff -ruN nepenthes-0.2.0/modules/module-portwatch/WatchDialogue.cpp nepenthes-0.2.0-r1345/modules/module-portwatch/WatchDialogue.cpp
  1523. --- nepenthes-0.2.0/modules/module-portwatch/WatchDialogue.cpp 2006-11-13 20:40:09.000000000 +0100
  1524. +++ nepenthes-0.2.0-r1345/modules/module-portwatch/WatchDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  1525. @@ -47,6 +47,9 @@
  1526. #include "Utilities.hpp"
  1527. +#include "EventManager.hpp"
  1528. +#include "SocketEvent.hpp"
  1529. +
  1530. #ifdef STDTAGS
  1531. #undef STDTAGS
  1532. #endif
  1533. @@ -77,7 +80,7 @@
  1534. WatchDialogue::~WatchDialogue()
  1535. {
  1536. logWarn("Unknown WatchDialogue %i bytes, port %i\n",m_Buffer->getSize(), m_Socket->getLocalPort());
  1537. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  1538. + HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  1539. delete m_Buffer;
  1540. }
  1541. diff -ruN nepenthes-0.2.0/modules/shellcode-generic/Makefile.am nepenthes-0.2.0-r1345/modules/shellcode-generic/Makefile.am
  1542. --- nepenthes-0.2.0/modules/shellcode-generic/Makefile.am 2006-11-13 20:40:07.000000000 +0100
  1543. +++ nepenthes-0.2.0-r1345/modules/shellcode-generic/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  1544. @@ -32,4 +32,4 @@
  1545. shellcodegeneric_la_SOURCES += sch_generic_leimbach_url_xor.cpp sch_generic_leimbach_url_xor.hpp
  1546. shellcodegeneric_la_SOURCES += sch_generic_wget.cpp sch_generic_wget.hpp
  1547. -shellcodegeneric_la_LDFLAGS = -module -no-undefined -avoid-version
  1548. +shellcodegeneric_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  1549. diff -ruN nepenthes-0.2.0/modules/shellcode-generic/sch_generic_cmd.cpp nepenthes-0.2.0-r1345/modules/shellcode-generic/sch_generic_cmd.cpp
  1550. --- nepenthes-0.2.0/modules/shellcode-generic/sch_generic_cmd.cpp 2006-11-13 20:40:07.000000000 +0100
  1551. +++ nepenthes-0.2.0-r1345/modules/shellcode-generic/sch_generic_cmd.cpp 2007-08-06 00:46:15.000000000 +0200
  1552. @@ -95,7 +95,7 @@
  1553. if((iResult = pcre_exec(m_pcre, 0, (char *) shellcode, len, 0, 0, (int *)piOutput, sizeof(piOutput)/sizeof(int32_t))) > 0)
  1554. {
  1555. // logDebug("GenricCMD (improve pcre debug) (%i bytes)\n",(*msg)->getSize());
  1556. -// g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *)(*msg)->getMsg(),(*msg)->getSize());
  1557. +// HEXDUMP(m_Socket,(byte *)(*msg)->getMsg(),(*msg)->getSize());
  1558. const char * pRemoteCommand;
  1559. diff -ruN nepenthes-0.2.0/modules/shellcode-generic/sch_generic_leimbach_url_xor.cpp nepenthes-0.2.0-r1345/modules/shellcode-generic/sch_generic_leimbach_url_xor.cpp
  1560. --- nepenthes-0.2.0/modules/shellcode-generic/sch_generic_leimbach_url_xor.cpp 2006-11-13 20:40:07.000000000 +0100
  1561. +++ nepenthes-0.2.0-r1345/modules/shellcode-generic/sch_generic_leimbach_url_xor.cpp 2007-08-06 00:46:15.000000000 +0200
  1562. @@ -203,7 +203,7 @@
  1563. pcre_free_substring(preload);
  1564. pcre_free_substring(xordecoder);
  1565. - g_Nepenthes->getUtilities()->hexdump(l_crit,(byte *)newshellcode, len);
  1566. +// g_Nepenthes->getUtilities()->hexdump(l_crit,(byte *)newshellcode, len);
  1567. Message *newMessage = new Message((char *)newshellcode, len, (*msg)->getLocalPort(), (*msg)->getRemotePort(),
  1568. (*msg)->getLocalHost(), (*msg)->getRemoteHost(), (*msg)->getResponder(), (*msg)->getSocket());
  1569. diff -ruN nepenthes-0.2.0/modules/shellcode-generic/sch_generic_url.cpp nepenthes-0.2.0-r1345/modules/shellcode-generic/sch_generic_url.cpp
  1570. --- nepenthes-0.2.0/modules/shellcode-generic/sch_generic_url.cpp 2006-11-13 20:40:07.000000000 +0100
  1571. +++ nepenthes-0.2.0-r1345/modules/shellcode-generic/sch_generic_url.cpp 2007-08-06 00:46:15.000000000 +0200
  1572. @@ -119,7 +119,7 @@
  1573. if((iResult = pcre_exec(m_pcre, 0, (char *) shellcode, len, 0, 0, (int *)piOutput, sizeof(piOutput)/sizeof(int32_t))) > 0)
  1574. {
  1575. -// g_Nepenthes->getUtilities()->hexdump(STDTAGS,shellcode,len);
  1576. +// HEXDUMP(m_Socket,shellcode,len);
  1577. const char * pUrl;
  1578. pcre_get_substring((char *) shellcode, (int *)piOutput, (int)iResult, 1, &pUrl);
  1579. diff -ruN nepenthes-0.2.0/modules/shellcode-signatures/Makefile.am nepenthes-0.2.0-r1345/modules/shellcode-signatures/Makefile.am
  1580. --- nepenthes-0.2.0/modules/shellcode-signatures/Makefile.am 2006-11-13 20:40:04.000000000 +0100
  1581. +++ nepenthes-0.2.0-r1345/modules/shellcode-signatures/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  1582. @@ -33,5 +33,5 @@
  1583. shellcodesignatures_la_SOURCES += sch_namespace_konstanzxor.cpp sch_namespace_konstanzxor.hpp
  1584. shellcodesignatures_la_SOURCES += sch_namespace_alphanumericxor.cpp sch_namespace_alphanumericxor.hpp
  1585. -shellcodesignatures_la_LDFLAGS = -module -no-undefined -avoid-version
  1586. +shellcodesignatures_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  1587. diff -ruN nepenthes-0.2.0/modules/shellcode-signatures/shellcode-signatures.sc nepenthes-0.2.0-r1345/modules/shellcode-signatures/shellcode-signatures.sc
  1588. --- nepenthes-0.2.0/modules/shellcode-signatures/shellcode-signatures.sc 2006-11-13 20:40:04.000000000 +0100
  1589. +++ nepenthes-0.2.0-r1345/modules/shellcode-signatures/shellcode-signatures.sc 2007-08-06 00:46:15.000000000 +0200
  1590. @@ -178,6 +178,13 @@
  1591. mapping (none,pre,decoder,size,key,post);
  1592. };
  1593. +xor::marburganderlahn
  1594. +{
  1595. + pattern
  1596. + "(.*)(\\xEB\\x0E\\x5A\\x4A\\x31\\xC9\\xB1(.)\\x80\\x34\\x11(.)\\xE2\\xFA\\xEB\\x05\\xE8\\xED\xFF\xFF\xFF)(.*)$";
  1597. + mapping (none,pre,decoder,size,key,post);
  1598. +};
  1599. +
  1600. /*
  1601. * too inaccurate
  1602. *
  1603. @@ -944,8 +951,8 @@
  1604. pattern
  1605. "\\xeb\\x02\\xeb\\x6b"
  1606. "\\xe8\\xf9\\xff\\xff\\xff\\x53\\x55\\x56\\x57\\x8b\\x6c\\x24\\x18\\x8b\\x45\\x3c"
  1607. - "\\x8b\\x54\\x05\\x78\\x03\\xd5\\x8b\\x4a\\x18\\x8b\\x5a\\x20\\x03\\xdd\\xe3\\x32"
  1608. - "\\x49\\x8b\\x34\\x8b\\x03\\xf5\\x33\\xff\\xfc\\x33\\xc0\\xac\\x3a\\xc4\\x74\\x07"
  1609. + "\\x8b\\x54.\\x78\\x03\\xd5\\x8b\\x4a\\x18\\x8b\\x5a\\x20\\x03\\xdd\\xe3\\x32"
  1610. + "\\x49\\x8b\\x34\\x8b\\x03\\xf5\\x33\\xff\\xfc\\x33\\xc0\\xac..\\x74\\x07"
  1611. "\\xc1\\xcf\\x0d\\x03\\xf8\\xeb\\xf2\\x3b\\x7c\\x24\\x14\\x75\\xe1\\x8b\\x5a\\x24"
  1612. "\\x03\\xdd\\x66\\x8b\\x0c\\x4b\\x8b\\x5a\\x1c\\x03\\xdd\\x8b\\x04\\x8b\\x03\\xc5"
  1613. "\\xeb\\x02\\x33\\xc0\\x5f\\x5e\\x5d\\x5b\\x89\\x44\\x24\\x04\\x8b\\x04\\x24\\x89"
  1614. diff -ruN nepenthes-0.2.0/modules/shellemu-winnt/VFSCommandFTP.cpp nepenthes-0.2.0-r1345/modules/shellemu-winnt/VFSCommandFTP.cpp
  1615. --- nepenthes-0.2.0/modules/shellemu-winnt/VFSCommandFTP.cpp 2006-11-13 20:40:06.000000000 +0100
  1616. +++ nepenthes-0.2.0-r1345/modules/shellemu-winnt/VFSCommandFTP.cpp 2007-08-06 00:46:15.000000000 +0200
  1617. @@ -425,7 +425,6 @@
  1618. logSpam("VFSCommandFTP Setting Hosts %i %i\n",remotehost,localhost);
  1619. remotehost = m_VFS->getDialogue()->getSocket()->getRemoteHost();
  1620. localhost = m_VFS->getDialogue()->getSocket()->getLocalHost();
  1621. -
  1622. }
  1623. logSpam("VFSCommandFTP LocalHost %s\n",inet_ntoa(*(in_addr *)&localhost));
  1624. diff -ruN nepenthes-0.2.0/modules/sqlhandler-postgres/Makefile.am nepenthes-0.2.0-r1345/modules/sqlhandler-postgres/Makefile.am
  1625. --- nepenthes-0.2.0/modules/sqlhandler-postgres/Makefile.am 2006-11-13 20:40:05.000000000 +0100
  1626. +++ nepenthes-0.2.0-r1345/modules/sqlhandler-postgres/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  1627. @@ -12,4 +12,4 @@
  1628. sqlhandlerpostgres_la_SOURCES = sqlhandler-postgres.cpp sqlhandler-postgres.hpp
  1629. -sqlhandlerpostgres_la_LDFLAGS = -module -no-undefined -avoid-version
  1630. +sqlhandlerpostgres_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  1631. diff -ruN nepenthes-0.2.0/modules/sqlhandler-postgres/sqlhandler-postgres.cpp nepenthes-0.2.0-r1345/modules/sqlhandler-postgres/sqlhandler-postgres.cpp
  1632. --- nepenthes-0.2.0/modules/sqlhandler-postgres/sqlhandler-postgres.cpp 2006-11-13 20:40:05.000000000 +0100
  1633. +++ nepenthes-0.2.0-r1345/modules/sqlhandler-postgres/sqlhandler-postgres.cpp 2007-08-06 00:46:15.000000000 +0200
  1634. @@ -145,6 +145,7 @@
  1635. m_PGTable = table;
  1636. m_PGUser = user;
  1637. m_PGPass = passwd;
  1638. + m_PGOptions = options;
  1639. m_Callback = cb;
  1640. }
  1641. @@ -760,6 +761,10 @@
  1642. "' user = '" + m_PGUser +
  1643. "' password = '" + m_PGPass +"'";
  1644. + if ( m_PGOptions.size() > 0 )
  1645. + ConnectString += m_PGOptions;
  1646. +
  1647. +
  1648. if (m_PGConnection != NULL)
  1649. PQfinish(m_PGConnection);
  1650. else
  1651. diff -ruN nepenthes-0.2.0/modules/sqlhandler-postgres/sqlhandler-postgres.hpp nepenthes-0.2.0-r1345/modules/sqlhandler-postgres/sqlhandler-postgres.hpp
  1652. --- nepenthes-0.2.0/modules/sqlhandler-postgres/sqlhandler-postgres.hpp 2006-11-13 20:40:05.000000000 +0100
  1653. +++ nepenthes-0.2.0-r1345/modules/sqlhandler-postgres/sqlhandler-postgres.hpp 2007-08-06 00:46:15.000000000 +0200
  1654. @@ -141,6 +141,7 @@
  1655. string m_PGTable;
  1656. string m_PGUser;
  1657. string m_PGPass;
  1658. + string m_PGOptions;
  1659. };
  1660. diff -ruN nepenthes-0.2.0/modules/submit-gotek/gotekCTRLDialogue.cpp nepenthes-0.2.0-r1345/modules/submit-gotek/gotekCTRLDialogue.cpp
  1661. --- nepenthes-0.2.0/modules/submit-gotek/gotekCTRLDialogue.cpp 2006-11-13 20:40:11.000000000 +0100
  1662. +++ nepenthes-0.2.0-r1345/modules/submit-gotek/gotekCTRLDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  1663. @@ -112,7 +112,7 @@
  1664. unsigned char sessionkey[8];
  1665. memcpy((char *)sessionkey,(char *)m_Buffer->getData(),8);
  1666. - g_Nepenthes->getUtilities()->hexdump(sessionkey,8);
  1667. +// g_Nepenthes->getUtilities()->hexdump(sessionkey,8);
  1668. @@ -128,13 +128,13 @@
  1669. byte hashme[1032];
  1670. memset(hashme,0,1032);
  1671. - g_Nepenthes->getUtilities()->hexdump(g_GotekSubmitHandler->getCommunityKey(),1024);
  1672. +// g_Nepenthes->getUtilities()->hexdump(g_GotekSubmitHandler->getCommunityKey(),1024);
  1673. memcpy(hashme,g_GotekSubmitHandler->getCommunityKey(),1024);
  1674. memcpy(hashme+1024,sessionkey,8);
  1675. - g_Nepenthes->getUtilities()->hexdump(hashme, 1032);
  1676. +// g_Nepenthes->getUtilities()->hexdump(hashme, 1032);
  1677. g_Nepenthes->getUtilities()->sha512(hashme, 1032, hash);
  1678. - g_Nepenthes->getUtilities()->hexdump(hash,64);
  1679. +// g_Nepenthes->getUtilities()->hexdump(hash,64);
  1680. m_Socket->doRespond((char *)hash,64);
  1681. diff -ruN nepenthes-0.2.0/modules/submit-gotek/gotekDATADialogue.cpp nepenthes-0.2.0-r1345/modules/submit-gotek/gotekDATADialogue.cpp
  1682. --- nepenthes-0.2.0/modules/submit-gotek/gotekDATADialogue.cpp 2006-11-13 20:40:11.000000000 +0100
  1683. +++ nepenthes-0.2.0-r1345/modules/submit-gotek/gotekDATADialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  1684. @@ -173,7 +173,7 @@
  1685. byte hashme[1032];
  1686. memset(hashme,0,1032);
  1687. - g_Nepenthes->getUtilities()->hexdump(g_GotekSubmitHandler->getCommunityKey(),1024);
  1688. +// g_Nepenthes->getUtilities()->hexdump(g_GotekSubmitHandler->getCommunityKey(),1024);
  1689. memcpy(hashme,g_GotekSubmitHandler->getCommunityKey(),1024);
  1690. memcpy(hashme+1024,&sessionkey,8);
  1691. g_Nepenthes->getUtilities()->sha512(hashme, 1032, hash);
  1692. diff -ruN nepenthes-0.2.0/modules/submit-http/HTTPSession.cpp nepenthes-0.2.0-r1345/modules/submit-http/HTTPSession.cpp
  1693. --- nepenthes-0.2.0/modules/submit-http/HTTPSession.cpp 1970-01-01 01:00:00.000000000 +0100
  1694. +++ nepenthes-0.2.0-r1345/modules/submit-http/HTTPSession.cpp 2007-08-06 00:46:15.000000000 +0200
  1695. @@ -0,0 +1,187 @@
  1696. +/********************************************************************************
  1697. + * Nepenthes
  1698. + * - finest collection -
  1699. + *
  1700. + *
  1701. + *
  1702. + * Copyright (C) 2006 Niklas Schiffler <nick@digitician.eu>
  1703. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  1704. + *
  1705. + * This program is free software; you can redistribute it and/or
  1706. + * modify it under the terms of the GNU General Public License
  1707. + * as published by the Free Software Foundation; either version 2
  1708. + * of the License, or (at your option) any later version.
  1709. + *
  1710. + * This program is distributed in the hope that it will be useful,
  1711. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1712. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1713. + * GNU General Public License for more details.
  1714. + *
  1715. + * You should have received a copy of the GNU General Public License
  1716. + * along with this program; if not, write to the Free Software
  1717. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  1718. + *
  1719. + *
  1720. + * contact nepenthesdev@users.sourceforge.net
  1721. + *
  1722. + *******************************************************************************/
  1723. +
  1724. +
  1725. +#include <curl/curl.h>
  1726. +#include <curl/types.h> /* new for v7 */
  1727. +#include <curl/easy.h> /* new for v7 */
  1728. +#include <sstream>
  1729. +#include <netinet/in.h>
  1730. +
  1731. +#include "HTTPSession.hpp"
  1732. +#include "submit-http.hpp"
  1733. +#include "DownloadBuffer.hpp"
  1734. +#include "DownloadUrl.hpp"
  1735. +
  1736. +using namespace nepenthes;
  1737. +
  1738. +HTTPSession::HTTPSession(string &url, string &email, string &user, string &password, Download* down)
  1739. +{
  1740. + state = S_ERROR;
  1741. + postInfo = NULL;
  1742. + postFile = NULL;
  1743. + curlInfoHandle = NULL;
  1744. + curlFileHandle = NULL;
  1745. +
  1746. + submitURL = url;
  1747. +
  1748. + if ( user.length() > 0 && password.length() > 0 )
  1749. + submitAuthStr = user + ":" + password;
  1750. +
  1751. + md5 = down->getMD5Sum();
  1752. + sha512 = down->getSHA512Sum();
  1753. + fileSize = down->getDownloadBuffer()->getSize();
  1754. + fileName = down->getDownloadUrl()->getFile();
  1755. + fileSourceURL = down->getUrl();
  1756. +
  1757. + fileBuffer = new uint8_t[fileSize];
  1758. + fileBuffer = (uint8_t*)memcpy(fileBuffer, down->getDownloadBuffer()->getData(), fileSize);
  1759. +
  1760. + curlInfoHandle = curl_easy_init();
  1761. + if ( curlInfoHandle )
  1762. + {
  1763. + struct curl_httppost* last = NULL;
  1764. +
  1765. + if ( email.length() > 0 )
  1766. + curl_formadd(&postInfo, &last, CURLFORM_COPYNAME, "email", CURLFORM_COPYCONTENTS, email.c_str(), CURLFORM_END);
  1767. +
  1768. + stringstream sSourceHost; sSourceHost << htonl(down->getRemoteHost());
  1769. + stringstream sTargetHost; sTargetHost << htonl(down->getLocalHost());
  1770. +
  1771. + curl_formadd(&postInfo, &last, CURLFORM_PTRNAME, "url", CURLFORM_COPYCONTENTS, fileSourceURL.c_str(), CURLFORM_END);
  1772. + curl_formadd(&postInfo, &last, CURLFORM_PTRNAME, "trigger", CURLFORM_COPYCONTENTS, down->getTriggerLine().c_str(), CURLFORM_END);
  1773. + curl_formadd(&postInfo, &last, CURLFORM_PTRNAME, "md5", CURLFORM_COPYCONTENTS, md5.c_str(), CURLFORM_END);
  1774. + curl_formadd(&postInfo, &last, CURLFORM_PTRNAME, "sha512", CURLFORM_COPYCONTENTS, sha512.c_str(), CURLFORM_END);
  1775. + curl_formadd(&postInfo, &last, CURLFORM_PTRNAME, "filetype", CURLFORM_COPYCONTENTS, down->getFileType().c_str(), CURLFORM_END);
  1776. + curl_formadd(&postInfo, &last, CURLFORM_PTRNAME, "source_host", CURLFORM_COPYCONTENTS, sSourceHost.str().c_str(), CURLFORM_END);
  1777. + curl_formadd(&postInfo, &last, CURLFORM_PTRNAME, "target_host", CURLFORM_COPYCONTENTS, sTargetHost.str().c_str(), CURLFORM_END);
  1778. + curl_formadd(&postInfo, &last, CURLFORM_PTRNAME, "filename", CURLFORM_COPYCONTENTS, down->getDownloadUrl()->getFile().c_str(), CURLFORM_END);
  1779. +
  1780. + setCURLOpts(curlInfoHandle, postInfo);
  1781. + }
  1782. +}
  1783. +
  1784. +HTTPSession::~HTTPSession()
  1785. +{
  1786. + delete [] fileBuffer;
  1787. + curl_formfree(postInfo);
  1788. + if ( postFile )
  1789. + curl_formfree(postFile);
  1790. + curl_easy_cleanup(curlInfoHandle);
  1791. + if ( curlFileHandle )
  1792. + curl_easy_cleanup(curlFileHandle);
  1793. +}
  1794. +
  1795. +CURL* HTTPSession::getSubmitInfoHandle()
  1796. +{
  1797. + return curlInfoHandle;
  1798. +}
  1799. +
  1800. +CURL* HTTPSession::getSubmitFileHandle()
  1801. +{
  1802. + curlFileHandle = curl_easy_init();
  1803. + if ( curlFileHandle )
  1804. + {
  1805. + postFile = NULL;
  1806. + struct curl_httppost* last = NULL;
  1807. +
  1808. + curl_formadd(&postFile, &last, CURLFORM_PTRNAME, "md5", CURLFORM_COPYCONTENTS, md5.c_str(), CURLFORM_END);
  1809. + curl_formadd(&postFile, &last, CURLFORM_PTRNAME, "sha512", CURLFORM_COPYCONTENTS, sha512.c_str(), CURLFORM_END);
  1810. +
  1811. + curl_formadd(&postFile, &last,
  1812. + CURLFORM_COPYNAME, "file",
  1813. + CURLFORM_BUFFER, fileName.c_str(),
  1814. + CURLFORM_BUFFERPTR, fileBuffer,
  1815. + CURLFORM_BUFFERLENGTH, fileSize,
  1816. + CURLFORM_END);
  1817. +
  1818. + setCURLOpts(curlFileHandle, postFile);
  1819. + }
  1820. + return curlFileHandle;
  1821. +}
  1822. +
  1823. +string HTTPSession::getMD5()
  1824. +{
  1825. + return md5;
  1826. +}
  1827. +
  1828. +string HTTPSession::getSHA512()
  1829. +{
  1830. + return sha512;
  1831. +}
  1832. +
  1833. +void HTTPSession::setCURLOpts(CURL* c, curl_httppost* post)
  1834. +{
  1835. + curl_easy_setopt(c, CURLOPT_HTTPPOST, post);
  1836. + curl_easy_setopt(c, CURLOPT_SSL_VERIFYHOST, false);
  1837. + curl_easy_setopt(c, CURLOPT_SSL_VERIFYPEER, false);
  1838. + curl_easy_setopt(c, CURLOPT_URL, submitURL.c_str());
  1839. + curl_easy_setopt(c, CURLOPT_USERAGENT, "Mozilla/4.0 (compatible; nepenthes; Linux)");
  1840. + curl_easy_setopt(c, CURLOPT_PRIVATE, (char*) this);
  1841. + curl_easy_setopt(c, CURLOPT_WRITEDATA, this);
  1842. + curl_easy_setopt(c, CURLOPT_WRITEFUNCTION, HTTPSession::WriteCallback);
  1843. +
  1844. + if ( submitAuthStr.length() > 0 )
  1845. + curl_easy_setopt(c, CURLOPT_USERPWD, submitAuthStr.c_str());
  1846. +}
  1847. +
  1848. +size_t HTTPSession::WriteCallback(char *buffer, size_t size, size_t nitems, void *p)
  1849. +{
  1850. + HTTPSession* s = (HTTPSession*)p;
  1851. + int32_t iSize = size * nitems;
  1852. +
  1853. + string res(buffer, iSize);
  1854. + if ( res.find("S_FILEREQUEST") != string::npos )
  1855. + s->setState(S_FILEREQUEST);
  1856. + else
  1857. + if ( res.find("S_FILEKNOWN") != string::npos )
  1858. + s->setState(S_FILEKNOWN);
  1859. + else
  1860. + if ( res.find("S_FILEOK") != string::npos )
  1861. + s->setState(S_FILEOK);
  1862. + else
  1863. + s->setState(S_ERROR);
  1864. +
  1865. +// delete(strBuf);
  1866. + return iSize;
  1867. +}
  1868. +
  1869. +uint8_t HTTPSession::getState()
  1870. +{
  1871. + return state;
  1872. +}
  1873. +
  1874. +void HTTPSession::setState(uint8_t s)
  1875. +{
  1876. + this->state = s;
  1877. +}
  1878. +
  1879. +string HTTPSession::getFileSourceURL()
  1880. +{
  1881. + return fileSourceURL;
  1882. +}
  1883. diff -ruN nepenthes-0.2.0/modules/submit-http/HTTPSession.hpp nepenthes-0.2.0-r1345/modules/submit-http/HTTPSession.hpp
  1884. --- nepenthes-0.2.0/modules/submit-http/HTTPSession.hpp 1970-01-01 01:00:00.000000000 +0100
  1885. +++ nepenthes-0.2.0-r1345/modules/submit-http/HTTPSession.hpp 2007-08-06 00:46:15.000000000 +0200
  1886. @@ -0,0 +1,82 @@
  1887. +/********************************************************************************
  1888. + * Nepenthes
  1889. + * - finest collection -
  1890. + *
  1891. + *
  1892. + *
  1893. + * Copyright (C) 2006 Niklas Schiffler <nick@digitician.eu>
  1894. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  1895. + *
  1896. + * This program is free software; you can redistribute it and/or
  1897. + * modify it under the terms of the GNU General Public License
  1898. + * as published by the Free Software Foundation; either version 2
  1899. + * of the License, or (at your option) any later version.
  1900. + *
  1901. + * This program is distributed in the hope that it will be useful,
  1902. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  1903. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  1904. + * GNU General Public License for more details.
  1905. + *
  1906. + * You should have received a copy of the GNU General Public License
  1907. + * along with this program; if not, write to the Free Software
  1908. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  1909. + *
  1910. + *
  1911. + * contact nepenthesdev@users.sourceforge.net
  1912. + *
  1913. + *******************************************************************************/
  1914. +
  1915. + /* $Id$ */
  1916. +
  1917. +#include <curl/curl.h>
  1918. +#include <curl/types.h>
  1919. +
  1920. +#include "Download.hpp"
  1921. +
  1922. +using namespace std;
  1923. +
  1924. +namespace nepenthes
  1925. +{
  1926. +
  1927. +
  1928. + class HTTPSession
  1929. + {
  1930. + public:
  1931. + static const uint8_t S_FILEKNOWN = 0;
  1932. + static const uint8_t S_FILEREQUEST = 1;
  1933. + static const uint8_t S_FILEOK = 2;
  1934. + static const uint8_t S_FILEPENDING = 3;
  1935. + static const uint8_t S_ERROR = 4;
  1936. +
  1937. + HTTPSession(string &url, string &email, string &user, string &password, Download* down);
  1938. + ~HTTPSession();
  1939. + CURL* getSubmitInfoHandle();
  1940. + CURL* getSubmitFileHandle();
  1941. + string getMD5();
  1942. + string getSHA512();
  1943. + void setCURLOpts(CURL* c, curl_httppost* post);
  1944. + uint8_t getState();
  1945. + void setState(uint8_t s);
  1946. + string getFileSourceURL();
  1947. +
  1948. + static size_t WriteCallback(char *buffer, size_t size, size_t nitems, void *userp);
  1949. +
  1950. + protected:
  1951. + CURL* curlInfoHandle;
  1952. + CURL* curlFileHandle;
  1953. + uint8_t* fileBuffer;
  1954. + size_t fileSize;
  1955. + struct curl_httppost* postInfo;
  1956. + struct curl_httppost* postFile;
  1957. + string fileName;
  1958. + string fileSourceURL;
  1959. + string md5;
  1960. + string sha512;
  1961. + string submitURL;
  1962. + string submitAuthStr;
  1963. + uint8_t state;
  1964. +
  1965. + };
  1966. +
  1967. +}
  1968. +
  1969. diff -ruN nepenthes-0.2.0/modules/submit-http/Makefile.am nepenthes-0.2.0-r1345/modules/submit-http/Makefile.am
  1970. --- nepenthes-0.2.0/modules/submit-http/Makefile.am 1970-01-01 01:00:00.000000000 +0100
  1971. +++ nepenthes-0.2.0-r1345/modules/submit-http/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  1972. @@ -0,0 +1,14 @@
  1973. +AUTOMAKE_OPTIONS = foreign
  1974. +
  1975. +AM_CPPFLAGS = -I$(top_srcdir)/nepenthes-core/include -I$(top_srcdir)/nepenthes-core/src -pipe -D _GNU_SOURCE
  1976. +AM_CXXFLAGS = -Wall -Werror
  1977. +
  1978. +AM_LDFLAGS = $(LIB_CURL)
  1979. +
  1980. +pkglib_LTLIBRARIES = submithttp.la
  1981. +
  1982. +submithttp_la_SOURCES = submit-http.cpp submit-http.hpp
  1983. +submithttp_la_SOURCES += HTTPSession.hpp HTTPSession.cpp
  1984. +submithttp_la_SOURCES += submit-http.conf.dist
  1985. +
  1986. +submithttp_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  1987. diff -ruN nepenthes-0.2.0/modules/submit-http/submit-http.conf.dist nepenthes-0.2.0-r1345/modules/submit-http/submit-http.conf.dist
  1988. --- nepenthes-0.2.0/modules/submit-http/submit-http.conf.dist 1970-01-01 01:00:00.000000000 +0100
  1989. +++ nepenthes-0.2.0-r1345/modules/submit-http/submit-http.conf.dist 2007-08-06 00:46:15.000000000 +0200
  1990. @@ -0,0 +1,8 @@
  1991. +submit-http
  1992. +{
  1993. + url "http://somehost.de/submit.php";
  1994. + email "your@email"; // optional
  1995. + user "httpuser"; // optional
  1996. + pass "httppass"; // optional
  1997. +};
  1998. +
  1999. diff -ruN nepenthes-0.2.0/modules/submit-http/submit-http.cpp nepenthes-0.2.0-r1345/modules/submit-http/submit-http.cpp
  2000. --- nepenthes-0.2.0/modules/submit-http/submit-http.cpp 1970-01-01 01:00:00.000000000 +0100
  2001. +++ nepenthes-0.2.0-r1345/modules/submit-http/submit-http.cpp 2007-08-06 00:46:15.000000000 +0200
  2002. @@ -0,0 +1,231 @@
  2003. +/********************************************************************************
  2004. + * Nepenthes
  2005. + * - finest collection -
  2006. + *
  2007. + *
  2008. + *
  2009. + * Copyright (C) 2006 Niklas Schiffler <nick@digitician.eu>
  2010. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  2011. + *
  2012. + * This program is free software; you can redistribute it and/or
  2013. + * modify it under the terms of the GNU General Public License
  2014. + * as published by the Free Software Foundation; either version 2
  2015. + * of the License, or (at your option) any later version.
  2016. + *
  2017. + * This program is distributed in the hope that it will be useful,
  2018. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2019. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2020. + * GNU General Public License for more details.
  2021. + *
  2022. + * You should have received a copy of the GNU General Public License
  2023. + * along with this program; if not, write to the Free Software
  2024. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  2025. + *
  2026. + *
  2027. + * contact nepenthesdev@users.sourceforge.net
  2028. + *
  2029. + *******************************************************************************/
  2030. +
  2031. + /* $Id$ */
  2032. +
  2033. +#include "submit-http.hpp"
  2034. +#include "Download.hpp"
  2035. +#include "Utilities.hpp"
  2036. +#include "SubmitManager.hpp"
  2037. +#include "LogManager.hpp"
  2038. +#include "Event.hpp"
  2039. +#include "EventManager.hpp"
  2040. +#include "EventHandler.cpp" // das ist Mist!
  2041. +#include "Config.hpp"
  2042. +#include "ModuleManager.hpp"
  2043. +
  2044. +#include "HTTPSession.hpp"
  2045. +
  2046. +using namespace nepenthes;
  2047. +
  2048. +
  2049. +Nepenthes *g_Nepenthes;
  2050. +
  2051. +
  2052. +HTTPSubmitHandler::HTTPSubmitHandler(Nepenthes *nepenthes)
  2053. +{
  2054. + m_ModuleName = "submit-http";
  2055. + m_ModuleDescription = "HTTP submit handler";
  2056. + m_ModuleRevision = "$Rev$";
  2057. + m_Nepenthes = nepenthes;
  2058. + m_SubmitterName = "submit-http";
  2059. + m_SubmitterDescription = "submit binary file via HTTP POST request";
  2060. + g_Nepenthes = nepenthes;
  2061. +
  2062. + m_Queued = 0;
  2063. + m_Timeout = time(NULL);
  2064. + m_Events.reset();
  2065. +}
  2066. +
  2067. +
  2068. +HTTPSubmitHandler::~HTTPSubmitHandler()
  2069. +{
  2070. +}
  2071. +
  2072. +bool HTTPSubmitHandler::Init()
  2073. +{
  2074. + logPF();
  2075. +
  2076. + if ( m_Config == NULL )
  2077. + {
  2078. + logCrit("I need a config\n");
  2079. + return false;
  2080. + }
  2081. +
  2082. + try
  2083. + {
  2084. + m_URL = m_Config->getValString("submit-http.url");
  2085. + }
  2086. + catch ( ... )
  2087. + {
  2088. + logCrit("Error: Config property \"url\" missing\n");
  2089. + return false;
  2090. + }
  2091. +
  2092. + try
  2093. + {
  2094. + m_Email = m_Config->getValString("submit-http.email");
  2095. + m_User = m_Config->getValString("submit-http.user");
  2096. + m_Password = m_Config->getValString("submit-http.pass");
  2097. + }
  2098. + catch ( ... )
  2099. + {
  2100. + }
  2101. +
  2102. + m_ModuleManager = m_Nepenthes->getModuleMgr();
  2103. +
  2104. + if ( (m_CurlStack = curl_multi_init()) == NULL )
  2105. + {
  2106. + logCrit("Could not init Curl Multi Perform Stack %s\n",strerror(errno));
  2107. + return false;
  2108. + }
  2109. +
  2110. + REG_SUBMIT_HANDLER(this);
  2111. + REG_EVENT_HANDLER(this);
  2112. + return true;
  2113. +}
  2114. +
  2115. +bool HTTPSubmitHandler::Exit()
  2116. +{
  2117. + curl_multi_cleanup(m_CurlStack);
  2118. + return true;
  2119. +}
  2120. +
  2121. +
  2122. +void HTTPSubmitHandler::Submit(Download *down)
  2123. +{
  2124. + logPF();
  2125. +
  2126. + if ( m_Events.test(EV_TIMEOUT) == false )
  2127. + m_Events.set(EV_TIMEOUT);
  2128. +
  2129. + HTTPSession* session = new HTTPSession(m_URL, m_Email, m_User, m_Password, down);
  2130. + curl_multi_add_handle(m_CurlStack, session->getSubmitInfoHandle());
  2131. + m_Queued++;
  2132. +}
  2133. +
  2134. +void HTTPSubmitHandler::Hit(Download *down)
  2135. +{
  2136. + Submit(down);
  2137. +}
  2138. +
  2139. +
  2140. +uint32_t HTTPSubmitHandler::handleEvent(Event *event)
  2141. +{
  2142. + logPF();
  2143. + if ( event->getType() != EV_TIMEOUT )
  2144. + {
  2145. + logCrit("Unwanted event %i\n",event->getType());
  2146. + return 1;
  2147. + }
  2148. +
  2149. + // do file info submits
  2150. + int32_t iQueue = 0;
  2151. + while ( curl_multi_perform(m_CurlStack, (int *)&iQueue) == CURLM_CALL_MULTI_PERFORM );
  2152. +
  2153. + if ( m_Queued > iQueue )
  2154. + {
  2155. + logSpam("m_Queued (%i) > (%i) iQueue\n", m_Queued, iQueue);
  2156. + CURLMsg * pMessage;
  2157. +
  2158. + while ( (pMessage = curl_multi_info_read(m_CurlStack, (int *)&iQueue)) )
  2159. + {
  2160. + if ( pMessage->msg == CURLMSG_DONE )
  2161. + {
  2162. + HTTPSession *session;
  2163. + char *cSession;
  2164. +
  2165. + curl_easy_getinfo(pMessage->easy_handle, CURLINFO_PRIVATE, (char**)&cSession);
  2166. + session = (HTTPSession *)cSession;
  2167. +
  2168. + uint8_t sessionState = session->getState();
  2169. +
  2170. + if ( sessionState == HTTPSession::S_FILEKNOWN || sessionState == HTTPSession::S_FILEREQUEST )
  2171. + {
  2172. + if ( pMessage->data.result )
  2173. + {
  2174. + logInfo("Error: Submitting file info (%s, %s) failed: %s\n", session->getMD5().c_str(), session->getFileSourceURL().c_str(), curl_easy_strerror(pMessage->data.result));
  2175. + delete session;
  2176. + curl_multi_remove_handle(m_CurlStack, pMessage->easy_handle);
  2177. + --m_Queued;
  2178. + continue;
  2179. + }
  2180. + logInfo("File info submitted (%s, %s)\n", session->getMD5().c_str(), session->getFileSourceURL().c_str());
  2181. + }
  2182. +
  2183. + switch ( sessionState )
  2184. + {
  2185. + case HTTPSession::S_FILEKNOWN:
  2186. + logInfo("File already known (%s, %s)\n", session->getMD5().c_str(), session->getFileSourceURL().c_str());
  2187. + break;
  2188. + case HTTPSession::S_FILEREQUEST:
  2189. + logInfo("File upload requested (%s, %s)\n", session->getMD5().c_str(), session->getFileSourceURL().c_str());
  2190. + session->setState(HTTPSession::S_FILEPENDING);
  2191. + curl_multi_add_handle(m_CurlStack, session->getSubmitFileHandle());
  2192. + break;
  2193. + case HTTPSession::S_FILEOK:
  2194. + logInfo("File uploaded (%s, %s)\n", session->getMD5().c_str(), session->getFileSourceURL().c_str());
  2195. + break;
  2196. + case HTTPSession::S_ERROR:
  2197. + logInfo("Error handling file (%s, %s)\n", session->getMD5().c_str(), session->getFileSourceURL().c_str());
  2198. + break;
  2199. + }
  2200. +
  2201. + curl_multi_remove_handle(m_CurlStack, pMessage->easy_handle);
  2202. +
  2203. + if ( sessionState == HTTPSession::S_FILEKNOWN ||
  2204. + sessionState == HTTPSession::S_FILEOK ||
  2205. + sessionState == HTTPSession::S_ERROR )
  2206. + {
  2207. + delete session;
  2208. + --m_Queued;
  2209. + }
  2210. + }
  2211. + }
  2212. + }
  2213. +
  2214. + if ( m_Queued == 0 )
  2215. + m_Events.reset(EV_TIMEOUT);
  2216. +
  2217. + m_Timeout = time(NULL) + 1;
  2218. + return 0;
  2219. +}
  2220. +
  2221. +
  2222. +extern "C" int32_t module_init(int32_t version, Module **module, Nepenthes *nepenthes)
  2223. +{
  2224. + if ( version == MODULE_IFACE_VERSION )
  2225. + {
  2226. + *module = new HTTPSubmitHandler(nepenthes);
  2227. + return 1;
  2228. + }
  2229. + else
  2230. + {
  2231. + return 0;
  2232. + }
  2233. +}
  2234. diff -ruN nepenthes-0.2.0/modules/submit-http/submit-http.hpp nepenthes-0.2.0-r1345/modules/submit-http/submit-http.hpp
  2235. --- nepenthes-0.2.0/modules/submit-http/submit-http.hpp 1970-01-01 01:00:00.000000000 +0100
  2236. +++ nepenthes-0.2.0-r1345/modules/submit-http/submit-http.hpp 2007-08-06 00:46:15.000000000 +0200
  2237. @@ -0,0 +1,72 @@
  2238. +/********************************************************************************
  2239. + * Nepenthes
  2240. + * - finest collection -
  2241. + *
  2242. + *
  2243. + *
  2244. + * Copyright (C) 2006 Niklas Schiffler <nick@digitician.eu>
  2245. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  2246. + *
  2247. + * This program is free software; you can redistribute it and/or
  2248. + * modify it under the terms of the GNU General Public License
  2249. + * as published by the Free Software Foundation; either version 2
  2250. + * of the License, or (at your option) any later version.
  2251. + *
  2252. + * This program is distributed in the hope that it will be useful,
  2253. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2254. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2255. + * GNU General Public License for more details.
  2256. + *
  2257. + * You should have received a copy of the GNU General Public License
  2258. + * along with this program; if not, write to the Free Software
  2259. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  2260. + *
  2261. + *
  2262. + * contact nepenthesdev@users.sourceforge.net
  2263. + *
  2264. + *******************************************************************************/
  2265. +
  2266. + /* $Id$ */
  2267. +
  2268. +#include <curl/curl.h>
  2269. +#include <curl/types.h> /* new for v7 */
  2270. +#include <curl/easy.h> /* new for v7 */
  2271. +
  2272. +#include "Nepenthes.hpp"
  2273. +#include "Module.hpp"
  2274. +#include "SubmitHandler.hpp"
  2275. +#include "EventHandler.hpp"
  2276. +#include "Download.hpp"
  2277. +
  2278. +
  2279. +using namespace std;
  2280. +
  2281. +namespace nepenthes
  2282. +{
  2283. +
  2284. + class HTTPSubmitHandler : public Module , public SubmitHandler, public EventHandler
  2285. + {
  2286. + public:
  2287. + HTTPSubmitHandler(Nepenthes *nep);
  2288. + ~HTTPSubmitHandler();
  2289. + bool Init();
  2290. + bool Exit();
  2291. +
  2292. + void Submit(Download *down);
  2293. + void Hit(Download *down);
  2294. +
  2295. + uint32_t handleEvent(Event *event);
  2296. +
  2297. + protected:
  2298. + CURLM* m_CurlStack;
  2299. + int32_t m_Queued;
  2300. + string m_URL;
  2301. + string m_Email;
  2302. + string m_User;
  2303. + string m_Password;
  2304. +
  2305. + };
  2306. +
  2307. +}
  2308. +
  2309. +extern nepenthes::Nepenthes *g_Nepenthes;
  2310. diff -ruN nepenthes-0.2.0/modules/submit-mwserv/Makefile.am nepenthes-0.2.0-r1345/modules/submit-mwserv/Makefile.am
  2311. --- nepenthes-0.2.0/modules/submit-mwserv/Makefile.am 1970-01-01 01:00:00.000000000 +0100
  2312. +++ nepenthes-0.2.0-r1345/modules/submit-mwserv/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  2313. @@ -0,0 +1,19 @@
  2314. +# nepenthes module Makefile
  2315. +# Paul Baecher, Maximillian Dornseif, Markus Koetter
  2316. +# $Id: Makefile.am 718 2006-12-28 23:29:59Z common $
  2317. +
  2318. +AUTOMAKE_OPTIONS = foreign
  2319. +
  2320. +AM_CPPFLAGS = -I$(top_srcdir)/nepenthes-core/include -I$(top_srcdir)/nepenthes-core/src -pipe -D _GNU_SOURCE
  2321. +AM_CXXFLAGS = -Wall -Werror
  2322. +
  2323. +AM_LDFLAGS = $(LIB_CURL)
  2324. +
  2325. +pkglib_LTLIBRARIES = submitmwserv.la
  2326. +
  2327. +submitmwserv_la_SOURCES = submit-mwserv.cpp submit-mwserv.hpp
  2328. +submitmwserv_la_SOURCES += TransferSession.cpp TransferSession.hpp
  2329. +submitmwserv_la_SOURCES += submit-mwserv.conf.dist
  2330. +
  2331. +submitmwserv_la_CXXFLAGS = -fno-strict-aliasing
  2332. +submitmwserv_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  2333. diff -ruN nepenthes-0.2.0/modules/submit-mwserv/TransferSession.cpp nepenthes-0.2.0-r1345/modules/submit-mwserv/TransferSession.cpp
  2334. --- nepenthes-0.2.0/modules/submit-mwserv/TransferSession.cpp 1970-01-01 01:00:00.000000000 +0100
  2335. +++ nepenthes-0.2.0-r1345/modules/submit-mwserv/TransferSession.cpp 2007-08-06 00:46:15.000000000 +0200
  2336. @@ -0,0 +1,402 @@
  2337. +/********************************************************************************
  2338. + * Nepenthes
  2339. + * - finest collection -
  2340. + *
  2341. + *
  2342. + *
  2343. + * Copyright (C) 2007 Georg Wicherski <gw@mwcollect.org>
  2344. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  2345. + *
  2346. + * This program is free software; you can redistribute it and/or
  2347. + * modify it under the terms of the GNU General Public License
  2348. + * as published by the Free Software Foundation; either version 2
  2349. + * of the License, or (at your option) any later version.
  2350. + *
  2351. + * This program is distributed in the hope that it will be useful,
  2352. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2353. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2354. + * GNU General Public License for more details.
  2355. + *
  2356. + * You should have received a copy of the GNU General Public License
  2357. + * along with this program; if not, write to the Free Software
  2358. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  2359. + *
  2360. + *
  2361. + * contact nepenthesdev@users.sourceforge.net
  2362. + *
  2363. + *******************************************************************************/
  2364. +
  2365. +#include "submit-mwserv.hpp"
  2366. +
  2367. +#include "LogManager.hpp"
  2368. +#include "EventManager.hpp"
  2369. +
  2370. +#include "POLLSocket.cpp"
  2371. +#include "Socket.cpp"
  2372. +
  2373. +
  2374. +
  2375. +#if defined(__GNUG__)
  2376. + #define MY_COMPILER "g++"
  2377. +#elif defined(__CYGWIN__)
  2378. + #define MY_COMPILER "cygwin"
  2379. +#else
  2380. + #define MY_COMPILER "unknown Compiler"
  2381. +#endif
  2382. +
  2383. +#if defined(__FreeBSD__)
  2384. +# define MY_OS "FreeBSD"
  2385. +#elif defined(linux) || defined (__linux)
  2386. +# define MY_OS "Linux"
  2387. +#elif defined (__MACOSX__) || defined (__APPLE__)
  2388. +# define MY_OS "Mac OS X"
  2389. +#elif defined(__NetBSD__)
  2390. +# define MY_OS "NetBSD"
  2391. +#elif defined(__OpenBSD__)
  2392. +# define MY_OS "OpenBSD"
  2393. +#elif defined(_WIN32) || defined(__WIN32__) || defined(__TOS_WIN__)
  2394. +# define MY_OS "Windows"
  2395. +#elif defined(CYGWIN)
  2396. +# define MY_OS "Cygwin\Windows"
  2397. +#else
  2398. +# define MY_OS "Unknown OS"
  2399. +#endif
  2400. +
  2401. +#if defined(__alpha__) || defined(__alpha) || defined(_M_ALPHA)
  2402. +# define MY_ARCH "Alpha"
  2403. +#elif defined(__arm__)
  2404. +# if defined(__ARMEB__)
  2405. +# define MY_ARCH "ARMeb"
  2406. +# else
  2407. +# define MY_ARCH "ARM"
  2408. +# endif
  2409. +#elif defined(i386) || defined(__i386__) || defined(__i386) || defined(_M_IX86) || defined(_X86_) || defined(__THW_INTEL)
  2410. +# define MY_ARCH "x86"
  2411. +#elif defined(__x86_64__) || defined(__amd64__)
  2412. +# define MY_ARCH "x86_64"
  2413. +#elif defined(__ia64__) || defined(_IA64) || defined(__IA64__) || defined(_M_IA64)
  2414. +# define MY_ARCH "Intel Architecture-64"
  2415. +#elif defined(__mips__) || defined(__mips) || defined(__MIPS__)
  2416. +# if defined(__mips32__) || defined(__mips32)
  2417. +# define MY_ARCH "MIPS32"
  2418. +# else
  2419. +# define MY_ARCH "MIPS"
  2420. +# endif
  2421. +#elif defined(__hppa__) || defined(__hppa)
  2422. +# define MY_ARCH "PA RISC"
  2423. +#elif defined(__powerpc) || defined(__powerpc__) || defined(__POWERPC__) || defined(__ppc__) || defined(_M_PPC) || defined(__PPC) || defined(__PPC__)
  2424. +# define MY_ARCH "PowerPC"
  2425. +#elif defined(__THW_RS6000) || defined(_IBMR2) || defined(_POWER) || defined(_ARCH_PWR) || defined(_ARCH_PWR2)
  2426. +# define MY_ARCH "RS/6000"
  2427. +#elif defined(__sparc__) || defined(sparc) || defined(__sparc)
  2428. +# define MY_ARCH "SPARC"
  2429. +#else
  2430. +# define MY_ARCH "Unknown Architecture"
  2431. +#endif
  2432. +
  2433. +
  2434. +
  2435. +namespace nepenthes
  2436. +{
  2437. +
  2438. +
  2439. +TransferSession::TransferSession(Type type, SubmitMwservModule * parent)
  2440. +{
  2441. + m_type = type;
  2442. + m_parent = parent;
  2443. +
  2444. + m_sample.binary = 0;
  2445. + m_multiHandle = 0;
  2446. + m_postInfo = m_postInfoLast = 0;
  2447. + m_curlHandle = 0;
  2448. +
  2449. + m_Type |= ST_NODEL;
  2450. +}
  2451. +
  2452. +void TransferSession::transfer(TransferSample& sample, string url)
  2453. +{
  2454. + m_sample = sample;
  2455. +
  2456. + if(!(m_curlHandle = curl_easy_init()) || !(m_multiHandle =
  2457. + curl_multi_init()))
  2458. + {
  2459. + logCrit("%s failed!\n", __PRETTY_FUNCTION__);
  2460. + return;
  2461. + }
  2462. +
  2463. + m_targetUrl = url;
  2464. + m_sample = sample;
  2465. +
  2466. + initializeHandle();
  2467. +}
  2468. +
  2469. +TransferSession::~TransferSession()
  2470. +{
  2471. + Exit();
  2472. +}
  2473. +
  2474. +void TransferSession::initializeHandle()
  2475. +{
  2476. + m_postInfo = m_postInfoLast = 0;
  2477. +
  2478. + curl_formadd(&m_postInfo, &m_postInfoLast, CURLFORM_PTRNAME, "guid",
  2479. + CURLFORM_COPYCONTENTS, m_sample.guid.c_str(), CURLFORM_END);
  2480. + curl_formadd(&m_postInfo, &m_postInfoLast, CURLFORM_PTRNAME,
  2481. + "maintainer", CURLFORM_COPYCONTENTS, m_sample.maintainer.c_str(),
  2482. + CURLFORM_END);
  2483. + curl_formadd(&m_postInfo, &m_postInfoLast, CURLFORM_PTRNAME, "secret",
  2484. + CURLFORM_COPYCONTENTS, m_sample.secret.c_str(), CURLFORM_END);
  2485. +
  2486. + if(m_type != TST_HEARTBEAT)
  2487. + {
  2488. + curl_formadd(&m_postInfo, &m_postInfoLast, CURLFORM_PTRNAME, "url",
  2489. + CURLFORM_COPYCONTENTS, m_sample.url.c_str(), CURLFORM_END);
  2490. + curl_formadd(&m_postInfo, &m_postInfoLast, CURLFORM_PTRNAME, "sha512",
  2491. + CURLFORM_COPYCONTENTS, m_sample.sha512.c_str(), CURLFORM_END);
  2492. + curl_formadd(&m_postInfo, &m_postInfoLast, CURLFORM_PTRNAME, "saddr",
  2493. + CURLFORM_COPYCONTENTS, m_sample.saddr.c_str(), CURLFORM_END);
  2494. + curl_formadd(&m_postInfo, &m_postInfoLast, CURLFORM_PTRNAME, "daddr",
  2495. + CURLFORM_COPYCONTENTS, m_sample.daddr.c_str(), CURLFORM_END);
  2496. +
  2497. + if(m_type == TST_SAMPLE)
  2498. + {
  2499. + curl_formadd(&m_postInfo, &m_postInfoLast, CURLFORM_PTRNAME, "data",
  2500. + CURLFORM_PTRCONTENTS, m_sample.binary, CURLFORM_CONTENTSLENGTH,
  2501. + m_sample.binarySize, CURLFORM_END);
  2502. + }
  2503. + }
  2504. + else
  2505. + {
  2506. + curl_formadd(&m_postInfo, &m_postInfoLast, CURLFORM_PTRNAME, "software",
  2507. + CURLFORM_COPYCONTENTS, "nepenthes " VERSION " (" MY_OS ", " MY_ARCH
  2508. + ", " MY_COMPILER ")", CURLFORM_END);
  2509. + }
  2510. +
  2511. + curl_easy_setopt(m_curlHandle, CURLOPT_HTTPPOST, m_postInfo);
  2512. + curl_easy_setopt(m_curlHandle, CURLOPT_FORBID_REUSE, 1);
  2513. + curl_easy_setopt(m_curlHandle, CURLOPT_SSL_VERIFYHOST, false);
  2514. + curl_easy_setopt(m_curlHandle, CURLOPT_SSL_VERIFYPEER, false);
  2515. + curl_easy_setopt(m_curlHandle, CURLOPT_URL, m_targetUrl.c_str());
  2516. + curl_easy_setopt(m_curlHandle, CURLOPT_USERAGENT,
  2517. + "nepenthes " VERSION " (" MY_OS ", " MY_ARCH ", " MY_COMPILER ")");
  2518. + curl_easy_setopt(m_curlHandle, CURLOPT_WRITEDATA, this);
  2519. + curl_easy_setopt(m_curlHandle, CURLOPT_WRITEFUNCTION,
  2520. + TransferSession::readData);
  2521. +
  2522. + CURLMcode error;
  2523. +
  2524. + if((error = curl_multi_add_handle(m_multiHandle, m_curlHandle)))
  2525. + logCrit("Error adding easy to multi: %s\n", curl_multi_strerror(error));
  2526. +
  2527. + int handles = 0;
  2528. +
  2529. + while(curl_multi_perform(m_multiHandle, &handles) ==
  2530. + CURLM_CALL_MULTI_PERFORM && handles);
  2531. +}
  2532. +
  2533. +//size_t function( void *ptr, size_t size, size_t nmemb, void *stream);
  2534. +size_t TransferSession::readData(void *buffer, size_t s, size_t n, void *data)
  2535. +{
  2536. + ((TransferSession *) data)->m_buffer.append((const char *)buffer, s * n);
  2537. + return s * n;
  2538. +}
  2539. +
  2540. +TransferSession::Status TransferSession::getTransferStatus()
  2541. +{
  2542. + if(m_type != TST_HEARTBEAT)
  2543. + {
  2544. + if(m_buffer == "OK")
  2545. + return TSS_OK;
  2546. + else if(m_buffer == "UNKNOWN")
  2547. + return TSS_UNKNOWN;
  2548. + else
  2549. + return TSS_ERROR;
  2550. + }
  2551. + else
  2552. + {
  2553. + if(m_buffer.substr(0, 4) == "OK: ")
  2554. + return TSS_HEARTBEAT;
  2555. + else
  2556. + return TSS_ERROR;
  2557. + }
  2558. +}
  2559. +
  2560. +bool TransferSession::Init()
  2561. +{
  2562. + return true;
  2563. +}
  2564. +
  2565. +bool TransferSession::Exit()
  2566. +{
  2567. + if(m_multiHandle)
  2568. + curl_multi_remove_handle(m_multiHandle, m_curlHandle);
  2569. +
  2570. + if(m_postInfo)
  2571. + curl_formfree(m_postInfo);
  2572. +
  2573. + if(m_curlHandle)
  2574. + curl_easy_cleanup(m_curlHandle);
  2575. +
  2576. + if(m_multiHandle)
  2577. + {
  2578. + curl_multi_cleanup(m_multiHandle);
  2579. + m_multiHandle = 0;
  2580. + }
  2581. +
  2582. + if(m_sample.binary)
  2583. + {
  2584. + delete [] m_sample.binary;
  2585. + m_sample.binary = 0;
  2586. + }
  2587. +
  2588. + return true;
  2589. +}
  2590. +
  2591. +bool TransferSession::wantSend()
  2592. +{
  2593. + fd_set readSet, writeSet, errorSet;
  2594. + int maxFd = 0;
  2595. + CURLMcode error;
  2596. + FD_ZERO(&readSet); FD_ZERO(&writeSet); FD_ZERO(&errorSet);
  2597. +
  2598. + if((error = curl_multi_fdset(m_multiHandle, &readSet, &writeSet, &errorSet,
  2599. + &maxFd)))
  2600. + {
  2601. + logCrit("Obtaining write socket failed: %s\n",
  2602. + curl_multi_strerror(error));
  2603. + return false;
  2604. + }
  2605. +
  2606. + return FD_ISSET(maxFd, &writeSet);
  2607. +}
  2608. +
  2609. +int32_t TransferSession::doSend()
  2610. +{
  2611. + return doRecv();
  2612. +}
  2613. +
  2614. +int32_t TransferSession::doRecv()
  2615. +{
  2616. + int handles = 0, queued = 0;
  2617. +
  2618. + while(curl_multi_perform(m_multiHandle, &handles) ==
  2619. + CURLM_CALL_MULTI_PERFORM && handles);
  2620. +
  2621. + CURLMsg * message;
  2622. +
  2623. + while((message = curl_multi_info_read(m_multiHandle, &queued)))
  2624. + {
  2625. + if(message->msg == CURLMSG_DONE)
  2626. + {
  2627. + if(message->data.result)
  2628. + {
  2629. + logCrit("Connection to %s failed: %s [\"%s\"]\n",
  2630. + m_targetUrl.c_str(), curl_easy_strerror(message->
  2631. + data.result), m_buffer.c_str());
  2632. +
  2633. + if(m_type == TST_HEARTBEAT)
  2634. + m_parent->scheduleHeartbeat(DEFAULT_HEARTBEAT_DELTA);
  2635. + else
  2636. + {
  2637. + m_parent->retrySample(m_sample);
  2638. + m_sample.binary = 0;
  2639. + }
  2640. + }
  2641. + else
  2642. + {
  2643. + switch(getTransferStatus())
  2644. + {
  2645. + case TransferSession::TSS_OK:
  2646. + logInfo("Transmitted %s to %s.\n", m_sample.url.c_str(),
  2647. + m_targetUrl.c_str());
  2648. +
  2649. + break;
  2650. +
  2651. + case TransferSession::TSS_UNKNOWN:
  2652. + logInfo("submit-mwserv: uploading data for %s\n",
  2653. + m_sample.url.c_str());
  2654. +
  2655. + m_parent->submitSample(m_sample);
  2656. + m_sample.binary = 0;
  2657. +
  2658. + break;
  2659. +
  2660. + case TransferSession::TSS_HEARTBEAT:
  2661. + {
  2662. + unsigned long delta = strtoul(m_buffer.substr(4).
  2663. + c_str(), 0, 0);
  2664. + logDebug("Next heartbeat in %u seconds.\n", delta);
  2665. +
  2666. + m_parent->scheduleHeartbeat(delta);
  2667. +
  2668. + break;
  2669. + }
  2670. +
  2671. + case TransferSession::TSS_ERROR:
  2672. + if(m_type == TST_HEARTBEAT)
  2673. + m_parent->scheduleHeartbeat(DEFAULT_HEARTBEAT_DELTA);
  2674. +
  2675. + logCrit("%s reported \"%s\"\n", m_targetUrl.c_str(),
  2676. + m_buffer.c_str());
  2677. +
  2678. + break;
  2679. + }
  2680. + }
  2681. +
  2682. + m_Type |= ~ST_NODEL;
  2683. + m_Status = SS_CLOSED;
  2684. + }
  2685. + }
  2686. +
  2687. + return 0;
  2688. +}
  2689. +
  2690. +int32_t TransferSession::getSocket()
  2691. +{
  2692. + if(!m_multiHandle)
  2693. + return -1;
  2694. +
  2695. + fd_set readSet, writeSet, errorSet;
  2696. + int maxFd = 0;
  2697. + CURLMcode error;
  2698. + FD_ZERO(&readSet); FD_ZERO(&writeSet); FD_ZERO(&errorSet);
  2699. +
  2700. + if((error = curl_multi_fdset(m_multiHandle, &readSet, &writeSet, &errorSet,
  2701. + &maxFd)))
  2702. + {
  2703. + logCrit("Obtaining read socket failed: %s\n",
  2704. + curl_multi_strerror(error));
  2705. + return -1;
  2706. + }
  2707. +
  2708. + if(maxFd == -1)
  2709. + return -1;
  2710. +
  2711. + if(!FD_ISSET(maxFd, &readSet) && !FD_ISSET(maxFd, &writeSet) &&
  2712. + !FD_ISSET(maxFd, &errorSet))
  2713. + {
  2714. + logCrit("maxFd not in set: %i!\n", maxFd);
  2715. + return -1;
  2716. + }
  2717. +
  2718. + return maxFd;
  2719. +}
  2720. +
  2721. +int32_t TransferSession::getsockOpt(int32_t level, int32_t optname,
  2722. + void *optval, socklen_t *optlen)
  2723. +{
  2724. + return getsockopt(getSocket(), level, optname, optval, optlen);
  2725. +}
  2726. +
  2727. +
  2728. +}
  2729. +
  2730. +
  2731. +bool TransferSession::checkTimeout()
  2732. +{
  2733. + // if the connection is bad, give curl a chance to take care, so we can get rid of the connection
  2734. + if (getSocket() == -1)
  2735. + doRecv();
  2736. +
  2737. + return false;
  2738. +}
  2739. diff -ruN nepenthes-0.2.0/modules/submit-mwserv/TransferSession.hpp nepenthes-0.2.0-r1345/modules/submit-mwserv/TransferSession.hpp
  2740. --- nepenthes-0.2.0/modules/submit-mwserv/TransferSession.hpp 1970-01-01 01:00:00.000000000 +0100
  2741. +++ nepenthes-0.2.0-r1345/modules/submit-mwserv/TransferSession.hpp 2007-08-06 00:46:15.000000000 +0200
  2742. @@ -0,0 +1,129 @@
  2743. +/********************************************************************************
  2744. + * Nepenthes
  2745. + * - finest collection -
  2746. + *
  2747. + *
  2748. + *
  2749. + * Copyright (C) 2007 Georg Wicherski <gw@mwcollect.org>
  2750. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  2751. + *
  2752. + * This program is free software; you can redistribute it and/or
  2753. + * modify it under the terms of the GNU General Public License
  2754. + * as published by the Free Software Foundation; either version 2
  2755. + * of the License, or (at your option) any later version.
  2756. + *
  2757. + * This program is distributed in the hope that it will be useful,
  2758. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2759. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2760. + * GNU General Public License for more details.
  2761. + *
  2762. + * You should have received a copy of the GNU General Public License
  2763. + * along with this program; if not, write to the Free Software
  2764. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  2765. + *
  2766. + *
  2767. + * contact nepenthesdev@users.sourceforge.net
  2768. + *
  2769. + *******************************************************************************/
  2770. +
  2771. +#include <curl/curl.h>
  2772. +#include <curl/types.h>
  2773. +#include <curl/easy.h>
  2774. +
  2775. +#include <string>
  2776. +using namespace std;
  2777. +
  2778. +#include "Nepenthes.hpp"
  2779. +#include "Module.hpp"
  2780. +#include "SubmitHandler.hpp"
  2781. +#include "Download.hpp"
  2782. +
  2783. +#include "POLLSocket.hpp"
  2784. +
  2785. +
  2786. +namespace nepenthes
  2787. +{
  2788. +
  2789. +
  2790. +struct TransferSample
  2791. +{
  2792. + string guid;
  2793. + string maintainer;
  2794. + string secret;
  2795. +
  2796. + string url;
  2797. + string saddr, daddr;
  2798. + string sha512;
  2799. +
  2800. + char * binary;
  2801. + unsigned int binarySize;
  2802. +};
  2803. +
  2804. +
  2805. +class SubmitMwservModule;
  2806. +
  2807. +class TransferSession : public POLLSocket
  2808. +{
  2809. +public:
  2810. + enum Type
  2811. + {
  2812. + TST_INSTANCE,
  2813. + TST_SAMPLE,
  2814. + TST_HEARTBEAT,
  2815. + };
  2816. +
  2817. + TransferSession(Type type, SubmitMwservModule * parent);
  2818. + virtual ~TransferSession();
  2819. +
  2820. + enum Status
  2821. + {
  2822. + TSS_OK,
  2823. + TSS_UNKNOWN,
  2824. + TSS_HEARTBEAT,
  2825. + TSS_ERROR,
  2826. + };
  2827. +
  2828. + TransferSession::Status getTransferStatus();
  2829. +
  2830. + void transfer(TransferSample& sample, string url);
  2831. +
  2832. + // POLLSocket
  2833. + bool Init();
  2834. + bool Exit();
  2835. +
  2836. + bool wantSend();
  2837. +
  2838. + int32_t doSend();
  2839. + int32_t doRecv();
  2840. + int32_t getSocket();
  2841. + int32_t getsockOpt(int32_t level, int32_t optname,
  2842. + void *optval, socklen_t *optlen);
  2843. + bool checkTimeout();
  2844. +
  2845. +protected:
  2846. + string m_targetUrl;
  2847. + TransferSample m_sample;
  2848. +
  2849. + CURL * m_curlHandle;
  2850. + CURLM * m_multiHandle;
  2851. + curl_httppost * m_postInfo, * m_postInfoLast;
  2852. +
  2853. + char * m_dataCopy;
  2854. + unsigned int m_dataSize;
  2855. +
  2856. + void initializeHandle();
  2857. + void recreateWithSampleData();
  2858. +
  2859. + string m_buffer;
  2860. +
  2861. + Type m_type;
  2862. + SubmitMwservModule * m_parent;
  2863. +
  2864. + unsigned long m_heartbeatDelta;
  2865. +
  2866. +private:
  2867. + static size_t readData(void *buffer, size_t size, size_t n, void *data);
  2868. +};
  2869. +
  2870. +
  2871. +}
  2872. diff -ruN nepenthes-0.2.0/modules/submit-mwserv/submit-mwserv.conf.dist nepenthes-0.2.0-r1345/modules/submit-mwserv/submit-mwserv.conf.dist
  2873. --- nepenthes-0.2.0/modules/submit-mwserv/submit-mwserv.conf.dist 1970-01-01 01:00:00.000000000 +0100
  2874. +++ nepenthes-0.2.0-r1345/modules/submit-mwserv/submit-mwserv.conf.dist 2007-08-06 00:46:15.000000000 +0200
  2875. @@ -0,0 +1,18 @@
  2876. +// lightweight libcurl based module for file submission via HTTP to the mwserv
  2877. +// python script suite (typically running on an apache2 with mod_python)
  2878. +// This is primarily used by the mwcollect Alliance - alliance.mwcollect.org
  2879. +
  2880. +submit-mwserv
  2881. +{
  2882. + // the url to send the submission requests to
  2883. + url = "";
  2884. +
  2885. + // username of the maintainer of this sensor
  2886. + maintainer = "";
  2887. +
  2888. + // guid of this sensor, as generated serverside; typically 8 chars
  2889. + guid = "";
  2890. +
  2891. + // shared secret used for authentication aka `password'; typically 48 chars
  2892. + secret = "";
  2893. +};
  2894. diff -ruN nepenthes-0.2.0/modules/submit-mwserv/submit-mwserv.cpp nepenthes-0.2.0-r1345/modules/submit-mwserv/submit-mwserv.cpp
  2895. --- nepenthes-0.2.0/modules/submit-mwserv/submit-mwserv.cpp 1970-01-01 01:00:00.000000000 +0100
  2896. +++ nepenthes-0.2.0-r1345/modules/submit-mwserv/submit-mwserv.cpp 2007-08-06 00:46:15.000000000 +0200
  2897. @@ -0,0 +1,224 @@
  2898. +/********************************************************************************
  2899. + * Nepenthes
  2900. + * - finest collection -
  2901. + *
  2902. + *
  2903. + *
  2904. + * Copyright (C) 2007 Georg Wicherski <gw@mwcollect.org>
  2905. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  2906. + *
  2907. + * This program is free software; you can redistribute it and/or
  2908. + * modify it under the terms of the GNU General Public License
  2909. + * as published by the Free Software Foundation; either version 2
  2910. + * of the License, or (at your option) any later version.
  2911. + *
  2912. + * This program is distributed in the hope that it will be useful,
  2913. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2914. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2915. + * GNU General Public License for more details.
  2916. + *
  2917. + * You should have received a copy of the GNU General Public License
  2918. + * along with this program; if not, write to the Free Software
  2919. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  2920. + *
  2921. + *
  2922. + * contact nepenthesdev@users.sourceforge.net
  2923. + *
  2924. + *******************************************************************************/
  2925. +
  2926. +#include "Download.hpp"
  2927. +#include "Utilities.hpp"
  2928. +#include "SubmitManager.hpp"
  2929. +#include "LogManager.hpp"
  2930. +#include "Event.hpp"
  2931. +#include "EventManager.hpp"
  2932. +#include "EventHandler.cpp"
  2933. +#include "Config.hpp"
  2934. +#include "ModuleManager.hpp"
  2935. +#include "SocketManager.hpp"
  2936. +
  2937. +#include "DownloadBuffer.hpp"
  2938. +#include "DownloadUrl.hpp"
  2939. +
  2940. +#include "submit-mwserv.hpp"
  2941. +
  2942. +#include <unistd.h>
  2943. +#include <sys/socket.h>
  2944. +#include <netinet/in.h>
  2945. +#include <arpa/inet.h>
  2946. +
  2947. +
  2948. +#define SUBMIT_URI "nepenthes/submit"
  2949. +#define HEARTBEAT_URI "heartbeat"
  2950. +
  2951. +
  2952. +namespace nepenthes
  2953. +{
  2954. +
  2955. +
  2956. +SubmitMwservModule::SubmitMwservModule(Nepenthes * nepenthes)
  2957. +{
  2958. + m_ModuleName = "submit-mwserv";
  2959. + m_ModuleDescription = "mwserv.py HTTP Post Submission";
  2960. + m_ModuleRevision = "$Rev: 921 $";
  2961. + m_Nepenthes = nepenthes;
  2962. + m_SubmitterName = "submit-mwserv";
  2963. + m_SubmitterDescription = "mwserv.py HTTP Post Submission";
  2964. +
  2965. + m_Timeout = 0;
  2966. + m_TimeoutIntervall = 0;
  2967. +}
  2968. +
  2969. +bool SubmitMwservModule::Init()
  2970. +{
  2971. + if(!m_Config)
  2972. + {
  2973. + logCrit("No configuration for submit-mwserv provided.\n");
  2974. + return false;
  2975. + }
  2976. +
  2977. + try
  2978. + {
  2979. + m_url = m_Config->getValString("submit-mwserv.url");
  2980. + m_guid = m_Config->getValString("submit-mwserv.guid");
  2981. + m_maintainer = m_Config->getValString("submit-mwserv.maintainer");
  2982. + m_secret = m_Config->getValString("submit-mwserv.secret");
  2983. + }
  2984. + catch(...)
  2985. + {
  2986. + logCrit("Missing configuration option for submit-mwserv.\n");
  2987. + return false;
  2988. + }
  2989. +
  2990. + if(m_guid.find(":") != string::npos || m_maintainer.find(":")
  2991. + != string::npos || m_secret.find(":") != string::npos ||
  2992. + m_guid.find("+") != string::npos || m_maintainer.find("+")
  2993. + != string::npos || m_secret.find("+") != string::npos)
  2994. + {
  2995. + logCrit("submit-mwserv: guid, maintainer or secret from configuration"
  2996. + "contained ':' or '+'; this is not allowed.\n");
  2997. + return false;
  2998. + }
  2999. +
  3000. + if(* m_url.rbegin() != '/')
  3001. + m_url += "/";
  3002. +
  3003. + REG_SUBMIT_HANDLER(this);
  3004. + REG_EVENT_HANDLER(this);
  3005. +
  3006. + handleEvent(0);
  3007. +
  3008. + return true;
  3009. +}
  3010. +
  3011. +bool SubmitMwservModule::Exit()
  3012. +{
  3013. + return true;
  3014. +}
  3015. +
  3016. +void SubmitMwservModule::Submit(Download * download)
  3017. +{
  3018. + Hit(download);
  3019. +}
  3020. +
  3021. +void SubmitMwservModule::Hit(Download * download)
  3022. +{
  3023. + TransferSample sample;
  3024. + TransferSession * session = new TransferSession(TransferSession::
  3025. + TST_INSTANCE, this);
  3026. +
  3027. + {
  3028. + struct in_addr saddr, daddr;
  3029. +
  3030. + saddr.s_addr = download->getRemoteHost();
  3031. + daddr.s_addr = download->getLocalHost();
  3032. +
  3033. + sample.saddr = inet_ntoa(saddr);
  3034. + sample.daddr = inet_ntoa(daddr);
  3035. +
  3036. + sample.guid = m_guid;
  3037. + sample.maintainer = m_maintainer;
  3038. + sample.secret = m_secret;
  3039. +
  3040. + sample.url = download->getUrl();
  3041. + sample.sha512 = download->getSHA512Sum();
  3042. +
  3043. + sample.binarySize = download->getDownloadBuffer()->getSize();
  3044. + sample.binary = new char[sample.binarySize];
  3045. + memcpy(sample.binary, download->getDownloadBuffer()->getData(),
  3046. + sample.binarySize);
  3047. + }
  3048. +
  3049. + session->transfer(sample, m_url + SUBMIT_URI);
  3050. + g_Nepenthes->getSocketMgr()->addPOLLSocket(session);
  3051. +}
  3052. +
  3053. +void SubmitMwservModule::retrySample(TransferSample& sample)
  3054. +{
  3055. + TransferSession * session = new TransferSession(TransferSession::
  3056. + TST_INSTANCE, this);
  3057. +
  3058. + session->transfer(sample, m_url + SUBMIT_URI);
  3059. + g_Nepenthes->getSocketMgr()->addPOLLSocket(session);
  3060. +}
  3061. +
  3062. +void SubmitMwservModule::submitSample(TransferSample& sample)
  3063. +{
  3064. + TransferSession * session = new TransferSession(TransferSession::
  3065. + TST_SAMPLE, this);
  3066. +
  3067. + session->transfer(sample, m_url + SUBMIT_URI);
  3068. + g_Nepenthes->getSocketMgr()->addPOLLSocket(session);
  3069. +}
  3070. +
  3071. +uint32_t SubmitMwservModule::handleEvent(Event * ev)
  3072. +{
  3073. + m_Events.reset(EV_TIMEOUT);
  3074. +
  3075. + TransferSample sample;
  3076. + TransferSession * session = new TransferSession(TransferSession::
  3077. + TST_HEARTBEAT, this);
  3078. +
  3079. + sample.guid = m_guid;
  3080. + sample.maintainer = m_maintainer;
  3081. + sample.secret = m_secret;
  3082. + sample.binary = 0;
  3083. +
  3084. + session->transfer(sample, m_url + HEARTBEAT_URI);
  3085. + g_Nepenthes->getSocketMgr()->addPOLLSocket(session);
  3086. +
  3087. + return 0;
  3088. +}
  3089. +
  3090. +void SubmitMwservModule::scheduleHeartbeat(unsigned long delta)
  3091. +{
  3092. + if(delta > MAX_HEARTBEAT_DELTA)
  3093. + {
  3094. + logInfo("Capping server heartbeat delta of %u sec to %u sec.\n", delta,
  3095. + MAX_HEARTBEAT_DELTA);
  3096. +
  3097. + delta = MAX_HEARTBEAT_DELTA;
  3098. + }
  3099. +
  3100. + m_Events.set(EV_TIMEOUT);
  3101. + m_Timeout = time(0) + delta;
  3102. +}
  3103. +
  3104. +
  3105. +extern "C" int32_t module_init(int32_t version, Module **module, Nepenthes *nepenthes)
  3106. +{
  3107. + g_Nepenthes = nepenthes;
  3108. +
  3109. + if(version == MODULE_IFACE_VERSION)
  3110. + {
  3111. + * module = new SubmitMwservModule(nepenthes);
  3112. + return 1;
  3113. + }
  3114. +
  3115. + return 0;
  3116. +}
  3117. +
  3118. +
  3119. +}
  3120. +
  3121. +Nepenthes * g_Nepenthes;
  3122. diff -ruN nepenthes-0.2.0/modules/submit-mwserv/submit-mwserv.hpp nepenthes-0.2.0-r1345/modules/submit-mwserv/submit-mwserv.hpp
  3123. --- nepenthes-0.2.0/modules/submit-mwserv/submit-mwserv.hpp 1970-01-01 01:00:00.000000000 +0100
  3124. +++ nepenthes-0.2.0-r1345/modules/submit-mwserv/submit-mwserv.hpp 2007-08-06 00:46:15.000000000 +0200
  3125. @@ -0,0 +1,78 @@
  3126. +/********************************************************************************
  3127. + * Nepenthes
  3128. + * - finest collection -
  3129. + *
  3130. + *
  3131. + *
  3132. + * Copyright (C) 2007 Georg Wicherski <gw@mwcollect.org>
  3133. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  3134. + *
  3135. + * This program is free software; you can redistribute it and/or
  3136. + * modify it under the terms of the GNU General Public License
  3137. + * as published by the Free Software Foundation; either version 2
  3138. + * of the License, or (at your option) any later version.
  3139. + *
  3140. + * This program is distributed in the hope that it will be useful,
  3141. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3142. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3143. + * GNU General Public License for more details.
  3144. + *
  3145. + * You should have received a copy of the GNU General Public License
  3146. + * along with this program; if not, write to the Free Software
  3147. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  3148. + *
  3149. + *
  3150. + * contact nepenthesdev@users.sourceforge.net
  3151. + *
  3152. + *******************************************************************************/
  3153. +
  3154. +#include <curl/curl.h>
  3155. +#include <curl/types.h>
  3156. +#include <curl/easy.h>
  3157. +
  3158. +#include "Nepenthes.hpp"
  3159. +#include "Module.hpp"
  3160. +#include "SubmitHandler.hpp"
  3161. +#include "EventHandler.hpp"
  3162. +#include "Download.hpp"
  3163. +
  3164. +#include "TransferSession.hpp"
  3165. +
  3166. +
  3167. +#define DEFAULT_HEARTBEAT_DELTA 30
  3168. +#define MAX_HEARTBEAT_DELTA 300
  3169. +
  3170. +
  3171. +using namespace std;
  3172. +
  3173. +namespace nepenthes
  3174. +{
  3175. +
  3176. +
  3177. +class SubmitMwservModule : public Module , public SubmitHandler,
  3178. + public EventHandler
  3179. +{
  3180. +public:
  3181. + SubmitMwservModule(Nepenthes * nepenthes);
  3182. +
  3183. + bool Init();
  3184. + bool Exit();
  3185. +
  3186. + void Submit(Download * download);
  3187. + void Hit(Download * download);
  3188. +
  3189. + uint32_t handleEvent(Event *event);
  3190. +
  3191. + void submitSample(TransferSample& sample);
  3192. + void retrySample(TransferSample& sample);
  3193. + void scheduleHeartbeat(unsigned long delta);
  3194. +
  3195. +protected:
  3196. + string m_url, m_guid, m_maintainer, m_secret;
  3197. + uint32_t m_inTransfer;
  3198. +};
  3199. +
  3200. +
  3201. +}
  3202. +
  3203. +extern nepenthes::Nepenthes *g_Nepenthes;
  3204. diff -ruN nepenthes-0.2.0/modules/submit-norman/Makefile.am nepenthes-0.2.0-r1345/modules/submit-norman/Makefile.am
  3205. --- nepenthes-0.2.0/modules/submit-norman/Makefile.am 2006-11-13 20:40:09.000000000 +0100
  3206. +++ nepenthes-0.2.0-r1345/modules/submit-norman/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  3207. @@ -12,4 +12,4 @@
  3208. submitnorman_la_SOURCES = submit-norman.conf.dist submit-norman.hpp submit-norman.cpp
  3209. -submitnorman_la_LDFLAGS = -module -no-undefined -avoid-version
  3210. +submitnorman_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  3211. diff -ruN nepenthes-0.2.0/modules/submit-norman/submit-norman.conf.dist nepenthes-0.2.0-r1345/modules/submit-norman/submit-norman.conf.dist
  3212. --- nepenthes-0.2.0/modules/submit-norman/submit-norman.conf.dist 2006-11-13 20:40:09.000000000 +0100
  3213. +++ nepenthes-0.2.0-r1345/modules/submit-norman/submit-norman.conf.dist 2007-08-06 00:46:15.000000000 +0200
  3214. @@ -1,8 +1,8 @@
  3215. submit-norman
  3216. {
  3217. // this is the adress where norman sandbox reports will be sent
  3218. - email "malware@mac.com";
  3219. - urls ("http://sandbox.norman.no/live_4.html",
  3220. + email "nsbx@mwcollect.org";
  3221. + urls ("http://www.norman.com/microsites/nsic/Submit/Special/45773/",
  3222. "http://luigi.informatik.uni-mannheim.de/submit.php?action=verify");
  3223. };
  3224. diff -ruN nepenthes-0.2.0/modules/submit-postgres/Makefile.am nepenthes-0.2.0-r1345/modules/submit-postgres/Makefile.am
  3225. --- nepenthes-0.2.0/modules/submit-postgres/Makefile.am 2006-11-13 20:40:05.000000000 +0100
  3226. +++ nepenthes-0.2.0-r1345/modules/submit-postgres/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  3227. @@ -13,5 +13,6 @@
  3228. submitpostgres_la_SOURCES = submit-postgres.cpp submit-postgres.hpp
  3229. submitpostgres_la_SOURCES += PGDownloadContext.cpp PGDownloadContext.hpp
  3230. submitpostgres_la_SOURCES += bencoding.c bencoding.h
  3231. +submitpostgres_la_SOURCES += submit-postgres.conf.dist
  3232. submitpostgres_la_LDFLAGS = -module -no-undefined -avoid-version
  3233. diff -ruN nepenthes-0.2.0/modules/vuln-asn1/IISDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-asn1/IISDialogue.cpp
  3234. --- nepenthes-0.2.0/modules/vuln-asn1/IISDialogue.cpp 2006-11-13 20:40:08.000000000 +0100
  3235. +++ nepenthes-0.2.0-r1345/modules/vuln-asn1/IISDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3236. @@ -43,6 +43,9 @@
  3237. #include "Socket.hpp"
  3238. +#include "EventManager.hpp"
  3239. +#include "SocketEvent.hpp"
  3240. +
  3241. #ifdef STDTAGS
  3242. #undef STDTAGS
  3243. #endif
  3244. @@ -79,7 +82,7 @@
  3245. case IIS_POST:
  3246. case IIS_GET:
  3247. logWarn("Unknown IIS %i bytes State %i\n",m_Buffer->getSize(), m_State);
  3248. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3249. + HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3250. break;
  3251. case IIS_SEARCH:
  3252. @@ -102,7 +105,7 @@
  3253. ConsumeLevel IISDialogue::incomingData(Message *msg)
  3254. {
  3255. m_Buffer->add(msg->getMsg(),msg->getSize());
  3256. -// g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3257. +// HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3258. // FIXME this can only recognize urldownloadtofile foobar
  3259. diff -ruN nepenthes-0.2.0/modules/vuln-asn1/SMBDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-asn1/SMBDialogue.cpp
  3260. --- nepenthes-0.2.0/modules/vuln-asn1/SMBDialogue.cpp 2006-11-13 20:40:08.000000000 +0100
  3261. +++ nepenthes-0.2.0-r1345/modules/vuln-asn1/SMBDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3262. @@ -43,8 +43,13 @@
  3263. #include "Utilities.hpp"
  3264. #include "ShellcodeManager.hpp"
  3265. +#include "EventManager.hpp"
  3266. +#include "SocketEvent.hpp"
  3267. +
  3268. #include "vuln-asn1.hpp"
  3269. +
  3270. +
  3271. #ifdef STDTAGS
  3272. #undef STDTAGS
  3273. #endif
  3274. @@ -227,5 +232,5 @@
  3275. void SMBDialogue::dump()
  3276. {
  3277. logWarn("Unknown %s Shellcode (Buffer %i bytes) (State %i)\n","ASN1_SMB",m_Buffer->getSize(),m_State);
  3278. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3279. + HEXDUMP(m_Socket,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3280. }
  3281. diff -ruN nepenthes-0.2.0/modules/vuln-bagle/BagleDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-bagle/BagleDialogue.cpp
  3282. --- nepenthes-0.2.0/modules/vuln-bagle/BagleDialogue.cpp 2006-11-13 20:40:09.000000000 +0100
  3283. +++ nepenthes-0.2.0-r1345/modules/vuln-bagle/BagleDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3284. @@ -124,7 +124,7 @@
  3285. }
  3286. logCrit("Unknown Bagle Auth (%i)\n",m_Buffer->getSize());
  3287. - g_Nepenthes->getUtilities()->hexdump(l_crit | STDTAGS ,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3288. +// g_Nepenthes->getUtilities()->hexdump(l_crit | STDTAGS ,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3289. if (m_Buffer->getSize() > 128 )
  3290. return CL_DROP;
  3291. diff -ruN nepenthes-0.2.0/modules/vuln-bagle/Makefile.am nepenthes-0.2.0-r1345/modules/vuln-bagle/Makefile.am
  3292. --- nepenthes-0.2.0/modules/vuln-bagle/Makefile.am 2006-11-13 20:40:09.000000000 +0100
  3293. +++ nepenthes-0.2.0-r1345/modules/vuln-bagle/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  3294. @@ -6,7 +6,6 @@
  3295. AM_CPPFLAGS = -I$(top_srcdir)/nepenthes-core/include -I$(top_srcdir)/nepenthes-core/src -pipe -D _GNU_SOURCE
  3296. AM_CXXFLAGS = -Wall -Werror
  3297. -AM_LDFLAGS = -lpcre
  3298. pkglib_LTLIBRARIES = vulnbagle.la
  3299. diff -ruN nepenthes-0.2.0/modules/vuln-dameware/DWDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-dameware/DWDialogue.cpp
  3300. --- nepenthes-0.2.0/modules/vuln-dameware/DWDialogue.cpp 2006-11-13 20:40:05.000000000 +0100
  3301. +++ nepenthes-0.2.0-r1345/modules/vuln-dameware/DWDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3302. @@ -48,6 +48,9 @@
  3303. #include "Utilities.hpp"
  3304. +#include "EventManager.hpp"
  3305. +#include "SocketEvent.hpp"
  3306. +
  3307. #ifdef STDTAGS
  3308. #undef STDTAGS
  3309. #endif
  3310. @@ -209,5 +212,5 @@
  3311. void DWDialogue::dump()
  3312. {
  3313. logWarn("Unknown %s Shellcode (Buffer %i bytes) (State %i)\n","DameWare",m_Buffer->getSize(),m_State);
  3314. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3315. + HEXDUMP(m_Socket,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3316. }
  3317. diff -ruN nepenthes-0.2.0/modules/vuln-dcom/DCOMDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-dcom/DCOMDialogue.cpp
  3318. --- nepenthes-0.2.0/modules/vuln-dcom/DCOMDialogue.cpp 2006-11-13 20:40:05.000000000 +0100
  3319. +++ nepenthes-0.2.0-r1345/modules/vuln-dcom/DCOMDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3320. @@ -39,6 +39,10 @@
  3321. #include "Utilities.hpp"
  3322. +#include "EventManager.hpp"
  3323. +#include "SocketEvent.hpp"
  3324. +
  3325. +
  3326. #ifdef STDTAGS
  3327. #undef STDTAGS
  3328. #endif
  3329. @@ -234,5 +238,5 @@
  3330. void DCOMDialogue::dump()
  3331. {
  3332. logWarn("Unknown %s Shellcode (Buffer %i bytes) (State %i)\n","DCOM",m_Buffer->getSize(),m_State);
  3333. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3334. + HEXDUMP(m_Socket,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3335. }
  3336. diff -ruN nepenthes-0.2.0/modules/vuln-ftpd/vuln-ftpd.cpp nepenthes-0.2.0-r1345/modules/vuln-ftpd/vuln-ftpd.cpp
  3337. --- nepenthes-0.2.0/modules/vuln-ftpd/vuln-ftpd.cpp 2006-11-13 20:40:03.000000000 +0100
  3338. +++ nepenthes-0.2.0-r1345/modules/vuln-ftpd/vuln-ftpd.cpp 2007-08-06 00:46:15.000000000 +0200
  3339. @@ -55,6 +55,9 @@
  3340. #include "Utilities.hpp"
  3341. +#include "EventManager.hpp"
  3342. +#include "SocketEvent.hpp"
  3343. +
  3344. #ifdef STDTAGS
  3345. #undef STDTAGS
  3346. #endif
  3347. @@ -220,7 +223,7 @@
  3348. uint32_t i = 0;
  3349. bool buffercut=false;
  3350. - g_Nepenthes->getUtilities()->hexdump((byte *) m_Buffer->getData(),m_Buffer->getSize());
  3351. +// g_Nepenthes->getUtilities()->hexdump((byte *) m_Buffer->getData(),m_Buffer->getSize());
  3352. while ( i < m_Buffer->getSize() )
  3353. {
  3354. buffercut = false;
  3355. @@ -418,7 +421,7 @@
  3356. void FTPdDialogue::dump()
  3357. {
  3358. logWarn("Unknown exploit %i bytes \n",m_Shellcode->getSize());
  3359. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Shellcode->getData(), m_Shellcode->getSize());
  3360. + HEXDUMP(m_Socket,(byte *) m_Shellcode->getData(), m_Shellcode->getSize());
  3361. }
  3362. ftp_exploit FTPdDialogue::identExploit(string line)
  3363. diff -ruN nepenthes-0.2.0/modules/vuln-iis/IISDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-iis/IISDialogue.cpp
  3364. --- nepenthes-0.2.0/modules/vuln-iis/IISDialogue.cpp 2006-11-13 20:40:10.000000000 +0100
  3365. +++ nepenthes-0.2.0-r1345/modules/vuln-iis/IISDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3366. @@ -49,6 +49,9 @@
  3367. #include "Message.hpp"
  3368. #include "Message.cpp"
  3369. +#include "EventManager.hpp"
  3370. +#include "SocketEvent.hpp"
  3371. +
  3372. #ifdef STDTAGS
  3373. #undef STDTAGS
  3374. #endif
  3375. @@ -85,7 +88,7 @@
  3376. case IIS_NULL:
  3377. case IIS_SSL:
  3378. logWarn("Unknown IIS SSL exploit %i bytes State %i\n",m_Buffer->getSize(), m_State);
  3379. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3380. + HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3381. break;
  3382. case IIS_DONE:
  3383. diff -ruN nepenthes-0.2.0/modules/vuln-lsass/LSASSDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-lsass/LSASSDialogue.cpp
  3384. --- nepenthes-0.2.0/modules/vuln-lsass/LSASSDialogue.cpp 2006-11-13 20:40:11.000000000 +0100
  3385. +++ nepenthes-0.2.0-r1345/modules/vuln-lsass/LSASSDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3386. @@ -46,6 +46,8 @@
  3387. #include "Buffer.hpp"
  3388. #include "Buffer.cpp"
  3389. +#include "EventManager.hpp"
  3390. +#include "SocketEvent.hpp"
  3391. #ifdef STDTAGS
  3392. #undef STDTAGS
  3393. @@ -281,6 +283,6 @@
  3394. void LSASSDialogue::dump()
  3395. {
  3396. logWarn("Unknown %s Shellcode (Buffer %i bytes) (State %i)\n","LSASS",m_Buffer->getSize(),m_State);
  3397. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3398. + HEXDUMP(m_Socket,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3399. }
  3400. diff -ruN nepenthes-0.2.0/modules/vuln-msdtc/MSDTCDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-msdtc/MSDTCDialogue.cpp
  3401. --- nepenthes-0.2.0/modules/vuln-msdtc/MSDTCDialogue.cpp 2006-11-13 20:40:05.000000000 +0100
  3402. +++ nepenthes-0.2.0-r1345/modules/vuln-msdtc/MSDTCDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3403. @@ -38,6 +38,8 @@
  3404. #include "ShellcodeManager.hpp"
  3405. #include "Utilities.hpp"
  3406. +#include "EventManager.hpp"
  3407. +#include "SocketEvent.hpp"
  3408. #ifdef STDTAGS
  3409. #undef STDTAGS
  3410. @@ -181,5 +183,5 @@
  3411. void MSDTCDialogue::dump()
  3412. {
  3413. logWarn("Unknown %s Shellcode (Buffer %i bytes) (State %i)\n","MSDTC",m_Buffer->getSize(),m_State);
  3414. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3415. + HEXDUMP(m_Socket,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3416. }
  3417. diff -ruN nepenthes-0.2.0/modules/vuln-msmq/MSMQDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-msmq/MSMQDialogue.cpp
  3418. --- nepenthes-0.2.0/modules/vuln-msmq/MSMQDialogue.cpp 2006-11-13 20:40:05.000000000 +0100
  3419. +++ nepenthes-0.2.0-r1345/modules/vuln-msmq/MSMQDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3420. @@ -43,6 +43,8 @@
  3421. #include "Nepenthes.hpp"
  3422. #include "LogManager.hpp"
  3423. +#include "EventManager.hpp"
  3424. +#include "SocketEvent.hpp"
  3425. using namespace nepenthes;
  3426. @@ -73,7 +75,7 @@
  3427. case MSMQ_NULL:
  3428. case MSMQ_SHELLCODE:
  3429. logWarn("Unknown MSMQ exploit %i bytes State %i\n",m_Buffer->getSize(), m_State);
  3430. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3431. + HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3432. break;
  3433. case MSMQ_DONE:
  3434. diff -ruN nepenthes-0.2.0/modules/vuln-mssql/MSSQLDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-mssql/MSSQLDialogue.cpp
  3435. --- nepenthes-0.2.0/modules/vuln-mssql/MSSQLDialogue.cpp 2006-11-13 20:40:03.000000000 +0100
  3436. +++ nepenthes-0.2.0-r1345/modules/vuln-mssql/MSSQLDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3437. @@ -41,6 +41,9 @@
  3438. #include "Utilities.hpp"
  3439. +#include "EventManager.hpp"
  3440. +#include "SocketEvent.hpp"
  3441. +
  3442. #ifdef STDTAGS
  3443. #undef STDTAGS
  3444. #endif
  3445. @@ -115,7 +118,7 @@
  3446. }
  3447. else
  3448. { // hexdump it
  3449. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte*)msg->getMsg(),msg->getSize());
  3450. + HEXDUMP(m_Socket,(byte*)msg->getMsg(),msg->getSize());
  3451. }
  3452. diff -ruN nepenthes-0.2.0/modules/vuln-netbiosname/SMBNameDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-netbiosname/SMBNameDialogue.cpp
  3453. --- nepenthes-0.2.0/modules/vuln-netbiosname/SMBNameDialogue.cpp 2006-11-13 20:40:05.000000000 +0100
  3454. +++ nepenthes-0.2.0-r1345/modules/vuln-netbiosname/SMBNameDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3455. @@ -49,6 +49,8 @@
  3456. #include "Utilities.hpp"
  3457. +#include "EventManager.hpp"
  3458. +#include "SocketEvent.hpp"
  3459. #ifdef STDTAGS
  3460. #undef STDTAGS
  3461. @@ -146,7 +148,7 @@
  3462. case SMBName_NEGOTIATE:
  3463. case SMBName_NULL:
  3464. logWarn("Unknown SMBName exploit %i bytes State %i\n",m_Buffer->getSize(), m_State);
  3465. -// g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3466. +// HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3467. break;
  3468. diff -ruN nepenthes-0.2.0/modules/vuln-netdde/NETDDEDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-netdde/NETDDEDialogue.cpp
  3469. --- nepenthes-0.2.0/modules/vuln-netdde/NETDDEDialogue.cpp 2006-11-13 20:40:05.000000000 +0100
  3470. +++ nepenthes-0.2.0-r1345/modules/vuln-netdde/NETDDEDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3471. @@ -49,6 +49,8 @@
  3472. #include "Utilities.hpp"
  3473. +#include "EventManager.hpp"
  3474. +#include "SocketEvent.hpp"
  3475. #ifdef STDTAGS
  3476. #undef STDTAGS
  3477. @@ -201,5 +203,5 @@
  3478. void NETDDEDialogue::dump()
  3479. {
  3480. logWarn("Unknown NETDDE exploit %i bytes State %i\n",m_Buffer->getSize(), m_State);
  3481. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3482. + HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3483. }
  3484. diff -ruN nepenthes-0.2.0/modules/vuln-optix/Makefile.am nepenthes-0.2.0-r1345/modules/vuln-optix/Makefile.am
  3485. --- nepenthes-0.2.0/modules/vuln-optix/Makefile.am 2006-11-13 20:40:08.000000000 +0100
  3486. +++ nepenthes-0.2.0-r1345/modules/vuln-optix/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  3487. @@ -12,4 +12,4 @@
  3488. vulnoptix_la_SOURCES = vuln-optix.conf.dist OPTIXBindDialogue.hpp OPTIXDownloadDialogue.hpp OPTIXDownloadHandler.hpp OPTIXShellDialogue.hpp vuln-optix.hpp OPTIXBindDialogue.cpp OPTIXDownloadDialogue.cpp OPTIXDownloadHandler.cpp OPTIXShellDialogue.cpp vuln-optix.cpp
  3489. -vulnoptix_la_LDFLAGS = -module -no-undefined -avoid-version
  3490. +vulnoptix_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  3491. diff -ruN nepenthes-0.2.0/modules/vuln-optix/OPTIXShellDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-optix/OPTIXShellDialogue.cpp
  3492. --- nepenthes-0.2.0/modules/vuln-optix/OPTIXShellDialogue.cpp 2006-11-13 20:40:08.000000000 +0100
  3493. +++ nepenthes-0.2.0-r1345/modules/vuln-optix/OPTIXShellDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3494. @@ -107,7 +107,7 @@
  3495. case OPTIX_AUTHED:
  3496. if (m_Buffer->getSize() >= 6)
  3497. {
  3498. - g_Nepenthes->getUtilities()->hexdump((byte *)m_Buffer->getData(),m_Buffer->getSize());
  3499. +// g_Nepenthes->getUtilities()->hexdump((byte *)m_Buffer->getData(),m_Buffer->getSize());
  3500. // we could do this with pcre ...
  3501. if (memcmp(m_Buffer->getData(),"019�\r\n",6) == 0)
  3502. {
  3503. diff -ruN nepenthes-0.2.0/modules/vuln-pnp/PNPDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-pnp/PNPDialogue.cpp
  3504. --- nepenthes-0.2.0/modules/vuln-pnp/PNPDialogue.cpp 2006-11-13 20:40:08.000000000 +0100
  3505. +++ nepenthes-0.2.0-r1345/modules/vuln-pnp/PNPDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3506. @@ -47,6 +47,8 @@
  3507. #include "Buffer.hpp"
  3508. #include "Buffer.cpp"
  3509. +#include "EventManager.hpp"
  3510. +#include "SocketEvent.hpp"
  3511. #ifdef STDTAGS
  3512. #undef STDTAGS
  3513. @@ -276,5 +278,5 @@
  3514. void PNPDialogue::dump()
  3515. {
  3516. logWarn("Unknown %s Shellcode (Buffer %i bytes) (State %i)\n","PNP",m_Buffer->getSize(),m_State);
  3517. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3518. + HEXDUMP(m_Socket,(byte *)m_Buffer->getData(),m_Buffer->getSize());
  3519. }
  3520. diff -ruN nepenthes-0.2.0/modules/vuln-realvnc/vuln-realvnc.cpp nepenthes-0.2.0-r1345/modules/vuln-realvnc/vuln-realvnc.cpp
  3521. --- nepenthes-0.2.0/modules/vuln-realvnc/vuln-realvnc.cpp 2006-11-13 20:40:07.000000000 +0100
  3522. +++ nepenthes-0.2.0-r1345/modules/vuln-realvnc/vuln-realvnc.cpp 2007-08-06 00:46:15.000000000 +0200
  3523. @@ -246,7 +246,7 @@
  3524. {
  3525. logSpam("VNC_HANDSHAKE\n");
  3526. - g_Nepenthes->getUtilities()->hexdump((byte *)m_Buffer->getData(),m_Buffer->getSize());
  3527. +// g_Nepenthes->getUtilities()->hexdump((byte *)m_Buffer->getData(),m_Buffer->getSize());
  3528. if (m_Buffer->getSize() >= strlen(rfb_version_003_008) &&
  3529. memcmp(m_Buffer->getData(),rfb_version_003_008,strlen(rfb_version_003_008)) == 0)
  3530. {
  3531. @@ -262,7 +262,7 @@
  3532. if ( m_State == VNC_AUTH)
  3533. {
  3534. logSpam("VNC_AUTH\n");
  3535. - g_Nepenthes->getUtilities()->hexdump((byte *)m_Buffer->getData(),m_Buffer->getSize());
  3536. +// g_Nepenthes->getUtilities()->hexdump((byte *)m_Buffer->getData(),m_Buffer->getSize());
  3537. if (m_Buffer->getSize() >= 1 )
  3538. {
  3539. if (1)// *(char *) (m_Buffer->getData()) == 1)
  3540. @@ -546,7 +546,7 @@
  3541. case 6:
  3542. logSpam("ClientReq: CutEvent\n");
  3543. - g_Nepenthes->getUtilities()->hexdump((byte *)m_Buffer->getData(),m_Buffer->getSize());
  3544. +// g_Nepenthes->getUtilities()->hexdump((byte *)m_Buffer->getData(),m_Buffer->getSize());
  3545. if (m_Buffer->getSize() >= 8 )
  3546. {
  3547. uint32_t cpbytes;
  3548. diff -ruN nepenthes-0.2.0/modules/vuln-sasserftpd/SasserFTPDDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-sasserftpd/SasserFTPDDialogue.cpp
  3549. --- nepenthes-0.2.0/modules/vuln-sasserftpd/SasserFTPDDialogue.cpp 2006-11-13 20:40:09.000000000 +0100
  3550. +++ nepenthes-0.2.0-r1345/modules/vuln-sasserftpd/SasserFTPDDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3551. @@ -49,6 +49,8 @@
  3552. #include "Utilities.hpp"
  3553. +#include "EventManager.hpp"
  3554. +#include "SocketEvent.hpp"
  3555. #ifdef STDTAGS
  3556. #undef STDTAGS
  3557. @@ -219,5 +221,5 @@
  3558. void SasserFTPDDialogue::dump()
  3559. {
  3560. logWarn("Unknown SasserFTPD exploit %i bytes State %i\n",m_Buffer->getSize(), m_State);
  3561. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3562. + HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3563. }
  3564. diff -ruN nepenthes-0.2.0/modules/vuln-sav/Makefile.am nepenthes-0.2.0-r1345/modules/vuln-sav/Makefile.am
  3565. --- nepenthes-0.2.0/modules/vuln-sav/Makefile.am 1970-01-01 01:00:00.000000000 +0100
  3566. +++ nepenthes-0.2.0-r1345/modules/vuln-sav/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  3567. @@ -0,0 +1,14 @@
  3568. +# nepenthes module Makefile
  3569. +# Paul Baecher, Maximillian Dornseif, Markus Koetter
  3570. +# $Id$
  3571. +
  3572. +AUTOMAKE_OPTIONS = foreign
  3573. +
  3574. +AM_CPPFLAGS = -I$(top_srcdir)/nepenthes-core/include -I$(top_srcdir)/nepenthes-core/src -pipe -D _GNU_SOURCE
  3575. +AM_CXXFLAGS = -Wall -Werror
  3576. +
  3577. +pkglib_LTLIBRARIES = vulnsav.la
  3578. +
  3579. +vulnsav_la_SOURCES = vuln-sav.cpp vuln-sav.hpp
  3580. +
  3581. +vulnsav_la_LDFLAGS = -module -no-undefined -avoid-version
  3582. diff -ruN nepenthes-0.2.0/modules/vuln-sav/vuln-sav.cpp nepenthes-0.2.0-r1345/modules/vuln-sav/vuln-sav.cpp
  3583. --- nepenthes-0.2.0/modules/vuln-sav/vuln-sav.cpp 1970-01-01 01:00:00.000000000 +0100
  3584. +++ nepenthes-0.2.0-r1345/modules/vuln-sav/vuln-sav.cpp 2007-08-06 00:46:15.000000000 +0200
  3585. @@ -0,0 +1,278 @@
  3586. +/********************************************************************************
  3587. + * Nepenthes
  3588. + * - finest collection -
  3589. + *
  3590. + *
  3591. + *
  3592. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  3593. + *
  3594. + * This program is free software; you can redistribute it and/or
  3595. + * modify it under the terms of the GNU General Public License
  3596. + * as published by the Free Software Foundation; either version 2
  3597. + * of the License, or (at your option) any later version.
  3598. + *
  3599. + * This program is distributed in the hope that it will be useful,
  3600. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3601. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3602. + * GNU General Public License for more details.
  3603. + *
  3604. + * You should have received a copy of the GNU General Public License
  3605. + * along with this program; if not, write to the Free Software
  3606. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  3607. + *
  3608. + *
  3609. + * contact nepenthesdev@users.sourceforge.net
  3610. + *
  3611. + *******************************************************************************/
  3612. +
  3613. + /* $Id$ */
  3614. +
  3615. +#include <ctype.h>
  3616. +
  3617. +#include "vuln-sav.hpp"
  3618. +
  3619. +#include "SocketManager.hpp"
  3620. +
  3621. +#include "DownloadManager.hpp"
  3622. +#include "LogManager.hpp"
  3623. +#include "DialogueFactoryManager.hpp"
  3624. +
  3625. +
  3626. +#include "Buffer.hpp"
  3627. +#include "Buffer.cpp"
  3628. +
  3629. +#include "Message.hpp"
  3630. +#include "Message.cpp"
  3631. +
  3632. +#include "ShellcodeManager.hpp"
  3633. +
  3634. +#include "Config.hpp"
  3635. +
  3636. +#include "Download.hpp"
  3637. +
  3638. +#ifdef STDTAGS
  3639. +#undef STDTAGS
  3640. +#endif
  3641. +#define STDTAGS l_mod
  3642. +
  3643. +using namespace nepenthes;
  3644. +
  3645. +
  3646. +/**
  3647. + * as we may need a global pointer to our Nepenthes in our modules,
  3648. + * and cant access the cores global pointer to nepenthes
  3649. + * we have to use a own global pointer to nepenthes per module
  3650. + * we need this pointer for logInfo() etc
  3651. + */
  3652. +Nepenthes *g_Nepenthes;
  3653. +
  3654. +/**
  3655. + * The Constructor
  3656. + * creates a new VulnSAV Module,
  3657. + * VulnSAV is an example for binding a socket & setting up the Dialogue & DialogueFactory
  3658. + *
  3659. + *
  3660. + * it can be used as a shell emu to allow trigger commands
  3661. + *
  3662. + *
  3663. + * sets the following values:
  3664. + * - m_DialogueFactoryName
  3665. + * - m_DialogueFactoryDescription
  3666. + *
  3667. + * @param nepenthes the pointer to our Nepenthes
  3668. + */
  3669. +VulnSAV::VulnSAV(Nepenthes *nepenthes)
  3670. +{
  3671. + m_ModuleName = "vuln-sav";
  3672. + m_ModuleDescription = "emulate the bug in symantec antivirus product";
  3673. + m_ModuleRevision = "$Rev$";
  3674. + m_Nepenthes = nepenthes;
  3675. +
  3676. + m_DialogueFactoryName = "SAV Factory";
  3677. + m_DialogueFactoryDescription = "Symantec Antivirus Client Dialogue Factory";
  3678. +
  3679. + g_Nepenthes = nepenthes;
  3680. +}
  3681. +
  3682. +VulnSAV::~VulnSAV()
  3683. +{
  3684. +
  3685. +}
  3686. +
  3687. +
  3688. +/**
  3689. + * Module::Init()
  3690. + *
  3691. + * binds the port, adds the DialogueFactory to the Socket
  3692. + *
  3693. + * @return returns true if everything was fine, else false
  3694. + * false indicates a fatal error
  3695. + */
  3696. +bool VulnSAV::Init()
  3697. +{
  3698. +/* if ( m_Config == NULL )
  3699. + {
  3700. + logCrit("I need a config\n");
  3701. + return false;
  3702. + }
  3703. +*/
  3704. + m_Nepenthes->getSocketMgr()->bindTCPSocket(0,2967,0,30,this);
  3705. + return true;
  3706. +}
  3707. +
  3708. +bool VulnSAV::Exit()
  3709. +{
  3710. + return true;
  3711. +}
  3712. +
  3713. +/**
  3714. + * DialogueFactory::createDialogue(Socket *)
  3715. + *
  3716. + * creates a new SAVDialogue
  3717. + *
  3718. + * @param socket the socket the DIalogue has to use, can be NULL if the Dialogue can handle it
  3719. + *
  3720. + * @return returns the new created dialogue
  3721. + */
  3722. +Dialogue *VulnSAV::createDialogue(Socket *socket)
  3723. +{
  3724. + return new SAVDialogue(socket);
  3725. +// return g_Nepenthes->getFactoryMgr()->getFactory("WinNTShell DialogueFactory")->createDialogue(socket);
  3726. +}
  3727. +
  3728. +
  3729. +
  3730. +
  3731. +
  3732. +
  3733. +
  3734. +/**
  3735. + * Dialogue::Dialogue(Socket *)
  3736. + * construktor for the SAVDialogue, creates a new SAVDialogue
  3737. + *
  3738. + * replies some crap to the socket
  3739. + *
  3740. + * @param socket the Socket the Dialogue has to use
  3741. + */
  3742. +SAVDialogue::SAVDialogue(Socket *socket)
  3743. +{
  3744. + m_Socket = socket;
  3745. + m_DialogueName = "SAVDialogue";
  3746. + m_DialogueDescription = "Symantec Antivirus Dialogue";
  3747. +
  3748. + m_ConsumeLevel = CL_ASSIGN;
  3749. +
  3750. + m_Buffer = new Buffer(512);
  3751. +}
  3752. +
  3753. +SAVDialogue::~SAVDialogue()
  3754. +{
  3755. + delete m_Buffer;
  3756. +}
  3757. +
  3758. +/**
  3759. + * Dialogue::incomingData(Message *)
  3760. + *
  3761. + * a small and ugly shell where we can use
  3762. + * "download protocol://localction:port/path/to/file
  3763. + * to trigger a download
  3764. + *
  3765. + * @param msg the Message the Socker received.
  3766. + *
  3767. + *
  3768. + * @return CL_ASSIGN
  3769. + */
  3770. +ConsumeLevel SAVDialogue::incomingData(Message *msg)
  3771. +{
  3772. +
  3773. + m_Buffer->add(msg->getMsg(),msg->getSize());
  3774. +
  3775. + if ( m_Buffer->getSize() > 0xcd0 )
  3776. + {
  3777. + Message *Msg = new Message((char *)m_Buffer->getData(), m_Buffer->getSize(),m_Socket->getLocalPort(), m_Socket->getRemotePort(),
  3778. + m_Socket->getLocalHost(), m_Socket->getRemoteHost(), m_Socket, m_Socket);
  3779. + sch_result sch;
  3780. + sch = g_Nepenthes->getShellcodeMgr()->handleShellcode(&Msg);
  3781. + delete Msg;
  3782. +
  3783. + if ( sch == SCH_DONE )
  3784. + {
  3785. + m_Buffer->clear();
  3786. + return CL_ASSIGN_AND_DONE;
  3787. + }
  3788. +
  3789. + }
  3790. +
  3791. + return CL_ASSIGN;
  3792. +}
  3793. +
  3794. +/**
  3795. + * Dialogue::outgoingData(Message *)
  3796. + * as we are not interested in these socket actions
  3797. + * we simply return CL_DROP to show the socket
  3798. + *
  3799. + * @param msg
  3800. + *
  3801. + * @return CL_DROP
  3802. + */
  3803. +ConsumeLevel SAVDialogue::outgoingData(Message *msg)
  3804. +{
  3805. + return CL_ASSIGN;
  3806. +}
  3807. +
  3808. +/**
  3809. + * Dialogue::handleTimeout(Message *)
  3810. + * as we are not interested in these socket actions
  3811. + * we simply return CL_DROP to show the socket
  3812. + *
  3813. + * @param msg
  3814. + *
  3815. + * @return CL_DROP
  3816. + */
  3817. +ConsumeLevel SAVDialogue::handleTimeout(Message *msg)
  3818. +{
  3819. + return CL_DROP;
  3820. +}
  3821. +
  3822. +/**
  3823. + * Dialogue::connectionLost(Message *)
  3824. + * as we are not interested in these socket actions
  3825. + * we simply return CL_DROP to show the socket
  3826. + *
  3827. + * @param msg
  3828. + *
  3829. + * @return CL_DROP
  3830. + */
  3831. +ConsumeLevel SAVDialogue::connectionLost(Message *msg)
  3832. +{
  3833. + return CL_DROP;
  3834. +}
  3835. +
  3836. +/**
  3837. + * Dialogue::connectionShutdown(Message *)
  3838. + * as we are not interested in these socket actions
  3839. + * we simply return CL_DROP to show the socket
  3840. + *
  3841. + * @param msg
  3842. + *
  3843. + * @return CL_DROP
  3844. + */
  3845. +ConsumeLevel SAVDialogue::connectionShutdown(Message *msg)
  3846. +{
  3847. + return CL_DROP;
  3848. +}
  3849. +
  3850. +
  3851. +
  3852. +
  3853. +extern "C" int32_t module_init(int32_t version, Module **module, Nepenthes *nepenthes)
  3854. +{
  3855. + if ( version == MODULE_IFACE_VERSION )
  3856. + {
  3857. + *module = new VulnSAV(nepenthes);
  3858. + return (1);
  3859. + } else
  3860. + {
  3861. + return (0);
  3862. + }
  3863. +}
  3864. diff -ruN nepenthes-0.2.0/modules/vuln-sav/vuln-sav.hpp nepenthes-0.2.0-r1345/modules/vuln-sav/vuln-sav.hpp
  3865. --- nepenthes-0.2.0/modules/vuln-sav/vuln-sav.hpp 1970-01-01 01:00:00.000000000 +0100
  3866. +++ nepenthes-0.2.0-r1345/modules/vuln-sav/vuln-sav.hpp 2007-08-06 00:46:15.000000000 +0200
  3867. @@ -0,0 +1,72 @@
  3868. +/********************************************************************************
  3869. + * Nepenthes
  3870. + * - finest collection -
  3871. + *
  3872. + *
  3873. + *
  3874. + * Copyright (C) 2005 Paul Baecher & Markus Koetter
  3875. + *
  3876. + * This program is free software; you can redistribute it and/or
  3877. + * modify it under the terms of the GNU General Public License
  3878. + * as published by the Free Software Foundation; either version 2
  3879. + * of the License, or (at your option) any later version.
  3880. + *
  3881. + * This program is distributed in the hope that it will be useful,
  3882. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  3883. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  3884. + * GNU General Public License for more details.
  3885. + *
  3886. + * You should have received a copy of the GNU General Public License
  3887. + * along with this program; if not, write to the Free Software
  3888. + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  3889. + *
  3890. + *
  3891. + * contact nepenthesdev@users.sourceforge.net
  3892. + *
  3893. + *******************************************************************************/
  3894. +
  3895. + /* $Id$ */
  3896. +
  3897. +#include "DialogueFactory.hpp"
  3898. +#include "Module.hpp"
  3899. +#include "ModuleManager.hpp"
  3900. +#include "SocketManager.hpp"
  3901. +#include "Nepenthes.hpp"
  3902. +#include "Dialogue.hpp"
  3903. +#include "Socket.hpp"
  3904. +
  3905. +using namespace std;
  3906. +
  3907. +namespace nepenthes
  3908. +{
  3909. +
  3910. + class Buffer;
  3911. +
  3912. + class VulnSAV : public Module , public DialogueFactory
  3913. + {
  3914. + public:
  3915. + VulnSAV(Nepenthes *);
  3916. + ~VulnSAV();
  3917. + Dialogue *createDialogue(Socket *socket);
  3918. + bool Init();
  3919. + bool Exit();
  3920. + };
  3921. +
  3922. + class SAVDialogue : public Dialogue
  3923. + {
  3924. + public:
  3925. + SAVDialogue(Socket *socket);
  3926. + ~SAVDialogue();
  3927. + ConsumeLevel incomingData(Message *msg);
  3928. + ConsumeLevel outgoingData(Message *msg);
  3929. + ConsumeLevel handleTimeout(Message *msg);
  3930. + ConsumeLevel connectionLost(Message *msg);
  3931. + ConsumeLevel connectionShutdown(Message *msg);
  3932. +
  3933. + protected:
  3934. + Buffer *m_Buffer;
  3935. +
  3936. + };
  3937. +
  3938. +}
  3939. +extern nepenthes::Nepenthes *g_Nepenthes;
  3940. diff -ruN nepenthes-0.2.0/modules/vuln-sav/x-2.conf.dist nepenthes-0.2.0-r1345/modules/vuln-sav/x-2.conf.dist
  3941. --- nepenthes-0.2.0/modules/vuln-sav/x-2.conf.dist 1970-01-01 01:00:00.000000000 +0100
  3942. +++ nepenthes-0.2.0-r1345/modules/vuln-sav/x-2.conf.dist 2007-08-06 00:46:15.000000000 +0200
  3943. @@ -0,0 +1,5 @@
  3944. +x-2
  3945. +{
  3946. + ports ("10002");
  3947. + accepttimeout "45";
  3948. +};
  3949. diff -ruN nepenthes-0.2.0/modules/vuln-ssh/Makefile.am nepenthes-0.2.0-r1345/modules/vuln-ssh/Makefile.am
  3950. --- nepenthes-0.2.0/modules/vuln-ssh/Makefile.am 2006-11-13 20:40:03.000000000 +0100
  3951. +++ nepenthes-0.2.0-r1345/modules/vuln-ssh/Makefile.am 2007-08-06 00:46:15.000000000 +0200
  3952. @@ -10,6 +10,6 @@
  3953. pkglib_LTLIBRARIES = vulnssh.la
  3954. -vulnssh_la_SOURCES = vuln-ssh.cpp vuln-ssh.hpp SSHSocket.cpp SSHSocket.hpp SSHDialogue.cpp SSHDialogue.hpp vuln-ssh.conf.dist
  3955. +vulnssh_la_SOURCES = vuln-ssh.cpp vuln-ssh.hpp SSHSocket.cpp SSHSocket.hpp SSHDialogue.cpp SSHDialogue.hpp
  3956. -vulnssh_la_LDFLAGS = -module -no-undefined -avoid-version
  3957. +vulnssh_la_LDFLAGS = -module -no-undefined -avoid-version $(AM_LDFLAGS)
  3958. diff -ruN nepenthes-0.2.0/modules/vuln-upnp/UPNPDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-upnp/UPNPDialogue.cpp
  3959. --- nepenthes-0.2.0/modules/vuln-upnp/UPNPDialogue.cpp 2006-11-13 20:40:10.000000000 +0100
  3960. +++ nepenthes-0.2.0-r1345/modules/vuln-upnp/UPNPDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3961. @@ -49,6 +49,8 @@
  3962. #include "Utilities.hpp"
  3963. +#include "EventManager.hpp"
  3964. +#include "SocketEvent.hpp"
  3965. #ifdef STDTAGS
  3966. #undef STDTAGS
  3967. @@ -190,5 +192,5 @@
  3968. void UPNPDialogue::dump()
  3969. {
  3970. logWarn("Unknown UPNP exploit %i bytes State %i\n",m_Buffer->getSize(), m_State);
  3971. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3972. + HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3973. }
  3974. diff -ruN nepenthes-0.2.0/modules/vuln-veritas/VERITASDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-veritas/VERITASDialogue.cpp
  3975. --- nepenthes-0.2.0/modules/vuln-veritas/VERITASDialogue.cpp 2006-11-13 20:40:09.000000000 +0100
  3976. +++ nepenthes-0.2.0-r1345/modules/vuln-veritas/VERITASDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  3977. @@ -49,6 +49,8 @@
  3978. #include "Utilities.hpp"
  3979. +#include "EventManager.hpp"
  3980. +#include "SocketEvent.hpp"
  3981. #ifdef STDTAGS
  3982. #undef STDTAGS
  3983. @@ -98,7 +100,7 @@
  3984. m_Buffer->add(msg->getMsg(),msg->getSize());
  3985. logInfo("Traffic for VERITAS (%i bytes)\n",msg->getSize());
  3986. - g_Nepenthes->getUtilities()->hexdump(STDTAGS|l_warn,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3987. +// g_Nepenthes->getUtilities()->hexdump(STDTAGS|l_warn,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3988. /*
  3989. switch (m_State)
  3990. @@ -189,5 +191,5 @@
  3991. void VERITASDialogue::dump()
  3992. {
  3993. logWarn("Unknown VERITAS exploit %i bytes State %i\n",m_Buffer->getSize(), m_State);
  3994. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3995. + HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  3996. }
  3997. diff -ruN nepenthes-0.2.0/modules/vuln-wins/WINSDialogue.cpp nepenthes-0.2.0-r1345/modules/vuln-wins/WINSDialogue.cpp
  3998. --- nepenthes-0.2.0/modules/vuln-wins/WINSDialogue.cpp 2006-11-13 20:40:10.000000000 +0100
  3999. +++ nepenthes-0.2.0-r1345/modules/vuln-wins/WINSDialogue.cpp 2007-08-06 00:46:15.000000000 +0200
  4000. @@ -41,6 +41,9 @@
  4001. #include "Socket.hpp"
  4002. +#include "EventManager.hpp"
  4003. +#include "SocketEvent.hpp"
  4004. +
  4005. #ifdef STDTAGS
  4006. #undef STDTAGS
  4007. #endif
  4008. @@ -123,5 +126,5 @@
  4009. {
  4010. logWarn("WINS unknown shellcode %i bytes State 0\n",m_Buffer->getSize());
  4011. - g_Nepenthes->getUtilities()->hexdump(STDTAGS,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  4012. + HEXDUMP(m_Socket,(byte *) m_Buffer->getData(), m_Buffer->getSize());
  4013. }
  4014. diff -ruN nepenthes-0.2.0/modules/x-4/x-4.cpp nepenthes-0.2.0-r1345/modules/x-4/x-4.cpp
  4015. --- nepenthes-0.2.0/modules/x-4/x-4.cpp 2006-11-13 20:40:11.000000000 +0100
  4016. +++ nepenthes-0.2.0-r1345/modules/x-4/x-4.cpp 2007-08-06 00:46:15.000000000 +0200
  4017. @@ -118,7 +118,7 @@
  4018. */
  4019. void X4::Submit(Download *down)
  4020. {
  4021. - m_Nepenthes->getUtilities()->hexdump((byte *)down->getDownloadBuffer()->getData(),down->getDownloadBuffer()->getSize());
  4022. +// m_Nepenthes->getUtilities()->hexdump((byte *)down->getDownloadBuffer()->getData(),down->getDownloadBuffer()->getSize());
  4023. }
  4024. /**
  4025. diff -ruN nepenthes-0.2.0/nepenthes-core/include/DNSQuery.hpp nepenthes-0.2.0-r1345/nepenthes-core/include/DNSQuery.hpp
  4026. --- nepenthes-0.2.0/nepenthes-core/include/DNSQuery.hpp 2006-11-13 20:40:01.000000000 +0100
  4027. +++ nepenthes-0.2.0-r1345/nepenthes-core/include/DNSQuery.hpp 2007-08-06 00:46:15.000000000 +0200
  4028. @@ -56,6 +56,7 @@
  4029. virtual ~DNSQuery();
  4030. virtual DNSCallback *getCallback();
  4031. + virtual void cancelCallback();
  4032. virtual string getDNS();
  4033. virtual uint16_t getQueryType();
  4034. virtual void *getObject();
  4035. diff -ruN nepenthes-0.2.0/nepenthes-core/include/Event.hpp nepenthes-0.2.0-r1345/nepenthes-core/include/Event.hpp
  4036. --- nepenthes-0.2.0/nepenthes-core/include/Event.hpp 2006-11-13 20:40:01.000000000 +0100
  4037. +++ nepenthes-0.2.0-r1345/nepenthes-core/include/Event.hpp 2007-08-06 00:46:15.000000000 +0200
  4038. @@ -71,6 +71,8 @@
  4039. #define EV_SHELLCODE_DONE 24
  4040. +#define EV_HEXDUMP 25
  4041. +
  4042. class Event
  4043. {
  4044. public:
  4045. diff -ruN nepenthes-0.2.0/nepenthes-core/include/SocketEvent.hpp nepenthes-0.2.0-r1345/nepenthes-core/include/SocketEvent.hpp
  4046. --- nepenthes-0.2.0/nepenthes-core/include/SocketEvent.hpp 2006-11-13 20:40:01.000000000 +0100
  4047. +++ nepenthes-0.2.0-r1345/nepenthes-core/include/SocketEvent.hpp 2007-08-06 00:46:15.000000000 +0200
  4048. @@ -137,5 +137,50 @@
  4049. Dialogue *m_Dialogue;
  4050. };
  4051. +#ifdef HAVE_DEBUG_LOGGING
  4052. +#define HEXDUMP(socket,data,size) \
  4053. +{ \
  4054. + HexdumpEvent *he = new HexdumpEvent(socket,data,size); \
  4055. + g_Nepenthes->getEventMgr()->handleEvent(he); \
  4056. + delete he; \
  4057. +}
  4058. +#else // HAVE_DEBUG_LOGGING
  4059. +#define HEXDUMP(socket,data,size)
  4060. +#endif // HAVE_DEBUG_LOGGING
  4061. +
  4062. +
  4063. +
  4064. + class HexdumpEvent : public Event
  4065. + {
  4066. + public:
  4067. + HexdumpEvent(Socket *s, void *data, uint32_t size)
  4068. + {
  4069. + m_EventType = EV_HEXDUMP;
  4070. + m_Socket = s;
  4071. + m_Size = size;
  4072. + m_Data = data;
  4073. + }
  4074. +
  4075. + virtual Socket *getSocket()
  4076. + {
  4077. + return m_Socket;
  4078. + }
  4079. +
  4080. + virtual void *getData()
  4081. + {
  4082. + return m_Data;
  4083. + }
  4084. +
  4085. + virtual uint32_t getSize()
  4086. + {
  4087. + return m_Size;
  4088. + }
  4089. +
  4090. + private:
  4091. + Socket *m_Socket;
  4092. + void *m_Data;
  4093. + uint32_t m_Size;
  4094. + };
  4095. +
  4096. }
  4097. diff -ruN nepenthes-0.2.0/nepenthes-core/include/Utilities.hpp nepenthes-0.2.0-r1345/nepenthes-core/include/Utilities.hpp
  4098. --- nepenthes-0.2.0/nepenthes-core/include/Utilities.hpp 2006-11-13 20:40:01.000000000 +0100
  4099. +++ nepenthes-0.2.0-r1345/nepenthes-core/include/Utilities.hpp 2007-08-06 00:46:15.000000000 +0200
  4100. @@ -130,10 +130,10 @@
  4101. void MD5Init(struct MD5Context *context);
  4102. void MD5Update(struct MD5Context *context, unsigned char const *buf,unsigned len);
  4103. void MD5Final(unsigned char digest[16], struct MD5Context *context);
  4104. -
  4105. +/*
  4106. virtual void hexdump(byte *data, uint32_t len);
  4107. virtual void hexdump(uint32_t mask, byte *data, uint32_t len);
  4108. -
  4109. +*/
  4110. virtual unsigned char *b64encode_alloc(unsigned char *in);
  4111. virtual unsigned char *b64encode_alloc(unsigned char *in, int32_t inlen);
  4112. virtual unsigned char *b64decode_alloc(unsigned char *in);
  4113. diff -ruN nepenthes-0.2.0/nepenthes-core/src/DNSQuery.cpp nepenthes-0.2.0-r1345/nepenthes-core/src/DNSQuery.cpp
  4114. --- nepenthes-0.2.0/nepenthes-core/src/DNSQuery.cpp 2006-11-13 20:40:03.000000000 +0100
  4115. +++ nepenthes-0.2.0-r1345/nepenthes-core/src/DNSQuery.cpp 2007-08-06 00:46:15.000000000 +0200
  4116. @@ -54,6 +54,15 @@
  4117. return m_Callback;
  4118. }
  4119. +
  4120. +/**
  4121. + * chancel the callback
  4122. + */
  4123. +void DNSQuery::cancelCallback()
  4124. +{
  4125. + m_Callback = NULL;
  4126. +}
  4127. +
  4128. /**
  4129. * get the dns to resolve
  4130. *
  4131. diff -ruN nepenthes-0.2.0/nepenthes-core/src/DNSResult.cpp nepenthes-0.2.0-r1345/nepenthes-core/src/DNSResult.cpp
  4132. --- nepenthes-0.2.0/nepenthes-core/src/DNSResult.cpp 2006-11-13 20:40:03.000000000 +0100
  4133. +++ nepenthes-0.2.0-r1345/nepenthes-core/src/DNSResult.cpp 2007-08-06 00:46:15.000000000 +0200
  4134. @@ -89,7 +89,7 @@
  4135. while ( test->i != -1 )
  4136. {
  4137. m_TXT.append(test->str,test->i);
  4138. - g_Nepenthes->getUtilities()->hexdump((byte *)test->str,test->i);
  4139. +// g_Nepenthes->getUtilities()->hexdump((byte *)test->str,test->i);
  4140. test++;
  4141. }
  4142. }
  4143. diff -ruN nepenthes-0.2.0/nepenthes-core/src/LogManager.cpp nepenthes-0.2.0-r1345/nepenthes-core/src/LogManager.cpp
  4144. --- nepenthes-0.2.0/nepenthes-core/src/LogManager.cpp 2006-11-13 20:40:02.000000000 +0100
  4145. +++ nepenthes-0.2.0-r1345/nepenthes-core/src/LogManager.cpp 2007-08-06 00:46:15.000000000 +0200
  4146. @@ -146,7 +146,7 @@
  4147. {
  4148. if ( m_Loggers.size() == 0)
  4149. {
  4150. - printf("%s",message);
  4151. +// printf("%s",message);
  4152. return;
  4153. }
  4154. diff -ruN nepenthes-0.2.0/nepenthes-core/src/Nepenthes.cpp nepenthes-0.2.0-r1345/nepenthes-core/src/Nepenthes.cpp
  4155. --- nepenthes-0.2.0/nepenthes-core/src/Nepenthes.cpp 2006-11-13 20:40:03.000000000 +0100
  4156. +++ nepenthes-0.2.0-r1345/nepenthes-core/src/Nepenthes.cpp 2007-08-06 00:46:15.000000000 +0200
  4157. @@ -43,6 +43,8 @@
  4158. #include <dirent.h>
  4159. #include <sys/utsname.h>
  4160. #include <ctype.h>
  4161. +#include <errno.h>
  4162. +#include <string.h>
  4163. #ifdef HAVE_LIBCAP
  4164. #undef _POSIX_SOURCE
  4165. @@ -211,7 +213,7 @@
  4166. { "user", 1, 0, 'u' },
  4167. { "version", 0, 0, 'V' },
  4168. { "verbose", 0, 0, 'v' },
  4169. - { "workingdir", 0, 0, 'w' },
  4170. + { "workingdir", 1, 0, 'w' },
  4171. { 0, 0, 0, 0 }
  4172. };
  4173. @@ -370,26 +372,27 @@
  4174. + m_LogManager->registerTag(l_crit, "crit");
  4175. + m_LogManager->registerTag(l_warn, "warn");
  4176. + m_LogManager->registerTag(l_debug, "debug");
  4177. + m_LogManager->registerTag(l_info, "info");
  4178. + m_LogManager->registerTag(l_spam, "spam");
  4179. + m_LogManager->registerTag(l_net, "net");
  4180. + m_LogManager->registerTag(l_script, "script");
  4181. + m_LogManager->registerTag(l_shell, "shell");
  4182. + m_LogManager->registerTag(l_mem, "mem");
  4183. + m_LogManager->registerTag(l_sc, "sc");
  4184. + m_LogManager->registerTag(l_dl, "down");
  4185. + m_LogManager->registerTag(l_mgr, "mgr");
  4186. + m_LogManager->registerTag(l_hlr, "handler");
  4187. + m_LogManager->registerTag(l_dia, "dia");
  4188. + m_LogManager->registerTag(l_sub, "submit");
  4189. + m_LogManager->registerTag(l_ev, "event");
  4190. + m_LogManager->registerTag(l_mod, "module");
  4191. + m_LogManager->registerTag(l_stdtag, "fixme");
  4192. +
  4193. if ( opt.m_runMode != runFileCheck || opt.m_verbose )
  4194. {
  4195. - m_LogManager->registerTag(l_crit, "crit");
  4196. - m_LogManager->registerTag(l_warn, "warn");
  4197. - m_LogManager->registerTag(l_debug, "debug");
  4198. - m_LogManager->registerTag(l_info, "info");
  4199. - m_LogManager->registerTag(l_spam, "spam");
  4200. - m_LogManager->registerTag(l_net, "net");
  4201. - m_LogManager->registerTag(l_script, "script");
  4202. - m_LogManager->registerTag(l_shell, "shell");
  4203. - m_LogManager->registerTag(l_mem, "mem");
  4204. - m_LogManager->registerTag(l_sc, "sc");
  4205. - m_LogManager->registerTag(l_dl, "down");
  4206. - m_LogManager->registerTag(l_mgr, "mgr");
  4207. - m_LogManager->registerTag(l_hlr, "handler");
  4208. - m_LogManager->registerTag(l_dia, "dia");
  4209. - m_LogManager->registerTag(l_sub, "submit");
  4210. - m_LogManager->registerTag(l_ev, "event");
  4211. - m_LogManager->registerTag(l_mod, "module");
  4212. - m_LogManager->registerTag(l_stdtag, "fixme");
  4213. if ( opt.m_consoleTags )
  4214. m_LogManager->addLogger(new ConsoleLogger(m_LogManager), m_LogManager->parseTagString(opt.m_consoleTags));
  4215. @@ -460,52 +463,53 @@
  4216. return 0;
  4217. - if ( opt.m_ringLogger == true )
  4218. + if ( opt.m_runMode != runFileCheck || opt.m_verbose )
  4219. {
  4220. - string rlpath;
  4221. - try
  4222. - {
  4223. - rlpath = m_Config->getValString("nepenthes.logmanager.ring_logging_file");
  4224. - }
  4225. - catch ( ... )
  4226. +
  4227. + if ( opt.m_ringLogger == true )
  4228. {
  4229. - logCrit("Could not find nepenthes.logmanager.ring_logging_file in Config\n");
  4230. - return false;
  4231. - }
  4232. + string rlpath;
  4233. + try
  4234. + {
  4235. + rlpath = m_Config->getValString("nepenthes.logmanager.ring_logging_file");
  4236. + } catch ( ... )
  4237. + {
  4238. + logCrit("Could not find nepenthes.logmanager.ring_logging_file in Config\n");
  4239. + return (false);
  4240. + }
  4241. - RingFileLogger *fl = new RingFileLogger(m_LogManager);
  4242. + RingFileLogger *fl = new RingFileLogger(m_LogManager);
  4243. - fl->setLogFileFormat((char *)rlpath.c_str());
  4244. - fl->setMaxFiles(5);
  4245. - fl->setMaxSize(1024 * 1024);
  4246. + fl->setLogFileFormat((char *)rlpath.c_str());
  4247. + fl->setMaxFiles(5);
  4248. + fl->setMaxSize(1024 * 1024);
  4249. - if ( opt.m_diskTags )
  4250. - m_LogManager->addLogger(fl, m_LogManager->parseTagString(opt.m_diskTags));
  4251. - else
  4252. - m_LogManager->addLogger(fl, l_all);
  4253. + if ( opt.m_diskTags )
  4254. + m_LogManager->addLogger(fl, m_LogManager->parseTagString(opt.m_diskTags));
  4255. + else
  4256. + m_LogManager->addLogger(fl, l_all);
  4257. - }
  4258. - else
  4259. - {
  4260. - string flpath;
  4261. - try
  4262. - {
  4263. - flpath = m_Config->getValString("nepenthes.logmanager.file_logging_file");
  4264. - }
  4265. - catch ( ... )
  4266. + } else
  4267. {
  4268. - logCrit("Could not find nepenthes.logmanager.file_logging_file in Config\n");
  4269. - return false;
  4270. - }
  4271. + string flpath;
  4272. + try
  4273. + {
  4274. + flpath = m_Config->getValString("nepenthes.logmanager.file_logging_file");
  4275. + } catch ( ... )
  4276. + {
  4277. + logCrit("Could not find nepenthes.logmanager.file_logging_file in Config\n");
  4278. + return (false);
  4279. + }
  4280. - FileLogger *fl = new FileLogger(m_LogManager);
  4281. - fl->setLogFile(flpath.c_str());
  4282. - if ( opt.m_diskTags )
  4283. - m_LogManager->addLogger(fl, m_LogManager->parseTagString(opt.m_diskTags));
  4284. - else
  4285. - m_LogManager->addLogger(fl, l_all);
  4286. + FileLogger *fl = new FileLogger(m_LogManager);
  4287. + fl->setLogFile(flpath.c_str());
  4288. + if ( opt.m_diskTags )
  4289. + m_LogManager->addLogger(fl, m_LogManager->parseTagString(opt.m_diskTags));
  4290. + else
  4291. + m_LogManager->addLogger(fl, l_all);
  4292. + }
  4293. }
  4294. if (opt.m_daemonize == true)
  4295. @@ -665,7 +669,7 @@
  4296. struct stat fileinfo;
  4297. if ( stat((const char*)argv[opti],&fileinfo) != 0 )
  4298. {
  4299. - printf("failed\n");
  4300. + printf("Could not stat %s: %s", (const char*)argv[opti], strerror(errno));
  4301. return -1;
  4302. }
  4303. @@ -680,7 +684,10 @@
  4304. )
  4305. {
  4306. - unlink(argv[opti]);
  4307. + if (unlink(argv[opti]) != 0)
  4308. + {
  4309. + printf("could not remove file %s (%s)\n",argv[opti],strerror(errno));
  4310. + }
  4311. }
  4312. }else
  4313. @@ -693,7 +700,7 @@
  4314. while ( (dirnode = readdir(bindir)) != NULL && m_running == true )
  4315. {
  4316. -#if !defined(CYGWIN) && !defined(CYGWIN32) &&!defined(__CYGWIN__) || !defined(__CYGWIN32__)
  4317. +#if defined(d_type_IS_NOT_A_POSIX_SPEC)
  4318. if ( dirnode->d_type == 8 )
  4319. #else
  4320. if (1)
  4321. @@ -708,7 +715,10 @@
  4322. )
  4323. {
  4324. - unlink(filepath.c_str());
  4325. + if (unlink(filepath.c_str()) != 0)
  4326. + {
  4327. + printf("could not remove file %s (%s)\n",filepath.c_str(),strerror(errno));
  4328. + }
  4329. }
  4330. }
  4331. }
  4332. diff -ruN nepenthes-0.2.0/nepenthes-core/src/SocketManager.cpp nepenthes-0.2.0-r1345/nepenthes-core/src/SocketManager.cpp
  4333. --- nepenthes-0.2.0/nepenthes-core/src/SocketManager.cpp 2006-11-13 20:40:03.000000000 +0100
  4334. +++ nepenthes-0.2.0-r1345/nepenthes-core/src/SocketManager.cpp 2007-08-06 00:46:15.000000000 +0200
  4335. @@ -273,13 +273,17 @@
  4336. }
  4337. }
  4338. + int32_t socketcounter, socketmax;
  4339. + socketcounter=0;
  4340. + socketmax = m_Sockets.size();
  4341. +
  4342. int32_t iPollRet = poll(polls,i,50);
  4343. if (iPollRet != 0)
  4344. {
  4345. // read sockets
  4346. i=0;
  4347. - for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++)
  4348. + for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(), socketcounter < socketmax ; itSocket++, socketcounter++)
  4349. {
  4350. if ( (*itSocket)->isPolled() == true )
  4351. {
  4352. @@ -303,7 +307,8 @@
  4353. // write sockets
  4354. i=0;
  4355. - for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++)
  4356. + socketcounter=0;
  4357. + for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(), socketcounter < socketmax; itSocket++, socketcounter++)
  4358. {
  4359. if ( (*itSocket)->isPolled() == true )
  4360. {
  4361. @@ -331,7 +336,8 @@
  4362. // accept new, non udp clients as udp does not accept()
  4363. i=0;
  4364. - for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(); itSocket++)
  4365. + socketcounter=0;
  4366. + for (itSocket = m_Sockets.begin();itSocket != m_Sockets.end(), socketcounter < socketmax; itSocket++, socketcounter++)
  4367. {
  4368. diff -ruN nepenthes-0.2.0/nepenthes-core/src/Utilities.cpp nepenthes-0.2.0-r1345/nepenthes-core/src/Utilities.cpp
  4369. --- nepenthes-0.2.0/nepenthes-core/src/Utilities.cpp 2006-11-13 20:40:02.000000000 +0100
  4370. +++ nepenthes-0.2.0-r1345/nepenthes-core/src/Utilities.cpp 2007-08-06 00:46:15.000000000 +0200
  4371. @@ -339,7 +339,7 @@
  4372. // ENDOF MD5Sum
  4373. -
  4374. +/*
  4375. void Utilities::hexdump(byte *data, uint32_t len)
  4376. {
  4377. @@ -430,7 +430,7 @@
  4378. }
  4379. -
  4380. +*/