├── settings.gradle ├── run-tests.sh ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── .gitignore ├── intel ├── trend_micro_magecart_011619.json └── anomali_magecart.json ├── src ├── test │ └── java │ │ └── org │ │ └── focalpoint │ │ └── isns │ │ └── burp │ │ └── srichecks │ │ ├── DNSResolverTest.java │ │ ├── JavaScriptIOCTest.java │ │ ├── IoCCheckerTest.java │ │ ├── JavascriptResourceTest.java │ │ └── ScriptFinderTest.java └── main │ └── java │ ├── org.focalpoint.isns.burp.srichecks │ ├── DriverServiceManager.java │ ├── IoCChecker.java │ ├── Requester.java │ ├── JavaScriptIOC.java │ ├── DNSResolver.java │ ├── PluginConfigurationTab.java │ ├── JavascriptResource.java │ └── ScriptFinder.java │ └── burp │ └── BurpExtender.java ├── tests.gradle ├── gradlew.bat ├── README.md ├── gradlew └── LICENSE /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'javascript-security-extension' 2 | -------------------------------------------------------------------------------- /run-tests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | #sudo systemd-resolve --flush-caches 3 | ./gradlew -b tests.gradle clean test 4 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/phefley/burp-javascript-security-extension/HEAD/gradle/wrapper/gradle-wrapper.jar -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore Gradle project-specific cache directory 2 | .gradle 3 | *.jar 4 | 5 | # Ignore Gradle build output directory 6 | build 7 | tlp-dont-share 8 | -------------------------------------------------------------------------------- /gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionBase=GRADLE_USER_HOME 2 | distributionPath=wrapper/dists 3 | distributionUrl=https\://services.gradle.org/distributions/gradle-5.0-bin.zip 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | -------------------------------------------------------------------------------- /intel/trend_micro_magecart_011619.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "source" : "https://blog.trendmicro.com/trendlabs-security-intelligence/new-magecart-attack-delivered-through-compromised-advertising-supply-chain/", 4 | "hashes" : { 5 | "sha256" : "56cca56e39431187a2bd95e53eece8f11d3cbe2ea7ee692fa891875f40f233f5" 6 | } 7 | }, 8 | { 9 | "source" : "https://blog.trendmicro.com/trendlabs-security-intelligence/new-magecart-attack-delivered-through-compromised-advertising-supply-chain/", 10 | "hashes" : { 11 | "sha256" : "f1f905558c1546cd6df67504462f0171f9fca1cfe8b0348940aad78265a5ef73" 12 | } 13 | }, 14 | { 15 | "source" : "https://blog.trendmicro.com/trendlabs-security-intelligence/new-magecart-attack-delivered-through-compromised-advertising-supply-chain/", 16 | "hashes" : { 17 | "sha256" : "87ee0ae3abcd8b4880bf48781eba16135ba03392079a8d78a663274fde4060cd" 18 | } 19 | }, 20 | { 21 | "source" : "https://blog.trendmicro.com/trendlabs-security-intelligence/new-magecart-attack-delivered-through-compromised-advertising-supply-chain/", 22 | "hashes" : { 23 | "sha256" : "80e40051baae72b37fee49ecc43e8dded645b1baf5ce6166c96a3bcf0c3582ce" 24 | } 25 | } 26 | ] -------------------------------------------------------------------------------- /src/test/java/org/focalpoint/isns/burp/srichecks/DNSResolverTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import org.junit.Test; 19 | import static org.junit.Assert.*; 20 | import java.util.Set; 21 | 22 | public class DNSResolverTest { 23 | 24 | @Test public void testResolution() { 25 | DNSResolver testunit = new DNSResolver(); 26 | String testHost = "focal-point.com"; 27 | Set results = testunit.getRecords(testHost, "A"); 28 | assertTrue(results.size() > 0); 29 | } 30 | 31 | 32 | @Test public void testCnameChain() { 33 | DNSResolver testunit = new DNSResolver(); 34 | String testHost = "sjs.bizographics.com"; 35 | System.out.println("Testing for bad CNAMES..."); 36 | testunit.printStringSet(testunit.getBadCnames(testHost)); 37 | assertFalse(testunit.hasBadCnames(testHost)); 38 | } 39 | 40 | 41 | @Test public void testForValidUrl() { 42 | DNSResolver testunit = new DNSResolver(); 43 | String testHost = "js.hs-scripts.com"; 44 | assertTrue(testunit.hasValidRecordsForAUrl(testHost)); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/test/java/org/focalpoint/isns/burp/srichecks/JavaScriptIOCTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import org.junit.Test; 19 | import static org.junit.Assert.*; 20 | import org.jsoup.nodes.Element; 21 | 22 | public class JavaScriptIOCTest { 23 | @Test public void testSourceSetGet() { 24 | JavaScriptIOC testunit = new JavaScriptIOC(); 25 | String testUrl = "https://code.jquery.com/jquery-3.3.1.js"; 26 | testunit.setSource(testUrl); 27 | assertEquals(testUrl, testunit.getSource()); 28 | } 29 | 30 | @Test public void testUrlSetGet() { 31 | JavaScriptIOC testunit = new JavaScriptIOC(); 32 | String testUrl = "https://code.jquery.com/jquery-3.3.1.js"; 33 | testunit.setUrl(testUrl); 34 | assertEquals(testUrl, testunit.getUrl()); 35 | } 36 | 37 | @Test public void testHashAddGet() { 38 | String algorithm = "md5"; 39 | String hashValue = "0cbc4295afe8e9a9341ce9db57801aa8"; 40 | JavaScriptIOC testunit = new JavaScriptIOC(); 41 | testunit.addHash(algorithm, hashValue); 42 | assertEquals(hashValue, testunit.getHash(algorithm)); 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /tests.gradle: -------------------------------------------------------------------------------- 1 | /* 2 | * This file was generated by the Gradle 'init' task. 3 | * 4 | * This generated file contains a sample Java project to get you started. 5 | * For more details take a look at the Java Quickstart chapter in the Gradle 6 | * user guide available at https://docs.gradle.org/5.0/userguide/tutorial_java_projects.html 7 | */ 8 | 9 | plugins { 10 | // Apply the java plugin to add support for Java 11 | id 'java' 12 | 13 | // Apply the application plugin to add support for building an application 14 | id 'application' 15 | } 16 | 17 | version = '1.1' 18 | 19 | test { 20 | testLogging { 21 | events "passed", "skipped", "failed" 22 | } 23 | } 24 | 25 | sourceCompatibility = '1.10' 26 | targetCompatibility = '1.10' 27 | 28 | repositories { 29 | // Use jcenter for resolving your dependencies. 30 | // You can declare any Maven/Ivy/file repository here. 31 | jcenter() 32 | } 33 | 34 | dependencies { 35 | // This dependency is found on compile classpath of this component and consumers. 36 | implementation 'com.google.guava:guava:26.0-jre' 37 | 38 | // https://mvnrepository.com/artifact/org.apache.clerezza.ext/org.json.simple 39 | compile group: 'org.apache.clerezza.ext', name: 'org.json.simple', version: '0.4' 40 | 41 | // https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java 42 | compile group: 'org.seleniumhq.selenium', name: 'selenium-java', version: '3.14.0' 43 | 44 | // https://mvnrepository.com/artifact/org.jsoup/jsoup/1.11.3 45 | // https://jsoup.org/ 46 | compile group: 'org.jsoup', name: 'jsoup', version: '1.11.3' 47 | 48 | // DNS library 49 | // https://mvnrepository.com/artifact/dnsjava/dnsjava 50 | compile group: 'dnsjava', name: 'dnsjava', version: '2.1.8' 51 | 52 | 53 | // Burp plugin requirements 54 | compile 'net.portswigger.burp.extender:burp-extender-api:1.7.13' 55 | 56 | // Use JUnit test framework 57 | testImplementation 'junit:junit:4.12' 58 | } 59 | 60 | // Define the main class for the application 61 | mainClassName = 'burp.BurpExtender' 62 | 63 | task fatJar(type: Jar) { 64 | baseName = project.name + '-all' 65 | from { configurations.compile.collect { it.isDirectory() ? it : zipTree(it) } } 66 | with jar 67 | } 68 | -------------------------------------------------------------------------------- /src/test/java/org/focalpoint/isns/burp/srichecks/IoCCheckerTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import org.junit.Test; 19 | import static org.junit.Assert.*; 20 | 21 | import org.focalpoint.isns.burp.srichecks.IoCChecker; 22 | import org.focalpoint.isns.burp.srichecks.JavaScriptIOC; 23 | import java.util.HashMap; 24 | 25 | public class IoCCheckerTest { 26 | @Test public void testCheckUrl() { 27 | // Checks to make sure that you can check a URL and obtain the correct source for it. 28 | IoCChecker testunit = new IoCChecker(); 29 | String testSource = "This is a source"; 30 | String testUrl = "https://www.focal-point.com"; 31 | testunit.addIoc(new JavaScriptIOC(testSource, testUrl)); 32 | assertTrue(testunit.checkUrl(testUrl)); 33 | assertEquals(testSource, testunit.getUrlSource(testUrl)); 34 | } 35 | 36 | @Test public void testCheckHash() { 37 | // Tests to make sure that you can check a algorithm/hash pair and obtain the source. 38 | String algorithm = "md5"; 39 | String hashValue = "0cbc4295afe8e9a9341ce9db57801aa8"; 40 | String testSource = "This is a source"; 41 | JavaScriptIOC testioc = new JavaScriptIOC(); 42 | testioc.addHash(algorithm, hashValue); 43 | testioc.setSource(testSource); 44 | IoCChecker testunit = new IoCChecker(); 45 | testunit.addIoc(testioc); 46 | HashMap hashLookup = new HashMap(); 47 | hashLookup.put(algorithm, hashValue); 48 | assertTrue(testunit.checkHash(algorithm, hashValue)); 49 | assertTrue(testunit.checkHashes(hashLookup)); 50 | assertEquals(testSource, testunit.getHashSource(algorithm, hashValue)); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | set DIRNAME=%~dp0 12 | if "%DIRNAME%" == "" set DIRNAME=. 13 | set APP_BASE_NAME=%~n0 14 | set APP_HOME=%DIRNAME% 15 | 16 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 17 | set DEFAULT_JVM_OPTS="-Xmx64m" 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windows variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | 53 | :win9xME_args 54 | @rem Slurp the command line arguments. 55 | set CMD_LINE_ARGS= 56 | set _SKIP=2 57 | 58 | :win9xME_args_slurp 59 | if "x%~1" == "x" goto execute 60 | 61 | set CMD_LINE_ARGS=%* 62 | 63 | :execute 64 | @rem Setup the command line 65 | 66 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 67 | 68 | @rem Execute Gradle 69 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 70 | 71 | :end 72 | @rem End local scope for the variables with windows NT shell 73 | if "%ERRORLEVEL%"=="0" goto mainEnd 74 | 75 | :fail 76 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 77 | rem the _cmd.exe /c_ return code! 78 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 79 | exit /b 1 80 | 81 | :mainEnd 82 | if "%OS%"=="Windows_NT" endlocal 83 | 84 | :omega 85 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # JavaScript Security Burp Extension 2 | This is a burp extension which adds passive checks to the Burp scanner. The following is a list of items it will look for: 3 | 4 | - Cross-Domain Script Includes (DOM) 5 | - JavaScript Missing Subresource Integrity Attributes 6 | - CSP Headers Do Not Require Subresource Integrity 7 | - Malicious/Vulnerable JavaScript Includes 8 | - Subresource Integrity Failed Validation 9 | - Cross-Domain Script Includes where DNS Resolution Fails 10 | 11 | It does this by looking at the HTML received and loads the DOM via a headless Chromium instance using Selenium. 12 | 13 | ## Licensing and Recognition 14 | Distributed under GPLv3. 15 | Copyright 2019: Focal Point Data Risk, LLC 16 | Written by: Peter Hefley 17 | 18 | ## Installation 19 | 1. Obtain a copy of this repo. 20 | 2. Ensure that Chrome/Chromium is installed in a standard location. 21 | 3. Obtain the appropriate chromedriver for your OS and version of Chrome (see: http://chromedriver.chromium.org/downloads/version-selection). Note the file location. 22 | 4. In burp, go to the extender tab, extensions sub-tab, and Add this extension. It is a Java extension type and you will need to select the included, or built, jar file. 23 | 5. Once started, select the "JavaScript Security" tab and set the correct chrome driver location. 24 | 25 | ## Configuration 26 | A "JavaScript Security" tab will appear in your burp session which allows you to configure two things: 27 | - The path to the chromedriver binary you want to use. This defaults to the bundled version appropriate for your operating system. Setting a chromedriver here will override the default. 28 | - The delay before evaluating the DOM (in seconds). As all of the JavaScript is gathered and run, the DOM may change over time. For advanced pages or slow connections, you might want to bump this up, but passive scans will take longer. The default, which I've had luck with, is 10 seconds. 29 | 30 | It is possible to load indicators of compromise (IOCs) as JSON files through the GUI tab. Examples are provided in the intel folder. 31 | 32 | ## Execution 33 | When you run passive checks, the checks installed will run. Any output or errors will appear on the Extender/Extensions tab under "JavaScript Security -- SRI and Threat Intel". 34 | 35 | ## Requirements 36 | 1. watch the DOM (not "html") and log every loaded JS as a finding (medium?). totally ignore scope 37 | 2. check every loaded js against a list of known compromised and make different alert 38 | 3. profit 39 | 4. When you can't load a JS resource, check to see if the domain is available. 40 | 41 | 42 | ## Known Issues 43 | I've seen weird caching issues with systemd-resolved, the default DNS service on Ubuntu. If you see resources which cannot be accessed due to DNS issues, consider disabling the DNS caching or clearing your cache. Both seem to help. 44 | 45 | ```/etc/systemd > cat resolved.conf | grep "Cache"``` 46 | 47 | ```Cache=no``` 48 | 49 | When you change your version of Chrome, you will also need to change your version of ChromeDriver, now. Google no longer supports drivers for a range of chrome versions. See http://chromedriver.chromium.org/downloads/version-selection 50 | 51 | 52 | ## References 53 | - https://developer.mozilla.org/en-US/docs/Web/Security/Subresource_Integrity 54 | - https://chromedriver.chromium.org/capabilities 55 | 56 | -------------------------------------------------------------------------------- /src/main/java/org.focalpoint.isns.burp.srichecks/DriverServiceManager.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import burp.IBurpExtenderCallbacks; 19 | 20 | import org.openqa.selenium.By; 21 | import org.openqa.selenium.WebDriver; 22 | import org.openqa.selenium.WebElement; 23 | import org.openqa.selenium.chrome.ChromeDriver; 24 | import org.openqa.selenium.chrome.ChromeOptions; 25 | import org.openqa.selenium.support.ui.ExpectedCondition; 26 | import org.openqa.selenium.support.ui.WebDriverWait; 27 | import org.openqa.selenium.StaleElementReferenceException; 28 | import org.openqa.selenium.TimeoutException; 29 | 30 | import org.openqa.selenium.chrome.ChromeDriverService; 31 | import org.openqa.selenium.remote.RemoteWebDriver; 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.io.FileOutputStream; 35 | import java.io.InputStream; 36 | 37 | public class DriverServiceManager { 38 | 39 | private String chromeDriverFilePath; 40 | private static String DEFAULT_DRIVER_PATH = "/usr/lib/chromium-browser/chromedriver"; 41 | private final static String SETTING_CHROMEDRIVER_PATH = "jssecurity.chromedriverpath"; 42 | private ChromeDriverService service; 43 | private IBurpExtenderCallbacks myCallbacks; 44 | 45 | public DriverServiceManager(){ 46 | // Just default to the default driver path 47 | chromeDriverFilePath = null; 48 | } 49 | 50 | public void setCallbacks(IBurpExtenderCallbacks cb){ 51 | myCallbacks = cb; 52 | // Get the filepath setting 53 | if (myCallbacks.loadExtensionSetting(SETTING_CHROMEDRIVER_PATH) != null){ 54 | chromeDriverFilePath = myCallbacks.loadExtensionSetting(SETTING_CHROMEDRIVER_PATH); 55 | } 56 | } 57 | 58 | 59 | public void startDriverService(){ 60 | if (chromeDriverFilePath != null) { 61 | try{ 62 | // https://seleniumhq.github.io/selenium/docs/api/java/ 63 | File driverFile; 64 | driverFile = new File(chromeDriverFilePath); 65 | service = new ChromeDriverService.Builder().usingDriverExecutable(driverFile).usingAnyFreePort().build(); 66 | service.start(); 67 | } 68 | catch (IOException e){ 69 | System.err.println("[JS-SRI][-] Could not start chromedriver service"); 70 | } 71 | catch (IllegalStateException e){ 72 | System.err.println("[JS-SRI][-] Could not start chromedriver service"); 73 | } 74 | } 75 | } 76 | 77 | public void stopDriverService(){ 78 | if (service != null) { 79 | service.stop(); 80 | } 81 | } 82 | 83 | public ChromeDriverService getService(){ 84 | return service; 85 | } 86 | 87 | private void reloadIfRunning(){ 88 | if (service != null){ 89 | if (service.isRunning()){ 90 | // Restart it 91 | stopDriverService(); 92 | startDriverService(); 93 | } 94 | } 95 | } 96 | 97 | private void reload(){ 98 | if (service != null){ 99 | if (service.isRunning()){ 100 | stopDriverService(); 101 | } 102 | } 103 | startDriverService(); 104 | } 105 | 106 | public void setDriverPath(String path){ 107 | chromeDriverFilePath = path; 108 | System.out.println("[JS-SRI] Set chromedriver path to " + path); 109 | reload(); 110 | } 111 | 112 | } -------------------------------------------------------------------------------- /src/test/java/org/focalpoint/isns/burp/srichecks/JavascriptResourceTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import org.junit.Test; 19 | import static org.junit.Assert.*; 20 | 21 | import java.util.HashMap; 22 | 23 | import org.jsoup.nodes.Element; 24 | 25 | public class JavascriptResourceTest { 26 | @Test public void testSrcSetGet() { 27 | JavascriptResource testunit = new JavascriptResource(); 28 | String testUrl = "https://code.jquery.com/jquery-3.3.1.js"; 29 | testunit.setSrc(testUrl); 30 | assertEquals(testUrl, testunit.getSrc()); 31 | } 32 | 33 | @Test public void testOriginalTagSetGet() { 34 | JavascriptResource testunit = new JavascriptResource(); 35 | String testUrl = "https://code.jquery.com/jquery-3.3.1.js"; 36 | String testTag = ""; 37 | testunit.setSrc(testUrl); 38 | testunit.setOriginalTag(testTag); 39 | assertEquals(testTag, testunit.getOriginalTag()); 40 | } 41 | 42 | @Test public void testTagParser() { 43 | JavascriptResource testunit = new JavascriptResource(); 44 | String testUrl = "https://code.jquery.com/jquery-3.3.1.js"; 45 | String testTag = ""; 46 | testunit.setSrc(testUrl); 47 | testunit.setOriginalTag(testTag); 48 | testunit.parseTag(); 49 | Element parsedTag = testunit.getParsedTag(); 50 | assertEquals(testUrl, parsedTag.attr("src")); 51 | } 52 | 53 | 54 | @Test public void testGetResource() { 55 | JavascriptResource testunit = new JavascriptResource(); 56 | String testUrl = "https://code.jquery.com/jquery-3.3.1.js"; 57 | testunit.setSrc(testUrl); 58 | testunit.setCallbacks(null); 59 | testunit.getResource(); 60 | assertTrue(testunit.hasData());; 61 | } 62 | 63 | @Test public void testHashing() { 64 | JavascriptResource testunit = new JavascriptResource(); 65 | String testUrl = "https://code.jquery.com/jquery-3.3.1.js"; 66 | testunit.setSrc(testUrl); 67 | testunit.setCallbacks(null); 68 | testunit.getResource(); 69 | testunit.calculateHashes(); 70 | String integrityValue = "sha256-2Kok7MbOyxpgUVvAk/HJ2jigOSYS2auK4Pfzbm7uH60="; // obtained from the jquery website 71 | assertEquals(integrityValue.substring(integrityValue.indexOf("-")+1), testunit.getHashes().get("sha256")); 72 | } 73 | 74 | @Test public void testIntegrity() { 75 | String testUrl = "https://code.jquery.com/jquery-3.3.1.min.js"; 76 | String originalTag = ""; 77 | JavascriptResource testunit = new JavascriptResource(null, testUrl, originalTag); 78 | System.out.println("Integrity Testing"); 79 | System.out.println("-----------------"); 80 | System.out.println("Original tag: " + originalTag); 81 | System.out.println("Hashes:"); 82 | HashMap hashes = testunit.getHashes(); 83 | for (String hashAlgo : hashes.keySet()){ 84 | System.out.println("\t" + hashAlgo + " : " + hashes.get(hashAlgo)); 85 | } 86 | System.out.println(); 87 | System.out.println(testunit.getData()); 88 | assertTrue(testunit.checkIntegrity()); 89 | } 90 | 91 | @Test public void testGithubIntegrity() { 92 | String testUrl = "https://github.githubassets.com/assets/compat-6e5ed2648dae3be3f9358af5732a780f.js"; 93 | String originalTag = ""; 94 | JavascriptResource testunit = new JavascriptResource(null, testUrl, originalTag); 95 | System.out.println("Github Integrity Testing"); 96 | System.out.println("-----------------"); 97 | System.out.println("Original tag: " + originalTag); 98 | System.out.println("Hashes:"); 99 | HashMap hashes = testunit.getHashes(); 100 | for (String hashAlgo : hashes.keySet()){ 101 | System.out.println("\t" + hashAlgo + " : " + hashes.get(hashAlgo)); 102 | } 103 | System.out.println(); 104 | System.out.println(testunit.getData()); 105 | assertTrue(testunit.checkIntegrity()); 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env sh 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Attempt to set APP_HOME 10 | # Resolve links: $0 may be a link 11 | PRG="$0" 12 | # Need this for relative symlinks. 13 | while [ -h "$PRG" ] ; do 14 | ls=`ls -ld "$PRG"` 15 | link=`expr "$ls" : '.*-> \(.*\)$'` 16 | if expr "$link" : '/.*' > /dev/null; then 17 | PRG="$link" 18 | else 19 | PRG=`dirname "$PRG"`"/$link" 20 | fi 21 | done 22 | SAVED="`pwd`" 23 | cd "`dirname \"$PRG\"`/" >/dev/null 24 | APP_HOME="`pwd -P`" 25 | cd "$SAVED" >/dev/null 26 | 27 | APP_NAME="Gradle" 28 | APP_BASE_NAME=`basename "$0"` 29 | 30 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 31 | DEFAULT_JVM_OPTS='"-Xmx64m"' 32 | 33 | # Use the maximum available, or set MAX_FD != -1 to use that value. 34 | MAX_FD="maximum" 35 | 36 | warn () { 37 | echo "$*" 38 | } 39 | 40 | die () { 41 | echo 42 | echo "$*" 43 | echo 44 | exit 1 45 | } 46 | 47 | # OS specific support (must be 'true' or 'false'). 48 | cygwin=false 49 | msys=false 50 | darwin=false 51 | nonstop=false 52 | case "`uname`" in 53 | CYGWIN* ) 54 | cygwin=true 55 | ;; 56 | Darwin* ) 57 | darwin=true 58 | ;; 59 | MINGW* ) 60 | msys=true 61 | ;; 62 | NONSTOP* ) 63 | nonstop=true 64 | ;; 65 | esac 66 | 67 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 68 | 69 | # Determine the Java command to use to start the JVM. 70 | if [ -n "$JAVA_HOME" ] ; then 71 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 72 | # IBM's JDK on AIX uses strange locations for the executables 73 | JAVACMD="$JAVA_HOME/jre/sh/java" 74 | else 75 | JAVACMD="$JAVA_HOME/bin/java" 76 | fi 77 | if [ ! -x "$JAVACMD" ] ; then 78 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 79 | 80 | Please set the JAVA_HOME variable in your environment to match the 81 | location of your Java installation." 82 | fi 83 | else 84 | JAVACMD="java" 85 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 86 | 87 | Please set the JAVA_HOME variable in your environment to match the 88 | location of your Java installation." 89 | fi 90 | 91 | # Increase the maximum file descriptors if we can. 92 | if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then 93 | MAX_FD_LIMIT=`ulimit -H -n` 94 | if [ $? -eq 0 ] ; then 95 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 96 | MAX_FD="$MAX_FD_LIMIT" 97 | fi 98 | ulimit -n $MAX_FD 99 | if [ $? -ne 0 ] ; then 100 | warn "Could not set maximum file descriptor limit: $MAX_FD" 101 | fi 102 | else 103 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 104 | fi 105 | fi 106 | 107 | # For Darwin, add options to specify how the application appears in the dock 108 | if $darwin; then 109 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 110 | fi 111 | 112 | # For Cygwin, switch paths to Windows format before running java 113 | if $cygwin ; then 114 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 115 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 116 | JAVACMD=`cygpath --unix "$JAVACMD"` 117 | 118 | # We build the pattern for arguments to be converted via cygpath 119 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 120 | SEP="" 121 | for dir in $ROOTDIRSRAW ; do 122 | ROOTDIRS="$ROOTDIRS$SEP$dir" 123 | SEP="|" 124 | done 125 | OURCYGPATTERN="(^($ROOTDIRS))" 126 | # Add a user-defined pattern to the cygpath arguments 127 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 128 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 129 | fi 130 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 131 | i=0 132 | for arg in "$@" ; do 133 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 134 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 135 | 136 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 137 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 138 | else 139 | eval `echo args$i`="\"$arg\"" 140 | fi 141 | i=$((i+1)) 142 | done 143 | case $i in 144 | (0) set -- ;; 145 | (1) set -- "$args0" ;; 146 | (2) set -- "$args0" "$args1" ;; 147 | (3) set -- "$args0" "$args1" "$args2" ;; 148 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 149 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 150 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 151 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 152 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 153 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 154 | esac 155 | fi 156 | 157 | # Escape application args 158 | save () { 159 | for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done 160 | echo " " 161 | } 162 | APP_ARGS=$(save "$@") 163 | 164 | # Collect all arguments for the java command, following the shell quoting and substitution rules 165 | eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS" 166 | 167 | # by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong 168 | if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then 169 | cd "$(dirname "$0")" 170 | fi 171 | 172 | exec "$JAVACMD" "$@" 173 | -------------------------------------------------------------------------------- /src/main/java/org.focalpoint.isns.burp.srichecks/IoCChecker.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import java.util.HashSet; 19 | import java.util.HashMap; 20 | 21 | // File I/O 22 | import java.io.FileNotFoundException; 23 | import java.io.FileReader; 24 | import java.io.IOException; 25 | 26 | // JSON Handling 27 | import org.json.simple.JSONArray; 28 | import org.json.simple.JSONObject; 29 | import org.json.simple.parser.JSONParser; 30 | import org.json.simple.parser.ParseException; 31 | 32 | import org.focalpoint.isns.burp.srichecks.JavaScriptIOC; 33 | 34 | public class IoCChecker { 35 | private HashSet iocs = new HashSet(); 36 | 37 | /** 38 | * Constructor for IoCCheckers. 39 | */ 40 | public IoCChecker(){ 41 | // add static IOCs here if you want 42 | } 43 | 44 | /** 45 | * Add a new indicator of compromise (IOC) object to this checker 46 | * @param newIoc The new IOC object to add, 47 | */ 48 | public void addIoc(JavaScriptIOC newIoc){ 49 | iocs.add(newIoc); 50 | } 51 | 52 | /** 53 | * Check to see if a given URL is a hit on any known intel 54 | * @param url The string of the URL to check. 55 | * @return Returns true if this is a hit and false if it does not match any known IOCs. 56 | */ 57 | public boolean checkUrl(String url){ 58 | for (JavaScriptIOC thisIoc : iocs){ 59 | if (thisIoc.getUrl().equals(url)){ 60 | return true; 61 | } 62 | } 63 | return false; 64 | } 65 | 66 | /** 67 | * Check to see if a given hash/algorithm set is a hit on any known intel 68 | * @param algorithm The string of the algorithm to check. 69 | * @param hashValue The base64 encoded hash value to check. 70 | * @return Returns true if this is a hit and false if it does not match any known IOCs. 71 | */ 72 | public boolean checkHash(String algorithm, String hashValue){ 73 | for (JavaScriptIOC thisIoc : iocs){ 74 | if (thisIoc.hasHash(algorithm)){ 75 | if (thisIoc.getHash(algorithm).equals(hashValue)){ 76 | return true; 77 | } 78 | } 79 | } 80 | return false; 81 | } 82 | 83 | /** 84 | * Check a set of hashes available against all known intel. 85 | * @param hashLookup A hashmap keyed by algorithm where the values are Base64 encoded hashes 86 | * @return Returns true if this is a hit and false if it does not match any known IOCs. 87 | */ 88 | public boolean checkHashes(HashMap hashLookup){ 89 | for (String algo : hashLookup.keySet()){ 90 | if (checkHash(algo, hashLookup.get(algo))){ 91 | return true; 92 | } 93 | } 94 | return false; 95 | } 96 | 97 | /** 98 | * Check a set of hashes available against all known intel and return the source for the first hit. 99 | * @param hashLookup A hashmap keyed by algorithm where the values are Base64 encoded hashes 100 | * @return Returns a string which was the source of the intel. 101 | */ 102 | public String getHashesSource(HashMap hashLookup){ 103 | for (String algo : hashLookup.keySet()){ 104 | if (checkHash(algo, hashLookup.get(algo))){ 105 | return getHashSource(algo, hashLookup.get(algo)); 106 | } 107 | } 108 | return null; 109 | } 110 | 111 | /** 112 | * Check to see if a given hash/algorithm set is a hit on any known intel and return the first source. 113 | * @param algorithm The string of the algorithm to check. 114 | * @param hashValue The base64 encoded hash value to check. 115 | * @return Returns a string which was the source of the intel. 116 | */ 117 | public String getHashSource(String algorithm, String hashValue){ 118 | for (JavaScriptIOC thisIoc : iocs){ 119 | if (thisIoc.hasHash(algorithm)){ 120 | if (thisIoc.getHash(algorithm).equals(hashValue)){ 121 | return thisIoc.getSource(); 122 | } 123 | } 124 | } 125 | return null; 126 | } 127 | 128 | /** 129 | * Check to see if a URL is a hit on any known intel and return the first source. 130 | * @param url The string of the URL to check. 131 | * @return Returns a string which was the source of the intel. 132 | */ 133 | public String getUrlSource(String url){ 134 | for (JavaScriptIOC thisIoc : iocs){ 135 | if (thisIoc.getUrl().equals(url)){ 136 | return thisIoc.getSource(); 137 | } 138 | } 139 | return null; 140 | } 141 | 142 | /** 143 | * Import IOCs from a JSON file 144 | * @param fileName the path to the JSON file to import. 145 | */ 146 | public void importIocsFromJson(String fileName){ 147 | JSONParser parser = new JSONParser(); 148 | try { 149 | JSONArray array = (JSONArray) parser.parse(new FileReader(fileName)); 150 | for (Object obj : array){ 151 | JSONObject iocJson = (JSONObject) obj; 152 | JavaScriptIOC newIoc = new JavaScriptIOC(iocJson); 153 | addIoc(newIoc); 154 | } 155 | } catch (FileNotFoundException e) { 156 | System.err.println("[JS-SRI][IOC-Import][-] File at " + fileName + " not found."); 157 | e.printStackTrace(); 158 | } catch (IOException e) { 159 | System.err.println("[JS-SRI][IOC-Import][-] IO exception for file " + fileName + "."); 160 | e.printStackTrace(); 161 | } catch (ParseException e) { 162 | System.err.println("[JS-SRI][IOC-Import][-] Parser exception for file " + fileName + "."); 163 | e.printStackTrace(); 164 | } 165 | } 166 | 167 | /** 168 | * Get the number of IOCs in this checker 169 | * @return the Integer count of IOCs 170 | */ 171 | public Integer getIocCount(){ 172 | return iocs.size(); 173 | } 174 | } -------------------------------------------------------------------------------- /src/main/java/org.focalpoint.isns.burp.srichecks/Requester.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import java.net.URL; 19 | import java.net.MalformedURLException; 20 | 21 | // For using the burp HTTP interface 22 | import burp.IHttpService; 23 | import burp.IExtensionHelpers; 24 | import burp.IBurpExtenderCallbacks; 25 | import burp.IHttpRequestResponse; 26 | import burp.IResponseInfo; 27 | 28 | import java.net.http.HttpClient; 29 | import java.net.http.HttpRequest; 30 | import java.net.http.HttpResponse; 31 | import java.net.http.HttpResponse.BodyHandlers; 32 | import java.net.URI; 33 | 34 | 35 | import java.util.Arrays; 36 | 37 | public class Requester { 38 | private IHttpService burpHttpService = null; 39 | private String urlString; 40 | private URL urlObj; 41 | private IHttpRequestResponse rr; 42 | private IExtensionHelpers myHelpers = null; 43 | private IBurpExtenderCallbacks myCallbacks = null; 44 | private short statusCode = 0; 45 | private String responseBody = ""; 46 | private byte[] responseBodyBytes = null; 47 | public static final String NO_DATA_RECEIVED = "NO DATA NO DATA NO DATA"; 48 | public static final String USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/60.0.3112.113 Safari/537.36"; 49 | 50 | /** 51 | * Public constructor for Requester objects 52 | * @param callbacks the burp suite callbacks object 53 | * @param url a String containing the URL you'll want to request 54 | * @return a new Requestor object 55 | */ 56 | public Requester(IBurpExtenderCallbacks callbacks, String url){ 57 | setCallbacks(callbacks); 58 | setUrl(url); 59 | makeService(); 60 | makeRequest(); 61 | } 62 | 63 | /** 64 | * Set the URL which the requestor will pull 65 | * @param url a String of the URL to obtain 66 | */ 67 | public void setUrl(String url){ 68 | urlString = url; 69 | try { 70 | urlObj = new URL(url); 71 | makeService(); 72 | } 73 | catch (MalformedURLException exception){ 74 | System.err.println("[JS-SRI][-] Could not parse URL " + url); 75 | } 76 | } 77 | 78 | /** 79 | * Set the callbacks object to link back to burp suite 80 | * @param callbacks the callbacks object provided to the burp extension 81 | */ 82 | public void setCallbacks(IBurpExtenderCallbacks callbacks){ 83 | myCallbacks = callbacks; 84 | if (myCallbacks == null){ 85 | myHelpers = null; 86 | } else { 87 | myHelpers = myCallbacks.getHelpers(); 88 | } 89 | } 90 | 91 | 92 | /** 93 | * Generate the HTTP service required to use the Burp HTTP interface 94 | */ 95 | public void makeService(){ 96 | if (!(myHelpers == null)){ 97 | Boolean useHttps = (urlObj.getProtocol().equals("https")); 98 | int port = 0; 99 | if (urlObj.getPort() == -1){ 100 | if (urlObj.getProtocol().equals("https")){ 101 | port = 443; 102 | } 103 | if (urlObj.getProtocol().equals("http")){ 104 | port = 80; 105 | } 106 | } 107 | else { 108 | port = urlObj.getPort(); 109 | } 110 | burpHttpService = myHelpers.buildHttpService(urlObj.getHost(), port, useHttps); 111 | } 112 | } 113 | 114 | /** 115 | * Make the HTTP request this object is set up for 116 | */ 117 | public void makeRequest(){ 118 | if (myCallbacks == null){ 119 | makeRequestWithoutBurp(); 120 | } else { 121 | makeRequestWithBurp(); 122 | } 123 | } 124 | 125 | /** 126 | * Make the HTTP request via burp 127 | */ 128 | public void makeRequestWithBurp(){ 129 | try { 130 | byte[] requestBytes = myHelpers.buildHttpRequest(urlObj); 131 | rr = myCallbacks.makeHttpRequest(burpHttpService, requestBytes); 132 | if (rr.getResponse() == null){ 133 | responseBody = NO_DATA_RECEIVED; 134 | } 135 | else { 136 | IResponseInfo responseObj = myHelpers.analyzeResponse(rr.getResponse()); 137 | statusCode = responseObj.getStatusCode(); 138 | if (statusCode == 200){ 139 | responseBodyBytes = Arrays.copyOfRange(rr.getResponse(), responseObj.getBodyOffset(), rr.getResponse().length); 140 | responseBody = myHelpers.bytesToString(responseBodyBytes); 141 | } 142 | else { 143 | responseBody = NO_DATA_RECEIVED; 144 | } 145 | } 146 | } 147 | catch (Exception e){ 148 | System.err.println("[-] There was an issue getting the JavaScript file at " + urlString); 149 | e.printStackTrace(); 150 | responseBody = NO_DATA_RECEIVED; 151 | } 152 | } 153 | 154 | /** 155 | * Make the HTTP request without using the burp callbacks interface 156 | */ 157 | public void makeRequestWithoutBurp(){ 158 | HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS).build(); 159 | HttpRequest request = HttpRequest.newBuilder() 160 | .uri(URI.create(urlString)) 161 | .build(); 162 | try { 163 | HttpResponse response = client.send(request, BodyHandlers.ofString()); 164 | statusCode = (short) response.statusCode(); 165 | responseBody = response.body(); 166 | responseBodyBytes = response.body().getBytes(); 167 | } 168 | catch (Exception ex) { 169 | System.err.println("[-] There was an issue getting the JavaScript file at " + urlString); 170 | ex.printStackTrace(); 171 | responseBody = NO_DATA_RECEIVED; 172 | } 173 | } 174 | 175 | /** 176 | * Get the HTTP status code that was provided 177 | * @return HTTP status code as a short 178 | */ 179 | public short getStatusCode(){ 180 | return statusCode; 181 | } 182 | 183 | /** 184 | * Get the response body from the request 185 | * @return the HTTP response body as a String 186 | */ 187 | public String getResponseBody(){ 188 | return responseBody; 189 | } 190 | 191 | /** 192 | * Get the response body from the request 193 | * @return the HTTP response body as an array of bytes 194 | */ 195 | public byte[] getResponseBodyBytes(){ 196 | return responseBodyBytes; 197 | } 198 | } -------------------------------------------------------------------------------- /src/main/java/org.focalpoint.isns.burp.srichecks/JavaScriptIOC.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import java.util.HashMap; 19 | import java.util.List; 20 | import java.util.Arrays; 21 | 22 | import org.json.simple.JSONObject; 23 | import org.json.simple.JSONArray; 24 | 25 | import java.security.MessageDigest; 26 | import java.security.NoSuchAlgorithmException; 27 | import java.nio.charset.StandardCharsets; 28 | 29 | import java.nio.ByteBuffer; 30 | 31 | 32 | public class JavaScriptIOC { 33 | private String url = ""; 34 | private String source = ""; 35 | private HashMap hashLookup = new HashMap(); 36 | public static List VALID_ALGORITHMS = Arrays.asList("md5", "sha1", "sha256", "sha384", "sha512"); 37 | 38 | 39 | /** 40 | * Constructor when you have a source only 41 | * @param sourceString The source for the IOC. 42 | */ 43 | public JavaScriptIOC(String sourceString){ 44 | setSource(sourceString); 45 | } 46 | 47 | /** 48 | * Constructor when you have a source and a URL 49 | * @param sourceString The source for the IOC. 50 | * @param urlString The string which is the URL IOC. 51 | */ 52 | public JavaScriptIOC(String sourceString, String urlString){ 53 | setSource(sourceString); 54 | setUrl(urlString); 55 | } 56 | 57 | /** 58 | * Default constructor 59 | */ 60 | public JavaScriptIOC(){} 61 | 62 | /** 63 | * Constructor when you have a source, URL, and a hash set 64 | * @param sourceString The source for the IOC. 65 | * @param urlString The string which is the URL IOC. 66 | * @param hashes A hashmap keyed by algorithm name of base64 encoded hash values. 67 | */ 68 | public JavaScriptIOC(String sourceString, String urlString, HashMap hashes){ 69 | hashLookup = hashes; 70 | setSource(sourceString); 71 | setUrl(urlString); 72 | } 73 | 74 | /** 75 | * Constructor when you have a JSONObject, which is used to import from a file. 76 | * @param jsonIoc A JSONObject to use from a file import to make a new IOC 77 | */ 78 | public JavaScriptIOC(JSONObject jsonIoc){ 79 | setSource((String) jsonIoc.get("source")); 80 | if (jsonIoc.containsKey("url")){ 81 | setUrl((String) jsonIoc.get("url")); 82 | } 83 | if (jsonIoc.containsKey("hashes")){ 84 | JSONObject hashes = (JSONObject) jsonIoc.get("hashes"); 85 | for (String algo : VALID_ALGORITHMS){ 86 | if (hashes.containsKey(algo)){ 87 | addHash(algo, (String) hashes.get(algo)); 88 | } 89 | } 90 | } 91 | } 92 | 93 | /** 94 | * Set the URL for this IOC 95 | * @param urlString The URL to set on this IOC 96 | */ 97 | public void setUrl(String urlString){ 98 | url = urlString; 99 | } 100 | 101 | /** 102 | * Get the URL referenced by this IOC 103 | * @return the URL IOC. An empty string ("") if not set. 104 | */ 105 | public String getUrl(){ 106 | return url; 107 | } 108 | 109 | /** 110 | * Set the source for this IOC 111 | * @param sourceString The source to set on this IOC 112 | */ 113 | public void setSource(String sourceString){ 114 | source = sourceString; 115 | } 116 | 117 | /** 118 | * Get the source referenced by this IOC 119 | * @return the IOC source. An empty string ("") if not set. 120 | */ 121 | public String getSource(){ 122 | return source; 123 | } 124 | 125 | /** 126 | * Add a hash IOC to this object 127 | * @param algorithmStr a String of the algorithm. Must be in "md5", "sha1", "sha256", "sha384", "sha512" 128 | * @param hashStr the base64 encoded hash 129 | */ 130 | public void addHash(String algorithmStr, String hashStr){ 131 | if (VALID_ALGORITHMS.contains(algorithmStr)){ 132 | hashLookup.put(algorithmStr, hashStr); 133 | } 134 | } 135 | 136 | /** 137 | * Does this object have a hash for a given algorithm? 138 | * @param algorithm a string of the algorithm name 139 | * @return true if it has a has for that algorithm, false otherwise 140 | */ 141 | public Boolean hasHash(String algorithm){ 142 | return hashLookup.containsKey(algorithm); 143 | } 144 | 145 | /** 146 | * Get the hash value for any given algorithm 147 | * @param algorithmStr The algorithm to get the hash for 148 | * @return The base64 encoded hash value or null if it doesn't have that hash 149 | */ 150 | public String getHash(String algorithmStr){ 151 | if (hasHash(algorithmStr)){ 152 | return hashLookup.get(algorithmStr); 153 | } 154 | else { 155 | return null; 156 | } 157 | } 158 | 159 | /** 160 | * Does this object equal another? This is needed for set management. 161 | * @param obj The object to test for equality to this instance 162 | * @return True if reasonably equal, false if not equal 163 | */ 164 | public boolean equals(Object obj){ 165 | if (!(obj instanceof JavaScriptIOC)){ 166 | return false; 167 | } 168 | if (obj == this){ 169 | return true; 170 | } 171 | JavaScriptIOC jsObj = (JavaScriptIOC) obj; 172 | if (!(jsObj.getSource().equals(source))){ 173 | return false; 174 | } 175 | if (!(jsObj.getUrl().equals(url))){ 176 | return false; 177 | } 178 | for (String algo : hashLookup.keySet()){ 179 | if (!(jsObj.hasHash(algo))){ 180 | return false; 181 | } 182 | else { 183 | if (!(jsObj.getHash(algo).equals(getHash(algo)))){ 184 | return false; 185 | } 186 | } 187 | } 188 | return true; 189 | } 190 | 191 | /** 192 | * Make a string out of this for internal use 193 | * @return a string representation of this object 194 | */ 195 | private String stringify(){ 196 | String outstr = ""; 197 | outstr += source + "|"; 198 | outstr += url + "|"; 199 | outstr += hashLookup.toString(); 200 | return outstr; 201 | } 202 | 203 | /** 204 | * Generate a hashcode (integer) unique to this object. Needed for set management. 205 | * String representation --> MD5 --> bytes --> integer 206 | * @return unique integer hashcode for this object. 207 | */ 208 | public int hashCode(){ 209 | // Make a unique int for each object 210 | String algorithm = "MD5"; 211 | try { 212 | MessageDigest digest = MessageDigest.getInstance(algorithm); 213 | byte[] encodedHash = digest.digest(stringify().getBytes(StandardCharsets.UTF_8)); 214 | return ByteBuffer.wrap(encodedHash).getInt(); 215 | } 216 | catch (NoSuchAlgorithmException ex) { 217 | System.err.println("[-] The provided algorithm string (" + algorithm + ") is not valid."); 218 | return -1; 219 | } 220 | } 221 | } -------------------------------------------------------------------------------- /src/main/java/org.focalpoint.isns.burp.srichecks/DNSResolver.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import org.xbill.DNS.Lookup; 19 | import org.xbill.DNS.Record; 20 | import org.xbill.DNS.TextParseException; 21 | import org.xbill.DNS.ARecord; 22 | import org.xbill.DNS.AAAARecord; 23 | import org.xbill.DNS.CNAMERecord; 24 | import org.xbill.DNS.SimpleResolver; 25 | 26 | import java.util.HashMap; 27 | import java.net.UnknownHostException; 28 | import java.util.Arrays; 29 | import java.util.List; 30 | import java.util.Set; 31 | import java.util.TreeSet; 32 | 33 | public class DNSResolver 34 | { 35 | public static final Integer CNAME = 5; 36 | public static final Integer A = 1; 37 | public static final Integer AAAA = 28; 38 | private static final String RESOLVER_NAME = null; 39 | //private static final String RESOLVER_NAME = "8.8.8.8"; // Set this if you want a different resolver. 40 | private HashMap typeLookup = new HashMap(); 41 | private SimpleResolver myResolver = null; 42 | 43 | 44 | public DNSResolver(){ 45 | typeLookup.put("CNAME", CNAME); 46 | typeLookup.put("A", A); 47 | typeLookup.put("AAAA", AAAA); 48 | try { 49 | if (RESOLVER_NAME != null){ 50 | myResolver = new SimpleResolver(RESOLVER_NAME); 51 | } else { 52 | myResolver = new SimpleResolver(); 53 | } 54 | } 55 | catch (UnknownHostException e){ 56 | System.err.print("[SRI][DNSResolver][-] could not bind DNS to resolver at " + RESOLVER_NAME); 57 | } 58 | } 59 | 60 | 61 | /** 62 | * A method to perform DNS queries using native Java 63 | * @param hostName a string of the hostname, or fqdn, to lookup 64 | * @param type a string of the DNS record type to look up 65 | * @return a set of strings which are results of the DNS query 66 | */ 67 | public Set getRecords(String hostName, Integer type) { 68 | Set retval = new TreeSet(); 69 | try { 70 | Lookup thisLookup = new Lookup(hostName, type); 71 | thisLookup.setResolver(myResolver); 72 | Record[] results = thisLookup.run(); 73 | if (results != null){ 74 | List records = Arrays.asList(results); 75 | for (Record record : records){ 76 | if ((type == A) || (type == AAAA)){ 77 | if (type == A){ 78 | ARecord thisRecord = (ARecord) record; 79 | retval.add(thisRecord.getAddress().getHostAddress()); 80 | } else { 81 | AAAARecord thisRecord = (AAAARecord) record; 82 | retval.add(thisRecord.getAddress().getHostAddress()); 83 | } 84 | } else { 85 | if (record.getType() == CNAME){ 86 | CNAMERecord thisRecord = (CNAMERecord) record; 87 | retval.add(thisRecord.getTarget().toString()); 88 | } else { 89 | retval.add(record.toString()); 90 | } 91 | } 92 | } 93 | } 94 | } 95 | catch (TextParseException e){ 96 | System.err.println("[SRI][-] There was an error parsing the name " + hostName); 97 | } 98 | return retval; 99 | } 100 | 101 | 102 | /** 103 | * A method to perform DNS queries using native Java 104 | * @param hostName a string of the hostname, or fqdn, to lookup 105 | * @param type a string of the DNS record type to look up 106 | * @return a set of strings which are results of the DNS query 107 | */ 108 | public Set getRecords(String hostName, String typeStr) { 109 | Set retval = new TreeSet(); 110 | if (typeLookup.containsKey(typeStr)){ 111 | retval.addAll(getRecords(hostName, typeLookup.get(typeStr))); 112 | } 113 | return retval; 114 | } 115 | 116 | 117 | /** 118 | * Follow the CNAME breadcrumb trail and find any which can't resolve 119 | * @param hostName a string of the hostname, or fqdn, to lookup 120 | * @return a set of strings which list the CNAME entries which could not be resolved 121 | */ 122 | public Set getBadCnames(String hostName){ 123 | Set retval = new TreeSet(); 124 | try { 125 | Lookup thisLookup = new Lookup(hostName, CNAME); 126 | thisLookup.setResolver(myResolver); 127 | Record[] results = thisLookup.run(); 128 | if (results != null){ 129 | List records = Arrays.asList(results); 130 | for (Record record : records){ 131 | CNAMERecord thisRecord = (CNAMERecord) record; 132 | String target = thisRecord.getTarget().toString(); 133 | if (hasRecordsOfType(target, CNAME)){ 134 | // check for more cnames down the tree 135 | retval.addAll(getBadCnames(target)); 136 | } else { 137 | if (!(hasRecordsOfType(target, A) || hasRecordsOfType(target, AAAA))){ 138 | // This one doesn't point to anything 139 | retval.add(target); 140 | } 141 | } 142 | } 143 | } 144 | } 145 | catch (TextParseException e){ 146 | System.err.println("[SRI][-] There was an error parsing the name " + hostName); 147 | } 148 | return retval; 149 | } 150 | 151 | 152 | /** 153 | * Are there any bad CNAMEs in the trail for this hostname? 154 | * @param hostName a string of the hostname, or fqdn, to lookup 155 | * @return a boolean value, true if there are CNAME entries which cannot be resolved 156 | */ 157 | public boolean hasBadCnames(String hostName){ 158 | return (getBadCnames(hostName).size() > 0); 159 | } 160 | 161 | 162 | /** 163 | * Does the FQDN have any DNS entries of a given type? 164 | * @param hostName a string of the hostname, or fqdn, to lookup 165 | * @param type a string of the DNS entry type 166 | * @return boolean, true if there are entries of the given type, false if not 167 | */ 168 | public boolean hasRecordsOfType(String hostName, Integer type){ 169 | return (getRecords(hostName, type).size() > 0); 170 | } 171 | 172 | 173 | /** 174 | * Does the FQDN have any DNS entries of a given type? 175 | * @param hostName a string of the hostname, or fqdn, to lookup 176 | * @param typeStr a string of the DNS entry type to check for (e.g., "CNAME", "A") 177 | * @return boolean, true if there are entries of the given type, false if not 178 | */ 179 | public boolean hasRecordsOfType(String hostName, String typeStr){ 180 | return (getRecords(hostName, typeStr).size() > 0); 181 | } 182 | 183 | 184 | /** 185 | * Does the given hostName have entries necessary to get a URL 186 | * @param hostName a string of the hostname, or fqdn, to lookup 187 | * @return boolean, true if this shakes out and could be used to get a resource 188 | */ 189 | public boolean hasValidRecordsForAUrl(String hostName){ 190 | if ((hasRecordsOfType(hostName, A) || hasRecordsOfType(hostName, AAAA)) || hasRecordsOfType(hostName, CNAME)){ 191 | // This should contain at least one record we can work with, but if it has CNAMEs let's lease them out 192 | if (hasRecordsOfType(hostName, "CNAME")){ 193 | return (!hasBadCnames(hostName)); 194 | } else { 195 | // Should be okay 196 | return true; 197 | } 198 | } else { 199 | return false; 200 | } 201 | } 202 | 203 | 204 | /** 205 | * Print a set of strings to stdout, one per line 206 | * @param setToPrint 207 | */ 208 | public void printStringSet(Set setToPrint){ 209 | for (String item : setToPrint){ 210 | System.out.println(item); 211 | } 212 | } 213 | 214 | 215 | /** 216 | * Print a set of strings to stderr, one per line 217 | * @param setToPrint 218 | */ 219 | public void printStringSetToError(Set setToPrint){ 220 | for (String item : setToPrint){ 221 | System.err.println(item); 222 | } 223 | } 224 | 225 | } -------------------------------------------------------------------------------- /src/main/java/org.focalpoint.isns.burp.srichecks/PluginConfigurationTab.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import java.awt.Color; 19 | import java.awt.Cursor; 20 | import java.awt.Dimension; 21 | import java.awt.Font; 22 | import java.awt.Label; 23 | import java.awt.event.ActionEvent; 24 | import java.awt.event.ActionListener; 25 | 26 | import javax.swing.SpringLayout; 27 | import javax.swing.JFileChooser; 28 | import javax.swing.JLabel; 29 | import javax.swing.JPanel; 30 | import javax.swing.JTextField; 31 | import javax.swing.JButton; 32 | 33 | import burp.IBurpExtenderCallbacks; 34 | 35 | import java.io.File; 36 | 37 | public class PluginConfigurationTab extends JPanel implements ActionListener{ 38 | private static PluginConfigurationTab panel; 39 | private static final Integer defaultDelay = 10; 40 | 41 | private JLabel delayLabel; 42 | private JTextField delayTextField; 43 | private JLabel driverChooserLabel; 44 | private JFileChooser driverChooser; 45 | private JTextField filePathField; 46 | private Label titleLabel; 47 | private JButton openChooserButton; 48 | 49 | private Label iocLabel; 50 | private JTextField iocCountField; 51 | private JButton openIocFileButton; 52 | private JFileChooser iocChooser; 53 | 54 | private IBurpExtenderCallbacks extensionCallbacks; 55 | 56 | private final static Integer MAX_FILE_FIELD_COLS = 60; 57 | private final static Integer MAX_DELAY_COLS = 3; 58 | private final static Integer MAX_IOC_FIELD_COLS = 3; 59 | private final static String SETTING_CHROMEDRIVER_PATH = "jssecurity.chromedriverpath"; 60 | private IoCChecker myIocChecker; 61 | 62 | private DriverServiceManager myServiceManager; 63 | 64 | /** 65 | * Default constructor 66 | */ 67 | public PluginConfigurationTab() { 68 | //render(); 69 | } 70 | 71 | /** 72 | * Get this instance 73 | * @return this instance 74 | */ 75 | public static PluginConfigurationTab getInstance() { 76 | if(panel == null) 77 | panel = new PluginConfigurationTab(); 78 | return panel; 79 | } 80 | 81 | /** 82 | * Set the IOC checker, linking the two so that the IOCs can be loaded 83 | * @param iocs An IOCChecker object used. 84 | */ 85 | public void setIocChecker(IoCChecker iocs){ 86 | myIocChecker = iocs; 87 | } 88 | 89 | /** 90 | * Set the callbacks object so configurations can be updated by the panel 91 | * @param cb The extensions call back object 92 | */ 93 | public void setCallbacks(IBurpExtenderCallbacks cb){ 94 | extensionCallbacks = cb; 95 | } 96 | 97 | /** 98 | * Set the driver service manager, linking the two so that the driver path can be modified 99 | * @param sm A driver service manager object to use 100 | */ 101 | public void setDriverServiceManager(DriverServiceManager sm){ 102 | myServiceManager = sm; 103 | } 104 | 105 | 106 | /** 107 | * Render the view 108 | */ 109 | public void render() { 110 | SpringLayout layout = new SpringLayout(); 111 | setLayout(layout); 112 | titleLabel = new Label("DOM Check Settings"); 113 | titleLabel.setForeground(new Color(229, 137, 0)); 114 | titleLabel.setFont(new Font("Dialog", Font.BOLD, 15)); 115 | layout.putConstraint(SpringLayout.NORTH, titleLabel, 5, SpringLayout.NORTH, getInstance()); 116 | layout.putConstraint(SpringLayout.WEST, titleLabel, 5, SpringLayout.WEST, getInstance()); 117 | 118 | // Driver chooser wiring 119 | driverChooser = new JFileChooser(); 120 | 121 | driverChooserLabel = new JLabel("Select the chromedriver to use:"); 122 | layout.putConstraint(SpringLayout.NORTH, driverChooserLabel, 5, SpringLayout.SOUTH, titleLabel); 123 | layout.putConstraint(SpringLayout.WEST, driverChooserLabel, 5, SpringLayout.WEST, getInstance()); 124 | 125 | // Try to set a default based on the settings 126 | if (extensionCallbacks.loadExtensionSetting(SETTING_CHROMEDRIVER_PATH) != null){ 127 | filePathField = new JTextField(extensionCallbacks.loadExtensionSetting(SETTING_CHROMEDRIVER_PATH)); 128 | File settingDriverPath = new File(extensionCallbacks.loadExtensionSetting(SETTING_CHROMEDRIVER_PATH)); 129 | driverChooser.setSelectedFile(settingDriverPath); 130 | } else { 131 | filePathField = new JTextField("None"); 132 | } 133 | 134 | 135 | filePathField.setColumns(MAX_FILE_FIELD_COLS); 136 | filePathField.setEditable(false); 137 | layout.putConstraint(SpringLayout.WEST, filePathField, 5, SpringLayout.EAST, driverChooserLabel); 138 | layout.putConstraint(SpringLayout.NORTH, filePathField, 5, SpringLayout.SOUTH, titleLabel); 139 | 140 | openChooserButton = new JButton("Select Driver..."); 141 | openChooserButton.addActionListener(this); 142 | layout.putConstraint(SpringLayout.WEST, openChooserButton, 5, SpringLayout.WEST, getInstance()); 143 | layout.putConstraint(SpringLayout.NORTH, openChooserButton, 5, SpringLayout.SOUTH, driverChooserLabel); 144 | 145 | // Delay wiring 146 | delayLabel = new JLabel("Delay (in seconds) to wait for the DOM to load:"); 147 | layout.putConstraint(SpringLayout.WEST, delayLabel, 5, SpringLayout.WEST, getInstance()); 148 | layout.putConstraint(SpringLayout.NORTH, delayLabel, 20, SpringLayout.SOUTH, openChooserButton); 149 | 150 | delayTextField = new JTextField(defaultDelay.toString()); 151 | delayTextField.setColumns(MAX_DELAY_COLS); 152 | layout.putConstraint(SpringLayout.WEST, delayTextField, 5, SpringLayout.EAST, delayLabel); 153 | layout.putConstraint(SpringLayout.NORTH, delayTextField, 20, SpringLayout.SOUTH, openChooserButton); 154 | 155 | // IoC wiring 156 | iocLabel = new Label("IoC Count: "); 157 | layout.putConstraint(SpringLayout.WEST, iocLabel, 5, SpringLayout.WEST, getInstance()); 158 | layout.putConstraint(SpringLayout.NORTH, iocLabel, 20, SpringLayout.SOUTH, delayLabel); 159 | iocCountField = new JTextField(myIocChecker.getIocCount().toString()); 160 | iocCountField.setColumns(MAX_IOC_FIELD_COLS); 161 | iocCountField.setEditable(false); 162 | layout.putConstraint(SpringLayout.WEST, iocCountField, 5, SpringLayout.EAST, iocLabel); 163 | layout.putConstraint(SpringLayout.NORTH, iocCountField, 20, SpringLayout.SOUTH, delayLabel); 164 | iocChooser = new JFileChooser(); 165 | openIocFileButton = new JButton("Import IoCs"); 166 | openIocFileButton.addActionListener(this); 167 | layout.putConstraint(SpringLayout.WEST, openIocFileButton, 5, SpringLayout.EAST, iocCountField); 168 | layout.putConstraint(SpringLayout.NORTH, openIocFileButton, 20, SpringLayout.SOUTH, delayLabel); 169 | 170 | 171 | // add to Pane 172 | add(titleLabel); 173 | add(driverChooserLabel); 174 | add(filePathField); 175 | add(openChooserButton); 176 | add(delayLabel); 177 | add(delayTextField); 178 | add(iocLabel); 179 | add(iocCountField); 180 | add(openIocFileButton); 181 | } 182 | 183 | /** 184 | * Get the delay from the GUI as an integer 185 | * If there's not an integer which can be parsed, reset this to the default 186 | * @return the delay (in seconds, as an integer) 187 | */ 188 | public Integer getDelay() { 189 | try { 190 | return Integer.parseInt(delayTextField.getText()); 191 | } 192 | catch (NumberFormatException e){ 193 | delayTextField.setText(defaultDelay.toString()); 194 | return defaultDelay; 195 | } 196 | } 197 | 198 | /** 199 | * Get the driver file path for the chromedriver which should be used by Selenium, from the GUI 200 | * @return a String which is the path to the chromedriver binary picked by the user in the GUI 201 | */ 202 | public String getDriverPath() { 203 | return driverChooser.getSelectedFile().getAbsolutePath(); 204 | } 205 | 206 | /** 207 | * Handle actions performed within the GUI 208 | * @param e an actionevent which occurred in the GUI 209 | */ 210 | public void actionPerformed(ActionEvent e){ 211 | // Handle the select button 212 | if (e.getSource() == openChooserButton){ 213 | int returnVal = driverChooser.showDialog(this, "Select Driver"); 214 | if (returnVal == JFileChooser.APPROVE_OPTION){ 215 | System.out.println("[JS-SRI][*] Selected " + getDriverPath() + " as the chrome-driver."); 216 | filePathField.setText(getDriverPath()); 217 | myServiceManager.setDriverPath(getDriverPath()); 218 | extensionCallbacks.saveExtensionSetting(SETTING_CHROMEDRIVER_PATH, getDriverPath()); 219 | } 220 | } 221 | // Handle the open IOC Button 222 | if (e.getSource() == openIocFileButton){ 223 | int returnVal = iocChooser.showOpenDialog(this); 224 | if (returnVal == JFileChooser.APPROVE_OPTION){ 225 | String filePath = iocChooser.getSelectedFile().getAbsolutePath(); 226 | System.out.println("[JS-SRI][*] Selected " + filePath + " for IoC import."); 227 | myIocChecker.importIocsFromJson(filePath); 228 | iocCountField.setText(myIocChecker.getIocCount().toString()); 229 | System.out.println("[JS-SRI][*] Imported IoCs from " + filePath + "."); 230 | } 231 | } 232 | } 233 | } -------------------------------------------------------------------------------- /src/test/java/org/focalpoint/isns/burp/srichecks/ScriptFinderTest.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import org.junit.Test; 19 | import static org.junit.Assert.*; 20 | 21 | import java.util.List; 22 | import java.util.ArrayList; 23 | 24 | import org.jsoup.nodes.Element; 25 | 26 | public class ScriptFinderTest { 27 | @Test public void testUrlSetGet() { 28 | ScriptFinder testunit = new ScriptFinder(); 29 | String testUrl = "https://code.jquery.com/jquery-3.3.1.js"; 30 | testunit.setUrl(testUrl); 31 | assertEquals(testUrl, testunit.getUrl()); 32 | } 33 | 34 | @Test public void testDriverStartStop() { 35 | ScriptFinder testunit = new ScriptFinder(); 36 | DriverServiceManager sm = new DriverServiceManager(); 37 | sm.startDriverService(); 38 | testunit.setDriverManager(sm); 39 | String testUrl = "https://code.jquery.com/jquery-3.3.1.js"; 40 | testunit.startDriver(); 41 | testunit.stopDriver(); 42 | // If you get here without any errors, you did a good thing. 43 | assertTrue(true); 44 | } 45 | 46 | @Test public void testUrlConditioning() { 47 | String testUrl1 = "jquery-3.3.1.min.js"; 48 | String testUrl = "https://code.jquery.com/test.html"; 49 | ScriptFinder testunit = new ScriptFinder(); 50 | String conditionedUrl = testunit.conditionReceivedUrl(testUrl1, testUrl); 51 | System.out.println("testing url conditioning..."); 52 | System.out.println(conditionedUrl); 53 | assertTrue(conditionedUrl.equals("https://code.jquery.com/jquery-3.3.1.min.js")); 54 | } 55 | 56 | @Test public void testSetAndParseHtml() { 57 | String testUrl1 = "https://code.jquery.com/jquery-3.3.1.min.js"; 58 | String testUrl2 = "https://code.jquery.com/jquery-3.3.1.js"; 59 | String testUrl = "https://code.jquery.com/test.html"; 60 | String TEST_HTML = "ThisisatestThisisstillatest"; 61 | ScriptFinder testunit = new ScriptFinder(); 62 | testunit.setUrl(testUrl); 63 | testunit.setHtml(TEST_HTML); 64 | List scripts = testunit.getHtmlScripts(); 65 | System.out.println("testSetAndParseHtml"); 66 | for (String scrSrc : scripts){ 67 | System.out.println(" - " + scrSrc); 68 | } 69 | System.out.println(); 70 | assertTrue(testunit.getScripts().contains(testUrl2)); 71 | assertTrue(scripts.contains(testUrl2)); 72 | assertTrue(testunit.getScripts().contains(testUrl1)); 73 | } 74 | 75 | @Test public void testScriptIsCrossDomain(){ 76 | ScriptFinder testunit = new ScriptFinder(); 77 | String testUrl = "https://code.jquery.com/jquery-3.3.1.js"; 78 | String crossDomainScript = "https://www.notarealdomain.com/jquery-3.3.1.js"; 79 | String notCrossDomainScript = "https://code.jquery.com/ascript.js"; 80 | testunit.setUrl(testUrl); 81 | assertTrue(testunit.scriptIsCrossDomain(crossDomainScript)); 82 | assertFalse(testunit.scriptIsCrossDomain(notCrossDomainScript)); 83 | } 84 | 85 | @Test public void testDownloadHtml(){ 86 | ScriptFinder testunit = new ScriptFinder(); 87 | String testUrl = "https://focal-point.com"; 88 | DriverServiceManager sm = new DriverServiceManager(); 89 | testunit.setDriverManager(sm); 90 | testunit.setUrl(testUrl); 91 | assertEquals(testUrl, testunit.getUrl()); 92 | testunit.retrieveHtml(); 93 | assertTrue(testunit.getHtml().contains("Focal Point")); 94 | } 95 | 96 | @Test public void testCheckForDomScripts(){ 97 | ScriptFinder testunit = new ScriptFinder(); 98 | String testUrl = "https://focal-point.com"; 99 | DriverServiceManager sm = new DriverServiceManager(); 100 | sm.startDriverService(); 101 | testunit.setDriverManager(sm); 102 | testunit.setUrl(testUrl); 103 | testunit.retrieveHtml(); 104 | testunit.checkForDomScripts(); 105 | System.out.println("HTML SCRIPTS"); 106 | System.out.println("============"); 107 | for (String thisScript : testunit.getHtmlScripts()){ 108 | System.out.println("* " + thisScript + " -- " + testunit.getHtmlTagFor(thisScript)); 109 | } 110 | System.out.println(); 111 | System.out.println("DOM SCRIPTS"); 112 | System.out.println("============"); 113 | for (String thisScript : testunit.getDomOnlyScripts()){ 114 | System.out.println("* " + thisScript + " -- " + testunit.getHtmlTagFor(thisScript)); 115 | } 116 | System.out.println("\n\n"); 117 | // If you get here without any errors, you did a good thing. 118 | assertTrue(true); 119 | } 120 | 121 | @Test public void runtimeTestFopo(){ 122 | final String KNOWN_HTML_SCRIPT = "https://js.hs-scripts.com/2762002.js"; 123 | final String KNOWN_DOM_SCRIPT = "https://js.usemessages.com/conversations-embed.js"; 124 | 125 | List sriScripts = new ArrayList<>(); 126 | List sriMissingScripts = new ArrayList<>(); 127 | String testUrl = "https://focal-point.com"; 128 | ScriptFinder testunit = new ScriptFinder(); 129 | DriverServiceManager sm = new DriverServiceManager(); 130 | sm.startDriverService(); 131 | testunit.setDriverManager(sm); 132 | testunit.setUrl(testUrl); 133 | testunit.retrieveHtml(); 134 | testunit.checkForDomScripts(); 135 | 136 | // Go through all of the scripts and find those which have an integrity attribute and those which don't. 137 | for (String scriptUrl : testunit.getScripts()){ 138 | String tag = testunit.getHtmlTagFor(scriptUrl); 139 | if (tag.contains("integrity=\"sha")){ 140 | sriScripts.add(scriptUrl); 141 | } 142 | else { 143 | sriMissingScripts.add(scriptUrl); 144 | } 145 | } 146 | 147 | // Check cross domain scripts 148 | assertTrue(testunit.getCrossDomainScripts().contains(KNOWN_DOM_SCRIPT)); 149 | assertTrue(testunit.getCrossDomainScripts().contains(KNOWN_HTML_SCRIPT)); 150 | assertTrue(testunit.getCrossDomainHtmlScripts().contains(KNOWN_HTML_SCRIPT)); 151 | assertTrue(testunit.getCrossDomainDomScripts().contains(KNOWN_DOM_SCRIPT)); 152 | 153 | System.out.println(testUrl); 154 | System.out.println(); 155 | System.out.println("HTML SCRIPTS"); 156 | System.out.println("============"); 157 | List htmlScripts = testunit.getHtmlScripts(); 158 | for (String thisScript : htmlScripts){ 159 | System.out.println("* \"" + thisScript + "\" -- " + testunit.getHtmlTagFor(thisScript)); 160 | } 161 | // Check for the known HTML script 162 | assertTrue(htmlScripts.contains(KNOWN_HTML_SCRIPT)); 163 | // Check to make sure the DOM script isn't there 164 | assertFalse(htmlScripts.contains(KNOWN_DOM_SCRIPT)); 165 | 166 | System.out.println(); 167 | System.out.println("DOM SCRIPTS"); 168 | System.out.println("============"); 169 | List domScripts = testunit.getDomOnlyScripts(); 170 | for (String thisScript : domScripts){ 171 | System.out.println("* \"" + thisScript + "\" -- " + testunit.getHtmlTagFor(thisScript)); 172 | } 173 | // Check for the known DOM script 174 | assertTrue(domScripts.contains(KNOWN_DOM_SCRIPT)); 175 | // Check to make sure the HTML script isn't there 176 | assertFalse(domScripts.contains(KNOWN_HTML_SCRIPT)); 177 | 178 | System.out.println(); 179 | System.out.println("SRI Scripts"); 180 | System.out.println("==========="); 181 | for (String thisScript : sriScripts){ 182 | System.out.println("* \"" + thisScript + "\" -- " + testunit.getHtmlTagFor(thisScript)); 183 | } 184 | // There should not be any 185 | assertEquals(0, sriScripts.size()); 186 | 187 | System.out.println(); 188 | System.out.println("SRI Missing Scripts"); 189 | System.out.println("==================="); 190 | for (String thisScript : sriMissingScripts){ 191 | System.out.println("* \"" + thisScript + "\" -- " + testunit.getHtmlTagFor(thisScript)); 192 | } 193 | // Check for both known scripts in sriMissing 194 | assertTrue(sriMissingScripts.contains(KNOWN_DOM_SCRIPT)); 195 | assertTrue(sriMissingScripts.contains(KNOWN_HTML_SCRIPT)); 196 | 197 | // If you get here without any errors, you did a good thing. 198 | assertTrue(true); 199 | } 200 | 201 | } 202 | -------------------------------------------------------------------------------- /intel/anomali_magecart.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 4 | "hashes" : { 5 | "sha1" : "d79aae3a361af9811c46a2cfdf64d59d3126de7d", 6 | "sha256" : "69fd11ffde20274f419b1126136ab001744600ef67f77c31750826077115ce33", 7 | "md5" : "434a1c9e65d68138666f86fbe2c630ff" 8 | } 9 | }, 10 | { 11 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 12 | "hashes" : { 13 | "sha1" : "4b348d4e99f921212aa37194020d2f4679c94755", 14 | "sha256" : "fc0fce7dfa5e5ead859be43469c2a8719f5c737df0d10dba94dfe5291fe04b4c", 15 | "md5" : "967f7722009eae576a7af1626eb43955" 16 | } 17 | }, 18 | { 19 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 20 | "hashes" : { 21 | "sha1" : "e4b58187282f2ae83a6f5f35f865d67163ff8bc5", 22 | "sha256" : "e54f23482b47bfc7f8dc7097b556e32644edc72996ea987dbe916eade48dccdf", 23 | "md5" : "46e0ac454f6dfb8c6436139c076df774" 24 | } 25 | }, 26 | { 27 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 28 | "hashes" : { 29 | "sha1" : "b7aa002e664e2a3ed76d2fe15c87bb43b9cbfa34", 30 | "sha256" : "bd1a1f2239eae87734d5eb8ffbea3bc343aca69373c860de1e46fe9689cfd70a", 31 | "md5" : "50321d8f0d0d9a44465995251bef98a1" 32 | } 33 | }, 34 | { 35 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 36 | "hashes" : { 37 | "sha1" : "0cc414e41fa0094c722f80010a3d413d05a5b42f", 38 | "sha256" : "c64adf966f5ebf7600ee6593ee391f02bfd14aec12e541357461b8bb1e156775", 39 | "md5" : "ad60c1ccb84e81e2f77b503054261920" 40 | } 41 | }, 42 | { 43 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 44 | "hashes" : { 45 | "sha1" : "86a0562d82c05460dc62898e9888b73eee4eb05f", 46 | "sha256" : "4de6c8209ba6e643ad1b773c2c12e910005b4dad9c09f6ed76a238ce089d8efb", 47 | "md5" : "180d903f47e3c7baa65825f65e09bca0" 48 | } 49 | }, 50 | { 51 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 52 | "hashes" : { 53 | "sha1" : "06ee6c14eb7fe625ae543a93f4ad86e7794f23fa", 54 | "sha256" : "02f1dc790c68ace0cf1fa5cfba6a72d9b84ea60d19196bef686d47b53bf42d80", 55 | "md5" : "0a4db14c632a6dfb66bd53c2c3efbf0b" 56 | } 57 | }, 58 | { 59 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 60 | "hashes" : { 61 | "sha1" : "f64d79c1ed4b7a96d763d0a19a7508bbbda25a5c", 62 | "sha256" : "be5c2e3a9fb3c605e7f4a2d80bb295bc6f1f7520a601014998ecbb4ac8d25da7", 63 | "md5" : "57a65a522efbc2d339de3c6fd89bdaa7" 64 | } 65 | }, 66 | { 67 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 68 | "hashes" : { 69 | "sha1" : "4c0576e7592c879a0a79c1e0df174572726a0c62", 70 | "sha256" : "957b45bf311166cd5730886f1b64028f23c758d700bb2be09aea57c293f84398", 71 | "md5" : "2ae7c73badcffa20d7ff999a809a9e5c" 72 | } 73 | }, 74 | { 75 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 76 | "hashes" : { 77 | "sha1" : "445f2ddab06bdf74b28585e810ae1a8ad439bc63", 78 | "sha256" : "a119c43f4bf93333959a33f6f5b731fd9040e277299e269a3d60c45d66df2112", 79 | "md5" : "db0cb908da4723a290478160d3b855d4" 80 | } 81 | }, 82 | { 83 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 84 | "hashes" : { 85 | "sha1" : "d7e870968fb87b4028c508d70ea0d2dd0d074aa9", 86 | "sha256" : "dd36d5d47ae45ea94123e447a95c9cba442b1bb43f84074e23549b29413cada8", 87 | "md5" : "5f56c50b6d537fef6762ef8899ecff51" 88 | } 89 | }, 90 | { 91 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 92 | "hashes" : { 93 | "sha1" : "f9da3210b6d7736fe5f7268c69ca8f60fda9c59d", 94 | "sha256" : "7da0cadd9477cf94f419a81c767c5d4b889139b870e63534e95d1593592bcd0f", 95 | "md5" : "5889b1826a45e10010e68cfe70eacdd4" 96 | } 97 | }, 98 | { 99 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 100 | "hashes" : { 101 | "sha1" : "355cb0ad31ed0d915250681e97a8b60f245fd7e3", 102 | "sha256" : "1eb0b4d0e7e0be23ae1184dc5f5fdb0db64a97f4f350d7e5efe7d5aebace015a", 103 | "md5" : "f884178d47d05be4abfa8ff81895dfcc" 104 | } 105 | }, 106 | { 107 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 108 | "hashes" : { 109 | "sha1" : "a6fd0f6a631c5089dfc97ce0558774cdec3c5416", 110 | "sha256" : "ba4909955cf17789e53580ad189725cf02771d0575d899eb436c3973647ff271", 111 | "md5" : "9cb61c81cd71d33a84e33f8ee3b81fc9" 112 | } 113 | }, 114 | { 115 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 116 | "hashes" : { 117 | "sha1" : "d28466d9be30a068035371b2e2a6cc0a2db33b92", 118 | "sha256" : "ff0079df61707bc5184c7c299e00695e7ca0e973b708c2affa0f6a28a5b4a866", 119 | "md5" : "4c1526a9d34b3e89ca238d6dbaacee81" 120 | } 121 | }, 122 | { 123 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 124 | "hashes" : { 125 | "sha1" : "059f9ed9041795956a9a17ef38842c8dd9279339", 126 | "sha256" : "b2b20a983a9d9cfa017d0766139eca1e524137e60db9d431ecbee0a237d54aca", 127 | "md5" : "fe59f6f0d088e07177361c773cd807ba" 128 | } 129 | }, 130 | { 131 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 132 | "hashes" : { 133 | "sha1" : "25ecc3fdfe0e9914217ad284b8d49a2c61420bbf", 134 | "sha256" : "f65e22f893e08cada99f31be5dcce2deb6685df5ba929ce5558df2a28a8333e4", 135 | "md5" : "787d1d1733a70e5107f414f9b1e7868d" 136 | } 137 | }, 138 | { 139 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 140 | "hashes" : { 141 | "sha1" : "848d3b1b78d0a69f329fd86a7895f0d1c83f5a5e", 142 | "sha256" : "f88d99661dde2aaed0221d3684d6c6fa50f8b91413568e290ea71d3f8012cb28", 143 | "md5" : "568edce319520bf9fac7151fc4f0138b" 144 | } 145 | }, 146 | { 147 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 148 | "hashes" : { 149 | "sha1" : "051459e1f8f14beed79ad297edc79afc2dcb0fab", 150 | "sha256" : "52ecec641a9a0f157f181b2a6bc7b62c2fbafb95f97e9096130312cd9858cc28", 151 | "md5" : "52f1ab47408c523e91ffe4aae2f1b9ea" 152 | } 153 | }, 154 | { 155 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 156 | "hashes" : { 157 | "sha1" : "dbc75abb41f4112a716ffef9520e3f454e3d4d5b", 158 | "sha256" : "aff54f029566038581f65dcde5940fce96e6b98665071ea49b3cd803d3441d93", 159 | "md5" : "f40ed59e2a32393a75f05766973c507d" 160 | } 161 | }, 162 | { 163 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 164 | "hashes" : { 165 | "sha1" : "dbc75abb41f4112a716ffef9520e3f454e3d4d5b", 166 | "sha256" : "aff54f029566038581f65dcde5940fce96e6b98665071ea49b3cd803d3441d93", 167 | "md5" : "f40ed59e2a32393a75f05766973c507d" 168 | } 169 | }, 170 | { 171 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 172 | "hashes" : { 173 | "sha1" : "dbc75abb41f4112a716ffef9520e3f454e3d4d5b", 174 | "sha256" : "02f1dc790c68ace0cf1fa5cfba6a72d9b84ea60d19196bef686d47b53bf42d80", 175 | "md5" : "f40ed59e2a32393a75f05766973c507d" 176 | } 177 | }, 178 | { 179 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 180 | "hashes" : { 181 | "sha1" : "e4f118c3f4c44129c50f2e5889447b5618b88604", 182 | "sha256" : "7809510b73475f418a95a4633b4b6b71a7bafba2322d5a5756537e02fe1518e5", 183 | "md5" : "98ceaced3fa4c06ad48c8eb52352d528" 184 | } 185 | }, 186 | { 187 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 188 | "url" : "http://jquery-js.com/latest/jquery.min.js" 189 | }, 190 | { 191 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 192 | "url" : "https://jquery-js.com/latest/jquery.min.js" 193 | }, 194 | { 195 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 196 | "url" : "http://g-analytics.com/__utm.gif?v=1&_v=j68&a=98811130&t=pageview&_s=1&sd=24-bit&sr=2560x1440&vp=2145x371&je=0&_u=AACAAEAB~&jid=1841704724&gjid=877686936&cid=1283183910.1527732071" 197 | }, 198 | { 199 | "source" : "https://www.anomali.com/blog/is-magecart-checking-out-your-secure-online-transactions", 200 | "url" : "https://g-analytics.com/__utm.gif?v=1&_v=j68&a=98811130&t=pageview&_s=1&sd=24-bit&sr=2560x1440&vp=2145x371&je=0&_u=AACAAEAB~&jid=1841704724&gjid=877686936&cid=1283183910.1527732071" 201 | } 202 | ] -------------------------------------------------------------------------------- /src/main/java/org.focalpoint.isns.burp.srichecks/JavascriptResource.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import java.util.HashMap; 19 | 20 | import org.jsoup.Jsoup; 21 | import org.jsoup.nodes.Document; 22 | import org.jsoup.nodes.Element; 23 | 24 | import org.focalpoint.isns.burp.srichecks.Requester; 25 | 26 | import burp.IBurpExtenderCallbacks; 27 | 28 | import java.net.URI; 29 | import java.security.MessageDigest; 30 | import java.security.NoSuchAlgorithmException; 31 | import java.nio.charset.StandardCharsets; 32 | import java.util.Base64; 33 | 34 | import org.focalpoint.isns.burp.srichecks.DNSResolver; 35 | 36 | public class JavascriptResource { 37 | private String src; 38 | private String originalTag; 39 | private Element parsedTag; 40 | private String data = ""; 41 | private byte[] binaryData = null; 42 | private Boolean dnsValid = false; 43 | private IBurpExtenderCallbacks callbacks = null; 44 | public static final String NO_DATA_RECEIVED = "NO DATA NO DATA NO DATA"; 45 | private HashMap hashes = new HashMap(); 46 | 47 | /** 48 | * Default constructor 49 | */ 50 | public JavascriptResource(){} 51 | 52 | /** 53 | * Constructor to use when you have all of the necessary items 54 | * @param callbacks The burp suite callbacks object, needed to use the HTTP interface 55 | * @param srcString The SRC attribute, or source, of the JavaScript resource 56 | * @param tagString A string of the HTML tag which was used to reference the JavaScript 57 | */ 58 | public JavascriptResource(IBurpExtenderCallbacks callbacks, String srcString, String tagString){ 59 | setSrc(srcString); 60 | setCallbacks(callbacks); 61 | setOriginalTag(tagString); 62 | getResource(); 63 | calculateHashes(); 64 | } 65 | 66 | /** 67 | * Set the source, or SRC attribute, of the object 68 | * @param newSrc A string containing the value of the SRC attribute for a JavaScript resource 69 | */ 70 | public void setSrc(String newSrc){ 71 | src = newSrc; 72 | } 73 | 74 | /** 75 | * Get the SRC for this object 76 | * @return a String of the SRC attribute for this JavaScript resource 77 | */ 78 | public String getSrc(){ 79 | return src; 80 | } 81 | 82 | /** 83 | * Set the callbacks to use for this object 84 | * @param cb IBurpExtenderCallbacks object to use for burp callbacks 85 | */ 86 | public void setCallbacks(IBurpExtenderCallbacks cb){ 87 | callbacks = cb; 88 | } 89 | 90 | /** 91 | * Get the callbacks used by this object 92 | * @return IBurpExtenderCallbacks object used by this object for burp interface 93 | */ 94 | public IBurpExtenderCallbacks getCallbacks(){ 95 | return callbacks; 96 | } 97 | 98 | /** 99 | * Set the original tag on this object, e.g., 100 | * @param ot the string of the original HTML tag 101 | */ 102 | public void setOriginalTag(String ot){ 103 | originalTag = ot; 104 | parseTag(); 105 | } 106 | 107 | /** 108 | * Get the original HTML tag 109 | * @return a string of the original HTML tag for this resource 110 | */ 111 | public String getOriginalTag(){ 112 | return originalTag; 113 | } 114 | 115 | /** 116 | * Parse the HTML tag that we have in to it's disparate parts, stored as a separate object. 117 | * Obtained using getParsedTag 118 | */ 119 | public void parseTag(){ 120 | Document doc = Jsoup.parse(originalTag); 121 | parsedTag = doc.getElementsByTag("script").first(); 122 | } 123 | 124 | /** 125 | * Get the parsedTag object 126 | * @return a jsoup Element object which is the original tag, all parsed out 127 | */ 128 | public Element getParsedTag(){ 129 | return parsedTag; 130 | } 131 | 132 | /** 133 | * Actually go and get the referenced JavaScript resource via HTTP through burp 134 | */ 135 | public void getResource(){ 136 | URI thisUri = URI.create(src); 137 | DNSResolver myResolver = new DNSResolver(); 138 | dnsValid = myResolver.hasValidRecordsForAUrl(thisUri.getHost()); 139 | if (dnsValid){ 140 | try { 141 | /* 142 | * There is a chance at this point that callbacks is null, that's okay 143 | * that is the way it should be for testing without going through burp 144 | */ 145 | Requester myRequester = new Requester(callbacks, src); 146 | data = myRequester.getResponseBody(); 147 | binaryData = myRequester.getResponseBodyBytes(); 148 | dnsValid = !(myResolver.hasBadCnames(thisUri.getHost())); 149 | // look, if we were able to get the resource, as long as it has no bad cnames, we're good 150 | dnsValid = true; 151 | } 152 | catch (Exception ex) { 153 | data = NO_DATA_RECEIVED; 154 | System.err.println("[JS-SRI][-] There was an issue getting the JavaScript file at " + src); 155 | dnsValid = myResolver.hasValidRecordsForAUrl(thisUri.getHost()); 156 | if (!(dnsValid)){ 157 | System.err.println("[JS-SRI][-] There was an issue getting the JavaScript file at " + src + ". DNS was not valid for " + thisUri.getHost() + "."); 158 | } 159 | } 160 | } else { 161 | System.err.println("[JS-SRI][-] There was an issue getting the JavaScript file at " + src + ". DNS was not valid for " + thisUri.getHost() + "."); 162 | data = NO_DATA_RECEIVED; 163 | } 164 | } 165 | 166 | /** 167 | * Does this resource have any data (the actual JavaScript file) that has been retrieved? 168 | * @return true if there is data present, false if not 169 | */ 170 | public boolean hasData(){ 171 | return (!data.equals(NO_DATA_RECEIVED)); 172 | } 173 | 174 | /** 175 | * Get the data for this resource 176 | * @return the string of the data 177 | */ 178 | public String getData(){ 179 | return data; 180 | } 181 | 182 | /** 183 | * Determine if the FQDN for the source URL could be looked up 184 | * @return true if the DNS hostname could be looked up, false if not 185 | */ 186 | public boolean hasValidHostname(){ 187 | return dnsValid; 188 | } 189 | 190 | /** 191 | * Hash the data we have and store the hashes 192 | * @param algorithm the Java MessageDigest algorithm to use to generate the hash 193 | * @return a base64 encoded representation of the hash value 194 | */ 195 | private String dataHasher(String algorithm) { 196 | if (hasData()){ 197 | try { 198 | MessageDigest digest = MessageDigest.getInstance(algorithm); 199 | byte[] encodedHash = digest.digest(binaryData); 200 | return Base64.getEncoder().encodeToString(encodedHash); 201 | } 202 | catch (NoSuchAlgorithmException ex) { 203 | System.err.println("[-] The provided algorithm string (" + algorithm + ") is not valid."); 204 | return ""; 205 | } 206 | } 207 | return ""; 208 | } 209 | 210 | /** 211 | * Calculate all of the hashes for all valid algorithms for this item 212 | */ 213 | public void calculateHashes(){ 214 | if (hasData()){ 215 | hashes.put("sha256",dataHasher("SHA-256")); 216 | hashes.put("sha384",dataHasher("SHA-384")); 217 | hashes.put("sha512",dataHasher("SHA-512")); 218 | hashes.put("md5",dataHasher("MD5")); 219 | hashes.put("sha1",dataHasher("SHA-1")); 220 | } 221 | } 222 | 223 | /** 224 | * Get the hashes for this object 225 | * @return a hashmap keyed by algorithm of all base64 encoded hashes for this object's data 226 | */ 227 | public HashMap getHashes(){ 228 | return hashes; 229 | } 230 | 231 | /** 232 | * Check to see if a given algorithm/hash value pair is a match for this object 233 | * @param hashValue the base64 encoded hash value to chec 234 | * @param algorithm the string name of the algorithm for this hash 235 | * @return true if the given algorithm/hash value pair is a match for this resource 236 | */ 237 | public Boolean checkHash(String hashValue, String algorithm){ 238 | if (hashes.keySet().contains(algorithm)) 239 | { 240 | return (hashes.get(algorithm).equals(hashValue)); 241 | } 242 | else { 243 | return false; 244 | } 245 | } 246 | 247 | /** 248 | * Get the integrity attribute from the HTML tag 249 | * @return a string of the integrity attribute, null if there is none 250 | */ 251 | public String getIntegrityAttribute(){ 252 | if (parsedTag.hasAttr("integrity")) { 253 | return parsedTag.attr("integrity"); 254 | } else { 255 | return null; 256 | } 257 | } 258 | 259 | /** 260 | * Check the SRI integrity of a javascript tag 261 | * @return true if the integrity attribute is correct, false otherwise 262 | */ 263 | public Boolean checkIntegrity(){ 264 | if (parsedTag.hasAttr("integrity")) { 265 | String integrityAttribute = getIntegrityAttribute(); 266 | String algorithm = integrityAttribute.substring(0, integrityAttribute.indexOf("-")); 267 | String hashToCheck = integrityAttribute.substring(integrityAttribute.indexOf("-")+1); 268 | return checkHash(hashToCheck, algorithm); 269 | } else { 270 | return false; 271 | } 272 | } 273 | } 274 | -------------------------------------------------------------------------------- /src/main/java/org.focalpoint.isns.burp.srichecks/ScriptFinder.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package org.focalpoint.isns.burp.srichecks; 17 | 18 | import org.focalpoint.isns.burp.srichecks.JavascriptResource; 19 | 20 | import burp.IBurpExtenderCallbacks; 21 | 22 | import org.openqa.selenium.By; 23 | import org.openqa.selenium.WebDriver; 24 | import org.openqa.selenium.WebElement; 25 | import org.openqa.selenium.chrome.ChromeDriver; 26 | import org.openqa.selenium.chrome.ChromeOptions; 27 | import org.openqa.selenium.support.ui.ExpectedCondition; 28 | import org.openqa.selenium.support.ui.WebDriverWait; 29 | import org.openqa.selenium.StaleElementReferenceException; 30 | import org.openqa.selenium.TimeoutException; 31 | 32 | import org.openqa.selenium.Cookie; 33 | 34 | import org.openqa.selenium.chrome.ChromeDriverService; 35 | import org.openqa.selenium.remote.RemoteWebDriver; 36 | import java.io.File; 37 | import java.io.IOException; 38 | import java.io.FileOutputStream; 39 | import java.io.InputStream; 40 | 41 | import java.util.concurrent.TimeUnit; 42 | 43 | import java.net.http.HttpClient; 44 | import java.net.http.HttpRequest; 45 | import java.net.http.HttpResponse; 46 | import java.net.http.HttpResponse.BodyHandlers; 47 | 48 | import org.jsoup.Jsoup; 49 | import org.jsoup.nodes.Document; 50 | import org.jsoup.nodes.Element; 51 | 52 | import java.util.List; 53 | import java.net.URL; 54 | import java.net.URI; 55 | import java.net.MalformedURLException; 56 | import java.util.ArrayList; 57 | import java.util.Collections; 58 | import java.util.HashMap; 59 | 60 | public class ScriptFinder{ 61 | private IBurpExtenderCallbacks myCallbacks; 62 | private Integer PAGE_WAIT_TIMEOUT = 10; 63 | private String url="NONE"; 64 | private String html="NONE"; 65 | private List requestHeaders = new ArrayList<>(); 66 | private List domScripts = new ArrayList<>(); 67 | private List htmlScripts = new ArrayList<>(); 68 | // Something to store a parsed URL 69 | private URL parsedUrl; 70 | // A webdriver service manager to handle the life and death of the driver objects 71 | private DriverServiceManager serviceManager = null; 72 | // A webdriver object 73 | private WebDriver driver; 74 | // A dictionary of dom and html script data, respectively 75 | private HashMap domScriptData = new HashMap(); 76 | private HashMap htmlScriptData = new HashMap(); 77 | 78 | 79 | 80 | public ScriptFinder(){ 81 | } 82 | 83 | /** 84 | * Set the driver service manager to use for this finder 85 | * @param sm the driver service manager to use 86 | */ 87 | public void setDriverManager(DriverServiceManager sm){ 88 | serviceManager = sm; 89 | } 90 | 91 | /** 92 | * Get rge driver service manager used by this instance 93 | * @return the driverservicemanager object being used by this object 94 | */ 95 | public DriverServiceManager getDriverManager(){ 96 | return serviceManager; 97 | } 98 | 99 | /** 100 | * Set the Burp Suite callbacks object to be used 101 | * @param callbacks the burp suite callbacks object to use for the HTTP interface 102 | */ 103 | public void setCallbacks(IBurpExtenderCallbacks callbacks){ 104 | myCallbacks = callbacks; 105 | } 106 | 107 | /** 108 | * Set the URL to be evaluated for JavaScript resources 109 | * @param urlString a String of the URL to be evaluated 110 | */ 111 | public void setUrl(String urlString){ 112 | url = urlString; 113 | try { 114 | parsedUrl = new URL(urlString); 115 | } 116 | catch (Exception e) { 117 | System.err.println("[-] Could not parse URL: " + urlString); 118 | } 119 | } 120 | 121 | /** 122 | * Get the URL being evaluated by this object 123 | * @return a string of the URL evaluated 124 | */ 125 | public String getUrl(){ 126 | return url; 127 | } 128 | 129 | /** 130 | * Set the delay, or timeout, for Selenium to wait and load everything 131 | * @param timeoutInSeconds an integer value of how many seconds to wait 132 | */ 133 | public void setTimeout(Integer timeoutInSeconds){ 134 | PAGE_WAIT_TIMEOUT = timeoutInSeconds; 135 | } 136 | 137 | /** 138 | * Get the timeout for this oject 139 | * @return an integer of how many seconds this object will force Selenium to wait before calling a DOM good 140 | */ 141 | public Integer getTimeout(){ 142 | return PAGE_WAIT_TIMEOUT; 143 | } 144 | 145 | /** 146 | * Set the request headers 147 | * @param headers - a list of request headers 148 | */ 149 | public void setRequestHeaders(List headers){ 150 | requestHeaders = new ArrayList<>(); 151 | requestHeaders.addAll(headers); 152 | } 153 | 154 | 155 | /** 156 | * There is no reason that this should ever be called within burp. It is just here for tests. 157 | * This uses incubated JDK libraries 158 | */ 159 | public void retrieveHtml(){ 160 | if (!url.equals("NONE")){ 161 | HttpClient client = HttpClient.newBuilder().followRedirects(HttpClient.Redirect.ALWAYS).build(); 162 | HttpRequest request = HttpRequest.newBuilder() 163 | .uri(URI.create(url)) 164 | .build(); 165 | try { 166 | HttpResponse response = client.send(request, BodyHandlers.ofString()); 167 | setHtml(response.body()); 168 | } 169 | catch (Exception ex) { 170 | System.err.println("[-] There was an issue getting the JavaScript file at " + url); 171 | System.err.println(ex.toString()); 172 | ex.printStackTrace(); 173 | } 174 | } 175 | } 176 | 177 | /** 178 | * Start the Selenium chrome driver instance with lean options 179 | */ 180 | public void startDriver(){ 181 | if (serviceManager != null){ 182 | ChromeOptions options = new ChromeOptions(); 183 | options.addArguments("--headless"); 184 | options.addArguments("--no-sandbox"); 185 | options.addArguments("--disable-dev-shm-usage"); 186 | HashMap prefs = new HashMap(); 187 | prefs.put("profile.managed_default_content_settings.images", 2); 188 | options.setExperimentalOption("prefs", prefs); 189 | 190 | driver = new RemoteWebDriver(serviceManager.getService().getUrl(), options); 191 | driver.manage().timeouts().implicitlyWait(PAGE_WAIT_TIMEOUT, TimeUnit.SECONDS); // Wait for the page to be completely loaded. Or reasonably loaded. 192 | } 193 | else { 194 | System.err.println("[JS-SRI][-] You must set a driver service manager before you can start a driver."); 195 | } 196 | } 197 | 198 | /** 199 | * sets the driver's cookies up based on the requestHeaders set 200 | */ 201 | private void setDriverCookies(){ 202 | // You can't set cookies until you have the domain set in the DOM, this is a fix for that 203 | try { 204 | driver.get(url); 205 | } 206 | catch (TimeoutException e){ 207 | System.err.println("[" + url + "][-] - timeout when connecting."); 208 | } 209 | 210 | // Set the driver's cookies based on the headers, if there are any 211 | if (requestHeaders != null){ 212 | for (String header: requestHeaders){ 213 | if (header.startsWith("Cookie: ")){ 214 | // This is a cookie header, split it up 215 | String cookieString = header.substring(8,header.length()); 216 | for (String kvPair : cookieString.split(";")){ 217 | String key = kvPair.split("=")[0].trim(); 218 | String value = kvPair.split("=")[1].trim(); 219 | Cookie cookieObj = new Cookie(key, value); 220 | try { 221 | driver.manage().addCookie(cookieObj); 222 | } 223 | catch (org.openqa.selenium.UnableToSetCookieException d){ 224 | System.err.println("[JS-SRI][-] Could not set cookie for key " + key + " and value " + value); 225 | } 226 | } 227 | } 228 | } 229 | } 230 | } 231 | 232 | 233 | /** 234 | * Load the DOM and check for any referenced scripts 235 | * Starts and stops the selenium instance 236 | */ 237 | public void checkForDomScripts(){ 238 | startDriver(); 239 | 240 | setDriverCookies(); 241 | 242 | // Now actually get the page 243 | try { 244 | driver.get(url); 245 | } 246 | catch (TimeoutException e){ 247 | System.err.println("[" + url + "][-] - timeout when connecting."); 248 | } 249 | List scripts = driver.findElements(By.xpath("//script")); 250 | for (WebElement scriptElement : scripts) { 251 | try { 252 | String src = scriptElement.getAttribute("src"); 253 | if (!((src == null) || (src.isEmpty()))){ 254 | String scriptTag = scriptElement.getAttribute("outerHTML"); 255 | if (!domScripts.contains(src)){ 256 | domScripts.add(src); 257 | } 258 | if (!domScriptData.containsKey(src)){ 259 | domScriptData.put(src, new JavascriptResource(myCallbacks, src, scriptTag)); 260 | } 261 | } 262 | } 263 | catch (StaleElementReferenceException e){ 264 | System.err.println("[" + url + "][-] - Error attempting to access a script tag on this item which is no longer in the driver DOM."); 265 | } 266 | } 267 | stopDriver(); 268 | } 269 | 270 | /** 271 | * Stop the selenium instance and kill it 272 | */ 273 | public void stopDriver(){ 274 | if (driver != null){ 275 | driver.close(); 276 | driver.quit(); 277 | } 278 | } 279 | 280 | /** 281 | * Condition a URL to get the full protocol, FQDN, and path from any given URL with respect to the base URL 282 | * @param urlToCondition the URL to condition to it's full glory 283 | * @param baseUrl the base URL to reference for protocol and FQDN as needed 284 | * @return the full URL reconstructed as a string 285 | */ 286 | public String conditionReceivedUrl(String urlToCondition, String baseUrl){ 287 | try { 288 | URL parsedBase = new URL(baseUrl); 289 | try { 290 | URL relativeUrl = new URL(parsedBase, urlToCondition); 291 | return relativeUrl.toString(); 292 | } 293 | catch (MalformedURLException e) { 294 | System.err.println("[-] Could not parse URL " + urlToCondition); 295 | return null; 296 | } 297 | } 298 | catch (MalformedURLException e){ 299 | System.err.println("[-] Could not parse base URL " + baseUrl); 300 | return null; 301 | } 302 | } 303 | 304 | 305 | /** 306 | * Take the HTML this object has and find all of the scripts within it 307 | */ 308 | private void getScriptsFromHtml(){ 309 | Document doc = Jsoup.parse(html); 310 | for (Element jsElement : doc.getElementsByTag("script")){ 311 | if (jsElement.hasAttr("src")){ 312 | String scriptSrc = conditionReceivedUrl(jsElement.attr("src"), url); 313 | String scriptTag = jsElement.outerHtml(); 314 | JavascriptResource scriptObject = new JavascriptResource(myCallbacks, scriptSrc, scriptTag); 315 | htmlScriptData.put(scriptSrc, scriptObject); 316 | htmlScripts.add(scriptSrc); 317 | } 318 | } 319 | } 320 | 321 | /** 322 | * Set the HTML for the page this object will evaluate 323 | * @param htmlString the string of the page's body, or HTML 324 | */ 325 | public void setHtml(String htmlString){ 326 | html = htmlString; 327 | // parse the html for scripts 328 | getScriptsFromHtml(); 329 | } 330 | 331 | /** 332 | * Get the HTML being reviewed by this object 333 | * @return a string of the HTML being evaluated here 334 | */ 335 | public String getHtml(){ 336 | return html; 337 | } 338 | 339 | /** 340 | * Get a list of the URLs, as strings, of JavaScript resources referenced by this page in the HTML 341 | * @return a list of the URLs, as strings, of JavaScript resources referenced by this page in the HTML 342 | */ 343 | public List getHtmlScripts(){ 344 | return htmlScripts; 345 | } 346 | 347 | /** 348 | * Get a list of the URLs, as strings, of JavaScript resources referenced by this page in DOM 349 | * @return a list of the URLs, as strings, of JavaScript resources referenced by this page in DOM 350 | */ 351 | public List getDomScripts(){ 352 | return domScripts; 353 | } 354 | 355 | /** 356 | * Given a list of URLs to JS resources, return a list of resources which are cross-domain 357 | * @param inList a list of strings which are URLs to JS resources 358 | * @return a list of strings which are URLs to cross-domain JS resources 359 | */ 360 | private List selectCrossDomainScripts(List inList){ 361 | List returnList = new ArrayList<>(); 362 | for (String thisScript : inList) { 363 | if (scriptIsCrossDomain(thisScript)) { 364 | returnList.add(thisScript); 365 | } 366 | } 367 | return returnList; 368 | } 369 | 370 | /** 371 | * Get a list of the cross-domain scripts referenced by the page's HTML 372 | * @return a List object of Strings which are URLs to JS resources referenced by the page's HTML 373 | */ 374 | public List getCrossDomainHtmlScripts(){ 375 | return selectCrossDomainScripts(htmlScripts); 376 | } 377 | 378 | /** 379 | * Get a list of the cross-domain scripts referenced by the page's DOM 380 | * @return a List object of Strings which are URLs to cross-domain JS resources referenced by the page's DOM 381 | */ 382 | public List getCrossDomainDomScripts(){ 383 | return selectCrossDomainScripts(domScripts); 384 | } 385 | 386 | /** 387 | * Get a list of the cross-domain scripts only referenced by the page's DOM 388 | * @return a List object of Strings which are URLs to cross-domain JS resources only referenced by the page's DOM 389 | */ 390 | public List getCrossDomainDomOnlyScripts(){ 391 | return selectCrossDomainScripts(getDomOnlyScripts()); 392 | } 393 | 394 | /** 395 | * Get a list of the scripts in the HTML/DOM which are cross-domain 396 | * @return a List object of Strings which are URLs to JS resources in the HTML/DOM which are cross-domain 397 | */ 398 | public List getCrossDomainScripts(){ 399 | return selectCrossDomainScripts(getScripts()); 400 | } 401 | 402 | /** 403 | * Get a list of the scripts not referenced by the page's HTML, but present in the DOM 404 | * @return a List object of Strings which are URLs to JS resources not referenced by the page's HTML, but present in the DOM 405 | */ 406 | public List getDomOnlyScripts(){ 407 | List returnList = new ArrayList<>(); 408 | for (String thisScript : domScripts){ 409 | if (!htmlScripts.contains(thisScript)){ 410 | returnList.add(thisScript); 411 | } 412 | } 413 | return returnList; 414 | } 415 | 416 | /** 417 | * Get a list of the cross-domain scripts not referenced by the page's HTML, but present in the DOM 418 | * @return a List object of Strings which are URLs to cross-domain JS resources not referenced by the page's HTML, but present in the DOM 419 | */ 420 | public List getDomOnlyCrossDomainScripts(){ 421 | return selectCrossDomainScripts(getDomOnlyScripts()); 422 | } 423 | 424 | /** 425 | * Get a list of the scripts not referenced by the page's HTML and DOM 426 | * @return a List object of Strings which are URLs to cross-domain JS resources referenced by the page's HTML and DOM 427 | */ 428 | public List getScripts(){ 429 | List allScripts = new ArrayList<>(); 430 | allScripts.addAll(htmlScripts); 431 | allScripts.addAll(domScripts); 432 | return allScripts; 433 | } 434 | 435 | /** 436 | * Get the JavascriptResource object from this finder for a given URL 437 | * @param scriptSrc the src attribute for a javascript resource referenced by this page/DOM 438 | * @return the javascriptresource object for this item, null if the src string isn't found 439 | */ 440 | public JavascriptResource getScriptObjectFor(String scriptSrc){ 441 | if (htmlScripts.contains(scriptSrc)) { 442 | return htmlScriptData.get(scriptSrc); 443 | } 444 | else { 445 | if (domScripts.contains(scriptSrc)) { 446 | return domScriptData.get(scriptSrc); 447 | } 448 | else { 449 | return null; 450 | } 451 | } 452 | } 453 | 454 | /** 455 | * Get the HTML tag, as a string, from this finder for a given URL 456 | * @param scriptSrc the src attribute for a javascript resource referenced by this page/DOM 457 | * @return the HTML tag, as a string, for this item, null if the src string isn't found 458 | */ 459 | public String getHtmlTagFor(String scriptSrc){ 460 | JavascriptResource resource = getScriptObjectFor(scriptSrc); 461 | if (resource != null) { 462 | return resource.getOriginalTag(); 463 | } 464 | else { 465 | return null; 466 | } 467 | } 468 | 469 | /** 470 | * Is a given URL cross-domain to the page evaluated by this object? 471 | * @param scriptUrlToCheck the url, as a string, to check 472 | * @return true if it's cross-domain, false otherwise 473 | */ 474 | public Boolean scriptIsCrossDomain(String scriptUrlToCheck){ 475 | try { 476 | URL parsedUrlToCheck = new URL(scriptUrlToCheck); 477 | return !parsedUrlToCheck.getHost().equals(parsedUrl.getHost()); 478 | } 479 | catch (Exception e) { 480 | System.err.println("[-] Could not parse the URL provided to scriptIsCrossDomain - " + scriptUrlToCheck); 481 | return false; 482 | } 483 | } 484 | } 485 | -------------------------------------------------------------------------------- /src/main/java/burp/BurpExtender.java: -------------------------------------------------------------------------------- 1 | /** 2 | * BurpSuite JavaScript Security Extension 3 | * Copyright (C) 2019 Focal Point Data Risk, LLC 4 | * Written by: Peter Hefley 5 | * This program is free software: you can redistribute it and/or modify it under the terms of the GNU General 6 | * Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) 7 | * any later version. 8 | * 9 | * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the 10 | * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for 11 | * more details. 12 | * 13 | * You should have received a copy of the GNU General Public License along with this program. 14 | * If not, see . 15 | */ 16 | package burp; 17 | 18 | import burp.IBurpExtender; 19 | import burp.IBurpExtenderCallbacks; 20 | import burp.IScannerCheck; 21 | import burp.IExtensionHelpers; 22 | import burp.IScanIssue; 23 | import burp.IHttpRequestResponse; 24 | import burp.IHttpService; 25 | import burp.IScannerInsertionPoint; 26 | import burp.ITab; 27 | import burp.IResponseInfo; 28 | import java.awt.Component; 29 | 30 | import java.net.URL; 31 | import java.util.ArrayList; 32 | import java.util.List; 33 | import java.util.HashMap; 34 | 35 | import java.util.regex.Matcher; 36 | import java.util.regex.Pattern; 37 | 38 | import org.focalpoint.isns.burp.srichecks.ScriptFinder; 39 | import org.focalpoint.isns.burp.srichecks.IoCChecker; 40 | import org.focalpoint.isns.burp.srichecks.JavascriptResource; 41 | import org.focalpoint.isns.burp.srichecks.PluginConfigurationTab; 42 | import org.focalpoint.isns.burp.srichecks.DriverServiceManager; 43 | 44 | import javax.swing.SwingUtilities; 45 | 46 | public class BurpExtender implements IBurpExtender, IScannerCheck, ITab 47 | { 48 | private IBurpExtenderCallbacks callbacks; 49 | private IExtensionHelpers helpers; 50 | private IoCChecker iocChecker; 51 | private DriverServiceManager serviceManager; 52 | private Integer scanNumber = 0; 53 | 54 | private PluginConfigurationTab panel; 55 | 56 | public BurpExtender(){ 57 | iocChecker = new IoCChecker(); 58 | serviceManager = new DriverServiceManager(); 59 | } 60 | 61 | // 62 | // implement IBurpExtender 63 | // 64 | 65 | @Override 66 | public void registerExtenderCallbacks(final IBurpExtenderCallbacks callbacks) 67 | { 68 | // keep a reference to our callbacks object 69 | this.callbacks = callbacks; 70 | 71 | // obtain an extension helpers object 72 | helpers = callbacks.getHelpers(); 73 | 74 | // set our extension name 75 | callbacks.setExtensionName("JavaScript Security -- SRI and Threat Intel"); 76 | 77 | // register ourselves as a custom scanner check 78 | callbacks.registerScannerCheck(this); 79 | 80 | // Setup the driverservicemanager 81 | serviceManager.setCallbacks(callbacks); 82 | serviceManager.startDriverService(); 83 | 84 | // Create the config tab 85 | SwingUtilities.invokeLater(new Runnable() { 86 | @Override 87 | public void run() { 88 | // main panel 89 | panel = new PluginConfigurationTab(); 90 | panel.setIocChecker(iocChecker); 91 | panel.setDriverServiceManager(serviceManager); 92 | panel.setCallbacks(callbacks); 93 | panel.render(); 94 | callbacks.customizeUiComponent(panel); 95 | 96 | // add the custom tab to Burp's UI 97 | callbacks.addSuiteTab(BurpExtender.this); 98 | } 99 | }); 100 | } 101 | 102 | @Override 103 | public String getTabCaption() { 104 | return "JavaScript Security"; 105 | } 106 | 107 | @Override 108 | public Component getUiComponent() { 109 | return panel; 110 | } 111 | 112 | // helper method to search a response for occurrences of a literal match string 113 | // and return a list of start/end offsets 114 | private List getMatches(byte[] response, byte[] match) 115 | { 116 | List matches = new ArrayList(); 117 | 118 | int start = 0; 119 | while (start < response.length) 120 | { 121 | start = helpers.indexOf(response, match, true, start, response.length); 122 | if (start == -1) 123 | break; 124 | matches.add(new int[] { start, start + match.length }); 125 | start += match.length; 126 | } 127 | 128 | return matches; 129 | } 130 | 131 | // Check for Cross-Domain Script Includes (DOM) 132 | public List checkCspForSriRequirements(IHttpRequestResponse baseRequestResponse){ 133 | List issues = new ArrayList<>(); 134 | String response = helpers.bytesToString(baseRequestResponse.getResponse()); 135 | if (!response.contains("Content-Security-Policy: require-sri-for script;")){ 136 | issues.add( 137 | new CustomScanIssue( 138 | baseRequestResponse.getHttpService(), 139 | helpers.analyzeRequest(baseRequestResponse).getUrl(), 140 | null, // No way to highlight this, 141 | "Content Security Policy does not Require Subresource Integrity", 142 | "The content security policy provided in the response headers does not require subresource integrity for script elements. Content security policies may do so by returning the following header:
Content-Security-Policy: require-sri-for script;
", 143 | "Low", 144 | "

When a script is served from a third-party source such as a public Content Delivery Network (CDN) location, the 'integrity' attribute of the 'script' tag should be used to confirm that the script can be trusted (i.e., it has not been modified from a version known to include only intended functionality and not be malicious). This attribute instructs the browser to load the third-party script, generate a hash of the file, and validate that its hash matches the hash of the exact version of the script known to be trusted before it can be executed. If the hash of the script loaded from the third-party source does not match the hash of the trusted version, most modern browsers will block the script's execution.

In order to enforce the use of subresource integrity for all scripts used across a site, the 'require-sri-for script' Content-Security-Policy directive should be used to instruct the browser to validate that the 'integrity' attribute is in place for all script elements.

" 145 | ) 146 | ); 147 | } 148 | return issues; 149 | } 150 | 151 | // Check for Cross-Domain Script Includes (DOM) 152 | public List checkForCrossDomainScriptIncludesDom(IHttpRequestResponse baseRequestResponse, ScriptFinder finder){ 153 | List issues = new ArrayList<>(); 154 | if (finder.getCrossDomainDomOnlyScripts().size() > 0){ 155 | String scriptString = ""; 156 | for (String scriptUrl : finder.getCrossDomainDomOnlyScripts()){ 157 | scriptString += "
  • " + scriptUrl + "
  • "; 158 | } 159 | issues.add( 160 | new CustomScanIssue( 161 | baseRequestResponse.getHttpService(), 162 | helpers.analyzeRequest(baseRequestResponse).getUrl(), 163 | null, // No way to highlight this, 164 | "Cross-Domain Script Includes (DOM)", 165 | "The following cross-domain JavaScript resources were loaded in to the DOM but were not present in the initial page:
      " + scriptString + "
    ", 166 | "Medium", 167 | "

    When an application includes a script from an external domain, this script is executed by the browser within the security context of the invoking application. The script can therefore do anything that the application's own scripts can do, such as loading additional third-party scripts into DOM, accessing application data, and performing actions within the context of the current user.

    If you include a script from an external domain, then you are trusting that domain with the data and functionality of your application, and you are trusting the domain's own security to prevent an attacker from modifying the script to perform malicious actions within your application.

    " 168 | ) 169 | ); 170 | } 171 | return issues; 172 | } 173 | 174 | // Check for Cross-Domain Script Includes (DOM) 175 | public List checkForSriIssues(IHttpRequestResponse baseRequestResponse, ScriptFinder finder){ 176 | List issues = new ArrayList<>(); 177 | List sriScripts = new ArrayList<>(); 178 | List sriMissingScripts = new ArrayList<>(); 179 | // Go through all of the scripts and find those which have an integrity attribute and those which don't. 180 | for (String scriptUrl : finder.getScripts()){ 181 | String tag = finder.getHtmlTagFor(scriptUrl); 182 | if (tag.contains("integrity=\"sha")){ 183 | sriScripts.add(scriptUrl); 184 | } 185 | else { 186 | sriMissingScripts.add(scriptUrl); 187 | } 188 | } 189 | if (sriMissingScripts.size() > 0){ 190 | // There are scripts missing SRI. Need to log an issue. 191 | for (String scriptUrl : sriMissingScripts){ 192 | List matches = getMatches(baseRequestResponse.getResponse(), finder.getHtmlTagFor(scriptUrl).getBytes()); 193 | issues.add( 194 | new CustomScanIssue( 195 | baseRequestResponse.getHttpService(), 196 | helpers.analyzeRequest(baseRequestResponse).getUrl(), 197 | new IHttpRequestResponse[] { callbacks.applyMarkers(baseRequestResponse, null, matches) }, 198 | "JavaScript Element Missing Subresource Integrity Attribute", 199 | "The following script references were present within the HTML or the DOM after loading and do not leverage an 'integrity' attribute to establish subresource integrity:
    • " + scriptUrl + "
    ", 200 | "Low", 201 | "

    When a script is served from a third-party source such as a public Content Delivery Network (CDN) location, the 'integrity' attribute of the 'script' tag should be used to confirm that the script can be trusted (i.e., it has not been modified from a version known to include only intended functionality and not be malicious). This attribute instructs the browser to load the third-party script, generate a hash of the file, and validate that its hash matches the hash of the exact version of the script known to be trusted before it can be executed. If the hash of the script loaded from the third-party source does not match the hash of the trusted version, most modern browsers will block the script's execution.

    In order to enforce the use of subresource integrity for all scripts used across a site, the 'require-sri-for script' Content-Security-Policy directive should be used to instruct the browser to validate that the 'integrity' attribute is in place for all script elements.

    " 202 | ) 203 | ); 204 | } 205 | } 206 | 207 | if (sriScripts.size() > 0){ 208 | // For all of the resources which use SRI attributes, check the hash 209 | for (String scriptUrl: sriScripts){ 210 | if (!finder.getScriptObjectFor(scriptUrl).checkIntegrity()){ 211 | // Integrity check failed 212 | List matches = getMatches(baseRequestResponse.getResponse(), finder.getHtmlTagFor(scriptUrl).getBytes()); 213 | String theseHashes = "
      "; 214 | HashMap hashes = finder.getScriptObjectFor(scriptUrl).getHashes(); 215 | for (String algorithm : hashes.keySet()){ 216 | theseHashes += "
    • " + algorithm + " : " + hashes.get(algorithm) + "
    • "; 217 | } 218 | theseHashes += "
    "; 219 | String integrityAttribute = finder.getScriptObjectFor(scriptUrl).getIntegrityAttribute(); 220 | issues.add( 221 | new CustomScanIssue( 222 | baseRequestResponse.getHttpService(), 223 | helpers.analyzeRequest(baseRequestResponse).getUrl(), 224 | new IHttpRequestResponse[] { callbacks.applyMarkers(baseRequestResponse, null, matches) }, 225 | "JavaScript Subresource Integrity Failure", 226 | "The following script references utilize subresource integrity, however the hash provided in the integrity attribute does not match the hash of the JavaScript obtained from the URL:
    • " + scriptUrl + "

    The original integrity attribute was: " + integrityAttribute + "

    The hashes obtained for the item are:" + theseHashes + "

    ", 227 | "High", 228 | "

    When a script is served from a third-party source such as a public Content Delivery Network (CDN) location, the 'integrity' attribute of the 'script' tag should be used to confirm that the script can be trusted (i.e., it has not been modified from a version known to include only intended functionality and not be malicious). This attribute instructs the browser to load the third-party script, generate a hash of the file, and validate that its hash matches the hash of the exact version of the script known to be trusted before it can be executed. If the hash of the script loaded from the third-party source does not match the hash of the trusted version, most modern browsers will block the script's execution.

    In order to enforce the use of subresource integrity for all scripts used across a site, the 'require-sri-for script' Content-Security-Policy directive should be used to instruct the browser to validate that the 'integrity' attribute is in place for all script elements.

    " 229 | ) 230 | ); 231 | } 232 | } 233 | } 234 | 235 | return issues; 236 | } 237 | 238 | // Check for Cross-Domain Script Includes (DOM) 239 | public List checkJavaScriptThreatIntel(IHttpRequestResponse baseRequestResponse, ScriptFinder finder){ 240 | List issues = new ArrayList<>(); 241 | for (String scriptUrl : finder.getScripts()){ 242 | JavascriptResource scriptObject = finder.getScriptObjectFor(scriptUrl); 243 | // Check for known, bad JavaScript hashes 244 | if (iocChecker.checkHashes(scriptObject.getHashes())){ 245 | // This is a bad resource based on the hash 246 | List matches = getMatches(baseRequestResponse.getResponse(), finder.getHtmlTagFor(scriptUrl).getBytes()); 247 | issues.add( 248 | new CustomScanIssue( 249 | baseRequestResponse.getHttpService(), 250 | helpers.analyzeRequest(baseRequestResponse).getUrl(), 251 | new IHttpRequestResponse[] { callbacks.applyMarkers(baseRequestResponse, null, matches) }, 252 | "Possibly Compromised JavaScript (Hash IoC)", 253 | "The JavaScript at " + scriptUrl + " is a known, compromised resource based on the following threat intelligence source:
    • " + iocChecker.getHashesSource(scriptObject.getHashes()) + "
    ", 254 | "High", 255 | "

    When a script is served from a third-party source such as a public Content Delivery Network (CDN) location, the 'integrity' attribute of the 'script' tag should be used to confirm that the script can be trusted (i.e., it has not been modified from a version known to include only intended functionality and not be malicious). This attribute instructs the browser to load the third-party script, generate a hash of the file, and validate that its hash matches the hash of the exact version of the script known to be trusted before it can be executed. If the hash of the script loaded from the third-party source does not match the hash of the trusted version, most modern browsers will block the script's execution.

    In order to enforce the use of subresource integrity for all scripts used across a site, the 'require-sri-for script' Content-Security-Policy directive should be used to instruct the browser to validate that the 'integrity' attribute is in place for all script elements.

    " 256 | ) 257 | ); 258 | } 259 | // Check for known, bad JavaScript paths 260 | if (iocChecker.checkUrl(scriptUrl)){ 261 | // This is a bad resource based on the path 262 | List matches = getMatches(baseRequestResponse.getResponse(), finder.getHtmlTagFor(scriptUrl).getBytes()); 263 | issues.add( 264 | new CustomScanIssue( 265 | baseRequestResponse.getHttpService(), 266 | helpers.analyzeRequest(baseRequestResponse).getUrl(), 267 | new IHttpRequestResponse[] { callbacks.applyMarkers(baseRequestResponse, null, matches) }, 268 | "Possibly Compromised JavaScript (URL IoC)", 269 | "The JavaScript at " + scriptUrl + " is a known, compromised resource based on the following threat intelligence source:
    • " + iocChecker.getUrlSource(scriptUrl) + "
    ", 270 | "High", 271 | "

    When a script is served from a third-party source such as a public Content Delivery Network (CDN) location, the 'integrity' attribute of the 'script' tag should be used to confirm that the script can be trusted (i.e., it has not been modified from a version known to include only intended functionality and not be malicious). This attribute instructs the browser to load the third-party script, generate a hash of the file, and validate that its hash matches the hash of the exact version of the script known to be trusted before it can be executed. If the hash of the script loaded from the third-party source does not match the hash of the trusted version, most modern browsers will block the script's execution.

    In order to enforce the use of subresource integrity for all scripts used across a site, the 'require-sri-for script' Content-Security-Policy directive should be used to instruct the browser to validate that the 'integrity' attribute is in place for all script elements.

    " 272 | ) 273 | ); 274 | } 275 | } 276 | 277 | return issues; 278 | } 279 | 280 | // Check for invalid JS links 281 | public List checkJavaScriptLinks(IHttpRequestResponse baseRequestResponse, ScriptFinder finder){ 282 | List issues = new ArrayList<>(); 283 | for (String scriptUrl : finder.getCrossDomainScripts()){ 284 | JavascriptResource scriptObject = finder.getScriptObjectFor(scriptUrl); 285 | // Check for missing data on object 286 | if (!scriptObject.hasValidHostname()){ 287 | // This JS resource had no DNS which could be resolved 288 | List matches = getMatches(baseRequestResponse.getResponse(), finder.getHtmlTagFor(scriptUrl).getBytes()); 289 | issues.add( 290 | new CustomScanIssue( 291 | baseRequestResponse.getHttpService(), 292 | helpers.analyzeRequest(baseRequestResponse).getUrl(), 293 | new IHttpRequestResponse[] { callbacks.applyMarkers(baseRequestResponse, null, matches) }, 294 | "Invalid Hostname for External JavaScript Resource", 295 | "

    The JavaScript at " + scriptUrl + " was not accessible during evaluation, as the hostname in the URL could not be resolved via DNS. This item should be evaluated for the potential of resource takeover.

    ", 296 | "Low", 297 | "

    When a script is served from a third-party source and the hostname for the source does not resolve, it may be possible for an attacker to register the domain and host malicious JavaScript at the indicated URL.

    " 298 | ) 299 | ); 300 | } 301 | } 302 | return issues; 303 | } 304 | 305 | private void log(Integer currentScanNumber, String urlString, String logString){ 306 | System.out.println("[JS-SRI][" + currentScanNumber + "] " + urlString + " - " + logString); 307 | } 308 | 309 | // 310 | // implement IScannerCheck 311 | // 312 | 313 | @Override 314 | public List doPassiveScan(IHttpRequestResponse baseRequestResponse) 315 | { 316 | scanNumber += 1; 317 | Integer currentScanNumber = scanNumber; 318 | // Create the issues array 319 | List issues = new ArrayList<>(); 320 | // Create a script finder for this instance 321 | ScriptFinder scriptFinder = new ScriptFinder(); 322 | scriptFinder.setCallbacks(callbacks); 323 | scriptFinder.setTimeout(panel.getDelay()); 324 | scriptFinder.setDriverManager(serviceManager); 325 | // Find the URL 326 | String url = helpers.analyzeRequest(baseRequestResponse).getUrl().toString(); 327 | // Get the response contents for the passive scan 328 | String response = helpers.bytesToString(baseRequestResponse.getResponse()); 329 | String html = ""; 330 | // Set the headers for the request 331 | scriptFinder.setRequestHeaders(helpers.analyzeRequest(baseRequestResponse).getHeaders()); 332 | 333 | log(currentScanNumber, url, "starting passive checks."); 334 | 335 | // Check the content type 336 | IResponseInfo responseInfo = helpers.analyzeResponse(baseRequestResponse.getResponse()); 337 | if(!responseInfo.getStatedMimeType().toLowerCase().contains("html")){ 338 | // This doesn't look like HTML to me 339 | log(currentScanNumber, url,"finished passive checks - not checking a response of " + responseInfo.getStatedMimeType() + " content type."); 340 | return issues; 341 | } 342 | 343 | if (url.endsWith(".js")){ 344 | // This is a JavaScript resource and I don't need to check it 345 | log(currentScanNumber, url,"finished passive checks - not checking a JS file."); 346 | return issues; 347 | } 348 | 349 | if (!response.contains("]*>([\\s\\S]*)<\\s*/\\s*html>"); 358 | Matcher matcher = pattern.matcher(response); 359 | if (matcher.find()){ 360 | html = matcher.group(0); 361 | scriptFinder.setHtml(html); 362 | log(currentScanNumber, url,"loading DOM in passive check."); 363 | scriptFinder.checkForDomScripts(); 364 | // Perform checks which require the DOM 365 | issues.addAll(checkForCrossDomainScriptIncludesDom(baseRequestResponse, scriptFinder)); 366 | } 367 | else { 368 | scriptFinder.setHtml(response); 369 | } 370 | 371 | // Now we can check the scripts 372 | log(currentScanNumber, url,"checking for JS files which could be hijacked."); 373 | issues.addAll(checkJavaScriptLinks(baseRequestResponse, scriptFinder)); 374 | log(currentScanNumber, url,"checking for SRI CSP requirements."); 375 | issues.addAll(checkCspForSriRequirements(baseRequestResponse)); 376 | log(currentScanNumber, url,"checking for SRI issues."); 377 | issues.addAll(checkForSriIssues(baseRequestResponse, scriptFinder)); 378 | log(currentScanNumber, url,"checking JavaScript resources against threat intel."); 379 | issues.addAll(checkJavaScriptThreatIntel(baseRequestResponse, scriptFinder)); 380 | log(currentScanNumber, url,"checks complete!"); 381 | 382 | if (issues.size() > 0){ 383 | return issues; 384 | } 385 | else { 386 | return null; 387 | } 388 | } 389 | 390 | @Override 391 | public List doActiveScan(IHttpRequestResponse baseRequestResponse, IScannerInsertionPoint insertionPoint) 392 | { 393 | // Empty capability 394 | return null; 395 | } 396 | 397 | @Override 398 | public int consolidateDuplicateIssues(IScanIssue existingIssue, IScanIssue newIssue) 399 | { 400 | // This method is called when multiple issues are reported for the same URL 401 | // path by the same extension-provided check. The value we return from this 402 | // method determines how/whether Burp consolidates the multiple issues 403 | // to prevent duplication 404 | // 405 | // Since the issue name and detail are sufficient to identify our issues as different, 406 | // if both issues have the same name and detail, only report the existing issue 407 | // otherwise report both issues 408 | boolean sameName = existingIssue.getIssueName().equals(newIssue.getIssueName()); 409 | boolean sameDetail = existingIssue.getIssueDetail().equals(newIssue.getIssueDetail()); 410 | if (sameName && sameDetail){ 411 | // same 412 | return -1; 413 | } else { 414 | // different 415 | return 0; 416 | } 417 | } 418 | } 419 | 420 | // 421 | // class implementing IScanIssue to hold our custom scan issue details 422 | // 423 | class CustomScanIssue implements IScanIssue 424 | { 425 | private IHttpService httpService; 426 | private URL url; 427 | private IHttpRequestResponse[] httpMessages; 428 | private String name; 429 | private String detail; 430 | private String severity; 431 | private String issueBackground; 432 | private String remediationBackground; // not wired 433 | private String remediationDetail; // not wired 434 | private Integer issueType = 134217728; 435 | 436 | public CustomScanIssue( 437 | IHttpService httpService, 438 | URL url, 439 | IHttpRequestResponse[] httpMessages, 440 | String name, 441 | String detail, 442 | String severity, 443 | String background) 444 | { 445 | this.httpService = httpService; 446 | this.url = url; 447 | this.httpMessages = httpMessages; 448 | this.name = name; 449 | this.detail = detail; 450 | this.severity = severity; 451 | this.issueBackground = background; 452 | } 453 | 454 | @Override 455 | public URL getUrl() 456 | { 457 | return url; 458 | } 459 | 460 | @Override 461 | public String getIssueName() 462 | { 463 | return name; 464 | } 465 | 466 | @Override 467 | public int getIssueType() 468 | { 469 | return 0; 470 | } 471 | 472 | @Override 473 | public String getSeverity() 474 | { 475 | return severity; 476 | } 477 | 478 | @Override 479 | public String getConfidence() 480 | { 481 | return "Certain"; 482 | } 483 | 484 | @Override 485 | public String getIssueBackground() 486 | { 487 | return issueBackground; 488 | } 489 | 490 | @Override 491 | public String getRemediationBackground() 492 | { 493 | return null; 494 | } 495 | 496 | @Override 497 | public String getIssueDetail() 498 | { 499 | return detail; 500 | } 501 | 502 | @Override 503 | public String getRemediationDetail() 504 | { 505 | return null; 506 | } 507 | 508 | @Override 509 | public IHttpRequestResponse[] getHttpMessages() 510 | { 511 | return httpMessages; 512 | } 513 | 514 | @Override 515 | public IHttpService getHttpService() 516 | { 517 | return httpService; 518 | } 519 | 520 | } 521 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | GNU GENERAL PUBLIC LICENSE 2 | Version 3, 29 June 2007 3 | 4 | Copyright (C) 2007 Free Software Foundation, Inc. 5 | Everyone is permitted to copy and distribute verbatim copies 6 | of this license document, but changing it is not allowed. 7 | 8 | Preamble 9 | 10 | The GNU General Public License is a free, copyleft license for 11 | software and other kinds of works. 12 | 13 | The licenses for most software and other practical works are designed 14 | to take away your freedom to share and change the works. By contrast, 15 | the GNU General Public License is intended to guarantee your freedom to 16 | share and change all versions of a program--to make sure it remains free 17 | software for all its users. We, the Free Software Foundation, use the 18 | GNU General Public License for most of our software; it applies also to 19 | any other work released this way by its authors. You can apply it to 20 | your programs, too. 21 | 22 | When we speak of free software, we are referring to freedom, not 23 | price. Our General Public Licenses are designed to make sure that you 24 | have the freedom to distribute copies of free software (and charge for 25 | them if you wish), that you receive source code or can get it if you 26 | want it, that you can change the software or use pieces of it in new 27 | free programs, and that you know you can do these things. 28 | 29 | To protect your rights, we need to prevent others from denying you 30 | these rights or asking you to surrender the rights. Therefore, you have 31 | certain responsibilities if you distribute copies of the software, or if 32 | you modify it: responsibilities to respect the freedom of others. 33 | 34 | For example, if you distribute copies of such a program, whether 35 | gratis or for a fee, you must pass on to the recipients the same 36 | freedoms that you received. You must make sure that they, too, receive 37 | or can get the source code. And you must show them these terms so they 38 | know their rights. 39 | 40 | Developers that use the GNU GPL protect your rights with two steps: 41 | (1) assert copyright on the software, and (2) offer you this License 42 | giving you legal permission to copy, distribute and/or modify it. 43 | 44 | For the developers' and authors' protection, the GPL clearly explains 45 | that there is no warranty for this free software. For both users' and 46 | authors' sake, the GPL requires that modified versions be marked as 47 | changed, so that their problems will not be attributed erroneously to 48 | authors of previous versions. 49 | 50 | Some devices are designed to deny users access to install or run 51 | modified versions of the software inside them, although the manufacturer 52 | can do so. This is fundamentally incompatible with the aim of 53 | protecting users' freedom to change the software. The systematic 54 | pattern of such abuse occurs in the area of products for individuals to 55 | use, which is precisely where it is most unacceptable. Therefore, we 56 | have designed this version of the GPL to prohibit the practice for those 57 | products. If such problems arise substantially in other domains, we 58 | stand ready to extend this provision to those domains in future versions 59 | of the GPL, as needed to protect the freedom of users. 60 | 61 | Finally, every program is threatened constantly by software patents. 62 | States should not allow patents to restrict development and use of 63 | software on general-purpose computers, but in those that do, we wish to 64 | avoid the special danger that patents applied to a free program could 65 | make it effectively proprietary. To prevent this, the GPL assures that 66 | patents cannot be used to render the program non-free. 67 | 68 | The precise terms and conditions for copying, distribution and 69 | modification follow. 70 | 71 | TERMS AND CONDITIONS 72 | 73 | 0. Definitions. 74 | 75 | "This License" refers to version 3 of the GNU General Public License. 76 | 77 | "Copyright" also means copyright-like laws that apply to other kinds of 78 | works, such as semiconductor masks. 79 | 80 | "The Program" refers to any copyrightable work licensed under this 81 | License. Each licensee is addressed as "you". "Licensees" and 82 | "recipients" may be individuals or organizations. 83 | 84 | To "modify" a work means to copy from or adapt all or part of the work 85 | in a fashion requiring copyright permission, other than the making of an 86 | exact copy. The resulting work is called a "modified version" of the 87 | earlier work or a work "based on" the earlier work. 88 | 89 | A "covered work" means either the unmodified Program or a work based 90 | on the Program. 91 | 92 | To "propagate" a work means to do anything with it that, without 93 | permission, would make you directly or secondarily liable for 94 | infringement under applicable copyright law, except executing it on a 95 | computer or modifying a private copy. Propagation includes copying, 96 | distribution (with or without modification), making available to the 97 | public, and in some countries other activities as well. 98 | 99 | To "convey" a work means any kind of propagation that enables other 100 | parties to make or receive copies. Mere interaction with a user through 101 | a computer network, with no transfer of a copy, is not conveying. 102 | 103 | An interactive user interface displays "Appropriate Legal Notices" 104 | to the extent that it includes a convenient and prominently visible 105 | feature that (1) displays an appropriate copyright notice, and (2) 106 | tells the user that there is no warranty for the work (except to the 107 | extent that warranties are provided), that licensees may convey the 108 | work under this License, and how to view a copy of this License. If 109 | the interface presents a list of user commands or options, such as a 110 | menu, a prominent item in the list meets this criterion. 111 | 112 | 1. Source Code. 113 | 114 | The "source code" for a work means the preferred form of the work 115 | for making modifications to it. "Object code" means any non-source 116 | form of a work. 117 | 118 | A "Standard Interface" means an interface that either is an official 119 | standard defined by a recognized standards body, or, in the case of 120 | interfaces specified for a particular programming language, one that 121 | is widely used among developers working in that language. 122 | 123 | The "System Libraries" of an executable work include anything, other 124 | than the work as a whole, that (a) is included in the normal form of 125 | packaging a Major Component, but which is not part of that Major 126 | Component, and (b) serves only to enable use of the work with that 127 | Major Component, or to implement a Standard Interface for which an 128 | implementation is available to the public in source code form. A 129 | "Major Component", in this context, means a major essential component 130 | (kernel, window system, and so on) of the specific operating system 131 | (if any) on which the executable work runs, or a compiler used to 132 | produce the work, or an object code interpreter used to run it. 133 | 134 | The "Corresponding Source" for a work in object code form means all 135 | the source code needed to generate, install, and (for an executable 136 | work) run the object code and to modify the work, including scripts to 137 | control those activities. However, it does not include the work's 138 | System Libraries, or general-purpose tools or generally available free 139 | programs which are used unmodified in performing those activities but 140 | which are not part of the work. For example, Corresponding Source 141 | includes interface definition files associated with source files for 142 | the work, and the source code for shared libraries and dynamically 143 | linked subprograms that the work is specifically designed to require, 144 | such as by intimate data communication or control flow between those 145 | subprograms and other parts of the work. 146 | 147 | The Corresponding Source need not include anything that users 148 | can regenerate automatically from other parts of the Corresponding 149 | Source. 150 | 151 | The Corresponding Source for a work in source code form is that 152 | same work. 153 | 154 | 2. Basic Permissions. 155 | 156 | All rights granted under this License are granted for the term of 157 | copyright on the Program, and are irrevocable provided the stated 158 | conditions are met. This License explicitly affirms your unlimited 159 | permission to run the unmodified Program. The output from running a 160 | covered work is covered by this License only if the output, given its 161 | content, constitutes a covered work. This License acknowledges your 162 | rights of fair use or other equivalent, as provided by copyright law. 163 | 164 | You may make, run and propagate covered works that you do not 165 | convey, without conditions so long as your license otherwise remains 166 | in force. You may convey covered works to others for the sole purpose 167 | of having them make modifications exclusively for you, or provide you 168 | with facilities for running those works, provided that you comply with 169 | the terms of this License in conveying all material for which you do 170 | not control copyright. Those thus making or running the covered works 171 | for you must do so exclusively on your behalf, under your direction 172 | and control, on terms that prohibit them from making any copies of 173 | your copyrighted material outside their relationship with you. 174 | 175 | Conveying under any other circumstances is permitted solely under 176 | the conditions stated below. Sublicensing is not allowed; section 10 177 | makes it unnecessary. 178 | 179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law. 180 | 181 | No covered work shall be deemed part of an effective technological 182 | measure under any applicable law fulfilling obligations under article 183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or 184 | similar laws prohibiting or restricting circumvention of such 185 | measures. 186 | 187 | When you convey a covered work, you waive any legal power to forbid 188 | circumvention of technological measures to the extent such circumvention 189 | is effected by exercising rights under this License with respect to 190 | the covered work, and you disclaim any intention to limit operation or 191 | modification of the work as a means of enforcing, against the work's 192 | users, your or third parties' legal rights to forbid circumvention of 193 | technological measures. 194 | 195 | 4. Conveying Verbatim Copies. 196 | 197 | You may convey verbatim copies of the Program's source code as you 198 | receive it, in any medium, provided that you conspicuously and 199 | appropriately publish on each copy an appropriate copyright notice; 200 | keep intact all notices stating that this License and any 201 | non-permissive terms added in accord with section 7 apply to the code; 202 | keep intact all notices of the absence of any warranty; and give all 203 | recipients a copy of this License along with the Program. 204 | 205 | You may charge any price or no price for each copy that you convey, 206 | and you may offer support or warranty protection for a fee. 207 | 208 | 5. Conveying Modified Source Versions. 209 | 210 | You may convey a work based on the Program, or the modifications to 211 | produce it from the Program, in the form of source code under the 212 | terms of section 4, provided that you also meet all of these conditions: 213 | 214 | a) The work must carry prominent notices stating that you modified 215 | it, and giving a relevant date. 216 | 217 | b) The work must carry prominent notices stating that it is 218 | released under this License and any conditions added under section 219 | 7. This requirement modifies the requirement in section 4 to 220 | "keep intact all notices". 221 | 222 | c) You must license the entire work, as a whole, under this 223 | License to anyone who comes into possession of a copy. This 224 | License will therefore apply, along with any applicable section 7 225 | additional terms, to the whole of the work, and all its parts, 226 | regardless of how they are packaged. This License gives no 227 | permission to license the work in any other way, but it does not 228 | invalidate such permission if you have separately received it. 229 | 230 | d) If the work has interactive user interfaces, each must display 231 | Appropriate Legal Notices; however, if the Program has interactive 232 | interfaces that do not display Appropriate Legal Notices, your 233 | work need not make them do so. 234 | 235 | A compilation of a covered work with other separate and independent 236 | works, which are not by their nature extensions of the covered work, 237 | and which are not combined with it such as to form a larger program, 238 | in or on a volume of a storage or distribution medium, is called an 239 | "aggregate" if the compilation and its resulting copyright are not 240 | used to limit the access or legal rights of the compilation's users 241 | beyond what the individual works permit. Inclusion of a covered work 242 | in an aggregate does not cause this License to apply to the other 243 | parts of the aggregate. 244 | 245 | 6. Conveying Non-Source Forms. 246 | 247 | You may convey a covered work in object code form under the terms 248 | of sections 4 and 5, provided that you also convey the 249 | machine-readable Corresponding Source under the terms of this License, 250 | in one of these ways: 251 | 252 | a) Convey the object code in, or embodied in, a physical product 253 | (including a physical distribution medium), accompanied by the 254 | Corresponding Source fixed on a durable physical medium 255 | customarily used for software interchange. 256 | 257 | b) Convey the object code in, or embodied in, a physical product 258 | (including a physical distribution medium), accompanied by a 259 | written offer, valid for at least three years and valid for as 260 | long as you offer spare parts or customer support for that product 261 | model, to give anyone who possesses the object code either (1) a 262 | copy of the Corresponding Source for all the software in the 263 | product that is covered by this License, on a durable physical 264 | medium customarily used for software interchange, for a price no 265 | more than your reasonable cost of physically performing this 266 | conveying of source, or (2) access to copy the 267 | Corresponding Source from a network server at no charge. 268 | 269 | c) Convey individual copies of the object code with a copy of the 270 | written offer to provide the Corresponding Source. This 271 | alternative is allowed only occasionally and noncommercially, and 272 | only if you received the object code with such an offer, in accord 273 | with subsection 6b. 274 | 275 | d) Convey the object code by offering access from a designated 276 | place (gratis or for a charge), and offer equivalent access to the 277 | Corresponding Source in the same way through the same place at no 278 | further charge. You need not require recipients to copy the 279 | Corresponding Source along with the object code. If the place to 280 | copy the object code is a network server, the Corresponding Source 281 | may be on a different server (operated by you or a third party) 282 | that supports equivalent copying facilities, provided you maintain 283 | clear directions next to the object code saying where to find the 284 | Corresponding Source. Regardless of what server hosts the 285 | Corresponding Source, you remain obligated to ensure that it is 286 | available for as long as needed to satisfy these requirements. 287 | 288 | e) Convey the object code using peer-to-peer transmission, provided 289 | you inform other peers where the object code and Corresponding 290 | Source of the work are being offered to the general public at no 291 | charge under subsection 6d. 292 | 293 | A separable portion of the object code, whose source code is excluded 294 | from the Corresponding Source as a System Library, need not be 295 | included in conveying the object code work. 296 | 297 | A "User Product" is either (1) a "consumer product", which means any 298 | tangible personal property which is normally used for personal, family, 299 | or household purposes, or (2) anything designed or sold for incorporation 300 | into a dwelling. In determining whether a product is a consumer product, 301 | doubtful cases shall be resolved in favor of coverage. For a particular 302 | product received by a particular user, "normally used" refers to a 303 | typical or common use of that class of product, regardless of the status 304 | of the particular user or of the way in which the particular user 305 | actually uses, or expects or is expected to use, the product. A product 306 | is a consumer product regardless of whether the product has substantial 307 | commercial, industrial or non-consumer uses, unless such uses represent 308 | the only significant mode of use of the product. 309 | 310 | "Installation Information" for a User Product means any methods, 311 | procedures, authorization keys, or other information required to install 312 | and execute modified versions of a covered work in that User Product from 313 | a modified version of its Corresponding Source. The information must 314 | suffice to ensure that the continued functioning of the modified object 315 | code is in no case prevented or interfered with solely because 316 | modification has been made. 317 | 318 | If you convey an object code work under this section in, or with, or 319 | specifically for use in, a User Product, and the conveying occurs as 320 | part of a transaction in which the right of possession and use of the 321 | User Product is transferred to the recipient in perpetuity or for a 322 | fixed term (regardless of how the transaction is characterized), the 323 | Corresponding Source conveyed under this section must be accompanied 324 | by the Installation Information. But this requirement does not apply 325 | if neither you nor any third party retains the ability to install 326 | modified object code on the User Product (for example, the work has 327 | been installed in ROM). 328 | 329 | The requirement to provide Installation Information does not include a 330 | requirement to continue to provide support service, warranty, or updates 331 | for a work that has been modified or installed by the recipient, or for 332 | the User Product in which it has been modified or installed. Access to a 333 | network may be denied when the modification itself materially and 334 | adversely affects the operation of the network or violates the rules and 335 | protocols for communication across the network. 336 | 337 | Corresponding Source conveyed, and Installation Information provided, 338 | in accord with this section must be in a format that is publicly 339 | documented (and with an implementation available to the public in 340 | source code form), and must require no special password or key for 341 | unpacking, reading or copying. 342 | 343 | 7. Additional Terms. 344 | 345 | "Additional permissions" are terms that supplement the terms of this 346 | License by making exceptions from one or more of its conditions. 347 | Additional permissions that are applicable to the entire Program shall 348 | be treated as though they were included in this License, to the extent 349 | that they are valid under applicable law. If additional permissions 350 | apply only to part of the Program, that part may be used separately 351 | under those permissions, but the entire Program remains governed by 352 | this License without regard to the additional permissions. 353 | 354 | When you convey a copy of a covered work, you may at your option 355 | remove any additional permissions from that copy, or from any part of 356 | it. (Additional permissions may be written to require their own 357 | removal in certain cases when you modify the work.) You may place 358 | additional permissions on material, added by you to a covered work, 359 | for which you have or can give appropriate copyright permission. 360 | 361 | Notwithstanding any other provision of this License, for material you 362 | add to a covered work, you may (if authorized by the copyright holders of 363 | that material) supplement the terms of this License with terms: 364 | 365 | a) Disclaiming warranty or limiting liability differently from the 366 | terms of sections 15 and 16 of this License; or 367 | 368 | b) Requiring preservation of specified reasonable legal notices or 369 | author attributions in that material or in the Appropriate Legal 370 | Notices displayed by works containing it; or 371 | 372 | c) Prohibiting misrepresentation of the origin of that material, or 373 | requiring that modified versions of such material be marked in 374 | reasonable ways as different from the original version; or 375 | 376 | d) Limiting the use for publicity purposes of names of licensors or 377 | authors of the material; or 378 | 379 | e) Declining to grant rights under trademark law for use of some 380 | trade names, trademarks, or service marks; or 381 | 382 | f) Requiring indemnification of licensors and authors of that 383 | material by anyone who conveys the material (or modified versions of 384 | it) with contractual assumptions of liability to the recipient, for 385 | any liability that these contractual assumptions directly impose on 386 | those licensors and authors. 387 | 388 | All other non-permissive additional terms are considered "further 389 | restrictions" within the meaning of section 10. If the Program as you 390 | received it, or any part of it, contains a notice stating that it is 391 | governed by this License along with a term that is a further 392 | restriction, you may remove that term. If a license document contains 393 | a further restriction but permits relicensing or conveying under this 394 | License, you may add to a covered work material governed by the terms 395 | of that license document, provided that the further restriction does 396 | not survive such relicensing or conveying. 397 | 398 | If you add terms to a covered work in accord with this section, you 399 | must place, in the relevant source files, a statement of the 400 | additional terms that apply to those files, or a notice indicating 401 | where to find the applicable terms. 402 | 403 | Additional terms, permissive or non-permissive, may be stated in the 404 | form of a separately written license, or stated as exceptions; 405 | the above requirements apply either way. 406 | 407 | 8. Termination. 408 | 409 | You may not propagate or modify a covered work except as expressly 410 | provided under this License. Any attempt otherwise to propagate or 411 | modify it is void, and will automatically terminate your rights under 412 | this License (including any patent licenses granted under the third 413 | paragraph of section 11). 414 | 415 | However, if you cease all violation of this License, then your 416 | license from a particular copyright holder is reinstated (a) 417 | provisionally, unless and until the copyright holder explicitly and 418 | finally terminates your license, and (b) permanently, if the copyright 419 | holder fails to notify you of the violation by some reasonable means 420 | prior to 60 days after the cessation. 421 | 422 | Moreover, your license from a particular copyright holder is 423 | reinstated permanently if the copyright holder notifies you of the 424 | violation by some reasonable means, this is the first time you have 425 | received notice of violation of this License (for any work) from that 426 | copyright holder, and you cure the violation prior to 30 days after 427 | your receipt of the notice. 428 | 429 | Termination of your rights under this section does not terminate the 430 | licenses of parties who have received copies or rights from you under 431 | this License. If your rights have been terminated and not permanently 432 | reinstated, you do not qualify to receive new licenses for the same 433 | material under section 10. 434 | 435 | 9. Acceptance Not Required for Having Copies. 436 | 437 | You are not required to accept this License in order to receive or 438 | run a copy of the Program. Ancillary propagation of a covered work 439 | occurring solely as a consequence of using peer-to-peer transmission 440 | to receive a copy likewise does not require acceptance. However, 441 | nothing other than this License grants you permission to propagate or 442 | modify any covered work. These actions infringe copyright if you do 443 | not accept this License. Therefore, by modifying or propagating a 444 | covered work, you indicate your acceptance of this License to do so. 445 | 446 | 10. Automatic Licensing of Downstream Recipients. 447 | 448 | Each time you convey a covered work, the recipient automatically 449 | receives a license from the original licensors, to run, modify and 450 | propagate that work, subject to this License. You are not responsible 451 | for enforcing compliance by third parties with this License. 452 | 453 | An "entity transaction" is a transaction transferring control of an 454 | organization, or substantially all assets of one, or subdividing an 455 | organization, or merging organizations. If propagation of a covered 456 | work results from an entity transaction, each party to that 457 | transaction who receives a copy of the work also receives whatever 458 | licenses to the work the party's predecessor in interest had or could 459 | give under the previous paragraph, plus a right to possession of the 460 | Corresponding Source of the work from the predecessor in interest, if 461 | the predecessor has it or can get it with reasonable efforts. 462 | 463 | You may not impose any further restrictions on the exercise of the 464 | rights granted or affirmed under this License. For example, you may 465 | not impose a license fee, royalty, or other charge for exercise of 466 | rights granted under this License, and you may not initiate litigation 467 | (including a cross-claim or counterclaim in a lawsuit) alleging that 468 | any patent claim is infringed by making, using, selling, offering for 469 | sale, or importing the Program or any portion of it. 470 | 471 | 11. Patents. 472 | 473 | A "contributor" is a copyright holder who authorizes use under this 474 | License of the Program or a work on which the Program is based. The 475 | work thus licensed is called the contributor's "contributor version". 476 | 477 | A contributor's "essential patent claims" are all patent claims 478 | owned or controlled by the contributor, whether already acquired or 479 | hereafter acquired, that would be infringed by some manner, permitted 480 | by this License, of making, using, or selling its contributor version, 481 | but do not include claims that would be infringed only as a 482 | consequence of further modification of the contributor version. For 483 | purposes of this definition, "control" includes the right to grant 484 | patent sublicenses in a manner consistent with the requirements of 485 | this License. 486 | 487 | Each contributor grants you a non-exclusive, worldwide, royalty-free 488 | patent license under the contributor's essential patent claims, to 489 | make, use, sell, offer for sale, import and otherwise run, modify and 490 | propagate the contents of its contributor version. 491 | 492 | In the following three paragraphs, a "patent license" is any express 493 | agreement or commitment, however denominated, not to enforce a patent 494 | (such as an express permission to practice a patent or covenant not to 495 | sue for patent infringement). To "grant" such a patent license to a 496 | party means to make such an agreement or commitment not to enforce a 497 | patent against the party. 498 | 499 | If you convey a covered work, knowingly relying on a patent license, 500 | and the Corresponding Source of the work is not available for anyone 501 | to copy, free of charge and under the terms of this License, through a 502 | publicly available network server or other readily accessible means, 503 | then you must either (1) cause the Corresponding Source to be so 504 | available, or (2) arrange to deprive yourself of the benefit of the 505 | patent license for this particular work, or (3) arrange, in a manner 506 | consistent with the requirements of this License, to extend the patent 507 | license to downstream recipients. "Knowingly relying" means you have 508 | actual knowledge that, but for the patent license, your conveying the 509 | covered work in a country, or your recipient's use of the covered work 510 | in a country, would infringe one or more identifiable patents in that 511 | country that you have reason to believe are valid. 512 | 513 | If, pursuant to or in connection with a single transaction or 514 | arrangement, you convey, or propagate by procuring conveyance of, a 515 | covered work, and grant a patent license to some of the parties 516 | receiving the covered work authorizing them to use, propagate, modify 517 | or convey a specific copy of the covered work, then the patent license 518 | you grant is automatically extended to all recipients of the covered 519 | work and works based on it. 520 | 521 | A patent license is "discriminatory" if it does not include within 522 | the scope of its coverage, prohibits the exercise of, or is 523 | conditioned on the non-exercise of one or more of the rights that are 524 | specifically granted under this License. You may not convey a covered 525 | work if you are a party to an arrangement with a third party that is 526 | in the business of distributing software, under which you make payment 527 | to the third party based on the extent of your activity of conveying 528 | the work, and under which the third party grants, to any of the 529 | parties who would receive the covered work from you, a discriminatory 530 | patent license (a) in connection with copies of the covered work 531 | conveyed by you (or copies made from those copies), or (b) primarily 532 | for and in connection with specific products or compilations that 533 | contain the covered work, unless you entered into that arrangement, 534 | or that patent license was granted, prior to 28 March 2007. 535 | 536 | Nothing in this License shall be construed as excluding or limiting 537 | any implied license or other defenses to infringement that may 538 | otherwise be available to you under applicable patent law. 539 | 540 | 12. No Surrender of Others' Freedom. 541 | 542 | If conditions are imposed on you (whether by court order, agreement or 543 | otherwise) that contradict the conditions of this License, they do not 544 | excuse you from the conditions of this License. If you cannot convey a 545 | covered work so as to satisfy simultaneously your obligations under this 546 | License and any other pertinent obligations, then as a consequence you may 547 | not convey it at all. For example, if you agree to terms that obligate you 548 | to collect a royalty for further conveying from those to whom you convey 549 | the Program, the only way you could satisfy both those terms and this 550 | License would be to refrain entirely from conveying the Program. 551 | 552 | 13. Use with the GNU Affero General Public License. 553 | 554 | Notwithstanding any other provision of this License, you have 555 | permission to link or combine any covered work with a work licensed 556 | under version 3 of the GNU Affero General Public License into a single 557 | combined work, and to convey the resulting work. The terms of this 558 | License will continue to apply to the part which is the covered work, 559 | but the special requirements of the GNU Affero General Public License, 560 | section 13, concerning interaction through a network will apply to the 561 | combination as such. 562 | 563 | 14. Revised Versions of this License. 564 | 565 | The Free Software Foundation may publish revised and/or new versions of 566 | the GNU General Public License from time to time. Such new versions will 567 | be similar in spirit to the present version, but may differ in detail to 568 | address new problems or concerns. 569 | 570 | Each version is given a distinguishing version number. If the 571 | Program specifies that a certain numbered version of the GNU General 572 | Public License "or any later version" applies to it, you have the 573 | option of following the terms and conditions either of that numbered 574 | version or of any later version published by the Free Software 575 | Foundation. If the Program does not specify a version number of the 576 | GNU General Public License, you may choose any version ever published 577 | by the Free Software Foundation. 578 | 579 | If the Program specifies that a proxy can decide which future 580 | versions of the GNU General Public License can be used, that proxy's 581 | public statement of acceptance of a version permanently authorizes you 582 | to choose that version for the Program. 583 | 584 | Later license versions may give you additional or different 585 | permissions. However, no additional obligations are imposed on any 586 | author or copyright holder as a result of your choosing to follow a 587 | later version. 588 | 589 | 15. Disclaimer of Warranty. 590 | 591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY 592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT 593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY 594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, 595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM 597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF 598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION. 599 | 600 | 16. Limitation of Liability. 601 | 602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING 603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS 604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY 605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE 606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF 607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD 608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS), 609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF 610 | SUCH DAMAGES. 611 | 612 | 17. Interpretation of Sections 15 and 16. 613 | 614 | If the disclaimer of warranty and limitation of liability provided 615 | above cannot be given local legal effect according to their terms, 616 | reviewing courts shall apply local law that most closely approximates 617 | an absolute waiver of all civil liability in connection with the 618 | Program, unless a warranty or assumption of liability accompanies a 619 | copy of the Program in return for a fee. 620 | 621 | END OF TERMS AND CONDITIONS 622 | 623 | How to Apply These Terms to Your New Programs 624 | 625 | If you develop a new program, and you want it to be of the greatest 626 | possible use to the public, the best way to achieve this is to make it 627 | free software which everyone can redistribute and change under these terms. 628 | 629 | To do so, attach the following notices to the program. It is safest 630 | to attach them to the start of each source file to most effectively 631 | state the exclusion of warranty; and each file should have at least 632 | the "copyright" line and a pointer to where the full notice is found. 633 | 634 | 635 | Copyright (C) 636 | 637 | This program is free software: you can redistribute it and/or modify 638 | it under the terms of the GNU General Public License as published by 639 | the Free Software Foundation, either version 3 of the License, or 640 | (at your option) any later version. 641 | 642 | This program is distributed in the hope that it will be useful, 643 | but WITHOUT ANY WARRANTY; without even the implied warranty of 644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 645 | GNU General Public License for more details. 646 | 647 | You should have received a copy of the GNU General Public License 648 | along with this program. If not, see . 649 | 650 | Also add information on how to contact you by electronic and paper mail. 651 | 652 | If the program does terminal interaction, make it output a short 653 | notice like this when it starts in an interactive mode: 654 | 655 | Copyright (C) 656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. 657 | This is free software, and you are welcome to redistribute it 658 | under certain conditions; type `show c' for details. 659 | 660 | The hypothetical commands `show w' and `show c' should show the appropriate 661 | parts of the General Public License. Of course, your program's commands 662 | might be different; for a GUI interface, you would use an "about box". 663 | 664 | You should also get your employer (if you work as a programmer) or school, 665 | if any, to sign a "copyright disclaimer" for the program, if necessary. 666 | For more information on this, and how to apply and follow the GNU GPL, see 667 | . 668 | 669 | The GNU General Public License does not permit incorporating your program 670 | into proprietary programs. If your program is a subroutine library, you 671 | may consider it more useful to permit linking proprietary applications with 672 | the library. If this is what you want to do, use the GNU Lesser General 673 | Public License instead of this License. But first, please read 674 | . 675 | --------------------------------------------------------------------------------