代码审计-DVWA-命令注入
首先说明,我水平不高,这是我在学习代码审计过程中写的记录笔记,难免有不正之处,还望指出。
Windows 10
php7.2.10 + apache
DVWA代码审计
命令执行
low
<?php
if (isset($_POST['Submit'])) {
$target = $_REQUEST['ip'];
if (stristr(php_uname('s'),'Windows NT')) {
$cmd = shell_exec('ping '.$target);
}else{
$cmd = shell_exec('ping -c 4 '.$target);
}
echo "<pre>{$cmd}</pre>";
}
?>
1、首先使用预定义变量$_POST[]来接收从form表单中传来的数据,使用isset()判断该值是否传入。
2、将接受数据中的ip的值赋给变量target。
3、进行主机系统判断,使用php_uname()获取服务器操作系统信息,win10系统中php_uname('s')返回的是Windows NT 。
4、stristr(a,b,c)函数搜索字符串b在另一字符串a中的第一次出现,并返回字符串剩余部分,且不区分大小写。如果不存在返回空,c的值为true或false,默认false,true返回字符串之前部分。
5、通过if进行判断是否为空后,使用shell_exec()执行并将所有输出流作为字符串返回。注意ping后面有空格。
6、通过分析可以看到,此执行过程无任何过滤。
medium
<?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>";
}
?>
1、在将ip的值赋给变量target后,定义了一个数组substitutions,该数组的功能是将&&和;替换为空。
2、使用字符串替换函数str_replace(a,b,c),将c中的a替换为b。
3、array_keys($subtitutions),返回的是数组的key,&&和;。
4、将target变量中的&&或;替换为空并重新赋值。
5、就是说中难度过滤了&&和;。
high
//其他内容跟中难度都一样,只是丰富了替换数组
$substitutions = array(
'&' => '',
';' => '',
'| ' => '',
'-' => '',
'$' => '',
'(' => '',
')' => '',
'`' => '',
'||' => '',
);
impose
<?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();
?>
1、使用checkToken()验证index.php页面的token,防止csrf。
2、stripslashes()函数删除由addslashes()添加的反斜杠。
3、explode()函数,将target字符串以'.'为分隔符打散为数组,因为正确的ip地址是以'.'为分隔符。
4、下面通过if判断,数组前4个是否是数字,是,再将前4个以'.'进行拼接;否,则输出用户输入有误。
5、generateSessionToken();用来生成token。
6、像最后这一种通过是不会存在命令注入的。因为它限制用户必须输入满足判定条件格式的内容,而满足该格式的只有IP地址。至于输入的ip地址范围不正确,那就不是该程序处理的事了。
代码审计-DVWA-命令注入的更多相关文章
- DVWA命令注入扣动分析
本周学习内容: 1.学习web应用安全权威指南: 2.观看安全学习视频: 实验内容: 进行DVWA命令注入漏洞 实验步骤: Low 1.打开DVWA,进入DVWA Security模块将 Level修 ...
- 《11招玩转网络安全》之第五招:DVWA命令注入
首先还是将DVWA的安全级别设置为Low,然后单击DVWA页面左侧的Command Injection按钮. 图5-1 Low级别的命令注入 这个就是最典型的命令注入接口.在文本框中输入一个IP ...
- dvwa——命令注入&文件包含
命令注入 commond_injection 源码.分析.payload: low: <?php if( isset( $_POST[ 'Submit' ] ) ) { // Get input ...
- PHP代码审计之命令注入
命令注入 命令注入就是通过利用无验证变量构造特殊语句对服务器进行渗透. 注入的种类有很多,而不仅仅是SQL Injection. php常见注入有以下几种(常见:,常见!!): 命令注入 (Comma ...
- PHP代码审计之命令注入攻击
PHP漏洞-命令注入攻击 命令注入攻击 PHP中可以使用下列5个函数来执行外部的应用程序或函数 system.exec.passthru.shell_exec.``(与shell_exec功能相同) ...
- DVWA系列精品教程:2、命令注入
文章更新于:2020-04-11 注:如何搭建环境参见:搭建DVWA Web渗透测试靶场 DVWA之命令注入漏洞 一.介绍 1.1.官方说明 1.2.总结 二.命令注入实践 2.1.安全级别:LOW ...
- PHP代码审计2-常用超全局变量,常用命令注入,常用XSS漏洞审计,文件包含
超全局变量 $GLOBALS — 引用全局作用域中可用的全部变量$_SERVER — 服务器和执行环境信息$_GET — HTTP GET 变量$_POST — HTTP POST 变量$_FILES ...
- 【DVWA】Command Injection(命令注入)通关教程
日期:2019-08-01 16:05:34 更新: 作者:Bay0net 介绍:利用命令注入,来复习了一下绕过过滤的方法,还可以写一个字典来 fuzz 命令注入的点. 0x01. 漏洞介绍 仅仅需要 ...
- DVWA各等级命令注入漏洞
漏洞描述 在web程序中,因为业务功能需求要通过web前端传递参数到后台服务器上执行,由于开发人员没有对输入进行严格过滤,导致攻击者可以构造一些额外的"带有非法目的的"命令,欺骗后 ...
- DVWA(四):Command Injection 全等级命令注入
Command Injection : 命令注入(Command Injection),对一些函数的参数没有做好过滤而导致用户可以控制输入的参数,使其恶意执行系统命令或这cmd.bash指令的一种注入 ...
随机推荐
- 用xcode打包完成,出现的Archive界面怎么打开?
要出现这个界面 只需在xcode界面进入windows 的下拉菜单Organizer
- LeetCode.1071-字符串最大公约数(Greatest Common Divisor of Strings)
这是小川的第391次更新,第421篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第253题(顺位题号是1071).对于字符串S和T,当且仅当S = T + ... + T ...
- Ciso三层交换 上vlan间互通, 端口映射到vlan
路由器2911配置: !hostname router interface GigabitEthernet0/0 ip address 10.0.0.2 255.0.0.0 ip nat outsid ...
- 【Linux开发】linux设备驱动归纳总结(八):3.设备管理的分层与面向对象思想
linux设备驱动归纳总结(八):3.设备管理的分层与面向对象思想 xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ...
- 统计学习方法 | 第1章 统计学习方法概论 | np.random.rand()函数
np.random.rand()函数 语法: np.random.rand(d0,d1,d2……dn) 注:使用方法与np.random.randn()函数相同 作用: 通过本函数可以返回一个或一组服 ...
- AKKA文档2.3(java版)—什么是角色
原文:http://doc.akka.io/docs/akka/2.3.5/general/actors.html译者:Vitas 什么是角色? 前面角色系统一节介绍了一群角色如何形成一个层次结构,并 ...
- 希尔排序--python
import random import time # 插入排序 def insertion_sort(arr, step): for i in range(step, len(arr)): for ...
- 在PostgreSQL中 pg_start_backup 做了什么?
# 在PostgreSQL中 pg_start_backup 做了什么?HM 2019-07-30 ## pg_start_backup 做一个备份开始标记,还做了一些其他的操作,下面进行探寻. * ...
- mysql语法难点
select * from emp where comm is null or comm=0;/*没有提成的员工*/ 查询有提成的员工所有信息 select * from emp where comm ...
- 2019.07.05 纪中_B
今日膜拜:czj大佬orz%%% 2019.07.05[NOIP提高组]模拟 B 组 今天做题的时候大概能判断出题人的考点,可是就是没学过...特别痛苦 T0:栈的定义,模拟就好了T1:感觉像是找规律 ...