picoCTF 2020 Mini-Competition

{"author" : ["ret2basic"]}

Pitter, Patter, Platters (Autopsy)

Challenge

'Suspicious' is written all over this disk image. Download suspicious.dd.sda1arrow-up-right

Solution

Open the .sda file in Autopsy. Click "Keyword Search" and search for the keyword "suspicious". Here we find two files:

  • suspicious-file.txt

  • suspicious-file.txt-slack

suspicious-file.txt says:

suspicious-file.txt Nothing to see here! But you may want to look here -->


------------------------------METADATA------------------------------

suspicious-file.txt-slack says:

suspicious-file.txt-slack }dc7079dd_3<_|Lm_111t5_3b{FTCocip
circle-info

File slack is the difference between the physical file size and the logical file size. Autopsy creates slack files (with the -slack extension) from any extra space at the end of a file. These files can be displayed or hidden from the data sources area and/or the views area. Go to "Tools => Options => Global Settings => Hide slack files in the:" and unselect the options in this section.

Reverse the string and get flag:

Web Gauntlet (SQLite Injection with WAF Bypass)

Challenge

Can you beat the filters? Log in as admin http://jupiter.challenges.picoctf.org:44979/arrow-up-right http://jupiter.challenges.picoctf.org:44979/filter.phparrow-up-right

Solution

Background Knowledge

If we enter user:password on the login page, the backend SQL query will be something like this:

Typically the very first payload for testing SQLi is ' or 1=1;--, which results in the following SQL query:

Here the leading ' closes the username field and anything comes after -- is considered as comment (hence ignored). Since '' evaluates to False and 1=1 evaluates to True, the entire SQL statement always evaluates to True.

Round 1

Filter: or

In this round, the boolean expression or is filtered. We have to come up with a different payload. Alternatively, since the SQL default admin user is named admin, one possible payload without using or is admin';--. The corresponding SQL query is:

The SQL query got executed is shown in the background:

Round 1 Done

Round 2

Filter: or and like = --

For this round, simply remove the -- from the payload for Round 1. The corresponding SQL query is:

This query is still semantically correct since ; closes the statement SELECT * FROM users WHERE username='admin':

Round 2 Done

Round 3

Filter: or and = like > < --

The payload for Round 2 works for this round as well:

Round 4

Filter: or and = like > < -- admin

Since admin is filtered, we have to come up with another approach. A typical solution for such filter is the UNION attack. The UNION keyword in SQL allows multiple SQL statements to be executed. For example:

In our case, we could construct an UNION attack as the following:

However, this payload does not work since space is filtered. To bypass this filter, let's replace all spaces with /**/ (empty comment is equivalent to space):

This payload works:

Round 4 Done

Round 5

Filter: or and = like > < -- union admin

Since union is filtered in this round, we should switch back to the admin';-- idea. There are two things that need to be changed:

  1. Since admin is filtered, we could split admin into adm'||'in, where || is used for concatenating strings in SQL.

  2. Since -- is filtered, we could replace ;-- with /* to comment out the things that we don't need.

The complete SQL query is:

Now go grab your flag:

Round 5 Done

Appendix: Source Code

Guessing Game 1 (ret2syscall)

Challenge

I made a simple game to show off my programming skills. See if you can beat it! vulnarrow-up-right vuln.carrow-up-right Makefilearrow-up-right nc jupiter.challenges.picoctf.org 26735

Makefile

The binary is statically linked, so things like ret2libc won't work.

Source Code

Note that the function get_random() does not return a random number at all since rand() is unseeded. To confirm:

The output is 83, no matter how many times you run it.

Also, pay attention to these two lines of the source code:

The correct answer to the question "What number would you like to guess?" should be 84.

Solution

Since the binary does not contain the string "/bin/sh\x00", we have to construct a 2-stage exploit:

  • Stage 1: Build a ROP chain for writing the string "/bin/sh\x00" to a writable memory location. A common choice is the .bss section. The address of .bss can be found using Pwntools elf.bss() method.

  • Stage 2: Do normal ret2syscall to execute execve("/bin/sh\x00", 0, 0).

Exploit

Guessing Game 2

circle-check

Challenge

It's the Return of your favorite game! vulnarrow-up-right vuln.carrow-up-right Makefilearrow-up-right nc jupiter.challenges.picoctf.org 57529

Makefile

The binary is dynamically linked this time, which makes ret2libc possible.

Source Code

Solution

Exploit

OPT Implementation

Challenge

Yay reversing! Relevant files: otparrow-up-right flag.txtarrow-up-right

Solution

Implementation

Last updated