命令执行

Commnd Execution 命令执行

因为没有过滤好特殊字符,导致可以执行一些恶意命令,被称作为命令执行

在操作系统中 “  &  、&& 、|  、 ||  ”都可以作为命令连接符使用

在linux上“ ; ” 可以代替“ |   ||  ”

 

 &前面为假,直接执行后面的语句

&& 前面为假直接报错,后面语句不执行

|   直接执行后面的语句

||  前面出错时,执行后面的语句

 

LOW级别

输入 127.0.0.1 && whoami 执行ping命令之后返回whoami的命令

 

查看源码

 

 <?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>";
}

?>

 

 

直接执行,没有进行过滤

 

MEDIUM级别

输入127.0.0.1&& whoami

发现执行错误

查看源码

 <?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>";
}

?>

 

将 && 和 ; 进行过滤

但依旧可以用 || 和 |、 &执行

输入 127.0.0.1  & whoami

 

 

 HIGH级别

查看源码 黑名单将大部分的连接符过滤掉了,但是黑名单容易过滤不全,下面黑名单第三个 ” |   “  

在 ”|“后面多了一个空格,所以我们构造语句127.0.0.1 |whoami

 <?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>";
}

?>

 

 成功执行

 

 

 IMPOSSIBLE级别

 查看源码

 <?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();

?>

 

采用token进行身份验证

stripslashes() 删除反斜杠

explode()将字符串打散成数组

is_number() 验证是否为数字字符串

过滤的严严实实,无法进行命令执行

 

转载于:https://www.cnblogs.com/gaonuoqi/p/11375205.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
MobaXterm是一款功能强大的终端仿真程序,支持多种操作系统,并具备一些高级功能,如图形界面内的文件管理、脚本编辑等。挂起命令运行是指在命令执行过程中暂停它,允许用户进行其他操作而不中断该命令。 以下是MobaXterm如何挂起命令运行的基本步骤: ### 步骤 1: 打开终端会话 首先,在MobaXterm窗口内打开一个远程服务器或本地终端会话。 ### 步骤 2: 输入并启动需要挂起的命令 例如,如果你想下载一个大文件,输入下载命令(通常为`wget`),然后按下回车键开始执行。默认情况下,MobaXterm将显示命令的进度条以及日志信息。 ### 步骤 3: 使用快捷键挂起命令命令正在执行的过程中,你可以按 `Ctrl + Z` 来挂起当前命令。此时,命令会被临时停止,MobaXterm界面返回到提示符状态。 ### 步骤 4: 切换至后台继续命令 如果需要退出当前会话去做其他事情,可以先按 `Ctrl + A` 然后输入 `bg` 键入,这会让暂停的进程进入后台继续执行。你还可以通过输入 `jobs -l` 查看当前所有进程的状态。 ### 步骤 5: 返回并恢复命令执行 当你准备回来处理命令时,只需要找到之前暂停的命令(可以用 `jobs` 查看列表),然后使用 `fg [job-id]` 或者直接 `fg` 将其拉回到前台执行。这里的 `[job-id]` 是在前一步看到的结果中命令行序号。 ### 相关问题: 1. **如何在MobaXterm中管理后台进程**?包括查看、重新调度或终止后台进程。 2. **MobaXterm是否支持热键自定义以加速日常操作**?如果有,如何设置这些热键。 3. **MobaXterm与SSH连接的安全性和性能优化技巧**有哪些建议?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值