|
|
|
|
@ -1,4 +1,4 @@
|
|
|
|
|
/* Copyright (C) 2007-2010 Open Information Security Foundation
|
|
|
|
|
/* Copyright (C) 2007-2014 Open Information Security Foundation
|
|
|
|
|
*
|
|
|
|
|
* You can copy, redistribute or modify this Program under the terms of
|
|
|
|
|
* the GNU General Public License version 2 as published by the Free
|
|
|
|
|
@ -130,22 +130,22 @@ static int SetupAnalyzer(idmef_analyzer_t *analyzer)
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
ret = idmef_analyzer_new_model(analyzer, &string);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
prelude_string_set_constant(string, ANALYZER_MODEL);
|
|
|
|
|
|
|
|
|
|
ret = idmef_analyzer_new_class(analyzer, &string);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
prelude_string_set_constant(string, ANALYZER_CLASS);
|
|
|
|
|
|
|
|
|
|
ret = idmef_analyzer_new_manufacturer(analyzer, &string);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
prelude_string_set_constant(string, ANALYZER_MANUFACTURER);
|
|
|
|
|
|
|
|
|
|
ret = idmef_analyzer_new_version(analyzer, &string);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
prelude_string_set_constant(string, VERSION);
|
|
|
|
|
|
|
|
|
|
@ -173,11 +173,11 @@ static int EventToImpact(const PacketAlert *pa, const Packet *p, idmef_alert_t *
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
ret = idmef_alert_new_assessment(alert, &assessment);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = idmef_assessment_new_impact(assessment, &impact);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
if ( (unsigned int)pa->s->prio < mid_priority )
|
|
|
|
|
@ -198,7 +198,7 @@ static int EventToImpact(const PacketAlert *pa, const Packet *p, idmef_alert_t *
|
|
|
|
|
idmef_action_t *action;
|
|
|
|
|
|
|
|
|
|
ret = idmef_action_new(&action);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
idmef_action_set_category(action, IDMEF_ACTION_CATEGORY_BLOCK_INSTALLED);
|
|
|
|
|
@ -207,7 +207,7 @@ static int EventToImpact(const PacketAlert *pa, const Packet *p, idmef_alert_t *
|
|
|
|
|
|
|
|
|
|
if (pa->s->class_msg) {
|
|
|
|
|
ret = idmef_impact_new_description(impact, &str);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
prelude_string_set_ref(str, pa->s->class_msg);
|
|
|
|
|
@ -258,11 +258,11 @@ static int EventToSourceTarget(const Packet *p, idmef_alert_t *alert)
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
|
|
|
|
|
ret = idmef_alert_new_source(alert, &source, IDMEF_LIST_APPEND);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = idmef_source_new_service(source, &service);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
if ( p->tcph || p->udph )
|
|
|
|
|
@ -272,25 +272,25 @@ static int EventToSourceTarget(const Packet *p, idmef_alert_t *alert)
|
|
|
|
|
idmef_service_set_iana_protocol_number(service, ip_proto);
|
|
|
|
|
|
|
|
|
|
ret = idmef_source_new_node(source, &node);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = idmef_node_new_address(node, &address, IDMEF_LIST_APPEND);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = idmef_address_new_address(address, &string);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
prelude_string_set_ref(string, saddr);
|
|
|
|
|
|
|
|
|
|
ret = idmef_alert_new_target(alert, &target, IDMEF_LIST_APPEND);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = idmef_target_new_service(target, &service);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
if ( p->tcph || p->udph )
|
|
|
|
|
@ -300,15 +300,15 @@ static int EventToSourceTarget(const Packet *p, idmef_alert_t *alert)
|
|
|
|
|
idmef_service_set_iana_protocol_number(service, ip_proto);
|
|
|
|
|
|
|
|
|
|
ret = idmef_target_new_node(target, &node);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = idmef_node_new_address(node, &address, IDMEF_LIST_APPEND);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = idmef_address_new_address(address, &string);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
prelude_string_set_ref(string, daddr);
|
|
|
|
|
@ -334,25 +334,25 @@ static int AddByteData(idmef_alert_t *alert, const char *meaning, const unsigned
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
|
|
|
|
|
ret = idmef_alert_new_additional_data(alert, &ad, IDMEF_LIST_APPEND);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
|
|
|
|
|
ret = idmef_additional_data_set_byte_string_ref(ad, data, size);
|
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
SCLogDebug("%s: error setting byte string data: %s.",
|
|
|
|
|
prelude_strsource(ret), prelude_strerror(ret));
|
|
|
|
|
SCReturnInt(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = idmef_additional_data_new_meaning(ad, &str);
|
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
SCLogDebug("%s: error creating additional-data meaning: %s.",
|
|
|
|
|
prelude_strsource(ret), prelude_strerror(ret));
|
|
|
|
|
SCReturnInt(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = prelude_string_set_ref(str, meaning);
|
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
SCLogDebug("%s: error setting byte string data meaning: %s.",
|
|
|
|
|
prelude_strsource(ret), prelude_strerror(ret));
|
|
|
|
|
SCReturnInt(-1);
|
|
|
|
|
@ -376,20 +376,20 @@ static int AddIntData(idmef_alert_t *alert, const char *meaning, uint32_t data)
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
ret = idmef_alert_new_additional_data(alert, &ad, IDMEF_LIST_APPEND);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
idmef_additional_data_set_integer(ad, data);
|
|
|
|
|
|
|
|
|
|
ret = idmef_additional_data_new_meaning(ad, &str);
|
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
SCLogDebug("%s: error creating additional-data meaning: %s.",
|
|
|
|
|
prelude_strsource(ret), prelude_strerror(ret));
|
|
|
|
|
SCReturnInt(-1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = prelude_string_set_ref(str, meaning);
|
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
SCLogDebug("%s: error setting integer data meaning: %s.",
|
|
|
|
|
prelude_strsource(ret), prelude_strerror(ret));
|
|
|
|
|
SCReturnInt(-1);
|
|
|
|
|
@ -512,11 +512,11 @@ static int AddSnortReference(idmef_classification_t *class, int gen_id, int sig_
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
|
|
|
|
|
ret = idmef_classification_new_reference(class, &ref, IDMEF_LIST_APPEND);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = idmef_reference_new_name(ref, &str);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
idmef_reference_set_origin(ref, IDMEF_REFERENCE_ORIGIN_VENDOR_SPECIFIC);
|
|
|
|
|
@ -526,19 +526,19 @@ static int AddSnortReference(idmef_classification_t *class, int gen_id, int sig_
|
|
|
|
|
else
|
|
|
|
|
ret = prelude_string_sprintf(str, "%u:%u", gen_id, sig_id);
|
|
|
|
|
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = idmef_reference_new_meaning(ref, &str);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = prelude_string_sprintf(str, "Snort Signature ID");
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = idmef_reference_new_url(ref, &str);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
if ( gen_id == 0 )
|
|
|
|
|
@ -565,18 +565,18 @@ static int EventToReference(const PacketAlert *pa, const Packet *p, idmef_classi
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
ret = idmef_classification_new_ident(class, &str);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
if ( pa->s->gid == 0 )
|
|
|
|
|
ret = prelude_string_sprintf(str, "%u", pa->s->id);
|
|
|
|
|
else
|
|
|
|
|
ret = prelude_string_sprintf(str, "%u:%u", pa->s->gid, pa->s->id);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
ret = AddSnortReference(class, pa->s->gid, pa->s->id);
|
|
|
|
|
if ( ret < 0 )
|
|
|
|
|
if (ret < 0)
|
|
|
|
|
SCReturnInt(ret);
|
|
|
|
|
|
|
|
|
|
SCReturnInt(0);
|
|
|
|
|
@ -676,7 +676,7 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
|
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
|
|
ret = prelude_init(0, NULL);
|
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
prelude_perror(ret, "unable to initialize the prelude library");
|
|
|
|
|
SCReturnPtr(NULL, "AlertPreludeCtx");
|
|
|
|
|
}
|
|
|
|
|
@ -696,7 +696,7 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ret = prelude_client_set_flags(client, prelude_client_get_flags(client) | PRELUDE_CLIENT_FLAGS_ASYNC_TIMER|PRELUDE_CLIENT_FLAGS_ASYNC_SEND);
|
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
SCLogDebug("Unable to set asynchronous send and timer.");
|
|
|
|
|
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
|
|
|
|
|
SCReturnPtr(NULL, "AlertPreludeCtx");
|
|
|
|
|
@ -705,7 +705,7 @@ static OutputCtx *AlertPreludeInitCtx(ConfNode *conf)
|
|
|
|
|
SetupAnalyzer(prelude_client_get_analyzer(client));
|
|
|
|
|
|
|
|
|
|
ret = prelude_client_start(client);
|
|
|
|
|
if ( ret < 0 ) {
|
|
|
|
|
if (ret < 0) {
|
|
|
|
|
prelude_perror(ret, "Unable to start prelude client");
|
|
|
|
|
prelude_client_destroy(client, PRELUDE_CLIENT_EXIT_STATUS_SUCCESS);
|
|
|
|
|
SCReturnPtr(NULL, "AlertPreludeCtx");
|
|
|
|
|
@ -864,7 +864,6 @@ err:
|
|
|
|
|
if (idmef != NULL)
|
|
|
|
|
idmef_message_destroy(idmef);
|
|
|
|
|
SCReturnInt(TM_ECODE_FAILED);
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void TmModuleAlertPreludeRegister (void) {
|
|
|
|
|
|