当前位置: 首页 > news >正文

dvwa命令执行漏洞分析

dvwa靶场命令执⾏漏洞

high难度的源码:

$target = trim($_REQUEST[ ‘ip’ ]);是一个接收id值的变量

array_keys()函数功能是返回包含原数组中所有键名的一个新数组。

str_replace() 函数如下,把字符串 “Hello world!” 中的字符 “world” 替换为 “Shanghai”:

str_replace("world","Shanghai","Hello world!");

shell_exec()函数是执行Linux命令函数,可以获取全部数据

<?phpif( 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$html .= "<pre>{$cmd}</pre>";
}?>

这段源码中的substitutions是一个php关联数组,它交互过滤了所有的特殊字符,将他们置为空,但是经过观察’| ’ => ''有一段空格,没有成功过滤:

$substitutions = array('&'  => '',';'  => '','| ' => '','-'  => '','$'  => '','('  => '',')'  => '','`'  => '','||' => '',);

impossible难度的源码:

这段代码中加入了CSRF token,如果user的token值与更改密码时的token值不相等或者不存在seesion_token值,便会报错,这样就防止了伪造攻击

stripslashes()函数:过滤字符串中的反斜杠。

explode()函数:将所有的字符串打散成为数组。

is_numeric() 函数:用于检测变量是否为数字或数字字符串。

Anti-CSRF token:同时对参数ip进行严格的限制,只有“数字.数字.数字.数字”的输入才会被接受,因此不存在命令注入漏洞。

防范措施:获取要测试的IP,利用函数根据.将其分割成4个数值,再重新拼接后进行测试。

$target = $octet[0] . '.' . $octet[1] . '.' . $octet[2] . '.' . $octet[3];

限制了只有数字.数字.数字.数字才会接受,所以杜绝了命令注入漏洞

<?phpif( isset( $_POST[ 'Submit' ]  ) ) {// Check Anti-CSRF tokencheckToken( $_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 integerif( ( 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$html .= "<pre>{$cmd}</pre>";}else {// Ops. Let the user name theres a mistake$html .= '<pre>ERROR: You have entered an invalid IP.</pre>';}
}// Generate Anti-CSRF token
generateSessionToken();?>

http://www.lryc.cn/news/170182.html

相关文章:

  • 今年嵌入式行情怎么样?
  • Unity WebGL 编译 报错: emcc2: error: ‘*‘ failed: [WinError 2] ϵͳ�Ҳ���ָ�����ļ���解决办法
  • 三维模型3DTile格式轻量化压缩处理的数据质量提升方法分析
  • Pycharm2022 pycharm64.exe.Vmoptions
  • sql注入之高权限注入和文件读写
  • Java 面经
  • 无涯教程-JavaScript - ROUNDUP函数
  • 【Linux旅行记】探究操作系统是如何进行管理的!
  • 【Linux C小技巧】零长度数组的使用
  • github 网页显示不全?
  • 寄存器介绍
  • 基于CNN-LSTM的时序预测MATLAB实战
  • MySQL高可用九种方案
  • react 通过ref 获取对应 dom 的位置信息
  • SpringSecurity学习 - 认证和授权
  • JDK jps命令复习
  • Android 13.0 屏蔽Launcher3桌面app图标的长按功能
  • 软考和PMP哪个含金量更高?
  • 第一章:最新版零基础学习 PYTHON 教程(第三节 - 下载并安装Python最新版本)
  • Spring 中三种 BeanName 生成器!
  • Go基础-文件、字符
  • 启动YOLO进行图片物体识别
  • BMS电池管理系统的蓝牙芯片 国产高性能 低功耗蓝牙Soc芯片PHY6222
  • 肖sir__mysql之三表__008
  • 【Linux】常用工具(上)
  • 【kafka】可视化工具KAFKA EAGLE安装分享
  • 【深度装机】深度U盘装机后黑屏闪光标
  • 【性能测试】JMeter:集合点,同步定时器的应用实例!
  • 21天学会C++:Day11----运算符重载
  • 面经pc端项目