[MRCTF2020]Ezaudit

首先我们进行目录扫描,发现www.zip可以下载到源码

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
<?php 
header('Content-type:text/html; charset=utf-8');
error_reporting(0);
if(isset($_POST['login'])){
$username = $_POST['username'];
$password = $_POST['password'];
$Private_key = $_POST['Private_key'];
if (($username == '') || ($password == '') ||($Private_key == '')) {
// 若为空,视为未填写,提示错误,并3秒后返回登录界面
header('refresh:2; url=login.html');
echo "用户名、密码、密钥不能为空啦,crispr会让你在2秒后跳转到登录界面的!";
exit;
}
else if($Private_key != '*************' )
{
header('refresh:2; url=login.html');
echo "假密钥,咋会让你登录?crispr会让你在2秒后跳转到登录界面的!";
exit;
}

else{
if($Private_key === '************'){
$getuser = "SELECT flag FROM user WHERE username= 'crispr' AND password = '$password'".';';
$link=mysql_connect("localhost","root","root");
mysql_select_db("test",$link);
$result = mysql_query($getuser);
while($row=mysql_fetch_assoc($result)){
echo "<tr><td>".$row["username"]."</td><td>".$row["flag"]."</td><td>";
}
}
}

}
// genarate public_key
function public_key($length = 16) {
$strings1 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$public_key = '';
for ( $i = 0; $i < $length; $i++ )
$public_key .= substr($strings1, mt_rand(0, strlen($strings1) - 1), 1);
return $public_key;
}

//genarate private_key
function private_key($length = 12) {
$strings2 = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789';
$private_key = '';
for ( $i = 0; $i < $length; $i++ )
$private_key .= substr($strings2, mt_rand(0, strlen($strings2) - 1), 1);
return $private_key;
}
$Public_key = public_key();
//$Public_key = KVQP0LdJKRaV3n9D how to get crispr's private_key???

通过审计代码,我们发现关键点一步是求出私钥,由于生成公钥使用的是mt_seed,即伪随机函数,我们只要通过公钥获取到种子值就能得到私钥

我们使用php_mt_seed这个脚本

我们先处理公钥数据成脚本需要的数据格式

题解

EasyBypass

我们进行代码审计

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<?php

highlight_file(__FILE__);

$comm1 = $_GET['comm1'];
$comm2 = $_GET['comm2'];


if(preg_match("/\'|\`|\\|\*|\n|\t|\xA0|\r|\{|\}|\(|\)|<|\&[^\d]|@|\||tail|bin|less|more|string|nl|pwd|cat|sh|flag|find|ls|grep|echo|w/is", $comm1))
$comm1 = "";
if(preg_match("/\'|\"|;|,|\`|\*|\\|\n|\t|\r|\xA0|\{|\}|\(|\)|<|\&[^\d]|@|\||ls|\||tail|more|cat|string|bin|less||tac|sh|flag|find|grep|echo|w/is", $comm2))
$comm2 = "";

$flag = "#flag in /flag";

$comm1 = '"' . $comm1 . '"';
$comm2 = '"' . $comm2 . '"';

$cmd = "file $comm1 $comm2";
system($cmd);
?>

代码对comm1和comm2进行正则匹配,再执行命令

我们需要做的就是绕过正则匹配和执行想要的命令

题解

[极客大挑战 2020]Roamphp1-Welcome(405报错)

我们打开页面,发现提示该页面无法正常运作(我还以为我网络出问题了呢)

image-20240723175809368

经过查询,我们发现是405报错,405的报错原因是由于请求方法不对,我们对页面进行抓包

题解

[WMCTF2020]Make PHP Great Again(require_once特性)

打开页面,进行代码审计

1
2
3
4
5
6
<?php
highlight_file(__FILE__);
require_once 'flag.php';
if(isset($_GET['file'])) {
require_once $_GET['file'];
}

我们要了解什么是require_once

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

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

php特性

[b01lers2020]Life on Mars(sql注入)

我们打开页面,发现啥信息都没有,我们随便点击一个地名抓包看看

image-20240715203732986

我们访问/query?search=amazonis_planitia

image-20240715203901604

我们进行sql注入

sql注入

[SUCTF 2018]GetShell(无字母数字rce)

我们打开页面源码,发现源码里有个链接

image-20240715194012415

我们点击后跳转到了新的页面,并发现了一串代码

rce

[GXYCTF2019]StrongestMind

打开页面,提示我们计算1000次答案给flag

我们直接上脚本

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

import requests
import re
import time

url = 'http://1ab3c450-eac5-4e70-930f-c0e7bd6c577c.node5.buuoj.cn:81'
session = requests.session()
req = session.get(url).text
flag = ""

for i in range(1010):
try:
result = re.findall("\<br\>\<br\>(\d.*?)\<br\>\<br\>",req)#获取[数字]
result = "".join(result)#提取字符串
result = eval(result)#运算
print("time: "+ str(i) +" "+"result: "+ str(result))

data = {"answer":result}
req = session.post(url,data=data).text
if "flag{" in req:
print(re.search("flag{.*}", req).group(0)[:50])
break
time.sleep(0.1)#防止访问太快断开连接
except:
print("[-]")

得到flag.

题解

[GKCTF 2021]easycms

url+admin.php,我们能够进入登录页面

image-20240621194103359

题目提示了密码是五位数弱密码

我们考虑admin/admin,admin/12345,实在不行再去fuzz

但admin/12345成功登录了进去

题解cms

[BJDCTF2020]EzPHP(代码审计&create_function的使用)

我们查看源码,发现一串base32加密的字符串

image-20240620210847610

我们解码,得到一个文件

php特性