Jun 11

My firewall sees this info, I want it in logs

Hints and Tips, Scripts -
1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.67 out of 5)
Loading ... Loading ...
Add comments

It is common for distributed organizations to have multiple engines in different locations as main gateways for protecting the perimeter of the local network.

Sometimes the firewall sees information that are unrelated specifically to network security; still, these information could be very useful to be centrally collected.

This post shows how it is possible to use StoneGate Central Log Processing to collect this information centrally.

Let’s set a need to be taken as a sample: collect information about network clients at remote location using their MAC address.

The base assumption is that the firewall has the information we’re looking for since it maintains an ARP table, whose content can be queried using CLI command ip n on StoneGate engine.
Sample output from this command would be:
192.168.1.1 dev eth1 lladdr 00:0c:ee:93:11:e5 STALE
192.168.34.80 dev eth0 lladdr 00:21:70:18:9f:cf REACHABLE
192.168.34.100 dev eth0 lladdr 00:0c:ee:b8:1f:56 REACHABLE
192.168.34.210 dev eth0 lladdr 00:0c:ee:b8:1f:56 REACHABLE
1192.168.1.40 dev eth1 lladdr 00:50:56:a9:66:25 REACHABLE

By using some shell scripting,
ip n | awk ‘{print $1 " – " $5 ";"}’

we could easily retrieve a better formatted information, like:
192.168.1.1 – 00:0c:ee:93:11:e5;
192.168.34.80 – 00:21:70:18:9f:cf;
192.168.34.100 – 00:0c:ee:b8:1f:56;
192.168..34.210 – 00:0c:ee:b8:1f:56;
10.1.1.140 – 00:50:56:a9:66:25;

Done this, we could use command sg-logger on StoneGate engine to forward the information to Log Server using the same channel used for standard logs.
The syntax is:
sg-logger – Sends log message

Usage:
  sg-logger -f facility_number -t type_number [-e event_number] [-i "info_string"] [-s] [-h]

Options:
  -f Set facility
  -t Set type
  -e Set event (Default: 0 (H2A_LOG_EVENT_UNDEFINED))
  -i Set info string for log message (Default: "")
  -s Dump information on option numbers to stdout
  -h Show this help message

Let’s now bundle everything in a script that considers only information on eth0:
#!/bin/bash
#Script to send arp table to StoneGate log server
IP_ARP="`ip n | grep eth0 | awk ‘{print $1 " – " $5 ";"}’`"
N=0
STRING_A=""
for i in  $IP_ARP; do
STRING_A="$STRING_A $i"
if [ $N -ge 50 ]; then
echo "IN"
sg-logger -f 8 -t 6 -i "ARP from $HOSTNAME: $STRING_A"
N=0
STRING_A=""
else
let N=$N+1;
fi
done
sg-logger -f 8 -t 6 -i "$ARP from $HOSTNAME: $STRING_A"
exit 0

Launching this script (remember to set execute permissions) will generate an entry in Log Browser with the information needed in info field.

Should you need to run this regularly, you can set it as a script in Tester tab in StoneGate Engine’s properties.

Enjoy!

written by RoarinPenguin - 2,877 views \\ tags: , ,

2 Responses to “My firewall sees this info, I want it in logs”

  1. docstephano Says:

    Ciao,
    Please, I want to see the end of the film…
    Let us show the resulting screenshot in the Log Viewer and help us completing this post with an Alert scenario …

  2. pakki Says:

    Hi,

    few of my nodes are so old (3.x), that there is no awk command. So I made few changes to this script (you should change eth1.220 to something or remove it and HOSTNAME to $HOSTNAME):

    #!/bin/bash
    #Script to send arp table to StoneGate log server
    ip ne | grep eth1.220 >/tmp/arp.output
    exec < /tmp/arp.output
    while read line
    do
    sg-logger -f 8 -t 6 -i “Arp table from HOSTNAME: $line”
    done
    rm -rf /tmp/arp.output
    exit 0

    Output is like:
    Creation time Information Message
    2009-06-24 13:09:26 Arp table from HOSTNAME: 10.202.65.20 dev eth1.220 lladdr 00:21:86:1d:dc:ae nud reachable
    2009-06-24 13:09:26 Arp table from HOSTNAME: 10.202.65.41 dev eth1.220 lladdr 00:11:25:25:56:95 nud reachable

    I can’t see any reason for Alerts, I don’t want to fill up my mailbox with arp tables ;-)

Leave a Reply

You must be logged in to post a comment.