This is a collection of directives for using SAM. Some environment variables have equivalent invocation flags. Environment variables are given preference in this document.
All environment variables can be found in sam/default.cfg.
[section]
key1 = value1
# comment
key2 = value2
The above can be overridden with environment set as follows:
export SAM__SECTION__KEY1=value1
export SAM__SECTION__KEY2=value2
The basic command depends on if you have cloned the repository or installed via pip.
If one has the repo, commands are executed as python sam/launcher.py ...
If one has the pip package samapper, commands are executed as samapper ...
It is strongly advised to install mysql for running SAM.
apt-get install python-dev mysql-server libmysqlclient-dev
Common environment variables:
export SAM__DATABASE__DBN=mysql
(database engine. mysql or sqlite)export SAM__DATABASE__DB=samdb
(database name)export SAM__DATABASE__USER=root
(database access username)export SAM__DATABASE__PW=mypass
(database access password)export SAM__WEBSERVER__LISTEN_PORT=8080
python sam/launcher.py --target=webserver
Given that plugins 'plugin1' and 'plugin2' have been placed in the folder '/opt/sam/plugins', configure your environment as follows:
export SAM__PLUGINS__ROOT=/opt/sam/plugins
export SAM__PLUGINS__ENABLED=ALL
(or comma-separated...=plugin1,plugin2
or a single plugin...=plugin2
)
python sam/launcher.py --target=webserver
SAM exposes the WSGI interface. Server software such as apache and nginx can support wsgi applications.
sam/server_webserver.py works as a WSGI endpoint sam/server_aggregator.py works as a WSGI endpoint
Complete server setup instructions are beyond the scope of this document, but the webpy cookbook pages and deployment page provides several examples.
#Collectors and Aggregators SAM is designed for receiving continuous input. The external devices send packets of traffic data to SAM's collectors, SAM's collectors send uniform traffic data to aggregators, and aggregators insert that data into the database.
Collectors are meant to be light and deployed wherever needed to receive traffic, simplify it, and forward it to the server.
Aggregators live on the server with the database and the webserver.
Webservers interact with the db and present web pages to your browser.
- Start up a webserver
export SAM__WEBSERVER__LISTEN_PORT=8080
python sam/launcher.py --target=webserver
- Navigate your browser to http://localhost:8080
- Open the Settings page
- In the Live Updates section, click the generate button to get an access key. Write this down.
- Start up the aggregator
export SAM__AGGREGATOR__LISTEN_PORT=8081
python sam/launcher.py --target=aggregator
- Start up the collector
export SAM__COLLECTOR__LISTEN_HOST=
(leave blank)export SAM__COLLECTOR__LISTEN_PORT=514
(use the port you expect to receive traffic logs on. Note: binding to system ports (<1024) will require privileged execution)export SAM__COLLECTOR__TARGET_ADDRESS=http://localhost:8081
(the address of the aggregator)export SAM__COLLECTOR__UPLOAD_KEY=abc123def456
(the access key you generated earlier)export SAM__COLLECTOR__FORMAT=asasyslog
(the format you expect to receive)python sam/launcher.py --target=collector
It will be visible in stdout of the collector and aggregator when traffic has been received and processed. Nothing will be visible in the webserver until the aggregator has done processing on its first buffer of traffic.
#Import Data
##Import Log Files Importing palo alto syslog file:
python sam/launcher.py --target=import --format=paloalto [--dest=default] /path/to/syslog.log
Where optional argument dest refers to the name of the data source to import in to. The same method applies to files of other formats:
# asa syslog
python sam/launcher.py --target=import --format=asasyslog /path/to/asa.log
# netflow log
python sam/launcher.py --target=import --format=netflow /path/to/nfcapd.1355764892
# tcpdump
python sam/launcher.py --target=import --format=tcpdump /path/to/tcpdump.log
# tshark
python sam/launcher.py --target=import --format=tshark /path/to/tshark.pcap
The following pipes collection of local traffic via tcpdump directly into sam, and enables WHOIS lookup on the IPs. After collecting for a minute or two, the traffic will be visible at localhost:8080. Note that network traffic collection is perfomed with elevated priviledges.
sudo tcpdump -i any -f --immediate-mode -l -n -Q inout -tt | python sam/launcher.py --local --whois --format=tcpdump
# data collection can be omitted of you just wish to view what was previously collected:
python sam/launcher.py --local
Please note that syntax for tcpdump may be slightly different on your own machine. The desired output format includes numeric unix timestamp, numeric IP address, numeric port
Also possible is the use of tshark:
sudo tshark -E separator=@ -e frame.number -e frame.time -e ip.src -e tcp.srcport -e udp.srcport -e ip.dst -e tcp.dstport -e udp.dstport -e frame.len -T fields | python sam/launcher.py --local --format=tshark
By default, --local mode uses sqlite and a temporary db file. This is controlled by environment variables prefixed with SAM__LOCAL__
export SAM__LOCAL__DBN=sqlite
export SAM__LOCAL__DB=/tmp/sam_local.db
Instructions are provided for Syslog and Netflow using the ASDM. Please refer to Cisco's support and documentation to enable logging via CLI.
-
Open the Configuration tab (top left)
-
Open the Device Management category (bottom left)
-
Expand the Logging tree-view folder (left)
-
Choose Event Lists tree-view item
-
Add an event list called TrafficEvents
- Leave Event Class / Severity empty
- Add IDs to the Message IDs list:
- 106100
- 106015
- 106023
- 313008
- 302013-302018
- 302020-302021
- 313001
- 710003
- Click OK to complete list creation
-
Choose Logging Filters tree-view item
-
Edit the “Syslog Servers” row
- Set “Syslogs from All Event Classes” to use event list TrafficEvents
- Click OK to complete edits
-
Choose the Syslog Servers tree-view item
-
Add a new entry:
- Interface: inside (if your logging machine is in your internal network)
- IP Address: your collector machine’s address
- Protocol: UDP
- Port: 5140
-
Choose the Logging Setup tree-view item
-
Check the “Enable logging” box
-
Apply and Save
-
Now is time to test your settings. In a terminal on the syslog-receiving machine:
nc -lku 5140
- This should show syslog messages in the console.
- Ctrl-C to stop listening.
-
Set environment variables:
export SAM__COLLECTOR__LISTEN_PORT=5140
export SAM__COLLECTOR__LISTEN_HOST=
export SAM__COLLECTOR__UPLOAD_KEY= <found in webserver settings>
export SAM__COLLECTOR__FORMAT=asasyslog
-
Start collector:
python sam/launcher.py --target=collector
The following instructions largely duplicate the descriptions given here (cisco.com).
- Open the Configuration tab (top left)
- Open the Device Management category (bottom left)
- Expand the Logging tree-view folder (left)
- Choose NetFlow tree-view item
- Add a collector
- Interface: inside
- IP Address or Hostname: Your IP or hostname
- UDP Port: 5140 or port of your choice not currently in use.
- OK to complete Add process.
- [Optional] Set the Template Timeout Rate to 5 minutes
- Open the Firewall category (bottom left)
- Choose the Service Policy Rules tree-view item
- Add a new rule
- Choose Global radio button
- On the next page, select Source and Destination IP Address as your Traffic Match Criteria
- On the next page, pick:
- Action: Match
- Source: any
- Destination: any
- Service: ip
- On the next page, choose Torn Down for Flow Event Type and ensure your collector has a checkmark for the send column.
- Apply changes and Save
- Test settings:
- record data with:
nfcapd -T all -l <log_directory> -p <port>
- translate data with:
nfdump -r <log_file_or_directory> -b -o "fmt:%pr,%sa,%sp,%da,%dp,%ts,%ibyt,%obyt,%ipkt,%opkt,%td"
- Set environment and start collector:
export SAM__COLLECTOR__UPLOAD_KEY= <found in webserver settings>
python sam/launcher.py --target=collector --format=netflow --port=8787
Note: NetFlow traffic packets cannot be interpreted by the receiver until the source has sent the appropriate templates. This means that netflow data may not appear to work over short durations. The default template transmission repeat time for a Cisco ASA 5505 is every 30 minutes.