>_ IzzyLab

Hands-on task

This task is step 16 of the course “Investigating a server”

Who planted someone else's SSH key

medium~12 min

Server access is handed out through the git repository /srv/access: lots of people have edited keys/authorized_keys. Today a stranger's key with the comment intruder@kali turned up in it.

  1. Find the commit in which this line first appeared, and write its full hash (40 characters) to /root/culprit.txt.
  2. Revoke the access: delete the line with this key from keys/authorized_keys (handy in the Editor tab) and commit the change. Don't touch the other keys and don't rewrite history — the evidence must stay in the past commits.
What you'll practise:
  • git blame
  • git log -S
  • line history
  • git rev-parse
  • investigation
  • git commit

Topic breakdown

When investigating an incident in a repository, what matters isn't the file's last change but the moment a specific line appeared in it. git blame labels every line with the commit that brought it in, and -L narrows the output to a line found by a pattern; the --porcelain format prints the full hash. The other route is the pickaxe search git log -S: it lists commits where the number of occurrences of the text changed, and the oldest of them is the appearance. The commit then shows the author and the time — that's where the conversation about how the key got into the access list starts. The key is removed with an ordinary new commit: history must not be rewritten, because the past commits are the evidence.

What's checked

  1. a full hash is written
  2. found the commit where the key appeared
  3. the stranger's key is deleted and committed
  4. the other keys and the history are in place

What it looks like