CloudSEK CTFs
blah blah blah
Last updated
blah blah blah
Last updated
The challenge was pretty straight forward, An anonymous person has shared a bevigil apk which lets the Internet folks to use the Enterprise Edition of Bevigil for free, So now our end goal is to find the flag hidden in /cookies.txt
The anonymous person has also told that the ProxyURL is been stored in the app's assets, surfing through Bevigil is not at all a big task, CloudSEK has designed Bevigil in a user-friendly way !
So, now when we take a closer look at the app's assets. We find three URL's out of which only one is the ProxyURL , we can either do a trial-and-error test on which of the URL works or simply visit the /resources/res/values/string.xml
to find out the ProxyURL
Here, the URL http://43.204.140.87:8000/
leads us to the actual CTF webpage. When we Inspect the source we find something interesting !
Taking a closer look at the comments, we find that the flag is hidden in /cookies.txt
which is hidden somewhere in the codebase, the request only accepts GET method and it checks if the getData
parameter is present or not, if it's present then the php code checks if the URL specified in the url
parameter begins with http://
and ends with bevigil.com
. The preg_match
function checks if the string matches the particular pattern or not !
So what is this /^http.[:]\/\/(bevigil.com\/)./
?
The above pattern is nothing but a Regex or a Regular expression, basically it's is a set of rules for matching patterns in strings, they can be used in many programming languages, including PHP to search and manipulate strings.
The php code now checks if our specified URL matches the Regular Expression or not, if it doesn't match then the $response
is set to false
, So how do we bypass this Regex is our next question ?
The answer is damn simple, we just have to break down the characters used in that Regex inorder to understand how the pattern works, we can use chatGPT
or regex101.com
for this case.
^
- This symbol indicates the start of a string.
http
- This is a literal string that must be present in the string being matched.
.
- This symbol matches any single character.
[:]
- This is a character class that matches a single colon character.
\/\/
- This is a literal string that matches two forward slashes.
(bevigil.com\/)
- This is a capture group that matches the string "bevigil.com/". The parentheses are used to define the capture group.
If we look closely, .
is not escaped and dot can match any character in regex. So httpa://bevigil.com
is also a valid url and httpx://bevigil.com
is also a valid url. We can use this to trick file_get_contents
!
file_get_contents
is the sink here, we can load local files, as shown in the example below.
Hence, the comments said that there is something called /cookies.txt
, so when we trigger it using the LFI - We get the FLAG !
Checking the source of the page gave this string
On decoding that, we get a base64 string
On decoding that - we get a php source code
https://gist.github.com/atoponce/bb672d93233121560d2841f67e41698b