声明: 本文章仅限于安全技术交流,禁止用于非法途径,如读者作出危害网络安全的行为后果自负,与作者无关!
前言
今天我们来讲一下,命令执行漏洞。
什么是命令执行漏洞?
命令执行漏洞简介命令执行漏洞就是黑客可以直接在web应用中执行系统命令,从而获取敏感信息或者拿下shell权限
low
我们先来看一下页面效果
这里看到是尝试ping 一个ip地址。我们再来看一下他的代码
<?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
我们还是先来看页面效果
页面效果还是一样的,我们来看一下代码
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
import warnings
warnings.filterwarnings('ignore')
import ssl
ssl._create_default_https_context = ssl._create_unverified_context
2.读入数据
代码如下(示例):
<?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>";
}
?>
这里看到定义了一个黑名单,把&&和;替换为空,但是我拼接的字符串有很多,就不差这两个。
使用low的语句还是可以被执行的。
high
还是一样来看页面效果
页面还是一样,进行来看代码
<?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>";
}
?>
这里的黑名单明显多了不少,但是在|后面竟然有个空格,这就有点扯淡了,那这里我就利用他这个漏洞来写,这种拼接字符串,可以不用空格也是可以的。
总结
说实话这个漏洞也算比较简单的,只要熟悉了windows和linux的基础命令,这里基本都玩的明白,这个漏洞也算是高危的,如果实战遇到直接起飞。好啦,以上内容为我个人理解,不喜勿喷,如有写错欢迎指出!