Merge remote-tracking branch 'origin/fastpath'

* origin/fastpath:
  Fix missing "irc-dcc-data" service field from IRC DCC connections.
  Change X509 extension value parsing to not abort on malloc failures.
This commit is contained in:
Robin Sommer 2014-05-01 20:25:48 -07:00
commit 55dfc54dd6
8 changed files with 78 additions and 27 deletions

View file

@ -1,5 +1,8 @@
2.2-392 | 2014-05-01 09:30:06 -0700 2.2-395 | 2014-05-01 20:25:48 -0700
* Fix missing "irc-dcc-data" service field from IRC DCC connections.
(Jon Siwek)
* Correct a notice for heartbleed. The notice is thrown correctly, * Correct a notice for heartbleed. The notice is thrown correctly,
just the message conteined wrong values. (Bernhard Amann) just the message conteined wrong values. (Bernhard Amann)

View file

@ -1 +1 @@
2.2-392 2.2-395

View file

@ -76,7 +76,7 @@ event irc_dcc_message(c: connection, is_orig: bool,
dcc_expected_transfers[address, p] = c$irc; dcc_expected_transfers[address, p] = c$irc;
} }
event expected_connection_seen(c: connection, a: Analyzer::Tag) &priority=10 event scheduled_analyzer_applied(c: connection, a: Analyzer::Tag) &priority=10
{ {
local id = c$id; local id = c$id;
if ( [id$resp_h, id$resp_p] in dcc_expected_transfers ) if ( [id$resp_h, id$resp_p] in dcc_expected_transfers )

View file

@ -159,6 +159,49 @@ RecordVal* file_analysis::X509::ParseCertificate(X509Val* cert_val)
return pX509Cert; return pX509Cert;
} }
StringVal* file_analysis::X509::GetExtensionFromBIO(BIO* bio)
{
BIO_flush(bio);
ERR_clear_error();
int length = BIO_pending(bio);
if ( ERR_peek_error() != 0 )
{
char tmp[120];
ERR_error_string_n(ERR_get_error(), tmp, sizeof(tmp));
reporter->Error("X509::GetExtensionFromBIO: %s", tmp);
BIO_free_all(bio);
return 0;
}
if ( length == 0 )
{
BIO_free_all(bio);
return new StringVal("");
}
// TODO: see about using regular malloc here, there were unknown problems
// using anything other than OPENSSL_malloc that need investigation.
char* buffer = (char*) OPENSSL_malloc(length);
if ( ! buffer )
{
// Just emit an error here and try to continue instead of aborting
// because it's unclear the length value is very reliable.
reporter->Error("X509::GetExtensionFromBIO malloc(%d) failed", length);
BIO_free_all(bio);
return 0;
}
BIO_read(bio, (void*) buffer, length);
StringVal* ext_val = new StringVal(length, buffer);
OPENSSL_free(buffer);
BIO_free_all(bio);
return ext_val;
}
void file_analysis::X509::ParseExtension(X509_EXTENSION* ex) void file_analysis::X509::ParseExtension(X509_EXTENSION* ex)
{ {
char name[256]; char name[256];
@ -178,20 +221,10 @@ void file_analysis::X509::ParseExtension(X509_EXTENSION* ex)
if( ! X509V3_EXT_print(bio, ex, 0, 0)) if( ! X509V3_EXT_print(bio, ex, 0, 0))
M_ASN1_OCTET_STRING_print(bio,ex->value); M_ASN1_OCTET_STRING_print(bio,ex->value);
BIO_flush(bio); StringVal* ext_val = GetExtensionFromBIO(bio);
int length = BIO_pending(bio);
// Use OPENSSL_malloc here. Using new or anything else can lead if ( ! ext_val )
// to interesting, hard to debug segfaults. ext_val = new StringVal(0, "");
char *buffer = (char*) OPENSSL_malloc(length);
if ( ! buffer )
out_of_memory("X509::ParseExtension");
BIO_read(bio, (void*)buffer, length);
StringVal* ext_val = new StringVal(length, buffer);
OPENSSL_free(buffer);
BIO_free_all(bio);
RecordVal* pX509Ext = new RecordVal(BifType::Record::X509::Extension); RecordVal* pX509Ext = new RecordVal(BifType::Record::X509::Extension);
pX509Ext->Assign(0, new StringVal(name)); pX509Ext->Assign(0, new StringVal(name));

View file

@ -37,6 +37,17 @@ public:
static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file) static file_analysis::Analyzer* Instantiate(RecordVal* args, File* file)
{ return new X509(args, file); } { return new X509(args, file); }
/**
* Retrieve an X509 extension value from an OpenSSL BIO to which it was
* written.
*
* @param bio the OpenSSL BIO to read. It will be freed by the function,
* including when an error occurs.
*
* @return The X509 extension value.
*/
static StringVal* GetExtensionFromBIO(BIO* bio);
protected: protected:
X509(RecordVal* args, File* file); X509(RecordVal* args, File* file);

View file

@ -78,18 +78,10 @@ function x509_get_certificate_string%(cert: opaque of x509, pem: bool &default=F
else else
i2d_X509_bio(bio, h->GetCertificate()); i2d_X509_bio(bio, h->GetCertificate());
BIO_flush(bio); StringVal* ext_val = file_analysis::X509::GetExtensionFromBIO(bio);
int length = BIO_pending(bio);
// use OPENSS_malloc here. Otherwhise, interesting problems will happen.
char *buffer = (char*) OPENSSL_malloc(length);
if ( ! buffer ) if ( ! ext_val )
out_of_memory("x509_get_certificate_string"); ext_val = new StringVal("");
BIO_read(bio, (void*) buffer, length);
StringVal* ext_val = new StringVal(length, buffer);
OPENSSL_free(buffer);
BIO_free_all(bio);
return ext_val; return ext_val;
%} %}

View file

@ -0,0 +1,11 @@
#separator \x09
#set_separator ,
#empty_field (empty)
#unset_field -
#path conn
#open 2014-05-01-19-07-07
#fields ts uid id.orig_h id.orig_p id.resp_h id.resp_p proto service duration orig_bytes resp_bytes conn_state local_orig missed_bytes history orig_pkts orig_ip_bytes resp_pkts resp_ip_bytes tunnel_parents
#types time string addr port addr port enum string interval count count string bool count string count count count count set[string]
1311189318.898709 CjhGID4nQcgTWjvg4c 192.168.1.77 57655 209.197.168.151 1024 tcp irc-dcc-data 2.256935 124 42208 SF - 0 ShAdDaFf 28 1592 43 44452 (empty)
1311189164.064603 CXWv6p3arKYeMETxOg 192.168.1.77 57640 66.198.80.67 6667 tcp irc 178.237017 453 25404 S3 - 0 ShADdaf 63 3761 52 28194 (empty)
#close 2014-05-01-19-07-07

View file

@ -3,6 +3,7 @@
# @TEST-EXEC: bro -r $TRACES/irc-dcc-send.trace %INPUT # @TEST-EXEC: bro -r $TRACES/irc-dcc-send.trace %INPUT
# @TEST-EXEC: btest-diff irc.log # @TEST-EXEC: btest-diff irc.log
# @TEST-EXEC: btest-diff conn.log
# dcc mime types are irrelevant to this test, so filter it out # dcc mime types are irrelevant to this test, so filter it out
event bro_init() event bro_init()