[PASECA2019]honey_shop

我们发现flag要1337块才能买,但我们只有1336块

我们点击图片,发现图片能够下载,那我们进行抓包看看

image-20240920194735999

这种url大多可以进行任意文件读取

session伪造

php特性

preg_match()

PHP: preg_match - Manual

数组绕过

preg_match()只能处理字符串,当传入的subject是数组时,会返回false

1
2
3
4
5
6
if(preg_match("/[0-9]/", $num)){
die("no no no!");
}
if(intval($num)){
echo $flag;
}

payload:

num[]=1

php特性

[GoogleCTF2019 Quals]Bnv

我们打开页面,没发现有啥信息,我们进行抓包

image-20240919204517785

我们看到json格式的,将json改为xml格式,尝试xxe注入

1
2
Content-type: application/json
Content-type: application/xml

首先构造DTD,声明实体b和元素message

其实之前做得题目都是不用申明元素的,这里如果不申明会报

xxe

[Black Watch 入群题]Web

我们点击热点进行抓包

image-20240909211806163

看url,我们考虑在id处进行注入

image-20240909211939251

有注入点,通过测试,我们发现过滤了空格

mysql

[HFCTF2020]BabyUpload

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
<?php
error_reporting(0);
session_save_path("/var/babyctf/");
session_start();
require_once "/flag";
highlight_file(__FILE__);
if($_SESSION['username'] ==='admin')
{
$filename='/var/babyctf/success.txt';
if(file_exists($filename)){
safe_delete($filename
die($flag);
}
}
else{
$_SESSION['username'] ='guest';
}
$direction = filter_input(INPUT_POST, 'direction');
$attr = filter_input(INPUT_POST, 'attr');
$dir_path = "/var/babyctf/".$attr;
if($attr==="private"){
$dir_path .= "/".$_SESSION['username'];
}
if($direction === "upload"){
try{
if(!is_uploaded_file($_FILES['up_file']['tmp_name'])){
throw new RuntimeException('invalid upload');
}
$file_path = $dir_path."/".$_FILES['up_file']['name'];
$file_path .= "_".hash_file("sha256",$_FILES['up_file']['tmp_name']);
if(preg_match('/(\.\.\/|\.\.\\\\)/', $file_path)){
throw new RuntimeException('invalid file path');
}
@mkdir($dir_path, 0700, TRUE);
if(move_uploaded_file($_FILES['up_file']['tmp_name'],$file_path)){
$upload_result = "uploaded";
}else{
throw new RuntimeException('error while saving');
}
} catch (RuntimeException $e) {
$upload_result = $e->getMessage();
}
} elseif ($direction === "download") {
try{
$filename = basename(filter_input(INPUT_POST, 'filename'));
$file_path = $dir_path."/".$filename;
if(preg_match('/(\.\.\/|\.\.\\\\)/', $file_path)){
throw new RuntimeException('invalid file path');
}
if(!file_exists($file_path)) {
throw new RuntimeException('file not exist');
}
header('Content-Type: application/force-download');
header('Content-Length: '.filesize($file_path));
header('Content-Disposition: attachment; filename="'.substr($filename, 0, -65).'"');
if(readfile($file_path)){
$download_result = "downloaded";
}else{
throw new RuntimeException('error while saving');
}
} catch (RuntimeException $e) {
$download_result = $e->getMessage();
}
exit;
}
?>

前面部分设置了session存储路径,启动了session并根目录下包含flag

1
2
3
4
5
error_reporting(0);
session_save_path("/var/babyctf/");
session_start();
require_once "/flag";

接下来判断session的username是否为admin,如果是,则判断/var/babyctf下是否存在

success.txt,如果存在,删除文件并输出flag,否则设置usename为guest

upload

[WMCTF2020]Make PHP Great Again 2.0

require_once 表达式和 require 表达式完全相同,唯一区别是 PHP 会检查该文件是否已经被包含过,如果是则不会再次包含。

由于 require_once 包含的软链接层数较多时 once 的 hash 匹配会直接失效造成重复包含。

php特性

[SWPU2019]Web4

打开页面发现一个登录框,输入账号和密码后没有反应

我们f12打开页面源码,发现js代码

image-20240908201027925

js主要功能是将username和password以json格式然后发给index.php?r=Login/Login。

我们进行抓包

sql注入json