• WEB安全 魔术引号及注入类型


    一、魔术引号

    1. magic_quotes_gpc 变量

    什么是魔术引号

    Warning
    本特性已自 PHP 5.3.0 起废弃并将自 PHP 5.4.0 起移除。
    当打开时,所有的 '(单引号),"(双引号),(反斜线)和 NULL 字符都会被自动加上一个反斜线进行转义。这和 addslashes() 作用完全相同。

    一共有三个魔术引号指令:

    magic_quotes_gpc 影响到 HTTP 请求数据(GET,POST 和 COOKIE)。不能在运行时改变。在 PHP 中默认值为 on。 参见 get_magic_quotes_gpc()。
    magic_quotes_runtime 如果打开的话,大部份从外部来源取得数据并返回的函数,包括从数据库和文本文件,所返回的数据都会被反斜线转义。该选项可在运行的时改变,在 PHP 中的默认值为 off。 参见 set_magic_quotes_runtime() 和 get_magic_quotes_runtime()。
    magic_quotes_sybase 如果打开的话,将会使用单引号对单引号进行转义而非反斜线。此选项会完全覆盖 magic_quotes_gpc。如果同时打开两个选项的话,单引号将会被转义成 ''。而双引号、反斜线 和 NULL 字符将不会进行转义。 如何取得其值参见 ini_get()。

    2. addslashes() 函数

    addslashes — 使用反斜线引用字符串

    说明 ¶

    string addslashes ( string $str )
    返回字符串,该字符串为了数据库查询语句等的需要在某些字符前加上了反斜线。这些字符是单引号(')、双引号(")、反斜线()与 NUL(NULL 字符)。

    一个使用 addslashes() 的例子是当你要往数据库中输入数据时。 例如,将名字 O'reilly 插入到数据库中,这就需要对其进行转义。 强烈建议使用 DBMS 指定的转义函数 (比如 MySQL 是 mysqli_real_escape_string(),PostgreSQL 是 pg_escape_string()),但是如果你使用的 DBMS 没有一个转义函数,并且使用 来转义特殊字符,你可以使用这个函数。 仅仅是为了获取插入数据库的数据,额外的 并不会插入。 当 PHP 指令 magic_quotes_sybase 被设置成 on 时,意味着插入 ' 时将使用 ' 进行转义。

    PHP 5.4 之前 PHP 指令 magic_quotes_gpc 默认是 on, 实际上所有的 GET、POST 和 COOKIE 数据都用被 addslashes() 了。 不要对已经被 magic_quotes_gpc 转义过的字符串使用 addslashes(),因为这样会导致双层转义。 遇到这种情况时可以使用函数 get_magic_quotes_gpc() 进行检测。

    参数 ¶

    str
    要转义的字符。

    返回值 ¶

    返回转义后的字符。

    3. 绕过方式

    GBK编码下使用宽字节注入:%df

     

    二、注入类型

    1. 数字型注入:

    demo代码:    $sql = "select * from news where id=$id"
    传入后:     $sql = "select * from news where id=1"
    绕过方式:   直接注入
    绕过代码:   $sql = "select * from news where id=1 union select 1,2,3"


    2. 字符型注入:

    demo代码:    $sql = "select * from news where id=‘$name’"
    传入后:        $sql = "select * from news where id=‘xiaodi’"
    绕过方式:     闭合前后单引号
    绕过方式:     $sql = "select * from news where id=‘xiaodi' union select 1,2,3 and '1'='1’"


    3. 搜索型注入:

    demo代码:   $sql = "select * from news where name like '%$username%' order by name"
    传入后:        $sql = "select * from news where name like '%xiaodi%' order by name"
    绕过方式:    闭合%正则符号和单引号
    绕过方式:    $sql = "select * from news where name like '%xiaodi%' union select 1,2,3 and '%'='%' order by name"

    end.

  • 相关阅读:
    vue-cli构建项目 npm run build后应该怎么运行在本地查看效果
    解析JSON数组
    Lambda
    keytool不是内部或外部命令
    XML布局
    HTML5本地存储IndexedDB基础使用
    Vue 2.0基础
    cs231n__3. LostFunction
    cs231n__2. K-nearest Neighbors
    week_Last
  • 原文地址:https://www.cnblogs.com/i-honey/p/7905953.html
Copyright © 2020-2023  润新知