细节影响成败之URL中“可有可无”的80端口

2019-11-26 6,654

image.png


引言

工作的时候遇到了一件有趣的事,如果给网址强制加上80端口,效果会是一样的吗?常识来说,80端口的有无并没有区别,因为我们知道http协议端口默认是80。(全文只考虑80端口)

RFC2616

翻阅RFC关于HTTP协议的文档,在14.23中说明了Host字段的相关标准( https://tools.ietf.org/html/rfc2616#section-14.23 )  

RFC 2616                        HTTP/1.1                       June 1999

    The Host request-header field specifies the Internet host and port
  number of the resource being requested, as obtained from the original
  URI given by the user or referring resource (generally an HTTP URL,
  as described in section 3.2.2). The Host field value MUST represent
  the naming authority of the origin server or gateway given by the
  original URL. This allows the origin server or gateway to
  differentiate between internally-ambiguous URLs, such as the root "/"
  URL of a server for multiple host names on a single IP address.

      Host = "Host" ":" host [ ":" port ] ; Section 3.2.2

  A "host" without any trailing port information implies the default
  port for the service requested (e.g., "80" for an HTTP URL). For
  example, a request on the origin server for
  <http://www.w3.org/pub/WWW/> would properly include:

      GET /pub/WWW/ HTTP/1.1
      Host: www.w3.org

文档中未说明客户端是否要省略80端口,但是告诉服务器如果在没有端口的情况下把80作为默认的端口。

由于HTTP协议中将URL的各个参数分解了,所以服务器端也无法直接获取一个完整的URL地址。

那么常见的工具是怎么进行处理80端口的呢,下面我们就来做实验

准备

浏览器三只(IE、Chrome、Firefox),发包工具三个(curl、Postman、python(requests)、go),流量侦测神器Wireshark。

配置Nginx,在web根路径下创建index.html,内容可以随意,正常访问的效果如下:


010.png


浏览器测试

首先我们分别使用IE、Chrome和Firefox分别访问带80端口和不带80端口的,从三个浏览器的表现来看,即使自己加了80端口,也会自动给你抹掉

001.gif

002.gif

003.gif


工具测试

1. 第一个工具是curl,我们先打开Wireshark进行抓包,然后分别构造两次数据包:

004.gif

在Wireshark中追踪两次的TCP流:

009.png


发现除了时间外两个报文无任何差别


2. 第二个工具是PostMan,步骤同上

005.gif

我们打开Wireshark追踪TCP流(由于keep-alive,所以两个包连在一起,但不影响)

007.png

发现在Host字段中已经出现了差异,加了80端口的会在Host字段中保留端口。


3. 第三个工具就是python的requests模块了


006.gif

008.png

我是用的python2.7最新requests库进行测试的,Wireshark发现两次请求的Host中均是没有带80端口的。requests库的GitHub地址: https://github.com/psf/requests



4. 第四个工具是golang,最近才学会golang,先来试试

011.gif

012.png



目前的情况是curl和python会在发送请求包的时候会在Host中去除掉80端口,postman和golang会在Host中保留端口。

总结

  1. 从标准文档来看,没有强制要求客户端的80端口是否要去掉或者带上。

  2. 从各类工具的测试效果来看,不同工具之间还是存在差距的,所以如果我们在做一些比较严格测试的时候需要选择适当的工具,尽量避免出现误差。

  3. 建议在写脚本/POC的时候注意80端口的问题,没有给定80端口建议不要强制给加上,否则一些服务器会出现解析问题导致错过一些信息


本文作者:Dem0ns

本文为安全脉搏专栏作者发布,转载请注明:https://www.secpulse.com/archives/119027.html

Tags:
评论  (0)
快来写下你的想法吧!

Dem0ns

文章数:3 积分: 5

https://github.com/nic329

安全问答社区

安全问答社区

脉搏官方公众号

脉搏公众号