Serialization Saga
This Capture The Flag (CTF) challenge is designed to assess your ability to identify and exploit fundamental insecure deserialization vulnerabilities. Can you successfully execute the necessary functions and retrieve the flags? Lesssgoo!
Solution
This challenge is vulnerable to insecure deserialization.
Serialization is the process of converting complex data structures, such as objects and their fields, into a "flatter" format that can be sent and received as a sequential stream of bytes, i.e. Objects ⇒ Bytes
Deserialization is the process of restoring this byte stream to a fully functional replica of the original object, i.e. Bytes ⇒ Objects.
We are provided with the above source code on the webpage.
Going through the code we can deduce that it takes a
GET
parameter namedsess
which is base64 encoded string. This base64 string gets decode and gets deserialized.In PHP, the
unserialize()
method invokes the magic method__wakeup()
for deserialization.In the
__wakeup()
magic method, we see that an array$func_map
has been defined with 3 items.$func_no
stores the number which will be used to access the array .$func_name
stores the function name but after performing a simple ROT13 shift.The below block of code performs a STRICT comparison(i.e. BOTH value and type should be same) between the func_name from the array(accessed using
$func_no
) and the ROT13 shifted$func_name
.We have 3 functions defined:
XVigil()
: outputs textBeVigil()
: outputs textGetMeDemFlagz()
: outputs the content offlag.txt
in the/tmp
directory.
We should craft a serialized payload keeping these things in mind:
func_no
should get value3
because the mapping in thefunc_map
array toGetMeDemFlagz
is at the 3rd indexROT13 of
GetMeDemFlagz
:TrgZrQrzSyntm
Base64 encoded and passed as a GET parameter
sess
in the url.{URL}/?sess=<base64 encoded string>
With the help of this page, we can craft a payload.
Final Payload:
O:8:"CloudSEK"
: An object with the 8-character class name"CloudSEK"
2
- the object has 2 attributess:7:"func_no"
: The key of the first attribute is the 7-character string"func_no"
i:3
: Value of first attribute is the 3rd index in func_map in the__wakeup()
functions:9:"func_name"
: The key of the second attribute is the 9-character string"func_name"
s:13:"TrgZrQrzSyntm"
: Value of second attribute is a 13 character stringTrgZrQrzSyntm
(from rot13 ofGetMeDemFlagz
)Base64 encoding the above payload:
Tzo4OiJDbG91ZFNFSyI6Mjp7czo3OiJmdW5jX25vIjtpOjM7czo5OiJmdW5jX25hbWUiO3M6MTM6IlRyZ1pyUXJ6U3ludG0iO30=
Passing above base64 string as a value to
sess
parameter and appending to the URL, we get the flag
FLAG
Last updated