【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

admin 2024年12月15日23:46:54评论18 views字数 3926阅读13分5秒阅读模式

那天下着很大的雨,母亲从城里走回来的时候,浑身就是一个泥人,那一刻我就知道我没有别的选择了

LDAP Injection (Search)

LDAP 全英文:Lightweight Directory Access Protocol,翻译过来就是轻量级的目录访问协议。其实就是访问目录,浏览目录。有很多企业存储一些数据信息,例如部门信息,部门里成员的信息,公司的可用设备信息等,这些信息单独放在类似于网站的那种数据库中的话,会显的有点大材小用,而把它们放在目录中,文本中最合适。好比在文档中搜索指定的内容,在目录中搜索指定的文件一样。 LDAP 也有自己指定的语法,也可理解为它是一个存储信息的数据库,为了搜索方便,很多网站提供了其查询的接口,和普通的搜索框无异,对于指定的搜索内容,在没有严格过滤的情况下,便可以造成LDAP 注入。

Mail Header Injection (SMTP)

通常的做法是网站实施联系表单,反过来将合法用户的电子邮件发送给消息的预期收件人。大多数情况下,这样的联系表单将设置SMTP标头From,Reply-to以便让收件人轻松处理联系表单中的通信,就像其他电子邮件一样。

不幸的是,除非用户的输入在插入SMTP头之前被验证,否则联系表单可能容易受到电子邮件头插入(也称为SMTP头注入)的攻击。这是因为攻击者可以将额外的头部注入到消息中,从而指示SMTP服务器执行与预期不同的指令。

OS Command Injection

漏洞url:http://range.anhunsec.cn:82/commandi.php

Level:low

payload:www.nsa.gov;whoami

【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

原理:在DNS查询之后再执行dir命令

Level:medium

查看源码

【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

commandi_check_1是把&和;替换了,还可以使用|

构造payload:www.nsa.gov| whoami

【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

Level:high

查看源码

【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

escapeshellcmd()函数用来跳过字符串中的特殊符号,防止恶意用户通过不正当方式破解服务器系统

OS Command lnjection - Blind

漏洞url:http://range.anhunsec.cn:82/commandi_blind.php

命令盲注就是注入后没有返回信息,要根据反应时间判断命令是否成功执行

输入127.0.0.1

【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

输入

||whoami `sleep 5 `

【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

PHP Code Injection

漏洞url:http://range.anhunsec.cn:82/phpi.php

Level:low

构造payload:?message=phpinfo();

【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

Level:medium&high

查看源码,使用了htmlspecialchars()函数无法绕过

【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

Server-Side Includes (SSI) Injection

SSI是英文"Server Side

Includes"的缩写,翻译成中文就是服务器端包含的意思。SSI是用于向HTML页面提供动态内容的Web应用程序上的指令。它们与CGI类似,不同之处在于SSI用于在加载当前页面之前或在页面可视化时执行某些操作。 为此,Web服务器在将页面提供给用户之前分析SSI,可在SHTML文件中使用SSI指令引用其他的html文件(#include),此时服务器会将SHTML中包含的SSI指令解释,再传送给客户端,此时的HTML中就不再有SSI指令了。Server-Side

Includes攻击允许通过在HTML页面中注入脚本或远程执行任意代码来利用Web应用程序。

一种对于这类漏洞的挖掘方式即是查看.stm,.shtm和.shtml的页面是否存在,但是缺少这些类型的页面并不意味着不存在SSI攻击。

默认Apache不开启SSI,SSI这种技术已经比较少用了 IIS和Apache都可以开启SSI功能

核心代码

<div id="main">  <h1>Server-Side Includes (SSI) Injection</h1>  <p>What is your IP address? Lookup your IP address... (<a href="http://sourceforge.net/projects/bwapp/files/bee-box/" target="_blank">bee-box</a> only)</p>  <form action="<?php echo($_SERVER["SCRIPT_NAME"]);?>" method="POST">      <p><label for="firstname">First name:</label><br />                                       //firstname表单      <input type="text" id="firstname" name="firstname"></p>      <p><label for="lastname">Last name:</label><br />                                         //lastname表单      <input type="text" id="lastname" name="lastname"></p>      <button type="submit" name="form" value="submit">Lookup</button>  </form>  <br />  <?php  if($field_empty == 1)                                                             //这里的PHP只是判断是否有输入  {      echo "<font color="red">Please enter both fields...</font>";  }  else  {      echo "";  }  ?></div>

防护代码

$field_empty = 0;function xss($data){  switch($_COOKIE["security_level"])  {      case "0" :          $data = no_check($data);          break;      case "1" :          $data = xss_check_4($data);          break;      case "2" :          $data = xss_check_3($data);          break;      default :          $data = no_check($data);          break;  }  return $data;}if(isset($_POST["form"])){  $firstname = ucwords(xss($_POST["firstname"]));                                           //ucwords()首字母大写  $lastname = ucwords(xss($_POST["lastname"]));  if($firstname == "" or $lastname == "")  {      $field_empty = 1;  }  else  {      $line = '<p>Hello ' . $firstname . ' ' . $lastname . ',</p><p>Your IP address is:' . '</p><h1><!--#echo var="REMOTE_ADDR" --></h1>';      // Writes a new line to the file      $fp = fopen("ssii.shtml", "w");      fputs($fp, $line, 200);      fclose($fp);      header("Location: ssii.shtml");      exit;  }}?>

low:

low级别,没有防护,能xss

【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

medium:

function xss_check_4($data){// addslashes - returns a string with backslashes before characters that need to be quoted in database queries etc.// These characters are single quote ('), double quote ("), backslash () and NUL (the NULL byte).// Do NOT use this for XSS or HTML validations!!!return addslashes($data);        }

addslashes()在符号前加反斜线

high:

function xss_check_3($data, $encoding = "UTF-8"){  // htmlspecialchars - converts special characters to HTML entities  // '&' (ampersand) becomes '&'  // '"' (double quote) becomes '"' when ENT_NOQUOTES is not set  // "'" (single quote) becomes ''' (or &apos;) only when ENT_QUOTES is set  // '<' (less than) becomes '<'  // '>' (greater than) becomes '>'  return htmlspecialchars($data, ENT_QUOTES, $encoding);}

将预定义的字符装换为html实体字符

文笔生疏,措辞浅薄,望各位大佬不吝赐教,万分感谢。

原文始发于微信公众号(儒道易行):【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行

免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉。
  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年12月15日23:46:54
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【bWAPP】OS Command Injection(Blind)&PHP Code Injection 系统命令执行https://cn-sec.com/archives/3511415.html
                  免责声明:文章中涉及的程序(方法)可能带有攻击性,仅供安全研究与教学之用,读者将其信息做其他用途,由读者承担全部法律及连带责任,本站不承担任何法律及连带责任;如有问题可邮件联系(建议使用企业邮箱或有效邮箱,避免邮件被拦截,联系方式见首页),望知悉.

发表评论

匿名网友 填写信息