Rack of Ethernet switches.

Visualizing Log Patterns with Color

Apache Logs in Color

Web server logs reveal patterns of activity by web crawlers. Some are indexing crawlers operated by search engines, some are mysterious. Another pattern is systematic blind searches for vulnerable server-side executables or other configuration problems. The pattern you want to see is the interested user who follows some path through the hyperlinks on your site, taking time to read the pages.

Maybe we could use color to help spot these patterns?

Maybe...

First, let's look at the result, then the explanation comes later. Here are the most recent client requests, starting most recent first. Your request for this page won't appear there as it isn't complete by the time this page was automatically generated with PHP. But if you reload the page you should see your initial request near the top.

194.187.170.129 21/Apr/2018:17:24:33 /travel/belgium/belgian-beers/absinthe-bar.html
54.144.14.134 21/Apr/2018:17:24:29 /travel/greece/greek-mainland.html
54.144.14.134 21/Apr/2018:17:24:12 /travel/france/budget-hotels/Index.html
54.144.14.134 21/Apr/2018:17:23:53 /travel/france/boat/canal-selection-and-logs.html
194.187.170.129 21/Apr/2018:17:23:50 /open-source/rhel-centos-5-6-7/packages-and-software.html
54.144.14.134 21/Apr/2018:17:23:36 /travel/france/normandy/brecourt-manor.html
180.76.15.141 21/Apr/2018:17:23:27 /travel/japan/tokyo-ueno/
54.144.14.134 21/Apr/2018:17:23:18 /travel/uk/dover/Index.html
54.144.14.134 21/Apr/2018:17:23:00 /cybersecurity/attack-study/200.213.105.90-i192-list.html
54.144.14.134 21/Apr/2018:17:22:40 /travel/china/hong-kong.html
54.144.14.134 21/Apr/2018:17:22:25 /radio/morse-code.html
54.144.14.134 21/Apr/2018:17:22:24 /robots.txt
194.187.170.129 21/Apr/2018:17:21:18 /cybersecurity/sysaudit.html
107.182.231.89 21/Apr/2018:17:21:10 /networking/commands.html
194.187.170.129 21/Apr/2018:17:20:56 /travel/russia/goodwill.html
72.207.201.225 21/Apr/2018:17:20:52 /travel/italy/paestum/
209.126.120.28 21/Apr/2018:17:20:50 /travel/france/school-lunch-menus/
40.77.167.43 21/Apr/2018:17:20:33 /travel/czech-republic/prague/
54.36.149.93 21/Apr/2018:17:20:22 /technical/ata-ide-sata-usb-cable-pinouts.html
34.245.21.178 21/Apr/2018:17:20:11 /travel/uk/scotland-isle-of-iona/ferry.html
86.190.79.81 21/Apr/2018:17:20:03 /travel/uk/scotland-isle-of-iona/ferry.html
104.131.147.112 21/Apr/2018:17:20:00 /
207.46.13.199 21/Apr/2018:17:19:53 /robots.txt
104.131.147.112 21/Apr/2018:17:19:50 /contact.html
104.131.147.112 21/Apr/2018:17:19:36 /cybersecurity/
194.187.170.129 21/Apr/2018:17:19:29 /cybersecurity/intrusion.html
104.131.147.112 21/Apr/2018:17:19:21 /cybersecurity/attack-study/
104.131.147.112 21/Apr/2018:17:19:11 /cybersecurity/authentication.html
104.131.147.112 21/Apr/2018:17:18:55 /cybersecurity/availability.html
104.131.147.112 21/Apr/2018:17:18:42 /cybersecurity/backdoors.html
194.187.170.129 21/Apr/2018:17:18:38 /travel/usa/washington-yardley.html
194.187.170.129 21/Apr/2018:17:18:32 /open-source/linux-alpha-kernel.html
104.131.147.112 21/Apr/2018:17:18:30 /cybersecurity/badguys.html
66.249.79.139 21/Apr/2018:17:18:20 /travel/belgium/bastogne-ardennes/ardennes-forest.html
104.131.147.112 21/Apr/2018:17:18:18 /cybersecurity/basics/
52.23.240.141 21/Apr/2018:17:18:15 /cybersecurity/privacy.html
85.194.76.180 21/Apr/2018:17:18:08 /cybersecurity/privacy.html
104.131.147.112 21/Apr/2018:17:18:05 /cybersecurity/bulletins.html
86.83.136.111 21/Apr/2018:17:18:02 /open-source/performance-tuning/ethernet.html
157.55.39.91 21/Apr/2018:17:17:57 /radio/frequencies.html
68.46.22.252 21/Apr/2018:17:17:57 /travel/greece/ios.html
66.249.79.135 21/Apr/2018:17:17:57 /technical/
104.131.147.112 21/Apr/2018:17:17:55 /cybersecurity/cipher-selection.html
104.131.147.112 21/Apr/2018:17:17:45 /cybersecurity/cloud-exploit.html
66.249.79.135 21/Apr/2018:17:17:39 /contact.html
71.61.37.113 21/Apr/2018:17:17:34 /turkish/nouns.html
194.187.170.129 21/Apr/2018:17:17:32 /open-source/rhel-centos-5-6-7/network-services.html
104.131.147.112 21/Apr/2018:17:17:28 /cybersecurity/cloud-survey.html
66.249.79.135 21/Apr/2018:17:17:11 /travel/greece/delphi.html
104.131.147.112 21/Apr/2018:17:17:06 /cybersecurity/cloud.html
104.131.147.112 21/Apr/2018:17:16:55 /cybersecurity/comptia/
104.131.147.112 21/Apr/2018:17:16:42 /cybersecurity/crypto/
104.131.147.112 21/Apr/2018:17:16:31 /cybersecurity/crypto/haiku.html
104.131.147.112 21/Apr/2018:17:16:19 /cybersecurity/crypto/hash-search.html
107.77.203.218 21/Apr/2018:17:16:13 /travel/france/school-lunch-menus/
104.131.147.112 21/Apr/2018:17:16:05 /cybersecurity/cyberwar.html
52.201.226.25 21/Apr/2018:17:15:54 /travel/japan/kamakura/hachiman-gu.html
104.131.147.112 21/Apr/2018:17:15:52 /cybersecurity/ec2-secure-storage.html
71.61.37.113 21/Apr/2018:17:15:47 /turkish/background.html
104.131.147.112 21/Apr/2018:17:15:38 /cybersecurity/extortion.html
104.131.147.112 21/Apr/2018:17:15:28 /cybersecurity/firewall.html
216.244.66.234 21/Apr/2018:17:15:24 /robots.txt
216.244.66.234 21/Apr/2018:17:15:24 /robots.txt
180.76.15.12 21/Apr/2018:17:15:19 /travel/usa/
194.187.170.129 21/Apr/2018:17:15:17 /cybersecurity/comptia/
104.131.147.112 21/Apr/2018:17:15:16 /cybersecurity/forensics.html
104.131.147.112 21/Apr/2018:17:15:05 /cybersecurity/generalinfo.html
132.68.52.192 21/Apr/2018:17:14:58 /open-source/performance-tuning/disks.html
104.131.147.112 21/Apr/2018:17:14:54 /cybersecurity/hacker-passwords.html
148.64.56.74 21/Apr/2018:17:14:41 /travel/athens-to-paris/veliko-tarnovo-bucharest.html
104.131.147.112 21/Apr/2018:17:14:43 /cybersecurity/hardware.html
71.61.37.113 21/Apr/2018:17:14:38 /turkish/
148.64.56.74 21/Apr/2018:17:14:32 /robots.txt
104.131.147.112 21/Apr/2018:17:14:28 /cybersecurity/history/
71.61.37.113 21/Apr/2018:17:14:22 /turkish/turkish-verbs.pdf
104.131.147.112 21/Apr/2018:17:14:15 /cybersecurity/hoax.html
209.126.120.17 21/Apr/2018:17:14:14 /open-source/raspberry-pi/nas.html
61.6.239.65 21/Apr/2018:17:14:06 /
104.131.147.112 21/Apr/2018:17:14:02 /cybersecurity/html-email.html
104.131.147.112 21/Apr/2018:17:13:48 /cybersecurity/infosec-response.html
54.236.1.15 21/Apr/2018:17:13:46 /travel/usa/new-york-hunter-s-thompson/
93.158.161.164 21/Apr/2018:17:13:38 /open-source/ssh.html
141.8.143.162 21/Apr/2018:17:13:37 /open-source/ssh.html
104.131.147.112 21/Apr/2018:17:13:36 /cybersecurity/intrusion-analysis/
188.27.168.250 21/Apr/2018:17:13:25 /
104.131.147.112 21/Apr/2018:17:13:21 /cybersecurity/intrusion.html
54.85.191.40 21/Apr/2018:17:13:16 /technical/hdmi.html
194.187.170.129 21/Apr/2018:17:13:10 /travel/russia/getting-there.html
104.131.147.112 21/Apr/2018:17:13:08 /cybersecurity/linux-hardening.html
104.131.147.112 21/Apr/2018:17:12:57 /cybersecurity/monitoring.html
104.131.147.112 21/Apr/2018:17:12:40 /cybersecurity/netaudit.html
104.131.147.112 21/Apr/2018:17:12:30 /cybersecurity/os-specific.html
104.131.147.112 21/Apr/2018:17:12:12 /cybersecurity/password-breaking.html
104.131.147.112 21/Apr/2018:17:12:01 /cybersecurity/password.html
75.97.35.207 21/Apr/2018:17:11:55 /travel/france/normandy/utah-beach.html
104.131.147.112 21/Apr/2018:17:11:41 /cybersecurity/physical.html
194.187.170.129 21/Apr/2018:17:11:26 /travel/russia/before-and-after.html
104.131.147.112 21/Apr/2018:17:11:22 /cybersecurity/pki-failures.html
104.131.147.112 21/Apr/2018:17:11:05 /cybersecurity/policy.html
104.131.147.112 21/Apr/2018:17:10:50 /cybersecurity/privacy-policy.html
104.131.147.112 21/Apr/2018:17:10:34 /cybersecurity/privacy.html
104.131.147.112 21/Apr/2018:17:10:17 /cybersecurity/qr-nfc.html
104.131.147.112 21/Apr/2018:17:10:06 /cybersecurity/refs.html
31.4.207.127 21/Apr/2018:17:10:03 /open-source/raspberry-pi/openvas.html
104.131.147.112 21/Apr/2018:17:09:55 /cybersecurity/regulations.html
104.131.147.112 21/Apr/2018:17:09:44 /cybersecurity/rfcs.html
34.216.252.127 21/Apr/2018:17:09:40 /travel/china/yangshuo.html
104.131.147.112 21/Apr/2018:17:09:34 /cybersecurity/root-password.html
104.131.147.112 21/Apr/2018:17:09:23 /cybersecurity/scam-analysis.html
104.131.147.112 21/Apr/2018:17:09:13 /cybersecurity/ssl-tls.html
194.187.170.129 21/Apr/2018:17:09:13 /travel/uk/Index.html
98.21.195.60 21/Apr/2018:17:09:12 /technical/dsl/
130.239.42.201 21/Apr/2018:17:09:10 /open-source/performance-tuning/disks.html
207.46.13.44 21/Apr/2018:17:09:04 /travel/belgium/belgian-beers/
104.131.147.112 21/Apr/2018:17:08:54 /cybersecurity/stack-hardening.html
118.208.66.58 21/Apr/2018:17:08:53 /open-source/openbsd-kernel.html
180.76.15.30 21/Apr/2018:17:08:44 /turkish/Index.html
104.131.147.112 21/Apr/2018:17:08:43 /cybersecurity/surveillance.html
107.77.234.208 21/Apr/2018:17:08:32 /open-source/raspberry-pi/nas.html
104.131.147.112 21/Apr/2018:17:08:31 /cybersecurity/sysaudit.html
104.131.147.112 21/Apr/2018:17:08:21 /cybersecurity/syslog-tls-cloud.html

Here's what's going on.

Each line above is a request from a client, extracted from Apache's /var/www/logs/access_log file. The client IP address, timestamp, and requested path were selected with awk and the client IP address converted to a country if possible with geoiplookup.

The first 3 octets or first 24 bits of the IP address are used to specify the hue, with chroma at 75% and intensity at 100%. The resulting red, green, and blue values are scaled to the range of 0-255 and printed as two-character hexadecimal in an HTML style string.

Low-numbered /8 networks appear as red, 20.0.0.0/8 through 40.0.0.0/8 are orange shifting to yellow, 50.0.0.0/8 through 110.0.0.0/8 are shades of green, the /16 networks 130.0.0.0/16 through about 180.0.0.0/16 are shades of blue, then it's shades of purple into magenta for the /24 networks 192.0.0.0/24 and up through 223.255.255.0/24.

The HTML file on the server has a line where PHP uses passthru() to call the following shell script:

#!/bin/sh

# Initial pipeline:
# tail		Just the last 200 (or slightly less after the grep)
# grep		... just the requests out of that
# cat | sort	... put into reverse order
# sed		... remove the quotes and square brackets
# awk		... print the IP address twice, timestamp, and requested path
# sed		... remove the first 3 dots to split first version of IP
#			address into octets, and remove any characters that
#			could cause trouble when inserted into this page
# I need to use the client IP address, field #5 at that point, to call
# geoiplookup.  So, send the initial pipeline into a while loop that
# assigns variables, sets a new variable, and then echoes the resulting
# collection into awk.
tail -200 /var/www/logs/access_log |
	grep 'GET.*200' |
	cat -n | sort -nr |
	sed -e 's/"/ /g' -e 's/\[//g' -e 's/\]//g' |
	awk '{print $2, $2, $5, $8}' |
	sed -e 's/\./ /' -e 's/\./ /' -e 's/\./ /' -e 's/[<>]//g' |
	while read IP1 IP2 IP3 IP4 CLIENTIP TIMESTAMP URL
	do
		COUNTRY=$( geoiplookup $CLIENTIP |
				sed 's/.*Edition: //' |
				sed 's/IP Address not found/Unknown/' )
		echo $IP1 $IP2 $IP3 $IP4 $CLIENTIP $COUNTRY $TIMESTAMP $URL |
		awk '{
			ip1 = $1;
			ip2 = $2;
			ip3 = $3;
			chroma = 0.75;
			hue = 6*(ip1*255*255 + ip2*255 + ip3)/(255*255*255);
			if (hue%2 > 1) {
				x = chroma*(1.0 - (hue%2 - 1));
			} else {
				x = chroma*(1.0 - (1 - hue%2));
			}
			if (hue < 1.0) {
				r = chroma;
				g = x;
				b = 0;
			} else if (hue < 2.0) {
				r = x;
				g = chroma;
				b = 0;
			} else if (hue < 3.0) {
				r = 0;
				g = chroma;
				b = x;
			} else if (hue < 4.0) {
				r = 0;
				g = x;
				b = chroma;
			} else if (hue < 5.0) {
				r = x;
				g = 0;
				b = chroma;
			} else {
				r = chroma;
				g = 0;
				b = x;
			}
			r = (r + 0.25)*255;
			g = (g + 0.25)*255;
			b = (b + 0.25)*255;

			printf("<div class=\"col-12 textleft\" ");
			printf("style=\"color:#000; background:#%02x%02x%02x;\"> ", r, g, b);
			for (i = 5; i <= NF; i++) {
				printf("%s ", $i);
			}
			printf("</div>\n");
		}'
	done 

Other Pages