├── LICENSE.md ├── README.md ├── test.php └── xwaf.php /LICENSE.md: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2019 Alemalakra ✓ 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # xWAF - Web Application Firewall 2 | Original Free Web Application Firewall, Open-Source. 3 | 4 | # Features 5 | 6 | - [x] XSS Vulns Fixed. 7 | - [x] SQL Injection Fixed. 8 | - [x] Anti-Cookie-Steal Method. 9 | - [x] HTML Malicious Code's Vulns Fixed. 10 | - [x] CSRF Easy to use, and validation. 11 | - [x] Block HTML Upgraded. 12 | - [x] Lightweight. 13 | - [x] Array Support, All Bypass fixed. 14 | - [x] Advanced Bot validation, Browser Validation. 15 | - [x] Most Poc's SQLi and XSS. 16 | - [x] Security upgraded. 17 | - [x] Errors supression. 18 | - [x] Cloudflare and BlazingFast Support. 19 | 20 | # Sample Usage 21 | ```php 22 | // Before all your code starts. 23 | require('xwaf.php'); 24 | $xWAF = new xWAF(); 25 | $xWAF->start(); 26 | // Your code below. 27 | ``` 28 | # Advanced Usage 29 | ```php 30 | // Before of all your CODE. 31 | require('xwaf.php'); 32 | $xWAF = new xWAF(); 33 | // Cloudflare Mode [Optional] 34 | $xWAF->useCloudflare(); 35 | // BlazingFast Mode [Optional] 36 | $xWAF->useBlazingfast(); 37 | // Use Own IP Header [Optional] 38 | $xWAF->customIPHeader('IP-Header'); 39 | // Anti-Cookie-Steal Method [Optional] 40 | $xWAF->antiCookieSteal('username'); // For trigger if on PHPSESSID is logged. 41 | 42 | // Check separated types. 43 | $xWAF->checkGET(); 44 | $xWAF->checkPOST(); 45 | $xWAF->checkCOOKIE(); 46 | // Your code below. 47 | ``` 48 | # CSRF Validation Example 49 | Please read test.php 50 | 51 | # Requirements 52 | 53 | - [x] Min: PHP5.3 (With common functions) 54 | -------------------------------------------------------------------------------- /test.php: -------------------------------------------------------------------------------- 1 | start(); 5 | // Done, Protection enabled. 6 | ?> 7 | xWAF Test 8 | 9 |
10 | verifyCSRF($_POST['csrf'])) { 15 | echo "Form Validation Completed without Errors or Vulns!


"; 16 | $Post = print_r($_POST); 17 | echo "". $Post .""; 18 | } else { 19 | echo "Invalid CSRF Token!"; 20 | } 21 | } 22 | // This is optional 23 | ?> 24 |
25 | Sample Input: 26 |
27 | CSRF: 28 |
29 | 30 |
31 |
32 | -------------------------------------------------------------------------------- /xwaf.php: -------------------------------------------------------------------------------- 1 | IPHeader = "REMOTE_ADDR"; 12 | $this->CookieCheck = true; 13 | $this->CookieCheckParam = 'username'; 14 | return true; 15 | } 16 | function shorten_string($string, $wordsreturned) { 17 | $retval = $string; 18 | $array = explode(" ", $string); 19 | if (count($array)<=$wordsreturned){ 20 | $retval = $string; 21 | } else { 22 | array_splice($array, $wordsreturned); 23 | $retval = implode(" ", $array)." ..."; 24 | } 25 | return $retval; 26 | } 27 | function vulnDetectedHTML($Method, $BadWord, $DisplayName, $TypeVuln) { 28 | header('HTTP/1.0 403 Forbidden'); 29 | echo '
xWAF - Access Denied
Web Application FirewallGithub

Access Denied - xWAF

If you think this block is an error please contact firewall developer and make sure to include the block details (displayed in the box below), so we can assist you in troubleshooting the issue.

Block details:

Your IP:'. $_SERVER[$this->IPHeader] .'
URL:'. htmlspecialchars($_SERVER['SERVER_NAME'].$_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8') .'
Your Browser: '.htmlspecialchars($_SERVER['HTTP_USER_AGENT'], ENT_QUOTES, 'UTF-8') . '
Block ID:'.$this->shorten_string(md5($TypeVuln.$Method.$DisplayName.$_SERVER[$this->IPHeader].date('DmY')), 7).'
Block reason:An attempted ' . htmlentities($TypeVuln) . ' was detected and blocked.
Time:' . date('Y-m-d H:i:s').'