dvwa命令执行漏洞分析

news/2025/2/14 6:09:51/

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.ppmy.cn/news/1111537.html

相关文章

笔试面试相关记录(3)

&#xff08;1&#xff09;String String和String.append()的底层实现 C中string append函数的使用与字符串拼接「建议收藏」-腾讯云开发者社区-腾讯云 (tencent.com) String String 在 第二个String中遇到\0就截止&#xff0c;append()的方法则是所有字符都会加在后面。 &…

vue-h5移动Web的Flex布局

Flex布局 Flexible布局&#xff0c;也就是弹性布局。 Flexible的优点是&#xff0c;不需要对元素设置固定的宽度和高度&#xff0c;元素的位置和大小也会跟着父元素或者浏览器的状态来自动适配。 同时还添加了水平居中和垂直居中的解决方案。 在页面中指定一个元素作为Flex布…

clickhouse在执行alter table update delete等命令后数据没有更新

clickhouse之删除数据或更新数据无效的解决思路 例如&#xff1a; ALTER TABLE 表名 DELETE WHERE 条件 ALTER TABLE 表名 UPDATE column1 expr1 [, ...] WHERE filter_expr分析原因&#xff1a; 我们都知道ClickHouse内核中的MergeTree存储一旦生成一个Data Part&#xff0…

opencv c++实现鼠标框选区域并显示选择的图片区域

OpenCV可以使用setMouseCallback设置鼠标事件的回调函数,从而然后根据需要进行处理。 setMouseCallback原型为: void cv::setMouseCallback(const cv::String& windowName, MouseCallback onMouse, void* userData = 0); 其中,参数说明如下:windowName:窗口名称 onMo…

Vue.js的服务器端渲染(SSR):为什么和如何

&#x1f337;&#x1f341; 博主猫头虎&#xff08;&#x1f405;&#x1f43e;&#xff09;带您 Go to New World✨&#x1f341; &#x1f984; 博客首页——&#x1f405;&#x1f43e;猫头虎的博客&#x1f390; &#x1f433; 《面试题大全专栏》 &#x1f995; 文章图文…

uni-app 实现自定义按 A~Z 排序的通讯录(字母索引导航)

创建 convertPinyin.js 文件 convertPinyin.js 将下面的内容复制粘贴到其中 const pinyin (function() {let Pinyin function(ops) {this.initialize(ops);},options {checkPolyphone: false,charcase: "default"};Pinyin.fn Pinyin.prototype {init: functi…

如何高效且优雅地使用Redis

本文从如下7个维度&#xff0c;带你全面理解Redis的最佳实践和优化&#xff1a; 内存性能可靠性运维安全资源规划监控 1、如何节省内存 1.1、控制Key的长度 在开发业务时&#xff0c;要提前预估Redis中写入key的数量&#xff0c;如果key数量达到了百万级别&#xff0c;那过…

如何使用 RunwayML 进行创意 AI 创作

标题&#xff1a;如何使用 RunwayML 进行创意 AI 创作 介绍 RunwayML 是一个基于浏览器的人工智能创作工具&#xff0c;可让用户使用各种 AI 功能来生成图像、视频、音乐、文字和其他创意内容。RunwayML 的功能包括&#xff1a; * 图像生成&#xff1a;使用生成式对抗网络 (…