ISSessions CTF 2021 Programming - NATO

· 2 min read

Converting NATO phonetic alphabet strings back to letters using bash scripting and sed regex.

NATO

Phonetic Alphabet, convert to the “normal” representation and send back within 3 seconds.

Solution

Bash scripting for all these web requests was my method. I could manipulate the needed data, and handle it pretty quickly. Since all these web style programming challenges have the same page format, I can reuse it between them.

Lets break down the commands.

#!/bin/bash
data=$(curl -c cookies "http://prognato.ctf.issessions.ca/" \
  | grep -oE "data\".*" \
  | grep -oE ">.*<" \
  | cut -c 2- \
  | grep -oE "[^<]+" \
  | tr -d '\n' \
  | sed 's/\(.\)[^ ]* */\1/g')
curl -b cookies "http://prognato.ctf.issessions.ca/index.php?answer=$data"

Breaking it down:

  • curl -c cookies — save cookies to a file for session persistence
  • grep -oE "data\".*" — find the line containing the data
  • grep -oE ">.*<" — extract inner contents of HTML tags
  • cut -c 2- | grep -oE "[^<]+" — remove angle brackets from each end
  • tr -d '\n' — remove the pesky grep newline (rookie mistake that kept tripping me up)
  • sed 's/\(.\)[^ ]* */\1/g' — the key regex: select each “word” (non-space character set) and replace it with just the first character. Since NATO phonetic alphabet uses the first letter of each word, this extracts the intended message.