百度杯CTF Write up集锦 WEB篇

这篇博客详细介绍了参与百度杯CTF比赛时遇到的WEB类题目,包括九月、十月、十二月和二月四个月份的挑战。作者通过解密cookie、文件上传漏洞利用、SQL注入、文件包含等技术,逐步解析了每个关卡的解决方案,最终获取flag。文章涵盖了代码分析、漏洞利用、文件读取和PHP相关知识。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

九月场

1.code

一开始的URL为

http://ace3c302efed4a9094cbac1dff0250e8add1b4b45f8249d4.game.ichunqiu.com/index.php?jpg=hei.jpg

尝试着令

jpg=index.php

得出了base64编码的文本
丢到解码器里解出文本index.php

<?php
/**
 * Created by PhpStorm.
 * Date: 2015/11/16
 * Time: 1:31
 */
header('content-type:text/html;charset=utf-8');
if(! isset($_GET['jpg']))
    header('Refresh:0;url=./index.php?jpg=hei.jpg');
$file = $_GET['jpg'];
echo '<title>file:'.$file.'</title>';
$file = preg_replace("/[^a-zA-Z0-9.]+/","", $file);
//在这里会匹配除了a-zA-Z0-9.之外的所有字符 所以_会被匹配到
$file = str_replace("config","_", $file);
//在这里想到用config代替_
$txt = base64_encode(file_get_contents($file));

echo "<img src='https://img-blog.csdnimg.cn/2022011918262297653.gif".$txt."'></img>";

/*
 * Can you find the flag file?
 *
 */

?>
这里有个知识点利用phpstorm编写的程序 在/.idea/workspace.xml的内容里包含了当前项目下所有的php文件。

那么访问
http://ace3c302efed4a9094cbac1dff0250e8add1b4b45f8249d4.game.ichunqiu.com/.idea/workspace.xml
得到

<list>
<option value="$PROJECT_DIR$/x.php"/>
<option value="$PROJECT_DIR$/config.php"/>
<option value="$PROJECT_DIR$/fl3g_ichuqiu.php"/>
</list>
看见了flag所在的文件

令上面的jpg=fl3g_ichuqiu.php
发现并没有内容返回看上面的index.php源码分析。
令jpg=fl3gconfigichuqiu.php
得到关键的代码

<?php
/**
 * Created by PhpStorm.
 * Date: 2015/11/16
 * Time: 1:31
 */
error_reporting(E_ALL || ~E_NOTICE);
include('config.php');
function random($length, $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz') {
   
    $hash = '';
    $max = strlen($chars) - 1;
    for($i = 0; $i < $length; $i++) {
        $hash .= $chars[mt_rand(0, $max)];
    }
    return $hash;
}

function encrypt($txt,$key){
   
    for($i=0;$i<strlen($txt);$i++){
        $tmp .= chr(ord($txt[$i])+10);
    }
    $txt = $tmp;
    $rnd=random(4);
    $key=md5($rnd.$key);
    $s=0;
    for($i=0;$i<strlen($txt);$i++){
        if($s == 32) $s = 0;
        $ttmp .= $txt[$i] ^ $key[++$s];
    }
    return base64_encode($rnd.$ttmp);
}
function decrypt($txt,$key){
   
    $txt=base64_decode($txt);
    $rnd = substr($txt,0,4);
    $txt = substr($txt,4);
    $key=md5($rnd.$key);

    $s=0;
    for($i=0;$i<strlen($txt);$i++){
        if($s == 32) $s = 0;
        $tmp .= $txt[$i]^$key[++$s];
    }
    for($i=0;$i<strlen($tmp);$i++){
        $tmp1 .= chr(ord($tmp[$i])-10);
    }
    return $tmp1;
}
$username = decrypt($_COOKIE['user'],$key);
if ($username == 'system'){
    echo $flag;
}else{
    setcookie('user',encrypt('guest',$key));
    echo "╮(╯▽╰)╭";
}
?>

这里有个关于cookie的加密解密函数,函数一步一步来解析的话很简单
在最后主要有一点

$username = decrypt($_COOKIE['user'],$key);
if ($username == 'system'){
    echo $flag;
}else{
    setcookie('user',encrypt('guest',$key));
    echo "╮(╯▽╰)╭";
}
这里cookie的值必须为system但系统默认为guest所以我们的任务就是将guest变为system
主要是把key解出来
下面有我的php代码
<?php

function decrypt($txt){
    $txt1="guest";
    $tmp2="";
    for($i=0;$i<strlen($txt1);$i++){
        $tmp2 .= chr(ord($txt1[$i])+10);
    }
    $txt1=$tmp2;

    $txt2="system";
    $tmp2="";
    for($i=0;$i<strlen($txt2);$i++){
        $tmp2 .= chr(ord($txt2[$i])+10);
    }
    $txt2=$tmp2;

    $txt=base64_decode($txt);
    $rnd = substr($txt,0,4);
    $ttmp = substr($txt,4);
    $s=0;
    $tmp="";
    $content="";
    for($i=0;$i<strlen($txt1);$i++){
        $tmp .= $txt1[$i]^$ttmp[$s++];
    }
    $a=$tmp;
    $temp='0123456789abcdef';
    $f=fopen('1.txt','w');
    for($i=0;$i<strlen($temp);$i++)
    {
        $tmp.=$temp[$
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值