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.

54.227.48.147 20/Feb/2018:09:28:48 /travel/usa/new-york-black-chamber/Index.html
54.227.48.147 20/Feb/2018:09:28:32 /open-source/rhel-centos-5-6-7/Index.html
202.251.224.100 20/Feb/2018:09:28:26 /open-source/unix-tips.html
54.227.48.147 20/Feb/2018:09:28:14 /cybersecurity/attack-study/attacker-perspective.html
40.77.167.42 20/Feb/2018:09:28:14 /travel/greece/trains.html
54.227.48.147 20/Feb/2018:09:27:58 /cybersecurity/attack-study/real-data-patterns.html
5.255.250.17 20/Feb/2018:09:27:56 /3d/xray/
123.231.121.9 20/Feb/2018:09:27:56 /
54.227.48.147 20/Feb/2018:09:27:41 /travel/japan/kofun/konabe.html
54.227.48.147 20/Feb/2018:09:27:25 /travel/greece/Index.html
188.190.36.15 20/Feb/2018:09:27:08 /cybersecurity/password-breaking.html
54.227.48.147 20/Feb/2018:09:27:08 /fun/sarah-palin-baby-name-generator.html
66.87.72.129 20/Feb/2018:09:27:03 /technical/dsl/
54.227.48.147 20/Feb/2018:09:26:51 /travel/turkey/ephesus/acts.html
54.227.48.147 20/Feb/2018:09:26:33 /travel/china/class-and-macau.html
54.227.48.147 20/Feb/2018:09:26:11 /travel/uk/national-grid-os-maps/Index.html
175.158.201.152 20/Feb/2018:09:26:09 /
54.227.48.147 20/Feb/2018:09:25:51 /cybersecurity/hostile/downloader-tibs.html
54.227.48.147 20/Feb/2018:09:25:31 /open-source/file-system.html
66.249.79.21 20/Feb/2018:09:25:17 /travel/uk/scotland-pitlochry/
5.255.250.17 20/Feb/2018:09:25:14 /travel/uk/orkney-sousterrain/
54.227.48.147 20/Feb/2018:09:25:11 /3d/newfossil.html
5.255.250.17 20/Feb/2018:09:25:11 /open-source/rhel-centos-5-6-7/selinux.html
54.227.48.147 20/Feb/2018:09:24:51 /open-source/stig-compliance.html
64.62.252.162 20/Feb/2018:09:24:51 /robots.txt
157.55.39.220 20/Feb/2018:09:24:33 /cybersecurity/history/uss-chaumont/logs.html
54.227.48.147 20/Feb/2018:09:24:32 /cybersecurity/hostile/trojan-agent.html
54.227.48.147 20/Feb/2018:09:24:15 /networking/Index.html
146.255.181.6 20/Feb/2018:09:24:13 /radio/tv-antenna.html
64.140.137.1 20/Feb/2018:09:24:04 /
84.201.133.97 20/Feb/2018:09:23:59 /robots.txt
54.227.48.147 20/Feb/2018:09:23:57 /travel/usa/ghostbusters/Index.html
5.255.250.17 20/Feb/2018:09:23:51 /open-source/vmware-networking.html
52.87.232.59 20/Feb/2018:09:23:49 /radio/probes.html
52.87.232.59 20/Feb/2018:09:23:43 /robots.txt
54.227.48.147 20/Feb/2018:09:23:39 /open-source/getting-started.html
95.141.63.38 20/Feb/2018:09:23:28 /turkish/verbs.html
84.201.244.125 20/Feb/2018:09:23:22 /open-source/xsane-invalid-argument.html
54.227.48.147 20/Feb/2018:09:23:20 /travel/usa/national-christmas-tree/Index.html
54.227.48.147 20/Feb/2018:09:22:59 /travel/france/seine-river-art-history-monet/chateau-gaillard.html
66.249.79.25 20/Feb/2018:09:22:54 /travel/greece/greek-mainland.html
54.227.48.147 20/Feb/2018:09:22:39 /open-source/linux-break-in-howto.html
180.76.15.5 20/Feb/2018:09:22:25 /travel/backpack/
54.227.48.147 20/Feb/2018:09:22:18 /fun/requests-for-quotes/ittehad-chemicals/iso-14001.html
46.188.42.75 20/Feb/2018:09:22:13 /networking/netstat-a.html
5.255.250.17 20/Feb/2018:09:22:09 /radio/internet-radio.html
80.154.98.131 20/Feb/2018:09:22:00 /technical/samsung-galaxy/ssh.html
54.227.48.147 20/Feb/2018:09:21:59 /3d/xray/scanner.html
5.255.250.17 20/Feb/2018:09:21:58 /open-source/samba-active-directory/freebsd-raspberry-pi.html
66.249.81.23 20/Feb/2018:09:21:53 /turkish/verbs.html
180.76.15.135 20/Feb/2018:09:21:52 /travel/turkey/goreme/
54.227.48.147 20/Feb/2018:09:21:40 /open-source/performance-tuning/applications.html
54.227.48.147 20/Feb/2018:09:21:23 /travel/bulgaria/Index.html
54.227.48.147 20/Feb/2018:09:21:03 /travel/turkey/olimpos/Index.html
54.227.48.147 20/Feb/2018:09:20:43 /brewing/how-to-brew-mead.html
90.101.244.135 20/Feb/2018:09:20:36 /radio/hfqrp.html
131.253.25.70 20/Feb/2018:09:20:14 /travel/france/normandy/utah-beach.html
54.36.148.84 20/Feb/2018:09:20:13 /travel/japan/kofun/empress-hibasuhime.html
54.227.48.147 20/Feb/2018:09:19:58 /open-source/samba-active-directory/Index.html
167.220.63.124 20/Feb/2018:09:19:53 /networking/sdn.html
92.252.41.211 20/Feb/2018:09:19:52 /open-source/linux-boot.html
54.227.48.147 20/Feb/2018:09:19:35 /travel/japan/koyasan/kongo-sanmai-in.html
174.122.154.124 20/Feb/2018:09:19:34 /travel/uk/dover/
197.231.22.190 20/Feb/2018:09:19:23 /
54.227.48.147 20/Feb/2018:09:19:15 /travel/france/boat-trip-canal-lateral-a-la-loire/la-chapelle-montlinard-to-cours-les-barres.html
54.227.48.147 20/Feb/2018:09:18:51 /3d/xray/Index.html
103.94.169.114 20/Feb/2018:09:18:49 /open-source/performance-tuning/ethernet.html
54.227.48.147 20/Feb/2018:09:18:30 /travel/usa/detroit/detroit-part2.html
87.195.195.218 20/Feb/2018:09:18:20 /technical/dsl/
54.227.48.147 20/Feb/2018:09:18:10 /fun/Index.html
54.227.48.147 20/Feb/2018:09:17:47 /3d/clsi/Index.html
54.227.48.147 20/Feb/2018:09:17:23 /open-source/migrate-rhel-to-centos.html
40.77.167.42 20/Feb/2018:09:17:22 /radio/?D=A
54.227.48.147 20/Feb/2018:09:17:02 /travel/usa/new-york-st-marks-place/1st-a-north.html
176.14.227.205 20/Feb/2018:09:16:58 /networking/netstat-a.html
122.161.107.129 20/Feb/2018:09:16:55 /
54.227.48.147 20/Feb/2018:09:16:39 /travel/japan/shinto-buddhism/shinto.html
54.227.48.147 20/Feb/2018:09:16:18 /travel/trinidad/Index.html
41.223.100.194 20/Feb/2018:09:16:15 /technical/convert-youtube-to-xvid.html
54.227.48.147 20/Feb/2018:09:15:55 /cybersecurity/netaudit.html
14.139.11.11 20/Feb/2018:09:15:39 /travel/uk/dover/
54.227.48.147 20/Feb/2018:09:15:33 /travel/italy/amalfi/Index.html
54.227.48.147 20/Feb/2018:09:15:11 /open-source/raspberry-pi/hardware.html
100.43.91.201 20/Feb/2018:09:15:03 /robots.txt
5.255.250.200 20/Feb/2018:09:14:59 /robots.txt
54.227.48.147 20/Feb/2018:09:14:51 /travel/athens-to-paris/sofia-veliko-tarnovo.html
54.227.48.147 20/Feb/2018:09:14:26 /travel/france/barbegal-les-baux-st-remy/Index.html
54.227.48.147 20/Feb/2018:09:14:03 /travel/turkey/pamukkale/Index.html
54.227.48.147 20/Feb/2018:09:13:39 /oliver-cromwell/crom-fu-fighting.html
160.226.234.110 20/Feb/2018:09:13:34 /
54.227.48.147 20/Feb/2018:09:13:17 /travel/japan/tokyo-asakusa/senso-ji.html
54.227.48.147 20/Feb/2018:09:12:52 /travel/france/boat/meals.html
103.219.206.63 20/Feb/2018:09:12:47 /technical/dsl/
54.227.48.147 20/Feb/2018:09:12:29 /turkish/turkish-suffixes.html
54.227.48.147 20/Feb/2018:09:12:05 /travel/usa/poe-in-new-york/Index.html
207.46.13.182 20/Feb/2018:09:11:52 /open-source/rhel-centos-5-6-7/kernel-and-clusters.html
54.227.48.147 20/Feb/2018:09:11:43 /travel/turkey/hans/Index.html
54.227.48.147 20/Feb/2018:09:11:20 /travel/russia/getting-there.html
54.227.48.147 20/Feb/2018:09:10:57 /travel/france/boat-trip-canal-lateral-a-la-loire/beaulieu-sur-loire-to-st-thibault.html
54.227.48.147 20/Feb/2018:09:10:32 /travel/japan/tokyo-shinjuku/Index.html
5.255.250.17 20/Feb/2018:09:10:31 /cybersecurity/history/cabinet-war-rooms.html
54.89.208.133 20/Feb/2018:09:10:29 /travel/japan/kamakura/kencho-ji.html
85.25.210.41 20/Feb/2018:09:10:03 /robots.txt
54.227.48.147 20/Feb/2018:09:10:01 /travel/uk/dover/Index.html
123.231.9.87 20/Feb/2018:09:09:55 /

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-xs-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