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.

661 lines
25 KiB

  1. # --- SDE-COPYRIGHT-NOTE-BEGIN ---
  2. # This copyright note is auto-generated by ./scripts/Create-CopyPatch.
  3. #
  4. # Filename: package/.../sancp/sancp-1.6.1-stable-prelude-3.diff
  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 sancp-1.6.1-stable.vanilla/Makefile sancp-1.6.1-stable/Makefile
  17. --- sancp-1.6.1-stable.vanilla/Makefile 2007-07-07 00:46:11.000000000 +0200
  18. +++ sancp-1.6.1-stable/Makefile 2007-07-24 13:44:01.000000000 +0200
  19. @@ -9,7 +9,7 @@
  20. # LINUX and BSD CFLAGS
  21. -CFLAGS = -O3 -I/usr/include/pcap -I/usr/local/include/pcap -I./ -L/usr/lib/libsocket.so -g -L/opt/csw/lib -ggdb
  22. +CFLAGS = -g -O3 -I/usr/include/pcap -I/usr/local/include/pcap -I./ -L/usr/lib/libsocket.so -g -L/opt/csw/lib -ggdb `libprelude-config --cflags`
  23. # LINUX LFLAGS
  24. LFLAGS = -lresolv -lnsl -lpcap -L/usr/lib/libpcap.so.0.6.2
  25. @@ -41,10 +41,10 @@
  26. bsd :
  27. @(echo "#define PLATFORM_BSD" > platform.h)
  28. @make final
  29. - g++ -Wall $(BFLAGS) $(CFLAGS) -o sancp sancp.o misc_functs.o check_packet.o statefull_logging.o build_acl.o apply_rule.o decode.o pcap_functions.o pcapFileHandle.o fileHandle.o MemoryPool.o permissions.o outputFileHandle.o help.o
  30. + g++ -Wall $(BFLAGS) $(CFLAGS) -o sancp sancp.o misc_functs.o check_packet.o statefull_logging.o build_acl.o apply_rule.o decode.o pcap_functions.o pcapFileHandle.o fileHandle.o MemoryPool.o permissions.o outputFileHandle.o help.o `libprelude-config --libs` `libprelude-config --ldflags`
  31. linux :
  32. @(echo "#define PLATFORM_LINUX" > platform.h)
  33. @make final
  34. - g++ -Wall $(LFLAGS) $(CFLAGS) -o sancp sancp.o misc_functs.o check_packet.o statefull_logging.o build_acl.o apply_rule.o decode.o pcap_functions.o pcapFileHandle.o fileHandle.o MemoryPool.o permissions.o outputFileHandle.o help.o
  35. + g++ -Wall $(LFLAGS) $(CFLAGS) -o sancp sancp.o misc_functs.o check_packet.o statefull_logging.o build_acl.o apply_rule.o decode.o pcap_functions.o pcapFileHandle.o fileHandle.o MemoryPool.o permissions.o outputFileHandle.o help.o `libprelude-config --libs` `libprelude-config --ldflags`
  36. diff -ruN sancp-1.6.1-stable.vanilla/apply_rule.cc sancp-1.6.1-stable/apply_rule.cc
  37. --- sancp-1.6.1-stable.vanilla/apply_rule.cc 2007-07-05 18:12:20.000000000 +0200
  38. +++ sancp-1.6.1-stable/apply_rule.cc 2007-07-24 13:44:01.000000000 +0200
  39. @@ -47,6 +47,12 @@
  40. tc->tcplag=myacl->tcplag;
  41. tc->status=myacl->status;
  42. tc->rid=myacl->rid;
  43. + tc->prelude_impact_severity=myacl->prelude_impact_severity;
  44. + tc->prelude_impact_completion=myacl->prelude_impact_completion;
  45. + tc->prelude_impact_type=myacl->prelude_impact_type;
  46. + tc->prelude_confidence_rating=myacl->prelude_confidence_rating;
  47. +
  48. +
  49. if(myacl->pmode==OMODE_UNIQ)
  50. {
  51. @@ -112,6 +118,10 @@
  52. nc->rgid=myacl->rgid;
  53. nc->zone=myacl->zone;
  54. nc->node=myacl->node;
  55. + nc->prelude_impact_severity=myacl->prelude_impact_severity;
  56. + nc->prelude_impact_completion=myacl->prelude_impact_completion;
  57. + nc->prelude_impact_type=myacl->prelude_impact_type;
  58. + nc->prelude_confidence_rating=myacl->prelude_confidence_rating;
  59. myacl->ctr++;
  60. return;
  61. }
  62. @@ -130,6 +140,10 @@
  63. nc->timeout=gVars.default_timeout;
  64. nc->tcplag=gVars.default_tcplag;
  65. nc->node=gVars.default_node;
  66. + nc->prelude_impact_severity=gVars.prelude_impact_severity;
  67. + nc->prelude_impact_completion=gVars.prelude_impact_completion;
  68. + nc->prelude_impact_type=gVars.prelude_impact_type;
  69. + nc->prelude_confidence_rating=gVars.prelude_confidence_rating;
  70. gVars.default_ctr++;
  71. #ifdef DEBUG
  72. printf("Setting stats: %d pcap: %d realtime: %d limit: %d timeout: %d tcplag: %d\n", nc->stats, nc->pcap, nc->realtime, nc->limit, nc->timeout, nc->tcplag);
  73. diff -ruN sancp-1.6.1-stable.vanilla/build_acl.cc sancp-1.6.1-stable/build_acl.cc
  74. --- sancp-1.6.1-stable.vanilla/build_acl.cc 2007-07-05 18:12:20.000000000 +0200
  75. +++ sancp-1.6.1-stable/build_acl.cc 2007-07-24 13:44:01.000000000 +0200
  76. @@ -1168,6 +1168,62 @@
  77. fprintf(stdout,"Didn't set default for %s to %s\n",tok,tmp);
  78. #endif
  79. }
  80. + if(strcmp(tok,"prelude_impact_severity")==0)
  81. + {
  82. + if((tmp = get_tok(&rules,accept))==NULL)
  83. + {
  84. + syslog(LOG_ERR,"Format error, prelude_impact_severity specified but none provided, using prelude_impact_severity %s\n",PRELUDE_IMPACT_SEVERITY);
  85. + free(rule);
  86. + return;
  87. + }
  88. + gVars.prelude_impact_severity = strdup(tmp);
  89. + free(rule);
  90. + }
  91. + if(strcmp(tok,"prelude_impact_completion")==0)
  92. + {
  93. + if((tmp = get_tok(&rules,accept))==NULL)
  94. + {
  95. + syslog(LOG_ERR,"Format error, prelude_impact_completion specified but none provided, using prelude_impact_completion %s\n",PRELUDE_IMPACT_COMPLETION);
  96. + free(rule);
  97. + return;
  98. + }
  99. + gVars.prelude_impact_completion = strdup(tmp);
  100. + free(rule);
  101. + }
  102. + if(strcmp(tok,"prelude_impact_type")==0)
  103. + {
  104. + if((tmp = get_tok(&rules,accept))==NULL)
  105. + {
  106. + syslog(LOG_ERR,"Format error, prelude_impact_type specified but none provided, using prelude_impact_type %s\n",PRELUDE_IMPACT_TYPE);
  107. + free(rule);
  108. + return;
  109. + }
  110. + gVars.prelude_impact_type = strdup(tmp);
  111. + free(rule);
  112. + }
  113. + if(strcmp(tok,"prelude_confidence_rating")==0)
  114. + {
  115. + if((tmp = get_tok(&rules,accept))==NULL)
  116. + {
  117. + syslog(LOG_ERR,"Format error, prelude_confidence_rating specified but none provided, using prelude_confidence_rating %s\n",PRELUDE_CONFIDENCE_RATING);
  118. + free(rule);
  119. + return;
  120. + }
  121. + gVars.prelude_confidence_rating = strdup(tmp);
  122. + free(rule);
  123. + }
  124. + if(strcmp(tok,"prelude_profile")==0)
  125. + {
  126. + if((tmp = get_tok(&rules,accept))==NULL)
  127. + {
  128. + syslog(LOG_ERR,"Format error, prelude_profile specified but none provided, using prelude_profile %s\n",PRELUDE_PROFILE);
  129. + free(rule);
  130. + return;
  131. + }
  132. + gVars.prelude_profile = strdup(tmp);
  133. + free(rule);
  134. + }
  135. +
  136. }
  137. void parse_var(char *c_rule, char *accept)
  138. @@ -1426,6 +1482,10 @@
  139. }else{
  140. n_acl->fH = 0;
  141. }
  142. + n_acl->prelude_impact_severity = gVars.prelude_impact_severity;
  143. + n_acl->prelude_impact_completion = gVars.prelude_impact_completion;
  144. + n_acl->prelude_impact_type = gVars.prelude_impact_type;
  145. + n_acl->prelude_confidence_rating = gVars.prelude_confidence_rating;
  146. // FIELD 0 - required - Get the h_proto
  147. n_acl->h_proto_h = 0xFFFF;
  148. @@ -2061,6 +2121,46 @@
  149. n_acl->retro = true;
  150. continue;
  151. }
  152. + if(strcmp(tok,"severity")==0)
  153. + {
  154. + if((tmp = get_tok(rules,accept))==NULL)
  155. + {
  156. + syslog(LOG_ERR,"Format error, severity specified but no option provided%s\n",rule);
  157. + return;
  158. + }
  159. + n_acl->prelude_impact_severity = strdup(tmp);
  160. + continue;
  161. + }
  162. + if(strcmp(tok,"completion")==0)
  163. + {
  164. + if((tmp = get_tok(rules,accept))==NULL)
  165. + {
  166. + syslog(LOG_ERR,"Format error, completion specified but no option provided%s\n",rule);
  167. + return;
  168. + }
  169. + n_acl->prelude_impact_completion = strdup(tmp);
  170. + continue;
  171. + }
  172. + if(strcmp(tok,"type")==0)
  173. + {
  174. + if((tmp = get_tok(rules,accept))==NULL)
  175. + {
  176. + syslog(LOG_ERR,"Format error, type specified but no option provided%s\n",rule);
  177. + return;
  178. + }
  179. + n_acl->prelude_impact_type = strdup(tmp);
  180. + continue;
  181. + }
  182. + if(strcmp(tok,"confidence")==0)
  183. + {
  184. + if((tmp = get_tok(rules,accept))==NULL)
  185. + {
  186. + syslog(LOG_ERR,"Format error, confidence specified but no option provided%s\n",rule);
  187. + return;
  188. + }
  189. + n_acl->prelude_confidence_rating = strdup(tmp);
  190. + continue;
  191. + }
  192. syslog(LOG_ERR,"Skipping, invalid option in rule: %s %s\n", tok,*rules);
  193. return;
  194. }
  195. diff -ruN sancp-1.6.1-stable.vanilla/docs/README sancp-1.6.1-stable/docs/README
  196. --- sancp-1.6.1-stable.vanilla/docs/README 2007-07-06 03:33:14.000000000 +0200
  197. +++ sancp-1.6.1-stable/docs/README 2007-07-24 13:44:01.000000000 +0200
  198. @@ -277,6 +277,10 @@
  199. strip-80211 { disable|enable }
  200. node <number>
  201. debug_pcap_raw { disable|enable }
  202. + prelude_impact_severity [string]
  203. + prelude_impact_completion [string]
  204. + prelude_impact_type [string]
  205. + prelude_confidence_rating [string]
  206. known_port syntax:
  207. -----------------------:
  208. @@ -310,6 +314,9 @@
  209. b) tagging options
  210. i.e. status=16 rid=1112 node=2
  211. + c) prelude options
  212. + i.e. severity=severe, completion=succeeded, type=other, confidence=high
  213. +
  214. [<ether protocol>[-<end_range>] [<src_ip{/<CIDR>|<dotted>}>] [<dst_ip{/<CIDR>|<dotted>}>] [{tcp|udp|icmp|<proto number>[-<end_range>] }]
  215. [<src_port>{-[<end_port_range>]}] [<dst_port>{-[<end_port_range>]}]
  216. { ignore | stats [{log|pass}] | realtime [{log|pass}] |
  217. diff -ruN sancp-1.6.1-stable.vanilla/gvars.h sancp-1.6.1-stable/gvars.h
  218. --- sancp-1.6.1-stable.vanilla/gvars.h 2007-07-05 18:12:20.000000000 +0200
  219. +++ sancp-1.6.1-stable/gvars.h 2007-07-24 13:44:01.000000000 +0200
  220. @@ -17,7 +17,8 @@
  221. /* Make certain all id's are represented in the same order (as strings) in fmtnames[] */
  222. /* 'null' is a place holder - in the list for field 0 */
  223. -enum id {null,sancp_id,start_time_gmt,start_time_local,stop_time_gmt,stop_time_local,erased_time_gmt,erased_time_local,eth_proto_hex,eth_proto,ip_proto,src_ip_decimal,src_ip_dotted,src_port,dst_ip_decimal,dst_ip_dotted,dst_port,duration,timeout,src_pkts,dst_pkts,src_bytes,dst_bytes,sflags_hex,sflags,sflags_1,sflags_2,sflags_U,sflags_A,sflags_P,sflags_R,sflags_S,sflags_F,dflags_hex,dflags,dflags_1,dflags_2,dflags_U,dflags_A,dflags_P,dflags_R,dflags_S,dflags_F,cflags_hex,cflags,cflags_DA,cflags_SA,cflags_DR,cflags_SR,cflags_DF,cflags_SF,ip_len_s,ip_ttl_s,ip_df_s,tcp_wss_s,tcp_mss_s,tcp_wscale_s,tcp_sack_ok_s,tcp_nop_s,ip_len_d,ip_ttl_d,ip_df_d,tcp_wss_d,tcp_mss_d,tcp_wscale_d,tcp_sack_ok_d,tcp_nop_d,total_bytes,collect,collected,climit,tcplag,pcap,realtime,stats,reversed,hash,rid,rgid,node,zone,status,retro,src_mac,dst_mac };
  224. +enum id
  225. +{null,sancp_id,start_time_gmt,start_time_local,stop_time_gmt,stop_time_local,erased_time_gmt,erased_time_local,eth_proto_hex,eth_proto,ip_proto,src_ip_decimal,src_ip_dotted,src_port,dst_ip_decimal,dst_ip_dotted,dst_port,duration,timeout,src_pkts,dst_pkts,src_bytes,dst_bytes,sflags_hex,sflags,sflags_1,sflags_2,sflags_U,sflags_A,sflags_P,sflags_R,sflags_S,sflags_F,dflags_hex,dflags,dflags_1,dflags_2,dflags_U,dflags_A,dflags_P,dflags_R,dflags_S,dflags_F,cflags_hex,cflags,cflags_DA,cflags_SA,cflags_DR,cflags_SR,cflags_DF,cflags_SF,ip_len_s,ip_ttl_s,ip_df_s,tcp_wss_s,tcp_mss_s,tcp_wscale_s,tcp_sack_ok_s,tcp_nop_s,ip_len_d,ip_ttl_d,ip_df_d,tcp_wss_d,tcp_mss_d,tcp_wscale_d,tcp_sack_ok_d,tcp_nop_d,total_bytes,collect,collected,climit,tcplag,pcap,realtime,stats,reversed,hash,rid,rgid,node,zone,status,retro,src_mac,dst_mac,prelude_impact_sevirty,prelude_impact_completion,prelude_impact_type,prelude_confidence_rating,prelude_profile };
  226. struct cnx_queue {
  227. struct cnx *head;
  228. @@ -102,5 +103,10 @@
  229. int stdout_fmt_len;
  230. pcap_t *ph; // pcap handle
  231. struct pcap_pkthdr *g_pkthdr;//
  232. + char *prelude_impact_severity;
  233. + char *prelude_impact_completion;
  234. + char *prelude_impact_type;
  235. + char *prelude_confidence_rating;
  236. + char *prelude_profile;
  237. };
  238. diff -ruN sancp-1.6.1-stable.vanilla/sancp.cc sancp-1.6.1-stable/sancp.cc
  239. --- sancp-1.6.1-stable.vanilla/sancp.cc 2007-07-05 18:12:20.000000000 +0200
  240. +++ sancp-1.6.1-stable/sancp.cc 2007-07-24 13:44:01.000000000 +0200
  241. @@ -48,7 +48,40 @@
  242. //char dfltfmt[]= { sancp_id,start_time_gmt,src_mac,dst_mac,eth_proto,src_ip_dotted,dst_ip_dotted,ip_proto,src_port,dst_port };
  243. char dfltfmt_human_readable[]= { sancp_id,start_time_gmt,stop_time_gmt,erased_time_gmt,eth_proto,ip_proto,src_ip_dotted,src_port,dst_ip_dotted,dst_port,duration,timeout,src_pkts,dst_pkts,src_bytes,dst_bytes,sflags_hex,dflags_hex,cflags_hex,ip_len_s,ip_ttl_s,ip_df_s,tcp_wss_s,tcp_mss_s,tcp_wscale_s,tcp_sack_ok_s,tcp_nop_s,ip_len_d,ip_ttl_d,ip_df_d,tcp_wss_d,tcp_mss_d,tcp_wscale_d,tcp_sack_ok_d,tcp_nop_d,total_bytes,collect,collected,climit,tcplag,pcap,realtime,stats,reversed,hash,rid,rgid,node,zone,status,retro,src_mac,dst_mac };
  244. +prelude_client_t *client;
  245. +static idmef_analyzer_t *idmef_analyzer;
  246. +int sancp_alert_init(prelude_client_t *client)
  247. +{
  248. + int ret;
  249. + prelude_string_t *string;
  250. +
  251. + idmef_analyzer = prelude_client_get_analyzer(client);
  252. + if ( ! idmef_analyzer )
  253. + return -1;
  254. +
  255. + ret = idmef_analyzer_new_model(idmef_analyzer, &string);
  256. + if ( ret < 0 )
  257. + return -1;
  258. + prelude_string_set_constant(string, PRELUDE_ANALYZER_MODEL);
  259. +
  260. + ret = idmef_analyzer_new_class(idmef_analyzer, &string);
  261. + if ( ret < 0 )
  262. + return -1;
  263. + prelude_string_set_constant(string, PRELUDE_ANALYZER_CLASS);
  264. +
  265. + ret = idmef_analyzer_new_manufacturer(idmef_analyzer, &string);
  266. + if ( ret < 0 )
  267. + return -1;
  268. + prelude_string_set_constant(string, PRELUDE_ANALYZER_MANUFACTURER);
  269. +
  270. + ret = idmef_analyzer_new_version(idmef_analyzer, &string);
  271. + if ( ret < 0 )
  272. + return -1;
  273. + prelude_string_set_constant(string, VERSION);
  274. +
  275. + return 0;
  276. +}
  277. /*************
  278. * Main *
  279. *************/
  280. @@ -56,6 +89,7 @@
  281. int main(int argc, char *argv[]) {
  282. extern struct gvars gVars;
  283. int cKey;
  284. + int ret;
  285. pid_t pid=0;
  286. /*
  287. @@ -102,6 +136,14 @@
  288. gVars.stdout_delimiter=DEFAULT_DELIMITER;
  289. gVars.stdout_eor=DEFAULT_EOR;
  290. + gVars.prelude_impact_severity=PRELUDE_IMPACT_SEVERITY;
  291. + gVars.prelude_impact_completion=PRELUDE_IMPACT_COMPLETION;
  292. + gVars.prelude_impact_type=PRELUDE_IMPACT_TYPE;
  293. + gVars.prelude_confidence_rating=PRELUDE_CONFIDENCE_RATING;
  294. + gVars.prelude_profile=PRELUDE_PROFILE;
  295. +
  296. +
  297. +
  298. for(cKey=0; cKey<HASH_KEYS; cKey++)
  299. {
  300. gVars.cnx_head[cKey]=NULL;
  301. @@ -116,6 +158,8 @@
  302. parse_args(argc, argv);
  303. +
  304. +
  305. if(gVars.human_readable){
  306. if(gVars.realtime_fmt_len!=sizeof(dfltfmt_human_readable)){
  307. free(gVars.realtime_fmt);
  308. @@ -143,7 +187,15 @@
  309. setsid();
  310. }
  311. + prelude_log_set_flags((prelude_log_flags_t)PRELUDE_LOG_FLAGS_SYSLOG);
  312. }
  313. +
  314. + /* Initialize prelude */
  315. + ret = prelude_init(&argc, argv);
  316. + if (ret < 0) {
  317. + prelude_perror(ret, "unable to initialize the prelude library");
  318. + exit_all(0);
  319. + }
  320. /* Retrieve the last cnxid from cache file if we haven't already in parse_args() */
  321. if(!gVars.cnx_id)
  322. @@ -197,6 +249,29 @@
  323. build_config(1);
  324. + /* Create prelude sensor */
  325. +
  326. + ret = prelude_client_new(&client, gVars.prelude_profile);
  327. + if ( ! client ) {
  328. + prelude_perror(ret, "Unable to create a prelude client object");
  329. + exit_all(0);
  330. + }
  331. +
  332. + /* Start prelude sensor */
  333. + sancp_alert_init(client);
  334. + ret = prelude_client_start(client);
  335. + if ( ret < 0 ) {
  336. + prelude_perror(ret, "Unable to start prelude client");
  337. + exit_all(0);
  338. + }
  339. +
  340. + ret = prelude_client_set_flags(client, (prelude_client_flags_t)
  341. + (PRELUDE_CLIENT_FLAGS_ASYNC_SEND|PRELUDE_CLIENT_FLAGS_ASYNC_TIMER));
  342. + if ( ret < 0 ) {
  343. + fprintf(stderr, "Unable to set asynchronous send and timer.\n");
  344. + exit_all(0);
  345. + }
  346. +
  347. /* Open files for output */
  348. /* Be r3al l33t h3r3 */
  349. diff -ruN sancp-1.6.1-stable.vanilla/sancp.h sancp-1.6.1-stable/sancp.h
  350. --- sancp-1.6.1-stable.vanilla/sancp.h 2007-07-06 06:18:04.000000000 +0200
  351. +++ sancp-1.6.1-stable/sancp.h 2007-07-24 13:44:01.000000000 +0200
  352. @@ -47,6 +47,10 @@
  353. #include "gvars.h"
  354. #endif
  355. +#include <libprelude/prelude.h>
  356. +#include <libprelude/prelude-log.h>
  357. +#include <netdb.h>
  358. +
  359. #define NCP_H
  360. #define Y 'Y'
  361. #define N 'N'
  362. @@ -79,6 +83,7 @@
  363. struct vars *next;
  364. };
  365. +extern prelude_client_t *client;
  366. int main(int argc, char *argv[]);
  367. struct cnx *process(struct cnx*, int len, u_char * pkt);
  368. char * createPcapFileName();
  369. @@ -185,6 +190,15 @@
  370. #define OMODE_RULE 5
  371. #define OMODE_UNIQ 6
  372. +#define PRELUDE_IMPACT_SEVERITY "medium"
  373. +#define PRELUDE_IMPACT_COMPLETION "succeeded"
  374. +#define PRELUDE_IMPACT_TYPE "other"
  375. +#define PRELUDE_CONFIDENCE_RATING "high"
  376. +#define PRELUDE_ANALYZER_MODEL "Sancp"
  377. +#define PRELUDE_ANALYZER_CLASS "NIDS"
  378. +#define PRELUDE_ANALYZER_MANUFACTURER "http://www.metre.net/sancp.html"
  379. +#define PRELUDE_PROFILE "sancp"
  380. +
  381. // Need to distinguish between classes of variables
  382. #define VCLASS_0 1 // eth_proto class vars
  383. #define VCLASS_1 2 // ip_addr class vars
  384. @@ -276,6 +290,10 @@
  385. u_int16_t rgid;
  386. u_int16_t node;
  387. u_int16_t zone;
  388. + char *prelude_impact_severity;
  389. + char *prelude_impact_completion;
  390. + char *prelude_impact_type;
  391. + char *prelude_confidence_rating;
  392. CBuffer *CBufferPtr;
  393. struct acl *next;
  394. };
  395. @@ -314,6 +332,10 @@
  396. u_int16_t rgid;
  397. u_int16_t node;
  398. u_int16_t zone;
  399. + char *prelude_impact_severity;
  400. + char *prelude_impact_completion;
  401. + char *prelude_impact_type;
  402. + char *prelude_confidence_rating;
  403. CBuffer *CBufferPtr;
  404. struct os_info os_info;
  405. struct os_info os_info2;
  406. diff -ruN sancp-1.6.1-stable.vanilla/statefull_logging.cc sancp-1.6.1-stable/statefull_logging.cc
  407. --- sancp-1.6.1-stable.vanilla/statefull_logging.cc 2007-07-05 18:12:20.000000000 +0200
  408. +++ sancp-1.6.1-stable/statefull_logging.cc 2007-07-24 13:44:01.000000000 +0200
  409. @@ -183,6 +183,208 @@
  410. snprintf(buf,len,"%s",currenttime);
  411. }
  412. +static int add_idmef_object(idmef_message_t *message, const char *object, const char *value)
  413. +{
  414. + int ret;
  415. + idmef_value_t *val;
  416. + idmef_path_t *path;
  417. +
  418. + ret = idmef_path_new(&path, object);
  419. + if ( ret < 0 )
  420. + return -1;
  421. +
  422. + ret = idmef_value_new_from_path(&val, path, value);
  423. + if ( ret < 0 ) {
  424. + idmef_path_destroy(path);
  425. + return -1;
  426. + }
  427. +
  428. + ret = idmef_path_set(path, message, val);
  429. +
  430. + idmef_value_destroy(val);
  431. + idmef_path_destroy(path);
  432. +
  433. + return ret;
  434. +}
  435. +
  436. +#define IDMEF(x) { \
  437. + int ret = (x); \
  438. + if (ret < 0) { idmef_message_destroy(idmef); printf("error\n"); return; } \
  439. + }
  440. +
  441. +void record_prelude(struct cnx *cn) {
  442. + char LOG[MAXENTRYLEN];
  443. +
  444. + idmef_message_t *idmef;
  445. + idmef_alert_t *alert;
  446. + idmef_time_t *time;
  447. +
  448. + struct servent *sourceservent;
  449. + struct protoent *protoent;
  450. +
  451. + IDMEF(idmef_message_new(&idmef));
  452. + IDMEF(idmef_message_new_alert(idmef, &alert));
  453. +
  454. + /* alert.detecttime */
  455. + if (cn->start_time) {
  456. + IDMEF(idmef_time_new_from_time(&time, &cn->start_time));
  457. + } else {
  458. + /* using the curen time */
  459. + IDMEF(idmef_time_new_from_gettimeofday(&time));
  460. + }
  461. + idmef_alert_set_detect_time(alert, time);
  462. +
  463. + /* alert.createtime */
  464. + time = NULL;
  465. + IDMEF(idmef_time_new_from_gettimeofday(&time));
  466. + idmef_alert_set_create_time(alert, time);
  467. +
  468. + /* alert.analyzer */
  469. + idmef_alert_set_analyzer(alert,idmef_analyzer_ref(prelude_client_get_analyzer(client)),0);
  470. +
  471. + /* alert.classification.text */
  472. + add_idmef_object(idmef, "alert.classification.text",
  473. + "Unauthorized network connectivity");
  474. +
  475. + /* alert.messageid */
  476. + snprintf(LOG,MAXENTRYLEN,"%lld",cn->cid);
  477. + add_idmef_object(idmef, "alert.messageid", LOG);
  478. +
  479. + /* alert.impact.severity */
  480. + add_idmef_object(idmef, "alert.assessment.impact.severity",
  481. + cn->prelude_impact_severity);
  482. +
  483. + /* alert.impact.completion */
  484. + add_idmef_object(idmef, "alert.assessment.impact.completion",
  485. + cn->prelude_impact_completion);
  486. +
  487. + /* alert.impact.type */
  488. + add_idmef_object(idmef, "alert.assessment.impact.type",
  489. + cn->prelude_impact_type);
  490. +
  491. + /* alert.confidence.rating */
  492. + add_idmef_object(idmef, "alert.assessment.confidence.rating",
  493. + cn->prelude_confidence_rating);
  494. +
  495. + /* alert.additionaldata(0) */
  496. + add_idmef_object(idmef, "alert.additionaldata(0).type", "integer");
  497. + add_idmef_object(idmef, "alert.additionaldata(0).meaning", "status");
  498. + snprintf(LOG,MAXENTRYLEN,"%u",cn->status);
  499. + add_idmef_object(idmef, "alert.additionaldata(0).integer", LOG);
  500. +
  501. + /* alert.additionaldata(1) */
  502. + add_idmef_object(idmef, "alert.additionaldata(1).type", "integer");
  503. + add_idmef_object(idmef, "alert.additionaldata(1).meaning", "Network node");
  504. + snprintf(LOG,MAXENTRYLEN,"%u",cn->node);
  505. + add_idmef_object(idmef, "alert.additionaldata(1).integer", LOG);
  506. +
  507. + /* IP versios */
  508. + if (cn->h_proto == 8) {
  509. + add_idmef_object(idmef, "alert.source(0).service.ip_version", "4");
  510. + add_idmef_object(idmef, "alert.target(0).service.ip_version", "4");
  511. + } else {
  512. + /* bail out */
  513. + idmef_message_destroy(idmef);
  514. + return;
  515. + }
  516. +
  517. + /* alert.source(0).node.address(0) (ip address) */
  518. + if(cn->reversed==CNX_REVERSED){
  519. + snprintf_inaddr_toa(LOG,MAXENTRYLEN,(struct in_addr*) &cn->d_ip,'\0');
  520. + }else{
  521. + snprintf_inaddr_toa(LOG,MAXENTRYLEN,(struct in_addr*) &cn->s_ip,'\0');
  522. + }
  523. + add_idmef_object(idmef, "alert.source(0).node.address(0).category",
  524. + "ipv4-addr");
  525. + add_idmef_object(idmef, "alert.source(0).node.address(0).address", LOG);
  526. +
  527. + /* alert.source(0).node.address(1) (mac address) */
  528. + add_idmef_object(idmef, "alert.source(0).node.address(1).category", "mac");
  529. + {
  530. + struct myether_addr *es=(struct myether_addr *)&cn->eth_hdr.ether_shost;
  531. + snprintf(LOG,MAXENTRYLEN,"%0x:%0x:%0x:%0x:%0x:%0x",es->octet[0],es->octet[1],es->octet[2],es->octet[3],es->octet[4],es->octet[5]);
  532. + }
  533. + add_idmef_object(idmef, "alert.source(0).node.address(1).address", LOG);
  534. +
  535. + protoent = getprotobynumber(cn->proto);
  536. +
  537. + /* alert.source(0).iana_protocol_number */
  538. + snprintf(LOG,MAXENTRYLEN,"%u",(cn->proto));
  539. + add_idmef_object(idmef, "alert.source(0).service.iana_protocol_number", LOG);
  540. +
  541. + /* alert.target(0).iana_protocol_number */
  542. + add_idmef_object(idmef, "alert.target(0).service.iana_protocol_number", LOG);
  543. +
  544. +
  545. + if (protoent) {
  546. + /* alert.source(0).iana_protocol_name */
  547. + add_idmef_object(idmef, "alert.source(0).service.iana_protocol_name",
  548. + protoent->p_name);
  549. +
  550. + /* alert.target(0).iana_protocol_name */
  551. + add_idmef_object(idmef, "alert.target(0).service.iana_protocol_name",
  552. + protoent->p_name);
  553. +
  554. + /* alert.source(0).service */
  555. + setservent(1);
  556. + if(cn->reversed==CNX_REVERSED){
  557. + snprintf(LOG,MAXENTRYLEN,"%u",ntohs(cn->d_port));
  558. + sourceservent = getservbyport(ntohs(cn->d_port), protoent->p_name);
  559. + }else{
  560. + snprintf(LOG,MAXENTRYLEN,"%u",ntohs(cn->s_port));
  561. + sourceservent = getservbyport(ntohs(cn->s_port), protoent->p_name);
  562. + }
  563. +
  564. + if (sourceservent && sourceservent->s_name)
  565. + add_idmef_object(idmef, "alert.source(0).service.name",
  566. + sourceservent->s_name );
  567. + add_idmef_object(idmef, "alert.source(0).service.port",
  568. + LOG);
  569. + add_idmef_object(idmef, "alert.source(0).service.protocol",
  570. + protoent->p_name);
  571. +
  572. + /* alert.target(0).service */
  573. + if(cn->reversed==CNX_REVERSED){
  574. + snprintf(LOG,MAXENTRYLEN,"%u",ntohs(cn->s_port));
  575. + sourceservent = getservbyport(ntohs(cn->s_port), protoent->p_name);
  576. + }else{
  577. + snprintf(LOG,MAXENTRYLEN,"%u",ntohs(cn->d_port));
  578. + sourceservent = getservbyport(ntohs(cn->d_port), protoent->p_name);
  579. + }
  580. +
  581. + if (sourceservent && sourceservent->s_name)
  582. + add_idmef_object(idmef, "alert.target(0).service.name",
  583. + sourceservent->s_name );
  584. + add_idmef_object(idmef, "alert.target(0).service.port",
  585. + LOG);
  586. + add_idmef_object(idmef, "alert.target(0).service.protocol",
  587. + protoent->p_name);
  588. + }
  589. +/*
  590. +*/
  591. +
  592. + /* alert.target(0).node.address(0) (ip address) */
  593. + if(cn->reversed==CNX_REVERSED){
  594. + snprintf_inaddr_toa(LOG,MAXENTRYLEN,(struct in_addr*) &cn->s_ip,'\0');
  595. + }else{
  596. + snprintf_inaddr_toa(LOG,MAXENTRYLEN,(struct in_addr*) &cn->d_ip,'\0');
  597. + }
  598. + add_idmef_object(idmef, "alert.target(0).node.address(0).category",
  599. + "ipv4-addr");
  600. + add_idmef_object(idmef, "alert.target(0).node.address(0).address", LOG);
  601. +
  602. + /* alert.target(0).node_address(1) (mac address) */
  603. + add_idmef_object(idmef, "alert.target(0).node.address(1).category", "mac");
  604. + {
  605. + struct myether_addr *es=(struct myether_addr *)&cn->eth_hdr.ether_dhost;
  606. + snprintf(LOG,MAXENTRYLEN,"%0x:%0x:%0x:%0x:%0x:%0x",es->octet[0],es->octet[1],es->octet[2],es->octet[3],es->octet[4],es->octet[5]);
  607. + }
  608. + add_idmef_object(idmef, "alert.target(0).node.address(1).address", LOG);
  609. +
  610. + prelude_client_send_idmef(client, idmef);
  611. + idmef_message_destroy(idmef);
  612. +}
  613. +
  614. void record(struct cnx *cn, outputFileHandle *fH)
  615. {
  616. @@ -199,8 +401,15 @@
  617. char eor=fH->getEor();
  618. + /* do we want prelude alert generation for this record? */
  619. +
  620. bzero(LOG,MAXENTRYLEN);
  621. + if (fH == gVars.sfH) {
  622. + record_prelude(cn);
  623. + }
  624. +
  625. +
  626. /*
  627. * Structure of a 48-bit Ethernet address.