Log Analysis
Command Line Log Analysis Tools
cutextracts column(s) from a file or text stream. Columns must be delineated by a consistent character.cut example.txt -d , -f 2prints the second column from example.txt where a comma is used to separate each column.
sortsorts the lines from a file or text stream.sort example.txtprints the sorted output of the lines from example.txt.sort -n example.txtuses numberical value to sort.sort -b example.txtignores blanks at the start of the line.sort -r example.txtreverses the sorting order.-kflag is useful for sorting databases.
uniqprints the result of removing any duplicate lines from a file or text stream.uniq example.txtprints the result of removing any duplicate lines from example.txt.- Usually use this after using
sort; it only removes adjacent duplicate lines.
grep“Global Regular Expression Print” searches for text that matches a specific pattern.grep match example.txtprints lines that contain the text “match” in example.txt.- grep IP address:
grep -E '[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}' example.txt - grep only valid IP address:
grep -E '^((25[0-5]|2[0-4][0-9]|[1]?[1-9][0-9]?).){3}(25[0-5]|2[0-4][0-9]|[1]?[1-9]?[0-9])$' example.txtpingto remove leading zeros.
wc“Word Count” gets a line count (followed by a word count and a byte count) of a file or text stream.wc example.txtprints the number of lines, words, bytes in example.txt.-lflag to print number of lines only.-cflag to print number of bytes only.-wflag to print number of words only. A word is defined as a string of characters delimited by spaces, tabs, or newline characters.
awkis a tool used to manipulate data. It can be used to extract specific columns from data.cat example.txt | awk '{print #2}'prints the second column in example.txt.
tailprints the last 10 lines of a file.tail example.txtprints the last 10 lines of example.txt.tail -12 example.txtprints the last 12 lines of example.txt.
headprints the first 10 lines of a file.head example.txtprints the first 10 lines of example.txt.head -7 example.txtprints the first 7 lines of example.txt.
SQLite
- SQLite Browser
sqlitebrowserGUI.
sqlite3 <file.sqlite>.tablesto see a list of tables..indexto see index..schemato see a list of schema..databases
Creating Programs to do Log Analysis
.jsonFile, Python analysis:- Find unique IPs, unique signatures, most popular category, total bytes sent, category of non TCP traffic
import json f = open('filename.json')
- Find unique IPs, unique signatures, most popular category, total bytes sent, category of non TCP traffic