PHP代码审计基础

一、GPC

  1. 整数类型不受GPC影响
  2. $_SERVER变量不受GPC保护
  3. $_FILES变量不受GPC保护
  4. 宽字节注入
  5. 数据库操作容易忘记添加单引号的地方如:in()/limit/order by/group by
  6. 只过滤了变量的值,但没有过滤key(有的程序会在代码中使用key,如带入SQL语句)
  7. php5.3以后$_REQUEST中不再包含$_COOKIE(可能导致过滤不全)
  8. GPC为on的时候,在php4和php<5.2.1的情况下GPC不处理数组第一维变量的key
  9. 在对参数进行过滤后又对其进行了其它的操作,如substr,str_replace等,这可能导致转义符被删除

二、特性

函数/语法特性
in_array 比较之前会对数据进行类型转换
is_numeric 十六进制可绕过
intval 会对字符串进行类型转换,只要第一个字符是数字即可转换成功
iconv 导致字符串截断
==与=== 双等号两边如果变量类型不同则会做类型转换
` ` 反引号命令执行
“” 双引号变量解析
$a($b) 动态函数执行
is_file 使用通配符(<,>)可绕过

三、危险函数


  • 代码执行
  1. eval
  2. preg_replace
  3. assert
  4. call_user_func
  5. call_user_func_array
  6. create_function
  7. array_map

  • 文件包含
  1. include
  2. require
  3. require_once
  4. include_once

  • 文件读取
  1. file_get_contents
  2. highlight_file
  3. fopen
  4. readfile
  5. fread
  6. fgetss
  7. fgets
  8. parse_ini_file
  9. show_source
  10. file()

  • 文件上传
  1. move_uploaded_file

  • 命令执行
  1. exec
  2. system
  3. popen
  4. passthru
  5. proc_open
  6. pcntl_exec
  7. shell_exec
  8. ` `

  • 变量覆盖
  1. $$
  2. extract
  3. parse_str
  4. mb_parse_str
  5. import_request_variables

  • 变量的编码与解码
  1. stripslashes
  2. base64_decode
  3. rawurldecode
  4. urldecode
  5. unserialize
  6. iconv
  7. mb_convert_encoding

  • 跨站脚本
  1. echo
  2. print
  3. printf
  4. sprintf
  5. print_f
  6. vprintf
  7. die
  8. var_dump
  9. var_export

  • 反序列化
  1. serialize
  2. unserialize
  3. __construct 构造函数
  4. __destruct 析构函数
  5. __toString 打印对象时自动调用
  6. __sleep 序列化时自动调用
  7. __wakeup 反序列化时自动调用

  • 枚举
  1. rand 使用rand处理session时,攻击者很容易暴力破解出session

四、阅读技巧

  1. 从index文件读起,了解程序运行流程
  2. 检查程序入口处做了哪些安全处理
  3. 检查数据库入口处做了哪些安全处理
  4. 检查数据库连接处代码
  5. 检查登陆、注册、找回密码、绑定邮箱、文件管理和文件上传等功能点
  6. 理清程序调用流程以及输入数据的流向,这样可以节约很多时间,可以有目的的查找漏洞

五、新技能

  1. 文件包含截断新姿势:http://www.hackersb.cn/hacker/105.html
      $a = $_GET['file'];
      include $a.'.html.php';

在可以控制协议的情况下,首先新建一个hello.html.php,内容为phpinfo(),然后压缩成zip,然后访问http://localhost/test/blog.php?file=zip://test.zip%23hello
注意:变量名需要在开头以控制协议

    1. 功能同上,协议更换为phar, 访问方式为:http://localhost/test/blog.php?file=phar://1.zip/1.php
原文地址:https://www.cnblogs.com/wwlww/p/8413222.html