I am able to apply the patch without any trouble, and barnyard2 compiles without any errors.
But Barnyard2 never seems to actually update the ip_source header field with the Original Client IP.
I wonder if the Barnyard2 devs can give any insight. I have sent this same email to the author of the patch as well.
- platform is debian squeeze
- using mysql backend 5.1.61-0+squeeze1
- snort 2.9.2.2
- barnyard2-1.9
I am starting barnyard2 like so (please note the "-j" option, which is added by the patch):
/usr/local/bin/barnyard2 -j -c /usr/local/etc/barnyard2.conf -d /var/log/snort/VLAN15 -f snortunified2.log -w /tmp/waldo -G /etc/snort/gen-msg.map -S /etc/snort/sid-msg.map -C /etc/snort/classification.config
From what I can tell in unified2 logs, the extrahdr data is logged and recorded appropriately. Record type=110 is being set and logged correctly by snort. Which I can clearly see in u2spewfoo, along with the Original Client IP field.
Barnyard2 w/ Patch appears to process the record (spi_unified2.c -> spooler.c), but the code path in spo_database.c that inserts xff_srcip into database queries never seems to get triggered.
Here is the relevant debug output from Barnyard2 w/ BARNYARD2_DEBUG=
spi_unified2.c:133: Header: Reading at byte position 596
spi_unified2.c:157: Header: Type=110 (36 bytes)
spi_unified2.c:175: Reading record type=110 (36 bytes)
spi_unified2.c:187: Record: Reading at byte position 604
spi_unified2.c:223: No debug available for record type: 110
spooler.c:744: XXF: Extra Data Header found
spooler.c:750: XXF: Data Header is type 4 (ok)
spooler.c:761: Event ID 1 1 1 (blog_lenght: 12
spooler.c:765: XXF: Extra Data is info and data type 1, and data size is 12 (ok)
spooler.c:769: XXF IP: 213.181.x.x [redacted for public consumption]
spooler.c:1107: Waldo write
dir: /var/log/snort/VLAN15
base: snortunified2.log
time: 1335174311
idx: 3
--
spi_unified2.c:133: Header: Reading at byte position 1601
spi_unified2.c:157: Header: Type=110 (36 bytes)
spi_unified2.c:175: Reading record type=110 (36 bytes)
spi_unified2.c:187: Record: Reading at byte position 1609
spi_unified2.c:223: No debug available for record type: 110
spooler.c:744: XXF: Extra Data Header found
spooler.c:750: XXF: Data Header is type 4 (ok)
spooler.c:761: Event ID 2 1 1 (blog_lenght: 12
spooler.c:765: XXF: Extra Data is info and data type 1, and data size is 12 (ok)
spooler.c:769: XXF IP: 188.70.x.x [ redacted for public consumption ]
spooler.c:1107: Waldo write
dir: /var/log/snort/VLAN15
base: snortunified2.log
time: 1335174311
idx: 7
Database debug looks like this. I've verified the integer converteted ip_src is the IP of the proxy server and *not* the IP from XFF:
spo_database.c:2901: database(debug): (INSERT INTO iphdr (sid, cid, ip_src, ip_dst, ip_ver, ip_hlen, ip_tos, ip_len, ip_id, ip_flags, ip_off, ip_ttl, ip_proto, ip_csum) VALUES (1,497,167841290,167838224,4,5,0,1500,56164,0,0,64,6,13724)) executed
Here's the spo_database.c code for XFF:
/* XFF patch - It changes IP packet src ip by alert src ip! */
if (BcUseXFF()) xff_srcip=ntohl(((Unified2IDSEvent *)event)->ip_source);
else xff_srcip=(u_long)ntohl(p->iph->ip_src.s_addr);
if(data->detail)
{
ret = SnortSnprintf(query->val, MAX_QUERY_LENGTH,
"INSERT INTO "
"iphdr (sid, cid, ip_src, ip_dst, ip_ver, ip_hlen, "
" ip_tos, ip_len, ip_id, ip_flags, ip_off,"
" ip_ttl, ip_proto, ip_csum) "
"VALUES (%u,%u,%lu,%lu,%u,%u,%u,%u,%u,%u,%u,%u,%u,%u)",
data->shared->sid,
data->shared->cid,
xff_srcip,
(u_long)ntohl(p->iph->ip_dst.s_addr),
IP_VER(p->iph),
IP_HLEN(p->iph),
p->iph->ip_tos,
ntohs(p->iph->ip_len),
ntohs(p->iph->ip_id),
p->frag_flag,
ntohs(p->frag_offset),
p->iph->ip_ttl,
p->iph->ip_proto,
ntohs(p->iph->ip_csum));
if (ret != SNORT_SNPRINTF_SUCCESS)
goto bad_query;
}