【PHP代码审计】代码审计中常见的函数


0x001 配置文件

config.php cache.config.php

0x002 文件读取函数

file_get_contents()、highlight_file()、fopen()、readfile()、fread()、fgetss()、fgets()、parse_ini_file()、show_source()、file()

0x003 文件上传函数

move_uploaded_file()

0x004 打印函数

print、print_r、echo、printf、sprintf、die、var_dump、var_export

0x005 文件包含

include()、include_once()、require()和require_once()

0x006 命令执行

system()、exec()、shell_exec()、passthru()、pcntl_exec()、popen()、proc_open()

命令执行过滤

1escapeshellcmd(), 过滤整条命令.

2escapeshellarg(),保证传入命令执行函数的参数是一字符串的形式存在的.

过滤了
‘&’、’;’、’`’、’|’、’*’、’?’、’~’、’<’、’>’、’^’、’(’、’)’、’[‘、’]’、’{
    
    ‘、’}’、’$’、’'、’\x0A’、’\xFF’、’%’,’和”

0x007 代码执行

eval()、assert()、preg_replace()、call_user_func()、call_user_func_array()、array_map()

call_user_func()、call_user_func_array()、array_map()
usort()、uasort()、uksort()、array_filter()、array_reduce()、array_diff_uassoc()、array_diff_ukey()
array_udiff()、array_udiff_assoc()、array_udiff_uassoc()
array_intersect_assoc()、array_intersect_uassoc()
array_uintersect()、array_uintersect_assoc()
array_uintersect_uassoc()、array_walk()、array_walk_recursive()
xml_set_character_data_handler()、xml_set_default_handler()
xml_set_element_handler()、xml_set_end_namespace_decl_handler()
xml_set_external_entity_ref_handler()、xml_set_notation_decl_handler()
xml_set_processing_instruction_handler()
xml_set_start_namespace_decl_handler()
xml_set_unparsed_entity_decl_handler()、stream_filter_register()
set_error_handler()、register_shutdown_function()、register_tick_function()

0x008 SQL注入

报错注入

floor()、updatexml()以及extractvalue()

GeometryCollection()、polygon()、GTID_SUBSET()、multipoint()、multilinestring()、multipolygon()、LINESTRING()、exp()

GeometryCollection()
id = 1 AND GeometryCollection((select * fromselect * fromselect user())a)b))

polygon()
id = 1 AND polygon((select * fromselect * fromselect user())a)b))

multipoint()
id = 1 AND multipoint((select * fromselect * fromselect user())a)b))

multilinestring()
id = 1 AND multilinestring((select * fromselect * fromselect user())a)b))

multipolygon()
id = 1 AND multipolygon((select * fromselect * fromselect user())a)b))

linestring()
id = 1 AND LINESTRING((select * fromselect * fromselect user())a)b))

exp()
id = 1 and EXP(~(SELECT*fromSELECT user())a))

二次注入

addslashes()、mysql_real_escape_string()、mysql_escape_string()转义符号

urldecode或者rawurldecode函数解码

宽字节注入

set character_set_client=gbk

过滤函数

1、magic_quotes_gpc负责对GET、POST、COOKIE的值进行过滤。

2、magic_quotes_runtime对从数据库或者文件中获取的数据进行过滤。

3、addslashes函数,参数必须是string4、mysql_[real_]escape_string函数,转义字符串

5、intval取整函数,针对int

0x009 变量覆盖

extract()函数和parse_str()

import_request_variables()函数则是用在没有开启全局变量注册的时候,调用了这个函数则相当于开启了全局变量注册,在PHP 5.4之后这个函数已经被取消。

0x010 逻辑漏洞

1in_array()判断是否属于数组中的一个.

2is_numeric()判断是否一个变量是数字,这里可以通过提交hex编码直接绕过,返回ture

3=====,===加入了类型判断

0x011 特殊点

1、$_SERVER变量不受gpc保护.

2、mb_convert_encoding也有可能出现编码转换问题

3、显示错误信息需要打开php.ini中的display_errors=on或者在代码中加入error_reporting()函数,其中最常用的是E_ALL、E_WARNING、E_NOTICE、E_ALL代表提示所有问题,E_WARNING代表显示错误信息,E_NOTICE则是显示基础提示信息。

4、iconv函数编码截断,如果出现chr(128)chr(255)之间的字符,就可以截断

5、php文件输入流
php://stdin
php://stdout
php://stderr 
php://input
php://output 
php://fd 
php://memory
php://temp 
php://filter
php://input是读取post提交上来的数据,output是将数据流输出,php://filter是一个文件操作协议,效果类似readfile(),file(),file_get_contents(),

6、php代码解析标签

(需要short_open_tag=on,默认开启)

7、正则表达式没有验证开头和结尾^$

8、windows findfirstfile利用12<<可以读取123456.txt

9、php可变变量,$$可以覆盖变量,双引号中的变量可能会被解析,
<?php $a="${@phpinfo()}";?>

$a = "${ phpinfo()}";    @换为空格
$a = "${      phpinfo()}"; tab
$a = "${/**/phpinfo()}"; 
甚至回车+-!~\都可以

转载:https://lorexxar.cn/2015/12/21/dmsj-book/#%E6%96%87%E4%BB%B6%E5%8C%85%E5%90%AB

猜你喜欢

转载自blog.csdn.net/weixin_44032232/article/details/115117784