[lighttpd]referer字段实现域名过滤及放行指定域名不走重定向

限制Post请求的CSRF攻击


增加到lighttpd.conf配置文件中
$HTTP["request-method"] == "POST" {
          $HTTP["referer"] !~ "^($|http://myweb.com)" {
              url.access-deny = ( "" )
          }
      }

域名重定向配置

判断host不是myweb.com,就重定向到http://myweb.com域名


增加到lighttpd.conf配置文件中

$HTTP["host"] !~ "myweb.com" {
    $HTTP["host"] !~ "myweb.com" {
		url.redirect= ( ".*" => "http://myweb.com" )
   }
}

域名重定向排除固定类型的请求

wireshark抓取http请求数据包

Hypertext Transfer Protocol
    POST /web/api HTTP/1.1\r\n
        [Expert Info (Chat/Sequence): POST /web/api HTTP/1.1\r\n]
            [POST /jrd/webapi HTTP/1.1\r\n]
            [Severity level: Chat]
            [Group: Sequence]
        Request Method: POST
        Request URI: /web/api
        Request Version: HTTP/1.1
    Origin: http://myweb.com\r\n
    Referer: http://myweb.com/login.html\r\n
    Accept: application/json\r\n
    Content-Type: application/json; charset=UTF-8\r\n
    Content-Length: 54\r\n
        [Content length: 54]
    Host: 192.168.8.1\r\n
    Connection: Keep-Alive\r\n
    Accept-Encoding: gzip\r\n
    User-Agent: okhttp/3.12.0\r\n
    \r\n
    [Full request URI: http://192.168.8.1/web/api]
    [HTTP request 1/1]
    [Response in frame: 93]
    File Data: 54 bytes

 判断主机不是myweb.com,referer字段不是http://myweb.com,就跳转到http://myweb.com

增加到lighttpd.conf配置文件中
$HTTP["host"] !~ "myweb.com" {
	$HTTP["referer"] !~ "^($|http://myweb.com)" {
        $HTTP["host"] !~ "myweb.com" {url.redirect= ( ".*" => "http://myweb.com" )}
        }
}

判断是POST请求的才实现重定向

请求方法是POST,然后referer不是http://myweb.com就重定向到http://myweb.com 

​
增加到lighttpd.conf配置文件中
$HTTP["request-method"] == "POST" {
	$HTTP["referer"] !~ "^($|http://myweb.com)" {
        $HTTP["host"] !~ "myweb.com" {url.redirect= ( ".*" => "http://myweb.com" )}
        }
}

​

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

wellnw

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值