作为一个网络安全小菜鸡,最近开始想研究CTF。一方面是学习巩固相关的知识,另一方面也想多学一些技巧。俗话说:好记性不如烂笔头。所以专门当个笔记一样写在这,把相关题目的思路写下来,日后忘记了可以多回顾。生命不息,学习不止。
刚入门有所磕磕绊绊,如果有师傅看到哪里写错了或哪里没写好,希望可以帮忙指出,感激不尽!
Bugku的题有一些因为环境问题已经做不出来,所以后面可能会和ctfshow换着做题。
每次历经困难后看到flag的界面总是很激动,长出一口气。
1.Simple_SSTI_1
ssti叫Server Side Template Injection,服务端模板注入。模板可以理解为一段固定好格式,等着你来填充信息的文件。以{{}}作为变量包裹的标识符。同时,这个符号包裹内还可以执行一些简单的表达式。
flask注入的三种模板:
{% … %}
{{ … }}
{# … #}
{{config}} 可以获取当前设置,可以直接访问 {{config['FLAG']}} 或者 {{config.FLAG}} 得到 flag。
题目显示为需要传入一个flag参数。
![](https://img-blog.csdnimg.cn/img_convert/bcab65f2c5b11dbd0cc7e5d0b53ecd0e.png)
查看源代码,提示在flask中,设置了secret_key。那就是在注入模板中输入内容就会显示对应的值。
![](https://img-blog.csdnimg.cn/img_convert/8699d0587589517b51061c3102819b95.png)
传入?flag={{SECRET_KEY}}显示空白。
![](https://img-blog.csdnimg.cn/img_convert/7940ac58116786af4a5b91384d999c7e.png)
根据上面的知识,在前面加上config即可。
![](https://img-blog.csdnimg.cn/img_convert/a5b0440cec1107ef31abfe165f5afd27.png)
2.Simple_SSTI_2
魔术对象:
__class__:返回类型所属的对象
__mro__:返回一个包含对象所继承的基类元组,方法在解析时按照元组的顺序解析。
__base__"返回该对象所继承的基类 // __base__和__mro__都是用来寻找基类的
__subclasses__:获取当前类的所有子类
__init__ :类的初始化方法
__globals__:对包含(保存)函数全局变量的字典的引用
os.popen():
__globals__[‘os’].popen(‘ls’,‘r’).read()
依旧是服务端模板注入,查看源代码没有可利用的信息。
![](https://img-blog.csdnimg.cn/img_convert/355961e4cdc48e471bfb3514c906249e.png)
先试试传入config。
![](https://img-blog.csdnimg.cn/img_convert/15a84df0d251e70ffa3b69089d5ca06a.png)
使用ls查看有哪些文件:
?flag={{config.__class__.__init__.__globals__[%27os%27].popen(%27ls%27,%27r%27).read()}}
![](https://img-blog.csdnimg.cn/img_convert/0d732b3373eb4b1bbfd2e9fd47b16e66.png)
发现了flag文件,直接cat查看?flag={{config.__class__.__init__.__globals__[%27os%27].popen(%27cat%20flag%27,%27r%27).read()}}
![](https://img-blog.csdnimg.cn/img_convert/74c4c1be103631fc12379c06240d3646.png)
3.Flask_FileUpload
os.system()函数:
os.system是os模块最基础的方法
原理:system函数可以将字符串转化成命令在服务器上运行
执行多条命令:
import os
os.system('cd /home ; mkdir 1.txt')
os.system('cd /home && mkdir 1.txt')
是一个文件上传的页面,查看源代码意思为:上传文件,我会返回python运行的结果
![](https://img-blog.csdnimg.cn/img_convert/b3b1b604e90d45a47de875635d5a518d.png)
试试上传一句话木马,果然失败了,并且源码限制了白名单为jpg、png。
![](https://img-blog.csdnimg.cn/img_convert/1a652a908da8d3246615d7c2243ddc24.png)
上传jpg发现可以,抓包中表明确实会用python执行。
![](https://img-blog.csdnimg.cn/img_convert/765a9709bcc49a82ab024a2378ff6e95.png)
使用os模块,并把后缀改为jpg上传抓包,发现jpg内的代码执行成功,但是没有显示flag,说明不在当前目录下。
![](https://img-blog.csdnimg.cn/img_convert/c666bf32c1ff9dfd1d5af1ce665b9389.png)
![](https://img-blog.csdnimg.cn/img_convert/c7bd58438f71d61c178de42e8a710198.png)
![](https://img-blog.csdnimg.cn/img_convert/0197e1d7623841b4efc94be4ab45056d.png)
重新上传查看根目录下的文件,发现flag位置。
![](https://img-blog.csdnimg.cn/img_convert/8a7d4e70941ba31d074d9a77e536447e.png)
![](https://img-blog.csdnimg.cn/img_convert/1df4261a09a28177539e32005b787b54.png)
burp直接repeater命令查看得到flag。
![](https://img-blog.csdnimg.cn/img_convert/0da6008f486274d33a81f2e27d017731.png)
4.滑稽
右键查看源码即可获得flag。
![](https://img-blog.csdnimg.cn/img_convert/553d31298d95bce9af2e2b0dddb472ee.png)
![](https://img-blog.csdnimg.cn/img_convert/bc1615a040209544a89f2d46adc5c3bf.png)
5.留言板
注:本来需要使用xss平台打管理员cookie,但是环境出了问题缺少存放管理员账号密码的数据库文件。
进入后是一个留言板界面,插入XSS代码提交。
![](https://img-blog.csdnimg.cn/img_convert/627dba369b50159407847c468c0f7b88.png)
![](https://img-blog.csdnimg.cn/img_convert/df494c050bec501883815c262982613b.png)
既然是留言板那应该需要管理员登录,并查看我们的XSS代码来获得管理员cookie。使用dirsearch扫描网站目录,发现admin.php。
![](https://img-blog.csdnimg.cn/img_convert/50311c1e03c96c449421a1daa006182f.png)
![](https://img-blog.csdnimg.cn/img_convert/f9f59e24362be29562de250de20d67d8.png)
因为网站问题少了个存放有账号密码的数据库文件,所以直接用账号admin,密码011be4d65feac1a8登录。
flag在cookie中,控制台输入alert(document.cookie)弹出cookie。
![](https://img-blog.csdnimg.cn/img_convert/5fc4d3aa9f79bcd803ac385a349d141e.png)
提交显示不正确,仔细一看发现花括号被编码了,解码即可。
![](https://img-blog.csdnimg.cn/img_convert/b92bc41097a33c9352bcf4f3f3f24c2e.png)
![](https://img-blog.csdnimg.cn/img_convert/7b88fa4ce8ecb12966b3acca3c1c7917.png)
6.计算器
进入后发现是一个计算题,口算下答案填进去就行了,但是发现写了1就写不了后面的数字了。
![](https://img-blog.csdnimg.cn/img_convert/29acfc4c5e47747bc2fe37a5af7104b0.png)
![](https://img-blog.csdnimg.cn/img_convert/8580168d20263dea0d47414908098350.png)
F12看看,发现输入框maxlength="1",意思是最大长度是1,直接改成999提交即可获得flag。
![](https://img-blog.csdnimg.cn/img_convert/568a9e310f9c659c9598a0dfd793491e.png)
![](https://img-blog.csdnimg.cn/img_convert/a8b1771292fbb1ac5fe4b6a34de8bf02.png)
![](https://img-blog.csdnimg.cn/img_convert/55051a3a97cea2456c499cf9b7366a11.png)
7.GET
代码告诉我们用get方式对what进行传参,直接输入?what=flag即可。
![](https://img-blog.csdnimg.cn/img_convert/4fc7222b062fa30e2fc7d5d64d50375a.png)
![](https://img-blog.csdnimg.cn/img_convert/0a0219e9ee79a145efd4521d0231b1c8.png)
8.POST
用POST方式对what进行传参。
![](https://img-blog.csdnimg.cn/img_convert/ff06b02c87d9e3ef9542214ad5b69ac1.png)
9.矛盾
进入页面显示的是源代码,通过GET方式传入num参数,如果传参不是数字(is_numeric() 函数用于检测变量是否为数字或数字字符串)输出参数。如果参数是1输出flag。
![](https://img-blog.csdnimg.cn/img_convert/53a8a35b53bbcd047a221858a625b631.png)
![](https://img-blog.csdnimg.cn/img_convert/b97a7422c3d90d1519739f3ec1234b94.png)
但是传参是1时没有反应,仔细查看源码发现$num==1,==表示检查数据内容并且自动进行类型转换。非数字字符开头的字符串被转换成0,数字开头的字符串保留数字。与上面的is_numeric($num)函数结合,因此需要一个不是数字字符串并且与1弱相等的字符串。
![](https://img-blog.csdnimg.cn/img_convert/9fa9e17b2ba602a755bcb7795504a387.png)
输入1'得到flag。
![](https://img-blog.csdnimg.cn/img_convert/bca799d5b3a4a4a9c16b544eefa3385b.png)
10.弹窗
进来后重复弹两个窗口,想查看源代码也显示空白。
![](https://img-blog.csdnimg.cn/img_convert/ad348f3cf6f6c40a13ad60e906aa2dec.png)
![](https://img-blog.csdnimg.cn/img_convert/0e2085634196cc782d1db68184c4a35b.png)
![](https://img-blog.csdnimg.cn/img_convert/fc3d49f1b547d5b36f8cdf53d8aaca0c.png)
![](https://img-blog.csdnimg.cn/img_convert/563e3bd146fba82d63c32a903ace80d9.png)
在burp抓包查看返回包时,发现了Unicode编码,解码即可得到flag。
![](https://img-blog.csdnimg.cn/img_convert/ccb846b55b3d5ccbd4fd15b0265d14d9.png)
![](https://img-blog.csdnimg.cn/img_convert/1a016294040f4688d2fe3b58560666a3.png)
11.你必须让它停下
进入后会一直刷新界面,其中有一个界面不一样,可能flag就在这个页面中。
![](https://img-blog.csdnimg.cn/img_convert/e7f2175e3ca973ecf02a2ad988482f19.png)
![](https://img-blog.csdnimg.cn/img_convert/982cfc6cf69492f150ce253eca5a6e70.png)
既然要抓取其中的一个界面,使用burp抓包拦截,一直到我们想要的数据包。
![](https://img-blog.csdnimg.cn/img_convert/dd14fcc614b33702da24481d4fa871e7.png)
flag就在其中。
![](https://img-blog.csdnimg.cn/img_convert/d36e5dbc316e624078f2254fb013fcdb.png)
12.game1
进入是一个游戏界面,抓包玩了一会,发现了三个参数score分数,IP地址,sign。sign的值感觉像是被编码过。放进base64解码,无法解析。应该是从编码入手,多试几次看看。
![](https://img-blog.csdnimg.cn/img_convert/3854fe65a19b45b55e79be21355e52bd.png)
![](https://img-blog.csdnimg.cn/img_convert/6ed2dc27670e10fb45c302ea18ba0d15.png)
重新玩了几次,发现sign的值前两位zM是固定的。
![](https://img-blog.csdnimg.cn/img_convert/ae348c8eeed8898a7cfd076bfaabfac4.png)
![](https://img-blog.csdnimg.cn/img_convert/7c17bd9bfff177eda99c74e994ad2946.png)
把zM去除重新base64解码成功。
![](https://img-blog.csdnimg.cn/img_convert/e222d1bb0917a03315f5179fa05ec04f.png)
把score改成10000,并把sign改为zM+经过base64编码后10000的值,发送数据包即可得到flag。
![](https://img-blog.csdnimg.cn/img_convert/ebcc93d66700421ec066f269820b23af.png)
![](https://img-blog.csdnimg.cn/img_convert/ec1aefb9e5b4522e86c80df095889696.png)
后面发现源码中也显示了经过base64编码,还是要仔细一些。多看看源码,有时候可以少走弯路。
![](https://img-blog.csdnimg.cn/img_convert/e3d72201ebdf9c7bc5474d9d82abb4f9.png)
13.网站被黑
进入显示网站有漏洞,那可能存在黑客留下的后门文件。使用dirseatch扫描,发现存在shell.php。
![](https://img-blog.csdnimg.cn/img_convert/0084668b998339c9f4225ab62993c7c0.png)
![](https://img-blog.csdnimg.cn/img_convert/9d3fa10fd39421c8b7e67674ea1369d1.png)
试了几次弱口令都不对,使用burp爆破出密码是hack,登录即可得到flag。
![](https://img-blog.csdnimg.cn/img_convert/c6afb13fcf8ed10d6a75d5bd78086e48.png)
![](https://img-blog.csdnimg.cn/img_convert/5d2bb8c045d0db51221137e459d9e7b0.png)
14.管理员系统
是一个登录界面,并且下面有很多n,应该里面藏着有用的信息,仔细查看源码看到最后发现有base64编码,解密得到test123,可能是账户或者密码。
![](https://img-blog.csdnimg.cn/img_convert/428c76d499c604456872890f9eee8376.png)
![](https://img-blog.csdnimg.cn/img_convert/39435f01c3d49414d809a602d176fb3c.png)
输入admin/123456登录,显示IP禁止访问,猜测和数据包中的IP参数有关。抓包查看发现确实没有请求头部。
![](https://img-blog.csdnimg.cn/img_convert/327675579209034302440f97a605c929.png)
X-Forwarded-For 是一个 HTTP 扩展头部。在数据包添加X-Forwarded-For:127.0.0.1重新发包即可。
![](https://img-blog.csdnimg.cn/img_convert/0d59e22a0dd05787538348d222217b77.png)
15.BP
进入后是个登录界面,用户告诉了我们是admin,密码提示是弱口令top1000中的z开头密码。随意输入密码后会显示“账号或密码错误”
![](https://img-blog.csdnimg.cn/img_convert/61ac3afd7805ca2ca9893fc940dab28e.png)
导入字典进行爆破,发现长度都一样无法找到爆破成功的数据。
![](https://img-blog.csdnimg.cn/img_convert/2fc99bf0cb146dae06f14a091f607304.png)
通过观察Response,发现错误的数据包中都包含特定JS代码告诉我们用户或密码错误。
![](https://img-blog.csdnimg.cn/img_convert/4df9fa85cd9465d9a3f79fcf25784aab.png)
所以只要标识出错误返回包中的code值,那么没有出现标识的就是正确的密码。需要用到burp中的options——Grep-Match:在响应中找出存在指定的内容的一项。
![](https://img-blog.csdnimg.cn/img_convert/e2d509662d6e674dcad5ecef34bafa3e.png)
爆破完成后发现zxc123返回包中没有错误code值,因此密码为zxc123。
![](https://img-blog.csdnimg.cn/img_convert/8f4cf0e76fe12027e51ed07b4ede2ade.png)
登录后即可获得flag。
![](https://img-blog.csdnimg.cn/img_convert/0597116719ac61d7b75216d48fb67b80.png)
16.eval
var_dump函数用于输出变量的相关信息,显示关于一个或多个表达式的结构信息。
show_source() 函数对文件进行语法高亮显示,是 highlight_file() 的别名。
考察文件包含,已经包含了flag.php,并且hello是变量,直接执行命令查看flag.php。
![](https://img-blog.csdnimg.cn/img_convert/7b53c835494218d11a6526901878f127.png)
发现显示不完全。
![](https://img-blog.csdnimg.cn/img_convert/73af980a09775269cd477bd41ac65efb.png)
查询whoami试试,可以正常显示。
![](https://img-blog.csdnimg.cn/img_convert/3ce3f3b43d3e295603b9ab0a20347c40.png)
后面发现显示不完全查看源码即可。
![](https://img-blog.csdnimg.cn/img_convert/3d8ec5b2d42600759aac8faa9e77b68b.png)
也可以用file函数读取文件。
![](https://img-blog.csdnimg.cn/img_convert/9521ef9387cad82ab442f735d39fb95e.png)
17.变量1
error_reporting(0)关闭错误报告,
包含flag1.php,
highlight_file(file)高亮显示文件,
preg_match("/^\w+$/"字符串的规则匹配,开头的 ^ 和结尾的 $ 让PHP从字符串开头检查到结尾,\w 匹配包括下划线的任何单词字符。等价于“[A-Za-z0-9_]
![](https://img-blog.csdnimg.cn/img_convert/44fac0c0e116e88291cc5380d7928e3c.png)
本题使用超全局变量$GLOBALS,还有其他超全局变量: $_SERVER 、$_REQUEST 、$_POST 、$_GET 、$_FILES 、$_ENV 、$_COOKIE 、$_SESSION。意味着它们在一个脚本的全部作用域中都可用。在函数或方法中无需执行 global $variable; 就可以访问它们。
![](https://img-blog.csdnimg.cn/img_convert/59b8175d5f1b2a2082640fb093c2b670.png)
18.头等舱
进入以后页面只有文字,没有其他信息,这时第一反应就是f12查看源代码并抓包
![](https://img-blog.csdnimg.cn/img_convert/71708e7a49d7c82759fbf3f22892ad81.png)
在返回包中的HTTP头部直接发现flag
![](https://img-blog.csdnimg.cn/img_convert/0a1d0776b8309b6302dee53b20d2652c.png)
19.社工——伪造
进入后是一个聊天框界面,需要和小美对话后拿到flag。
输入qq号登录后聊天并不会给。
![](https://img-blog.csdnimg.cn/img_convert/2990fa7f12584304996c077b50e493d3.png)
查看小美空间,找到了关键信息:
1.只有她男朋友问她要才会给flag,需要伪造成她男朋友
2.如何伪造呢?有她男朋友的qq号和qq昵称‘小bug’
qq号无法再创建一模一样的,qq昵称可以改成一样的。重新登录把昵称改成'小bug'再向小美发送flag即可
![](https://img-blog.csdnimg.cn/img_convert/6f97ad9ed6de1684f6e3e5dca6afcdc3.png)
20.source
右键查看源代码中有一个flag,但是假的
![](https://img-blog.csdnimg.cn/img_convert/47c915b0d2dafa2615aa6db3a76aa89b.png)
使用diesearch扫描目录,发现有.git文件泄露和flag.txt,访问flag.txt也是个假flag
![](https://img-blog.csdnimg.cn/img_convert/f5312ccfb9d4e369b0e9c2977d55eb28.png)
![](https://img-blog.csdnimg.cn/img_convert/d120bf6fc5a8ccdd5891e23944516e58.png)
![](https://img-blog.csdnimg.cn/img_convert/782948731b3074e4c574d7a244d5dca7.png)
打包下载.git文件:wget -r http://114.67.175.224:16353/.git/
![](https://img-blog.csdnimg.cn/img_convert/17d79eee7e94470d3517360b26d3106d.png)
使用git reflog查看文件历史操作记录
![](https://img-blog.csdnimg.cn/img_convert/5ab7b0a7f88369da3ff2c5bb0c7253ea.png)
使用git show显示提交或者某个文件的历史修改详细信息
![](https://img-blog.csdnimg.cn/img_convert/83a2889e2e9f6f68af0aab011facb643.png)
在文件40c6d51找到正确的flag
![](https://img-blog.csdnimg.cn/img_convert/6ef091ddedee695943b849fe3d617767.png)
21.源代码
查看源代码发现两个值p1、p2,并用url解码得到
p1=function checkSubmit(){var a=document.getElementById("password");if("undefined"!=typeof a){if("67d709b2b
p2=aa648cf6e87a7114f1"==a.value)return!0;alert("Error");a.focus();return!1}}document.getElementById("levelQuest").οnsubmit=checkSubmit;
合并得到代码:
function checkSubmit(){var a=document.getElementById("password");if("undefined"!=typeof a{if("67d709b2b54aa2aa648cf6e87a7114f1"==a.value)return!0;alert("Error");a.focus();return!1}}document.getElementById("levelQuest").οnsubmit=checkSubmit;
代码意思为在表单提交前验证密码输入框中的值是否于"67d709b2b54aa2aa648cf6e87a7114f1",把这个值输入并提交即可得到flag
22.文件包含
点击“click me”,url显示了“index.php?file=show.php”,存在文件包含
url输入“?file=/flag”可直接显示flag
也可以使用php://filter伪协议读取index.php源码。url输入“file=php://filter/read=convert.base64-encode/resource=index.php”,并用base64解码
![](https://img-blog.csdnimg.cn/img_convert/a94d72187e9705f3add6619e67f68216.png)
![](https://img-blog.csdnimg.cn/img_convert/534c4b10d1c3dd94ee82ac60f70921d7.png)
23.好像需要密码
页面显示输入5位数密码查看,使用burp爆破。
![](https://img-blog.csdnimg.cn/img_convert/c4e6b837c7977a3990114b4a0d4e086a.png)
爆破出正确密码,得到flag
![](https://img-blog.csdnimg.cn/img_convert/085d7097205241c37890316a1bcf5c1f.png)
24.备份是个好习惯
页面是一段字符串,并且是两段d41d8cd98f00b204e9800998ecf8427e重复的两段,通过cmd5解码为空密码
![](https://img-blog.csdnimg.cn/img_convert/e635ffb991315ee2b9920158caf62189.png)
使用目录扫描出备份文件index.php.bak
![](https://img-blog.csdnimg.cn/img_convert/76e5bac0d3d69c38c1cc0fb4b5ee6c59.png)
查看bak文件,这段代码的功能是从URL中获取参数并计算它们的MD5哈希值,如果两个参数的哈希值相同但参数值不同,则输出$flag变量的值,这里使用了一个从另一个文件flag.php中导入的变量。
include_once "flag.php"; #导入flag.php文件中的变量,此处包括$flag变量。 ini_set("display_errors", 0); #设置错误显示为0,避免意外泄露代码信息。
$str = strstr($_SERVER['REQUEST_URI'], '?'); #从请求的URL中获取参数并去掉开头的'?'。 $str = substr($str,1);
$str = str_replace('key','',$str); #用空字符替换'key',从而获得原始参数。 parse_str($str); #解析字符串并存储在$key1和$key2变量中。 echo md5($key1);
echo md5($key2); #输出$key1和$key2的MD5哈希值。 if(md5($key1) == md5($key2) && $key1 !== $key2){
echo $flag."取得flag";
} #如果$key1和$key2的哈希值相同但参数值不同,则输出$flag变量的值。
分析代码,首先对key进行了过滤,并且key1和key2需要参数不同但哈希值相同,那么需要两个都为空的不同值。
(1)经MD5加密后的值为0e.....格式,会认定为科学计数法,表示0×10的n次方为0且相等。
下面字符串的md5值为0e开头:
QNKCDZO
240610708
s878926199a
s155964671a
s214587387a
构造url:?kkeyey1=240610708&kkeyey2=s155964671a
![](https://img-blog.csdnimg.cn/img_convert/3cc3580531d7bb497c43568d260648e0.png)
(2)经查阅还可以使用数组绕过。md5()函数无法处理数组,如果传入数组会返回NULL。那么传入两个不同的数组即可
构造url:?kkeyey1[]=123&kekeyy2[]=456
![](https://img-blog.csdnimg.cn/img_convert/588ea2309bebd2e59a8aa4ad6e664d27.png)