├── LICENSE ├── README.md ├── community_rules.txt ├── passive └── FiddleZAP_passive.js ├── standalone └── FiddleZAP_standalone.js └── user_rules.txt /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # FiddleZAP 2 | 3 | FiddleZAP is a simplified version of [EKFiddle](https://github.com/malwareinfosec/EKFiddle) for OWASP ZAP. 4 | 5 | With ZAP as your web proxy, you are able to flag malicious traffic based on predefined regular expressions. 6 | 7 | Example: Alert, highlighting and tagging when a regex matches on a string within the HTML source code of a compromised website 8 | 9 | ![image](https://user-images.githubusercontent.com/25351665/132754774-bd5278ee-dad4-4107-bfa5-472b777fd52e.png) 10 | 11 | ![image](https://user-images.githubusercontent.com/25351665/132754478-ad225161-0f66-4cc7-903b-73c89817e737.png) 12 | 13 | # Installation 14 | 15 | - Download and install ZAP: https://www.zaproxy.org/download/ 16 | 17 | - Download or clone the FiddleZAP directory into your Documents folder. 18 | 19 | It should have the following structure: 20 | 21 | ![image](https://user-images.githubusercontent.com/25351665/132750706-3965d2cb-5834-4144-bd15-3115c0dd3a67.png) 22 | 23 | ![image](https://user-images.githubusercontent.com/25351665/132750818-9ec7bbea-deff-41b0-abac-15b645768e57.png) 24 | 25 | There are 2 scripts (standalone, passive rules). The former is used to run manually on the currently loaded session (web traffic), the latter automatically runs while recording traffic. 26 | 27 | ## Stand Alone 28 | 29 | First, install the standalone script: 30 | 31 | - Click on the Load script icon: 32 | 33 | ![image](https://user-images.githubusercontent.com/25351665/132749274-64f83b76-6c01-4121-b934-3d0621c4b628.png) 34 | 35 | - Select the following parameters: 36 | 37 | ![image](https://user-images.githubusercontent.com/25351665/132750572-7cfa0fdd-9204-4d12-8c1e-7250c87c7577.png) 38 | 39 | - It now shows under standalone: 40 | 41 | ![image](https://user-images.githubusercontent.com/25351665/132749556-ae47b44b-d595-4e51-9ee4-f86815eeaf9b.png) 42 | 43 | ## Passive Rules 44 | 45 | Next, install the passive rules script: 46 | 47 | - Click on the Load script icon: 48 | 49 | ![image](https://user-images.githubusercontent.com/25351665/132749999-418b061f-78fd-4b5b-9890-eb3316d5605c.png) 50 | 51 | - Select the following parameters: 52 | 53 | ![image](https://user-images.githubusercontent.com/25351665/132750390-4789935d-cc73-4f6f-a6b0-3f251d5bd72c.png) 54 | 55 | The FiddleZAP script should now show up under Passive Rules. If it is not enabled, right-click on it and select Enable script. 56 | 57 | ![image](https://user-images.githubusercontent.com/25351665/132750118-f2a792d4-c8ec-478f-aba2-55cf8c85c122.png) 58 | 59 | # Features 60 | 61 | ## Regexes (rules) to detect malicious traffic 62 | 63 | Rules for FiddleZAP can look for URI patterns and source code patterns (session body). 64 | 65 | - A ``community_rules.txt`` file is provided with some examples. 66 | 67 | - The ``user_rules.txt`` is your own rules file. 68 | 69 | Rules are automatically loaded and used to scan incoming traffic (if Passive Rules script is enabled). If you want to run rules on previously captured traffic, you need to run the standalone script. 70 | 71 | ![image](https://user-images.githubusercontent.com/25351665/132890280-e1322936-38f8-4735-b003-b27a8c166c87.png) 72 | 73 | ## Color coding and tagging of matching web sessions 74 | 75 | (This feature requires the neonmarker add-on) 76 | 77 | ![image](https://user-images.githubusercontent.com/25351665/131417750-d06aa169-c862-4daa-abb9-55d941ea98a6.png) 78 | 79 | ## Detailed alerts 80 | 81 | ![image](https://user-images.githubusercontent.com/25351665/131417845-5289925e-573a-4eef-b42b-cf406ff9e9bb.png) 82 | 83 | 84 | -------------------------------------------------------------------------------- /community_rules.txt: -------------------------------------------------------------------------------- 1 | # These are community regexes for OWASP ZAP 2 | # 3 | # The syntax is as follows: 4 | # 5 | # alertType:[type of rule]; alertTitle:""; alertRegex://; alertColor:""; alertRisk:[integer]; alertConfidence:[integer]; alertDesc:""; alertSolution:""; alertReference:""; alertCweId:[integer]; alertWascId:[integer] 6 | # 7 | # alertType:[SourceCode/URI] 8 | # alertTitle:"A short name for the threat" 9 | # alertRegex:/[a-Z]/ 10 | # alertColor:"" // in Hex (i.e. 0xEA9999) 11 | # alertRisk:[integer] // risk: 0: info, 1: low, 2: medium, 3: high 12 | # alertConfidence:[integer] // confidence: 0: falsePositive, 1: low, 2: medium, 3: high, 4: confirmed 13 | # alertDesc:"A short description of the threat" 14 | # alertSolution:"A short description of possible mitigations" 15 | # alertReference:"https://myrefence.com" 16 | # alertCweId:[integer] 17 | # alertWascId:[integer] 18 | 19 | 20 | ## Social engineering (malware) 21 | 22 | alertType:SourceCode; alertTitle:"FakeUpdates (hacked site)"; alertRegex:/\("cmVmZXJyZXI="\)\]\|\|'';/; alertColor:"0xEA9999"; alertRisk:3; alertConfidence:4; alertDesc:""; alertSolution:""; alertReference:"https://blog.malwarebytes.com/threat-analysis/2018/04/fakeupdates-campaign-leverages-multiple-website-platforms/"; alertCweId:0; alertWascId:0 23 | alertType:URI; alertTitle:"FakeUpdates (domain shadowing)"; alertRegex:/(report\?r=dj\w+ZjaWQ9Mj)|(report\?r=Y2lkPTI(1|2)M)/; alertColor:"0xEA9999"; alertRisk:3; alertConfidence:4; alertDesc:""; alertSolution:""; alertReference:"https://blog.malwarebytes.com/threat-analysis/2018/04/fakeupdates-campaign-leverages-multiple-website-platforms/"; alertCweId:0; alertWascId:0 24 | alertType:SourceCode; alertTitle:"FakeCertificate Campaign"; alertRegex:/\[0\].appendChild\(jspp22\);|\/\/chrome.html\\">"\s\+\s"<\/frameset>";|IaNeUmeiuVNaming/; alertColor:"0xEA9999"; alertRisk:3; alertConfidence:4; alertDesc:""; alertSolution:""; alertReference:"https://twitter.com/MBThreatIntel/status/1439995792693944324?s=20"; alertCweId:0; alertWascId:0 25 | alertType:SourceCode; alertTitle:"Gootloader"; alertRegex:/j\$k([0-9]{1,10})j\$k/; alertColor:"0xEA9999"; alertRisk:3; alertConfidence:4; alertDesc:""; alertSolution:""; alertReference:"https://news.sophos.com/en-us/2021/08/12/gootloaders-mothership-controls-malicious-content/"; alertCweId:0; alertWascId:0 26 | 27 | 28 | ## Social engineering (scams) 29 | 30 | alertType:SourceCode; alertTitle:"Fake jQuery Campaign"; alertRegex:/\\x73\\x6A\\x2E\\x79\\x72\\x65\\x75\\x71\\x6A\\x2/; alertColor:"0xEA9999"; alertRisk:3; alertConfidence:4; alertDesc:""; alertSolution:""; alertReference:"https://blog.sucuri.net/2017/04/wordpress-security-unwanted-redirects-via-infected-javascript-files.html"; alertCweId:0; alertWascId:0 31 | alertType:SourceCode; alertTitle:"LNKR Campaign"; alertRegex:/lat\?jsonp=__[a-z]{3}_cb_[0-9]{9}&(#|amp)|addons\/lnkr30_nt\.min\.js/; alertColor:"0xEA9999"; alertRisk:3; alertConfidence:4; alertDesc:""; alertSolution:""; alertReference:"https://twitter.com/baberpervez2/status/1194090555468394496?s=20"; alertCweId:0; alertWascId:0 32 | 33 | 34 | # Magecart 35 | 36 | alertType:SourceCode; alertTitle:"Magecart (Q_logger)"; alertRegex:/var\s\w=\{isOpen:!1,orientation:void\s0,detectInterval:null\}/; alertColor:"0xEA9999"; alertRisk:3; alertConfidence:4; alertDesc:""; alertSolution:""; alertReference:"https://twitter.com/AffableKraut/status/1385030485676544001?s=20"; alertCweId:0; alertWascId:0 37 | alertType:SourceCode; alertTitle:"Magecart (Fake Clicky)"; alertRegex:/=','script','Y2hlY2tvdXQ=',/; alertColor:"0xEA9999"; alertRisk:3; alertConfidence:4; alertDesc:""; alertSolution:""; alertReference:"https://twitter.com/GroupIB_GIB/status/1185237251762069504?s=20"; alertCweId:0; alertWascId:0 38 | alertType:SourceCode; alertTitle:"Magecart (Google loop)"; alertRegex:/l1l1= 0) { 20 | var FiddleZAPPath = (System.getProperty('user.home') + '\\Documents\\' + 'FiddleZAP' + '\\'); 21 | print('Windows OS: ' + FiddleZAPPath); 22 | } 23 | if (OS.indexOf("mac") >= 0) { 24 | var FiddleZAPPath = (System.getProperty('user.home') + '/Documents/' + 'FiddleZAP' + '/'); 25 | print('Mac OS: ' + FiddleZAPPath); 26 | } 27 | if (OS.indexOf("nix") >= 0 || 28 | OS.indexOf("nux") >= 0 || 29 | OS.indexOf("aix") > 0) { 30 | var FiddleZAPPath = (System.getProperty('user.home') + '/Documents/' + 'FiddleZAP' + '/'); 31 | print('Linux OS: ' + FiddleZAPPath); 32 | } 33 | 34 | // Override path 35 | // if for some reason the path is not correct 36 | // you can uncomment the below and write your own 37 | // var FiddleZAPPath = ''; 38 | 39 | 40 | // Load rules (regexes) 41 | // rulesPath 42 | communityRules = FiddleZAPPath + 'community_rules.txt' 43 | userRules = FiddleZAPPath + 'user_rules.txt' 44 | 45 | var rulesArray = []; 46 | 47 | var communityRulesArr = loadScriptFromFile(communityRules).split("\r\n"); 48 | var userRulesArr = loadScriptFromFile(userRules).split("\r\n"); 49 | 50 | var tempArr = communityRulesArr.concat(userRulesArr); 51 | 52 | for (var i = 0; i < tempArr.length; i++) { 53 | if (tempArr[i].startsWith("alertType")) { 54 | var alertType = tempArr[i].split('alertType:').pop().split('; alertTitle:')[0]; 55 | var alertTitle = tempArr[i].split('alertTitle:\"').pop().split('\"; alertRegex:')[0]; 56 | var alertRegex = new RegExp(tempArr[i].split('alertRegex:\/').pop().split('\/; alertColor:')[0], 'g'); 57 | var alertColor = Number(tempArr[i].split('alertColor:\"').pop().split('\"; alertRisk:')[0]); 58 | var alertRisk = Number(tempArr[i].split('alertRisk:').pop().split('; alertConfidence:')[0]); 59 | var alertConfidence = Number(tempArr[i].split('alertConfidence:').pop().split('; alertDesc:')[0]); 60 | var alertDesc = tempArr[i].split('alertDesc:\"').pop().split('\"; alertSolution:')[0]; 61 | var alertSolution = tempArr[i].split('alertSolution:\"').pop().split('\"; alertReference:')[0]; 62 | var alertReference = tempArr[i].split('alertReference:"').pop().split('\"; alertCweId:')[0]; 63 | var alertCweId = Number(tempArr[i].split('alertCweId:').pop().split('; alertWascId:')[0]); 64 | var alertWascId = Number(tempArr[i].split('alertWascId:').pop().split('\$')[0]); 65 | 66 | rulesArray.push({ 67 | "alertType": alertType, 68 | "alertTitle": alertTitle, 69 | "alertRegex": alertRegex, 70 | "alertColor": alertColor, 71 | "alertRisk": alertRisk, 72 | "alertConfidence": alertConfidence, 73 | "alertDesc": alertDesc, 74 | "alertSolution": alertSolution, 75 | "alertReference": alertReference, 76 | "alertCweId": alertCweId, 77 | "alertWascId": alertWascId 78 | }); 79 | } 80 | } 81 | 82 | print('Rules have been loaded'); 83 | 84 | /** 85 | * Passively scans an HTTP message. The scan function will be called for 86 | * request/response made via ZAP, actual messages depend on the function 87 | * "appliesToHistoryType", defined below. 88 | * 89 | * @param ps - the PassiveScan parent object that will do all the core interface tasks 90 | * (i.e.: providing access to Threshold settings, raising alerts, etc.). 91 | * This is an ScriptsPassiveScanner object. 92 | * @param msg - the HTTP Message being scanned. This is an HttpMessage object. 93 | * @param src - the Jericho Source representation of the message being scanned. 94 | */ 95 | 96 | function scan(ps, msg, src) { 97 | // Overall dynamic variables 98 | var url = msg.getRequestHeader().getURI().toString(); 99 | var hostname = msg.getRequestHeader().getHostName().toString() 100 | var body = msg.getResponseBody().toString() 101 | 102 | // Ignore certain types of content 103 | var contenttype = msg.getResponseHeader().getHeader("Content-Type") 104 | var unwantedfiletypes = ['image/png', 'image/jpeg', 'image/gif', 'application/x-shockwave-flash', 'application/pdf'] 105 | 106 | if (unwantedfiletypes.indexOf("" + contenttype) >= 0) { 107 | // Ignore unwanted content 108 | return 109 | } else { 110 | // Loop through rules Array 111 | for (var i = 0; i < rulesArray.length; i++) { 112 | // Check for SourceCode in body 113 | if (rulesArray[i].alertType == "SourceCode") { 114 | if (rulesArray[i].alertRegex.test(body)) { 115 | rulesArray[i].alertRegex.lastIndex = 0 // Reset index 116 | // Look for match 117 | var matchFound = [] 118 | var comm 119 | while (comm = rulesArray[i].alertRegex.exec(body)) { 120 | matchFound.push(comm[0]); 121 | } 122 | // A match was found 123 | print("Found " + rulesArray[i].alertTitle + " in: " + url); 124 | // Call function to tag and alert 125 | tagAlert(ps, 126 | rulesArray[i].alertTitle, 127 | hostname, rulesArray[i].alertRisk, 128 | rulesArray[i].alertConfidence, 129 | rulesArray[i].alertDesc, 130 | rulesArray[i].alertRegex.source, 131 | rulesArray[i].alertSolution, 132 | rulesArray[i].alertReference, 133 | rulesArray[i].alertCweId, 134 | rulesArray[i].alertWascId) 135 | } 136 | } 137 | // Check for URI in url 138 | if (rulesArray[i].alertType == "URI") { 139 | if (rulesArray[i].alertRegex.test(url)) { 140 | rulesArray[i].alertRegex.lastIndex = 0 // Reset index 141 | // Look for match 142 | var matchFound = [] 143 | var comm 144 | while (comm = rulesArray[i].alertRegex.exec(url)) { 145 | matchFound.push(comm[0]); 146 | } 147 | // A match was found 148 | print("Found " + rulesArray[i].alertTitle + " in: " + url); 149 | // Call function to tag and alert 150 | tagAlert(ps, 151 | rulesArray[i].alertTitle, 152 | hostname, rulesArray[i].alertRisk, 153 | rulesArray[i].alertConfidence, 154 | rulesArray[i].alertDesc, 155 | rulesArray[i].alertRegex.source, 156 | rulesArray[i].alertSolution, 157 | rulesArray[i].alertReference, 158 | rulesArray[i].alertCweId, 159 | rulesArray[i].alertWascId) 160 | } 161 | } 162 | 163 | } // end of loop through alert rules 164 | 165 | } // end of unwanted files check 166 | 167 | } // end of function 168 | 169 | /** 170 | * Tells whether or not the scanner applies to the given history type. 171 | * 172 | * @param {Number} historyType - The ID of the history type of the message to be scanned. 173 | * @return {boolean} Whether or not the message with the given type should be scanned by this scanner. 174 | */ 175 | function appliesToHistoryType(historyType) { 176 | // For example, to just scan spider messages: 177 | // return historyType == org.parosproxy.paros.model.HistoryReference.TYPE_SPIDER; 178 | 179 | // Default behaviour scans default types. 180 | return PluginPassiveScanner.getDefaultHistoryTypes().contains(historyType); 181 | } 182 | 183 | 184 | function loadScriptFromFile(file) { 185 | var Files = Java.type('java.nio.file.Files'); 186 | var Paths = Java.type('java.nio.file.Paths'); 187 | var String = Java.type('java.lang.String'); 188 | 189 | var filePath = Paths.get(file); 190 | return new String(Files.readAllBytes(filePath), 'UTF-8'); 191 | } 192 | 193 | function tagAlert(ps, alertTitle, hostname, alertRisk, alertConfidence, alertDesc, alertRegex, alertSolution, alertReference, alertCweId, alertWascId) { 194 | ps.addTag(alertTitle); 195 | if (extNeon != null) { 196 | extNeon.addColorMapping(alertTitle, alertColor); 197 | } 198 | ps.newAlert() 199 | .setRisk(alertRisk) 200 | .setConfidence(alertConfidence) 201 | .setName(alertTitle + " at: " + hostname) 202 | .setDescription(alertDesc) 203 | .setParam('') 204 | .setEvidence(alertRegex) 205 | .setOtherInfo('') 206 | .setSolution(alertSolution) 207 | .setReference(alertReference) 208 | .setCweId(alertCweId) 209 | .setWascId(alertWascId) 210 | .raise(); 211 | } -------------------------------------------------------------------------------- /standalone/FiddleZAP_standalone.js: -------------------------------------------------------------------------------- 1 | // FiddleZAP is a simplified version of EKFiddle for OWASP ZAP 2 | // This is the standalone script 3 | // version: 0.0.2 4 | 5 | // Declare global variables 6 | var extNeon = org.parosproxy.paros.control.Control.getSingleton().getExtensionLoader().getExtension("ExtensionNeonMarker"); 7 | var System = Java.type('java.lang.System'); 8 | var extHist = org.parosproxy.paros.control.Control.getSingleton(). 9 | getExtensionLoader().getExtension(org.parosproxy.paros.extension.history.ExtensionHistory.NAME); 10 | var extensionAlert = org.parosproxy.paros.control.Control.getSingleton().getExtensionLoader().getExtension( 11 | org.zaproxy.zap.extension.alert.ExtensionAlert.NAME) 12 | 13 | // Warn user if Neonmarker add-on was not found 14 | if (extNeon != null) { 15 | print('Neonmarker add-on installed properly'); 16 | } else { 17 | print('Please install the Neonmarker add-on to have color mapping'); 18 | } 19 | 20 | // Warn user if extension alert is not installed 21 | if (extensionAlert != null) { 22 | print('extensionAlert add-on installed properly'); 23 | } else { 24 | print('Please install the extensionAlert'); 25 | } 26 | 27 | // Get operating system 28 | var OS = System.getProperty('os.name').toLowerCase(); 29 | if (OS.indexOf("win") >= 0) { 30 | var FiddleZAPPath = (System.getProperty('user.home') + '\\Documents\\' + 'FiddleZAP' + '\\'); 31 | print('Windows OS: ' + FiddleZAPPath); 32 | } 33 | if (OS.indexOf("mac") >= 0) { 34 | var FiddleZAPPath = (System.getProperty('user.home') + '/Documents/' + 'FiddleZAP' + '/'); 35 | print('Mac OS: ' + FiddleZAPPath); 36 | } 37 | if (OS.indexOf("nix") >= 0 || 38 | OS.indexOf("nux") >= 0 || 39 | OS.indexOf("aix") > 0) { 40 | var FiddleZAPPath = (System.getProperty('user.home') + '/Documents/' + 'FiddleZAP' + '/'); 41 | print('Linux OS: ' + FiddleZAPPath); 42 | } 43 | 44 | // Override path 45 | // if for some reason the path is not correct 46 | // you can uncomment the below and write your own 47 | // var FiddleZAPPath = ''; 48 | 49 | 50 | // Load rules (regexes) 51 | // rulesPath 52 | communityRules = FiddleZAPPath + 'community_rules.txt' 53 | userRules = FiddleZAPPath + 'user_rules.txt' 54 | 55 | var rulesArray = []; 56 | 57 | var communityRulesArr = loadScriptFromFile(communityRules).split("\r\n"); 58 | var userRulesArr = loadScriptFromFile(userRules).split("\r\n"); 59 | 60 | var tempArr = communityRulesArr.concat(userRulesArr); 61 | 62 | for (var i = 0; i < tempArr.length; i++) { 63 | if (tempArr[i].startsWith("alertType")) { 64 | var alertType = tempArr[i].split('alertType:').pop().split('; alertTitle:')[0]; 65 | var alertTitle = tempArr[i].split('alertTitle:\"').pop().split('\"; alertRegex:')[0]; 66 | var alertRegex = new RegExp(tempArr[i].split('alertRegex:\/').pop().split('\/; alertColor:')[0], 'g'); 67 | var alertColor = Number(tempArr[i].split('alertColor:\"').pop().split('\"; alertRisk:')[0]); 68 | var alertRisk = Number(tempArr[i].split('alertRisk:').pop().split('; alertConfidence:')[0]); 69 | var alertConfidence = Number(tempArr[i].split('alertConfidence:').pop().split('; alertDesc:')[0]); 70 | var alertDesc = tempArr[i].split('alertDesc:\"').pop().split('\"; alertSolution:')[0]; 71 | var alertSolution = tempArr[i].split('alertSolution:\"').pop().split('\"; alertReference:')[0]; 72 | var alertReference = tempArr[i].split('alertReference:"').pop().split('\"; alertCweId:')[0]; 73 | var alertCweId = Number(tempArr[i].split('alertCweId:').pop().split('; alertWascId:')[0]); 74 | var alertWascId = Number(tempArr[i].split('alertWascId:').pop().split('\$')[0]); 75 | 76 | rulesArray.push({ 77 | "alertType": alertType, 78 | "alertTitle": alertTitle, 79 | "alertRegex": alertRegex, 80 | "alertColor": alertColor, 81 | "alertRisk": alertRisk, 82 | "alertConfidence": alertConfidence, 83 | "alertDesc": alertDesc, 84 | "alertSolution": alertSolution, 85 | "alertReference": alertReference, 86 | "alertCweId": alertCweId, 87 | "alertWascId": alertWascId 88 | }); 89 | } 90 | } 91 | 92 | print('Rules have been loaded'); 93 | 94 | function listChildren(node, level) { 95 | var j; 96 | for (j = 0; j < node.getChildCount(); j++) { 97 | uri = node.getChildAt(j).getHistoryReference().getURI().toString(); 98 | msg = node.getChildAt(j).getHistoryReference().getHttpMessage(); 99 | hostname = node.getChildAt(j).getHistoryReference().getURI().getHost().toString(); 100 | currentId = node.getChildAt(j).getHistoryReference().getHistoryId(); 101 | 102 | // Loop through rules Array 103 | for (var i = 0; i < rulesArray.length; i++) { 104 | 105 | // Call URI regexes function 106 | URIRegexes(rulesArray[i].alertType, rulesArray[i].alertRegex, currentId, uri, 107 | rulesArray[i].alertTitle, hostname, rulesArray[i].alertRisk, rulesArray[i].alertConfidence, 108 | rulesArray[i].alertDesc, rulesArray[i].alertSolution, rulesArray[i].alertReference, rulesArray[i].alertCweId, rulesArray[i].alertWascId); 109 | 110 | // Call SourceCode regexes function 111 | responseLength = msg.getResponseBody().length(); 112 | if (responseLength > 0) { 113 | responseBody = msg.getResponseBody().toString(); 114 | SourceCodeRegexes(responseBody, rulesArray[i].alertType, rulesArray[i].alertRegex, currentId, uri, 115 | rulesArray[i].alertTitle, hostname, rulesArray[i].alertRisk, rulesArray[i].alertConfidence, 116 | rulesArray[i].alertDesc, rulesArray[i].alertSolution, rulesArray[i].alertReference, rulesArray[i].alertCweId, rulesArray[i].alertWascId); 117 | } 118 | } 119 | 120 | listChildren(node.getChildAt(j), level + 1); 121 | } 122 | } 123 | 124 | root = org.parosproxy.paros.model.Model.getSingleton(). 125 | getSession().getSiteTree().getRoot(); 126 | 127 | listChildren(root, 0); 128 | 129 | 130 | function loadScriptFromFile(file) { 131 | var Files = Java.type('java.nio.file.Files'); 132 | var Paths = Java.type('java.nio.file.Paths'); 133 | var String = Java.type('java.lang.String'); 134 | 135 | var filePath = Paths.get(file); 136 | return new String(Files.readAllBytes(filePath), 'UTF-8'); 137 | } 138 | 139 | function tagAlert(hr, alertType, alertRegex, currentId, uri, alertTitle, hostname, 140 | alertRisk, alertConfidence, alertDesc, alertSolution, alertReference, alertCweId, alertWascId) { 141 | hr.addTag(alertTitle); 142 | if (extNeon != null) { 143 | extNeon.addColorMapping(alertTitle, alertColor); 144 | } 145 | 146 | if (extensionAlert != null) { 147 | var alert = new org.parosproxy.paros.core.scanner.Alert(1, alertRisk, 3, alertTitle) 148 | alert.setMessage(msg) 149 | alert.setUri(msg.getRequestHeader().getURI().toString()) 150 | alert.setDescription(alertDesc); 151 | alert.setReference(alertReference); 152 | alert.setEvidence(alertRegex.toString()) 153 | extensionAlert.alertFound(alert, hr) 154 | } 155 | } 156 | 157 | function URIRegexes(alertType, alertRegex, currentId, uri, alertTitle, hostname, 158 | alertRisk, alertConfidence, alertDesc, alertSolution, alertReference, alertCweId, alertWascId) { 159 | // Check for URI in url 160 | if (alertType == "URI") { 161 | if (alertRegex.test(uri)) { 162 | alertRegex.lastIndex = 0 // Reset index 163 | // Look for match 164 | var matchFound = [] 165 | var comm 166 | while (comm = alertRegex.exec(uri)) { 167 | matchFound.push(comm[0]); 168 | } 169 | // A match was found 170 | print("Found " + alertTitle + " in: " + uri); 171 | // Call function to tag and alert 172 | hr = extHist.getHistoryReference(currentId); 173 | tagAlert(hr, alertType, alertRegex, currentId, uri, alertTitle, hostname, alertRisk, 174 | alertConfidence, alertDesc, alertSolution, alertReference, alertCweId, alertWascId); 175 | 176 | } 177 | } 178 | } 179 | 180 | function SourceCodeRegexes(responseBody, alertType, alertRegex, currentId, uri, alertTitle, hostname, 181 | alertRisk, alertConfidence, alertDesc, alertSolution, alertReference, alertCweId, alertWascId) { 182 | // Check for SourceCode in responseBody 183 | if (alertType == "SourceCode") { 184 | if (alertRegex.test(responseBody)) { 185 | alertRegex.lastIndex = 0 // Reset index 186 | // Look for match 187 | var matchFound = [] 188 | var comm 189 | while (comm = alertRegex.exec(responseBody)) { 190 | matchFound.push(comm[0]); 191 | } 192 | // A match was found 193 | print("Found " + alertTitle + " in: " + uri); 194 | // Call function to tag and alert 195 | hr = extHist.getHistoryReference(currentId); 196 | tagAlert(hr, alertType, alertRegex, currentId, uri, alertTitle, hostname, alertRisk, 197 | alertConfidence, alertDesc, alertSolution, alertReference, alertCweId, alertWascId); 198 | 199 | } 200 | } 201 | } -------------------------------------------------------------------------------- /user_rules.txt: -------------------------------------------------------------------------------- 1 | # These are the user regexes for OWASP ZAP 2 | # 3 | # The syntax is as follows: 4 | # 5 | # alertType:[type of rule]; alertTitle:""; alertRegex://; alertColor:""; alertRisk:[integer]; alertConfidence:[integer]; alertDesc:""; alertSolution:""; alertReference:""; alertCweId:[integer]; alertWascId:[integer] 6 | # alertType:[SourceCode/URI] 7 | # alertTitle:"A short name for the threat" 8 | # alertRegex:/[a-Z]/ 9 | # alertColor:"" // in Hex (i.e. 0xEA9999) 10 | # alertRisk:[integer] // risk: 0: info, 1: low, 2: medium, 3: high 11 | # alertConfidence:[integer] // confidence: 0: falsePositive, 1: low, 2: medium, 3: high, 4: confirmed 12 | # alertDesc:"A short description of the threat" 13 | # alertSolution:"A short description of possible mitigations" 14 | # alertReference:"https://myrefence.com" 15 | # alertCweId:[integer] 16 | # alertWascId:[integer] 17 | 18 | --------------------------------------------------------------------------------