├── settings.gradle ├── docs ├── logo.png ├── BH2012_LucaCarettoni_WP_FINAL.pdf ├── BH2012_LucaCarettoni_PRESO_FINAL.pdf └── DeepSec_2012_Luca_Carettoni_-_AMF_Testing_Made_Easy.pdf ├── src ├── burp │ ├── blazer.policy │ ├── BurpExtender.java │ └── BlazerSecurityManager.java └── com │ └── mtso │ └── blazer │ ├── add.png │ ├── burn.png │ ├── jar.png │ ├── play.png │ ├── stop.png │ ├── export.png │ ├── green01.png │ ├── pause.png │ ├── red03.png │ ├── teal02.png │ ├── orange04.png │ ├── terminal.png │ ├── ThreadCompleteListener.java │ ├── ManualRequestExample.java │ ├── NotifyingThread.java │ ├── MessageSkeleton.java │ ├── MessageTask.java │ ├── AMFUtil.java │ ├── GenericUtil.java │ ├── Exporter.java │ ├── MessageGenerator.java │ ├── TaskSpecification.java │ ├── TaskManager.java │ ├── JavaUtil.java │ └── ObjectGenerator.java ├── dist ├── Blazer_v0.2.jar ├── Blazer_v0.3.jar └── Blazer_v0.3.1.jar ├── BappManifest.bmf ├── BappDescription.html ├── README.md └── LICENSE /settings.gradle: -------------------------------------------------------------------------------- 1 | rootProject.name = 'blazer' 2 | -------------------------------------------------------------------------------- /docs/logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/docs/logo.png -------------------------------------------------------------------------------- /src/burp/blazer.policy: -------------------------------------------------------------------------------- 1 | grant { 2 | permission java.security.AllPermission; 3 | }; 4 | -------------------------------------------------------------------------------- /dist/Blazer_v0.2.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/dist/Blazer_v0.2.jar -------------------------------------------------------------------------------- /dist/Blazer_v0.3.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/dist/Blazer_v0.3.jar -------------------------------------------------------------------------------- /dist/Blazer_v0.3.1.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/dist/Blazer_v0.3.1.jar -------------------------------------------------------------------------------- /src/com/mtso/blazer/add.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/add.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/burn.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/burn.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/jar.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/jar.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/play.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/play.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/stop.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/stop.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/export.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/export.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/green01.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/green01.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/pause.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/pause.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/red03.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/red03.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/teal02.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/teal02.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/orange04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/orange04.png -------------------------------------------------------------------------------- /src/com/mtso/blazer/terminal.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/src/com/mtso/blazer/terminal.png -------------------------------------------------------------------------------- /docs/BH2012_LucaCarettoni_WP_FINAL.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/docs/BH2012_LucaCarettoni_WP_FINAL.pdf -------------------------------------------------------------------------------- /docs/BH2012_LucaCarettoni_PRESO_FINAL.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/docs/BH2012_LucaCarettoni_PRESO_FINAL.pdf -------------------------------------------------------------------------------- /docs/DeepSec_2012_Luca_Carettoni_-_AMF_Testing_Made_Easy.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/PortSwigger/blazer/master/docs/DeepSec_2012_Luca_Carettoni_-_AMF_Testing_Made_Easy.pdf -------------------------------------------------------------------------------- /BappManifest.bmf: -------------------------------------------------------------------------------- 1 | Uuid: 7c385950b7e84257ad5d3338bb5882b4 2 | ExtensionType: 1 3 | Name: Blazer 4 | RepoName: blazer 5 | ScreenVersion: 0.3 6 | SerialVersion: 4 7 | MinPlatformVersion: 0 8 | ProOnly: False 9 | Author: Luca Carettoni 10 | ShortDescription: Generates and fuzzes custom AMF messages. 11 | EntryPoint: build/libs/blazer-all.jar 12 | BuildCommand: gradle fatJar 13 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/ThreadCompleteListener.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ThreadCompleteListener.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | /* 18 | * This interface is used to implement a basic thread notification mechanism. 19 | * Based on http://stackoverflow.com/a/702460 20 | */ 21 | interface ThreadCompleteListener { 22 | 23 | void notifyOfThreadComplete(final Thread thread); 24 | } 25 | -------------------------------------------------------------------------------- /BappDescription.html: -------------------------------------------------------------------------------- 1 |

This extension can be used to generate and fuzz custom AMF messages. 2 | It is designed and implemented to make AMF testing easy, and yet allows researchers to control fully the entire security testing process.

3 | 4 |

Blazer implements a new testing approach, introduced at Black Hat USA 2012. 5 | This automated gray-box testing technique allows security researchers to improve the coverage and the effectiveness of fuzzing efforts targeting complex applications.

6 | 7 |

Features include:

8 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/ManualRequestExample.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ManualRequestExample.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import java.io.PrintWriter; 18 | 19 | /** 20 | * A basic example on how to use Blazer from a stand-alone Java program 21 | * 22 | * Custom clients can use "com.mtso.blazer.MessageGenerator" and 23 | * "com.mtso.blazer.MessageSkeleton" to build and send valid AMF messages 24 | */ 25 | public class ManualRequestExample { 26 | 27 | public static void main(String[] args) { 28 | // blazeds-turnkey-4.0.1.21287 test-case 29 | MessageGenerator myGen = new MessageGenerator("127.0.0.1", "8080", "http://127.0.0.1:8400/samples/messagebroker/amf", "fakeCookie", new PrintWriter(System.out), new PrintWriter(System.err)); 30 | MessageSkeleton message = new MessageSkeleton("productService", "getProductsByName"); 31 | //add your custom parameters here! 32 | message.addPar("Nokia"); 33 | myGen.send(message); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/NotifyingThread.java: -------------------------------------------------------------------------------- 1 | /* 2 | * NotifyingThread.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import java.util.Set; 18 | import java.util.concurrent.CopyOnWriteArraySet; 19 | 20 | /* 21 | * This class extends thread to implement a notification mechanism. 22 | * Based on http://stackoverflow.com/a/702460 23 | */ 24 | abstract class NotifyingThread extends Thread { 25 | 26 | private final Set listeners = new CopyOnWriteArraySet(); 27 | 28 | protected final void addListener(final ThreadCompleteListener listener) { 29 | listeners.add(listener); 30 | } 31 | 32 | protected final void removeListener(final ThreadCompleteListener listener) { 33 | listeners.remove(listener); 34 | } 35 | 36 | protected final void notifyListeners() { 37 | for (ThreadCompleteListener listener : listeners) { 38 | listener.notifyOfThreadComplete(this); 39 | } 40 | } 41 | 42 | @Override 43 | public final void run() { 44 | try { 45 | doRun(); 46 | } finally { 47 | notifyListeners(); 48 | } 49 | } 50 | 51 | protected abstract void doRun(); 52 | } -------------------------------------------------------------------------------- /src/com/mtso/blazer/MessageSkeleton.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MessageSkeleton.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import java.util.Vector; 18 | 19 | /* 20 | * This class contains the skeleton of a basic AMF request 21 | */ 22 | public class MessageSkeleton { 23 | 24 | private String destination; 25 | private String operation; 26 | private Vector parameters; 27 | private String parSignatures; 28 | 29 | public MessageSkeleton(String destination, String operation, String parSignatures) { 30 | this.destination = destination; 31 | this.operation = operation; 32 | this.parameters = new Vector(); 33 | this.parSignatures = parSignatures; 34 | } 35 | 36 | /* 37 | * This method is supposed to be used through BeanShell only 38 | */ 39 | protected MessageSkeleton(String destination, String operation) { 40 | this.destination = destination; 41 | this.operation = operation; 42 | this.parameters = new Vector(); 43 | this.parSignatures = null; 44 | } 45 | 46 | public String getDestination() { 47 | return destination; 48 | } 49 | 50 | public String getOperation() { 51 | return operation; 52 | } 53 | 54 | public String getParSignatures() { 55 | return parSignatures; 56 | } 57 | 58 | public String getPacketString() { 59 | return destination + ":" + operation + ":" + parameters.toString() + System.currentTimeMillis(); 60 | } 61 | 62 | public boolean addPar(Object par) { 63 | return this.parameters.add(par); 64 | } 65 | 66 | public Vector getPars() { 67 | return this.parameters; 68 | } 69 | 70 | public void resetPars() { 71 | this.parameters.clear(); 72 | } 73 | 74 | public int getParsSize() { 75 | return this.parameters.size(); 76 | } 77 | } -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Blazer - AMF Testing Made Easy! ![Blazer Logo](http://i.imgur.com/SSTc20K.png "Blazer Logo") 2 | 3 | **Blazer** is a custom [AMF messages][4] generator with fuzzing capabilities, developed as [Burp Suite plugin][1]. 4 | This extension can be used to generate and fuzz custom AMF messages. It is designed and implemented to make AMF testing easy, and yet allow researchers to control fully the entire security testing process. 5 | 6 | Using Blazer, testing AMF-based applications is easier and more robust. As it is highly integrated in a well-known testing suite, web security practitioners can start using the tool with minimal setup in few seconds. 7 | 8 | ### From 0 to AMF messages generation and fuzzing in just few clicks 9 | 10 | Blazer implements a new testing approach, introduced at [Black Hat USA 2012][5]. This automated gray-box testing technique allows security researchers to improve the coverage and the effectiveness of fuzzing efforts targeting complex applications. 11 | 12 | For further details, please refer to the wiki [documentation](https://github.com/ikkisoft/blazer/wiki) and the original [whitepaper][7] and [presentation][6]. Another recent presentation is available on [SlideShare][8]. 13 | 14 | ![Blazer UI][3] 15 | 16 | Features: 17 | 18 | - Automatic Java objects generation from method signatures via Java reflection and "best-fit" heuristics 19 | - Fuzzing capabilities, with customizable data pools and attack vectors 20 | - Ability to start, pause, restore and stop testing 21 | - Easy-to-use internal methods to construct custom AMF messages 22 | - Embedded BeanShell for manual testing 23 | - JARs, classes and Java src import feature 24 | - AMF request/response export functionality (AMF2XML) 25 | - Sandboxing using a custom security manager 26 | - Highly integrated in Burp Suite 27 | - Support for Java server-side remoting technologies (Adobe BlazeDS, Adobe LiveCycle Data Services, GraniteDS, ...) 28 | 29 | Blazer has been developed in Java as a Burp Suite extension and released under the [GNU General Public License][2]. 30 | Burp extensions are supported by both free and professional Burp Suite versions. 31 | 32 | > **Disclaimer:** 33 | > Please note that I am not actively maintaining this extension anymore. Feel free to fork and improve it! 34 | 35 | [1]: http://portswigger.net/burp/ 36 | [2]: http://www.gnu.org/licenses/ 37 | [3]: http://i.imgur.com/VEfrW.png 38 | [4]: http://en.wikipedia.org/wiki/Action_Message_Format 39 | [5]: http://www.blackhat.com/usa/bh-us-12-briefings.html#Carettoni 40 | [6]: https://github.com/ikkisoft/blazer/blob/master/docs/BH2012_LucaCarettoni_PRESO_FINAL.pdf 41 | [7]: https://github.com/ikkisoft/blazer/blob/master/docs/BH2012_LucaCarettoni_WP_FINAL.pdf 42 | [8]: http://www.slideshare.net/ikkisoft/amf-testing-made-easy-deepsec-2012 43 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/MessageTask.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MessageTask.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | /* 18 | * This class is responsible for the actual object generation and trasmission 19 | */ 20 | class MessageTask extends NotifyingThread implements Comparable { 21 | 22 | private ObjectGenerator testCaseObj; 23 | private int objPermutations; 24 | private MessageSkeleton msgSpecification; 25 | private MessageGenerator msgGenerator; 26 | private boolean threadPaused; 27 | private boolean threadStopped; 28 | 29 | protected MessageTask(ObjectGenerator testCaseObj, int objPermutations, MessageSkeleton msgSpecification, MessageGenerator msgGenerator) { 30 | this.testCaseObj = testCaseObj; 31 | this.objPermutations = objPermutations; 32 | this.msgSpecification = msgSpecification; 33 | this.msgGenerator = msgGenerator; 34 | threadPaused = false; 35 | threadStopped = false; 36 | } 37 | 38 | @Override 39 | protected void doRun() { 40 | 41 | int permCounter = 0; 42 | 43 | threadIteration: 44 | // Iterate for all requested permutations 45 | while (permCounter < objPermutations) { 46 | 47 | msgSpecification.resetPars(); 48 | 49 | // Generate method's parameters as in the signature 50 | String[] argSignatures = msgSpecification.getParSignatures().split(","); 51 | for (int argCont = 0; argCont < argSignatures.length; argCont++) { 52 | if (!argSignatures[argCont].isEmpty()) { 53 | Object tcObj = testCaseObj.generate(argSignatures[argCont].trim()); 54 | msgSpecification.addPar(tcObj); 55 | } 56 | } 57 | 58 | msgGenerator.send(msgSpecification); 59 | TaskManager.oneMoreDone(); 60 | permCounter++; 61 | 62 | //Occasionally, check if we need to pause the thread 63 | synchronized (this) { 64 | if (threadStopped) { 65 | break threadIteration; 66 | } 67 | while (threadPaused) { 68 | try { 69 | wait(); 70 | } catch (InterruptedException ie) { 71 | } 72 | } 73 | } 74 | 75 | } 76 | //All iterations completed, it's time to disconnect the AMFConnection 77 | msgGenerator.disconnectAll(); 78 | } 79 | 80 | // compareTo() implementation to allow array sorting 81 | public int compareTo(Object o) { 82 | MessageTask obj = (MessageTask) o; 83 | if (this.getId() < obj.getId()) { 84 | return -1; 85 | } else if (this.getId() > obj.getId()) { 86 | return 1; 87 | } else { 88 | return 0; 89 | } 90 | } 91 | 92 | protected void pauseThread() { 93 | threadPaused = true; 94 | } 95 | 96 | protected void resumeThread() { 97 | threadPaused = false; 98 | } 99 | 100 | protected void stopThread() { 101 | threadStopped = true; 102 | } 103 | } 104 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/AMFUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * AMFUtil.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import flex.messaging.io.SerializationContext; 18 | import flex.messaging.io.amf.ActionContext; 19 | import flex.messaging.io.amf.ActionMessage; 20 | import flex.messaging.io.amf.AmfMessageDeserializer; 21 | import flex.messaging.messages.RemotingMessage; 22 | import java.io.ByteArrayInputStream; 23 | import java.io.PrintWriter; 24 | 25 | /* 26 | * This class implements multiple AMF auxiliary utils 27 | */ 28 | public class AMFUtil { 29 | 30 | /* 31 | * Verify that the request contains a valid AMF message. 32 | * The "Content-Type" header can also be used, however this is more reliable 33 | */ 34 | public static boolean isAMF(byte[] request, PrintWriter stdOut, PrintWriter stdErr) { 35 | 36 | Object[] out; 37 | byte[] requestBody; 38 | 39 | SerializationContext serialContext = SerializationContext.getSerializationContext(); 40 | AmfMessageDeserializer localAmfMessageDeserializer = new AmfMessageDeserializer(); 41 | requestBody = GenericUtil.getBody(request); 42 | try { 43 | localAmfMessageDeserializer.initialize(serialContext, new ByteArrayInputStream(requestBody, 0, requestBody.length), null); 44 | ActionMessage localActionMessage = new ActionMessage(); 45 | localAmfMessageDeserializer.readMessage(localActionMessage, new ActionContext()); 46 | //Expecting at least one "flex.messaging.messages.RemotingMessage". Note that messages can be encapsulated 47 | for (int i = 0; i < localActionMessage.getBodyCount(); i++) { 48 | out = (Object[]) localActionMessage.getBody(i).getData(); 49 | for (int j = 0; j < out.length; j++) { 50 | if (out[j] instanceof RemotingMessage) { 51 | return true; 52 | } 53 | } 54 | } 55 | } catch (flex.messaging.MessageException exM) { 56 | if (exM.getCode().equalsIgnoreCase("Client.Message.Encoding")) { 57 | //Something wrong while deserializating. Custom objects? 58 | stdErr.println("[!] Blazer isAMF Exception: " + exM.toString().trim()); 59 | return true; //load Blazer anyway 60 | } else { 61 | return false; 62 | } 63 | } catch (Exception ex) { 64 | stdErr.println("[!] Blazer isAMF Exception: " + ex.toString().trim()); 65 | stdErr.println("[!] Does the request contain a valid 'flex.messaging.messages.RemotingMessage' ?!?"); 66 | return false; 67 | } 68 | return false; 69 | } 70 | 71 | /* 72 | * Extract ActionMessage from an HTTP request/response 73 | */ 74 | public static ActionMessage extractAM(byte[] reqresp, PrintWriter stdOut, PrintWriter stdErr) { 75 | 76 | ActionMessage localActionMessage = null; 77 | 78 | SerializationContext serialContext = SerializationContext.getSerializationContext(); 79 | AmfMessageDeserializer localAmfMessageDeserializer = new AmfMessageDeserializer(); 80 | byte[] body = GenericUtil.getBody(reqresp); 81 | 82 | try { 83 | localAmfMessageDeserializer.initialize(serialContext, new ByteArrayInputStream(body, 0, body.length), null); 84 | localActionMessage = new ActionMessage(); 85 | localAmfMessageDeserializer.readMessage(localActionMessage, new ActionContext()); 86 | } catch (Exception ex) { 87 | stdErr.println("[!] Blazer extractAM Exception: " + ex.toString().trim()); 88 | } 89 | return localActionMessage; 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/GenericUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * GenericUtil.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import java.io.BufferedReader; 18 | import java.io.DataInputStream; 19 | import java.io.File; 20 | import java.io.FileInputStream; 21 | import java.io.InputStreamReader; 22 | import java.io.PrintWriter; 23 | import java.util.ArrayList; 24 | import java.util.Map; 25 | 26 | /* 27 | * This class implements multiple general purpose auxiliary utils 28 | */ 29 | public class GenericUtil { 30 | 31 | /* 32 | * Retrieve the HTTP message body from a request/response 33 | */ 34 | public static byte[] getBody(byte[] request) { 35 | int offset = 0; 36 | byte[] body = null; 37 | 38 | for (int i = 0; i < request.length; i++) { 39 | if (i + 3 <= request.length) { 40 | if (request[i] == 13 && request[i + 1] == 10 && request[i + 2] == 13 && request[i + 3] == 10) { 41 | offset = i + 4; //Got a \r\n\r\n 42 | } 43 | } 44 | } 45 | 46 | if (offset != 0 && offset < request.length) { 47 | body = new byte[request.length - offset]; 48 | int cont = 0; 49 | for (int i = offset; i < request.length; i++) { 50 | body[cont] = request[i]; 51 | cont++; 52 | } 53 | } 54 | return body; 55 | } 56 | 57 | /* 58 | * Retrieve the cookies header field from a request/response 59 | */ 60 | public static String getCookies(byte[] request) { 61 | 62 | String requestStr = new String(request); 63 | String cookies = ""; 64 | 65 | if (requestStr.contains("Cookie:")) { 66 | cookies = requestStr.substring(requestStr.indexOf("Cookie:")); 67 | cookies = cookies.substring(7, cookies.indexOf("\r\n")).trim(); 68 | } 69 | 70 | return cookies; 71 | } 72 | 73 | /* 74 | * Retrieve the content of a given wordlist 75 | */ 76 | public static String[] retrieveWordlist(File file, PrintWriter stdOut, PrintWriter stdErr) { 77 | 78 | ArrayList lineIter = new ArrayList(); 79 | try { 80 | FileInputStream fstream = new FileInputStream(file); 81 | DataInputStream in = new DataInputStream(fstream); 82 | BufferedReader br = new BufferedReader(new InputStreamReader(in)); 83 | String strLine; 84 | while ((strLine = br.readLine()) != null) { 85 | lineIter.add(strLine); 86 | } 87 | in.close(); 88 | } catch (Exception ioe) { 89 | stdErr.println("[!] Blazer GenericUtil Exception: " + ioe.toString().trim()); 90 | } 91 | 92 | String[] strArray = new String[lineIter.size()]; 93 | return (String[]) lineIter.toArray(strArray); 94 | } 95 | 96 | /* 97 | * Retrieve the proxy settings from Burp's configuration dump 98 | * E.g. "proxy.listener0 => 1.8888.1.0..0.0.1.0..0..0." 99 | */ 100 | public static String burpProxySettings(Map configs) { 101 | String[] fields; 102 | String burpHost = "", burpPort = ""; 103 | //Search the first active listener 104 | for (int i = 0; i < configs.size(); i++) { 105 | if (configs.containsKey("proxy.listener" + i)) { 106 | fields = ((String) (configs.get("proxy.listener" + i))).split("\\."); 107 | if (fields[0].equalsIgnoreCase("1")) { 108 | //Retrieve the port value 109 | burpPort = fields[1]; 110 | //Retrieve the host value 111 | String fullHost = fields[2]; 112 | if (fullHost.charAt(0) == '1') { 113 | burpHost = "127.0.0.1"; //localhost 114 | } else if (fullHost.charAt(0) == '0') { 115 | burpHost = "127.0.0.1"; //all interfaces, use localhost 116 | } else if (fullHost.charAt(0) == '2') { 117 | burpHost = fullHost.substring(1); //custom network interface 118 | if (burpHost.contains("|")) { //In case, convert | back to . 119 | burpHost = burpHost.replaceAll("\\|", "."); 120 | } 121 | } 122 | } 123 | } 124 | } 125 | return burpHost + ":" + burpPort; 126 | } 127 | 128 | /* 129 | * String repeat basic implementation 130 | */ 131 | public static String repeat(String str, int times) { 132 | 133 | if (str == null) { 134 | return null; 135 | } 136 | StringBuilder sb = new StringBuilder(); 137 | for (int i = 0; i < times; i++) { 138 | sb.append(str); 139 | } 140 | return sb.toString(); 141 | } 142 | } 143 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/Exporter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Exporter.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import burp.BurpExtender; 18 | import burp.IHttpRequestResponse; 19 | import com.thoughtworks.xstream.XStream; 20 | import java.io.BufferedWriter; 21 | import java.io.File; 22 | import java.io.FileNotFoundException; 23 | import java.io.FileWriter; 24 | import java.io.IOException; 25 | import java.lang.reflect.InvocationTargetException; 26 | import java.net.MalformedURLException; 27 | import java.net.URL; 28 | import java.text.DateFormat; 29 | import java.util.Date; 30 | import java.util.regex.Pattern; 31 | 32 | /* 33 | * This class is used by the AMF2XML export functionality 34 | */ 35 | public class Exporter { 36 | 37 | private XStream xstream; 38 | private File exportFile = null; 39 | private boolean exportRequests = false; 40 | private boolean exportResponses = false; 41 | private Object[] applicationLibs = null; 42 | private TaskManager manager; 43 | 44 | public Exporter(TaskManager manager, boolean exportRequests, boolean exportResponses, File exportFile) { 45 | 46 | xstream = new XStream(); 47 | 48 | this.exportFile = exportFile; 49 | this.exportResponses = exportResponses; 50 | this.exportRequests = exportRequests; 51 | this.manager = manager; 52 | this.applicationLibs = manager.getTask().getLibraries().toArray(); 53 | 54 | /* 55 | * Include all application libraries at runtime 56 | */ 57 | try { 58 | 59 | URL[] classUrls = new URL[applicationLibs.length]; 60 | 61 | for (int lCont = 0; lCont < applicationLibs.length; lCont++) { 62 | String absoluteVodka = ((File) applicationLibs[lCont]).getCanonicalPath(); 63 | if (absoluteVodka.endsWith(".jar")) { 64 | classUrls[lCont] = (new File(absoluteVodka)).toURI().toURL(); //loading JARs 65 | } else if (absoluteVodka.endsWith(".class")) { 66 | String classPathName = JavaUtil.retrieveCanonicalNameFromClass(((File) applicationLibs[lCont])); 67 | if (File.separator.equalsIgnoreCase("/")) { 68 | classPathName = classPathName.replaceAll("\\.", "/") + ".class"; 69 | } else { 70 | classPathName = classPathName.replaceAll("\\.", "\\\\") + ".class"; 71 | } 72 | absoluteVodka = absoluteVodka.replaceAll(Pattern.quote(classPathName), ""); 73 | classUrls[lCont] = (new File(absoluteVodka)).toURI().toURL(); //loading top directory containing selected classes 74 | } 75 | } 76 | 77 | JavaUtil.addURLs(classUrls, manager.getStdOut(), manager.getStdErr()); 78 | 79 | } catch (MalformedURLException ex) { 80 | manager.getStdErr().println("[!] AMF2XML Exporter MalformedURLException: " + ex.toString().trim()); 81 | } catch (NoSuchMethodException ex) { 82 | manager.getStdErr().println("[!] AMF2XML Exporter NoSuchMethodException: " + ex.toString().trim()); 83 | } catch (IllegalArgumentException ex) { 84 | manager.getStdErr().println("[!] AMF2XML Exporter IllegalArgumentException: " + ex.toString().trim()); 85 | } catch (IllegalAccessException ex) { 86 | manager.getStdErr().println("[!] AMF2XML Exporter IllegalAccessException: " + ex.toString().trim()); 87 | } catch (InvocationTargetException ex) { 88 | manager.getStdErr().println("[!] AMF2XML Exporter InvocationTargetException: " + ex.toString().trim()); 89 | } catch (FileNotFoundException ex) { 90 | manager.getStdErr().println("[!] AMF2XML Exporter FileNotFoundException: " + ex.toString().trim()); 91 | } catch (IOException ex) { 92 | manager.getStdErr().println("[!] AMF2XML Exporter IOException: " + ex.toString().trim()); 93 | } 94 | } 95 | 96 | public void export(IHttpRequestResponse[] messageInfo) throws Exception { 97 | 98 | StringBuilder reqsDet = new StringBuilder(); 99 | 100 | //Header 101 | reqsDet.append(GenericUtil.repeat("-", 100)).append(System.getProperty("line.separator")); 102 | DateFormat formatter = DateFormat.getDateTimeInstance(DateFormat.LONG, DateFormat.LONG); 103 | reqsDet.append(BurpExtender.getBanner()).append(" - AMF2XML Export - ").append(formatter.format(new Date())).append(System.getProperty("line.separator")); 104 | reqsDet.append(GenericUtil.repeat("-", 100)).append(System.getProperty("line.separator")); 105 | 106 | for (IHttpRequestResponse singleMsg : messageInfo) { 107 | //Request or Response details 108 | reqsDet.append("Host:").append(singleMsg.getHttpService().getHost()).append(System.getProperty("line.separator")); 109 | reqsDet.append("Port:").append(singleMsg.getHttpService().getPort()).append(System.getProperty("line.separator")); 110 | reqsDet.append("Protocol:").append(singleMsg.getHttpService().getProtocol()).append(System.getProperty("line.separator")); 111 | reqsDet.append("Comment:").append(singleMsg.getComment()).append(System.getProperty("line.separator")); 112 | if (exportRequests) { 113 | reqsDet.append("HTTP Request:").append(System.getProperty("line.separator")).append(xstream.toXML(AMFUtil.extractAM(singleMsg.getRequest(), manager.getStdOut(), manager.getStdErr())).replaceAll("\n", System.getProperty("line.separator"))).append(System.getProperty("line.separator")); 114 | } 115 | if (exportResponses) { 116 | reqsDet.append("HTTP Response:").append(System.getProperty("line.separator")).append(xstream.toXML(AMFUtil.extractAM(singleMsg.getResponse(), manager.getStdOut(), manager.getStdErr())).replaceAll("\n", System.getProperty("line.separator"))).append(System.getProperty("line.separator")); 117 | } 118 | reqsDet.append(GenericUtil.repeat("-", 100)).append(System.getProperty("line.separator")); 119 | } 120 | 121 | if (exportFile != null) { //Export to file 122 | try { 123 | if (!exportFile.exists()) { 124 | exportFile.createNewFile(); 125 | } 126 | FileWriter fw = new FileWriter(exportFile.getAbsoluteFile()); 127 | BufferedWriter bw = new BufferedWriter(fw); 128 | bw.write(reqsDet.toString()); 129 | bw.close(); 130 | manager.getStdOut().println("[*] AMF2XML Exporter just saved: " + exportFile.getCanonicalPath()); 131 | } catch (IOException ex) { 132 | manager.getStdErr().println("[!] AMF2XML Exporter File IOException:" + ex.toString().trim()); 133 | } 134 | } else { //Export to standard output 135 | manager.getStdOut().println(reqsDet.toString()); 136 | } 137 | } 138 | } 139 | -------------------------------------------------------------------------------- /src/burp/BurpExtender.java: -------------------------------------------------------------------------------- 1 | /* 2 | * BurpExtender.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package burp; 16 | 17 | import com.mtso.blazer.AMFUtil; 18 | import com.mtso.blazer.BlazerUIView; 19 | import com.mtso.blazer.TaskManager; 20 | import java.net.URL; 21 | import javax.swing.JOptionPane; 22 | import javax.swing.JPanel; 23 | import javax.swing.JTabbedPane; 24 | import javax.swing.UIManager; 25 | import javax.swing.UIManager.LookAndFeelInfo; 26 | 27 | /* 28 | * This class implements the IBurpExtender interface to make use of Burp Extender 29 | * 30 | * As of v1.5.01, Burp Extender uses a new API. This extension has been adapted to run 31 | * on both old and new versions, with native support for Burp standard output and error tabs 32 | */ 33 | public class BurpExtender implements IBurpExtender { 34 | 35 | private static String version = "v0.3"; 36 | private static boolean flagSM = false; 37 | 38 | public static String getBanner() { 39 | return "Blazer " + version; 40 | } 41 | 42 | public void registerExtenderCallbacks(IBurpExtenderCallbacks callbacks) { 43 | callbacks.issueAlert("[" + getBanner() + "]"); 44 | callbacks.registerMenuItem("Blazer - AMF Testing", new CustomMenuItem(callbacks)); 45 | callbacks.registerMenuItem("Blazer - AMF2XML Export", new CustomMenuItem(callbacks)); 46 | callbacks.registerMenuItem("Blazer - Enable/Disable Security Manager", new CustomMenuItem(callbacks)); 47 | callbacks.setProxyInterceptionEnabled(false); //avoid interception. In case, users can re-enable it from the GUI 48 | } 49 | 50 | public byte[] processProxyMessage(int i, boolean bln, String string, int i1, boolean bln1, String string1, String string2, String string3, String string4, String string5, byte[] bytes, int[] ints) { 51 | //do nothing 52 | return bytes; 53 | } 54 | 55 | public void applicationClosing() { 56 | //do nothing 57 | } 58 | 59 | public void processHttpMessage(String string, boolean bln, IHttpRequestResponse ihrr) { 60 | //do nothing 61 | } 62 | 63 | public void newScanIssue(IScanIssue isi) { 64 | //do nothing 65 | } 66 | 67 | public static void toggleSM() { 68 | if (flagSM == true) { 69 | flagSM = false; 70 | } else { 71 | flagSM = true; 72 | } 73 | } 74 | 75 | public static boolean getFlagSM() { 76 | return flagSM; 77 | } 78 | 79 | public void setCommandLineArgs(String[] strings) { 80 | //do nothing 81 | } 82 | } 83 | 84 | class CustomMenuItem implements IMenuItemHandler { 85 | 86 | private IBurpExtenderCallbacks callbacks; 87 | private TaskManager manager; 88 | 89 | public CustomMenuItem(IBurpExtenderCallbacks callbacks) { 90 | this.callbacks = callbacks; 91 | } 92 | 93 | public void menuItemClicked(String menuItemCaption, IHttpRequestResponse[] messageInfo) { 94 | if (messageInfo[0].getRequest() == null) return; 95 | 96 | try { 97 | // User clicked on the Blazer extension contextual menu 98 | if (menuItemCaption.equalsIgnoreCase("Blazer - AMF Testing")) { //Standard Blazer GUI 99 | BlazerUIView gui = initializeAndDisplay(messageInfo); 100 | 101 | //Does the request contain a valid AMF RemotingMessage? Just notify the user 102 | if (!AMFUtil.isAMF(messageInfo[0].getRequest(), manager.getStdOut(), manager.getStdErr())) { 103 | this.callbacks.issueAlert("[Blazer] The request does not contain a valid AMF RemotingMessage"); 104 | } 105 | 106 | //Remove export tab 107 | JPanel myJPanel = (JPanel) gui.getComponent(0); 108 | JTabbedPane myJTabbedPane = (JTabbedPane) myJPanel.getComponent(0); 109 | Thread.sleep(500); 110 | myJTabbedPane.remove(5); 111 | gui.setVisible(true); 112 | 113 | /* 114 | * Deploy our custom SecurityManager 115 | * 116 | * (1) By default, we grant "java.security.AllPermission" for all 117 | * (2) BlazerSecurityManager checks the execution stack and detect unauthorized operations originated from ObjectGenerator.generate() 118 | */ 119 | ClassLoader cl = getClass().getClassLoader(); 120 | URL policyURL = cl.getResource("burp/blazer.policy"); 121 | System.setProperty("java.security.policy", policyURL.toString()); 122 | SecurityManager security = System.getSecurityManager(); 123 | if (security == null && BurpExtender.getFlagSM()) { 124 | System.setSecurityManager(new BlazerSecurityManager(manager)); 125 | } 126 | } else if (menuItemCaption.equalsIgnoreCase("Blazer - AMF2XML Export")) { //Export Blazer GUI 127 | BlazerUIView gui = initializeAndDisplay(messageInfo); 128 | 129 | //Does the request contain a valid AMF RemotingMessage? Just notify the user 130 | if (!AMFUtil.isAMF(messageInfo[0].getRequest(), manager.getStdOut(), manager.getStdErr())) { 131 | this.callbacks.issueAlert("[Blazer] The request does not contain a valid AMF RemotingMessage"); 132 | } 133 | 134 | //Remove unused tabs 135 | JPanel myJPanel = (JPanel) gui.getComponent(0); 136 | JTabbedPane myJTabbedPane = (JTabbedPane) myJPanel.getComponent(0); 137 | Thread.sleep(500); 138 | myJTabbedPane.remove(1); 139 | myJTabbedPane.remove(1); 140 | myJTabbedPane.remove(1); 141 | myJTabbedPane.remove(1); 142 | gui.setVisible(true); 143 | } else if (menuItemCaption.equalsIgnoreCase("Blazer - Enable/Disable Security Manager")) { //Disable SecurityManager option 144 | BurpExtender.toggleSM(); 145 | if (BurpExtender.getFlagSM()) { 146 | this.callbacks.issueAlert("[Blazer] Custom Security Manager has been enabled"); 147 | JOptionPane.showMessageDialog(null, "Using the Security Manager, any security exception will automatically shutdown Burp Suite and Blazer", "Alert!", JOptionPane.ERROR_MESSAGE); 148 | } else { 149 | this.callbacks.issueAlert("[Blazer] Custom Security Manager has been disabled"); 150 | } 151 | } 152 | } catch (Exception ex) { 153 | manager.getStdErr().println("[!] Blazer BurpExtender Exception: "); 154 | manager.getStdErr().println(ex.toString()); 155 | } 156 | } 157 | 158 | private BlazerUIView initializeAndDisplay(IHttpRequestResponse[] messageInfo) throws Exception { 159 | manager = new TaskManager(callbacks, messageInfo); 160 | 161 | return new BlazerUIView(manager); 162 | } 163 | } 164 | -------------------------------------------------------------------------------- /src/burp/BlazerSecurityManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * BlazerSecurityManager.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package burp; 16 | 17 | import com.mtso.blazer.TaskManager; 18 | import java.io.FileDescriptor; 19 | import java.net.InetAddress; 20 | import java.security.Permission; 21 | 22 | /** 23 | * This is a custom Java SecurityManager used to limit operations originated 24 | * from com.mtso.blazer.ObjectGenerato.generate() 25 | */ 26 | public class BlazerSecurityManager extends SecurityManager { 27 | 28 | private TaskManager manager; 29 | 30 | public BlazerSecurityManager(TaskManager manager) { 31 | super(); 32 | this.manager = manager; 33 | } 34 | 35 | public void detectException(String checkName) { 36 | for (StackTraceElement elem : Thread.currentThread().getStackTrace()) { 37 | if ("com.mtso.blazer.ObjectGenerator".equals(elem.getClassName()) && "generate".equals(elem.getMethodName())) { 38 | manager.issueAlert("[Blazer] SecurityManager: UNAUTHORIZED OPERATION detected by " + checkName); 39 | manager.issueAlert("[Blazer] SecurityManager will shutdown all Java processes to prevent a potentially dangerous operation"); 40 | manager.getStdErr().println("[!] BlazerSecurityManager ---------> UNAUTHORIZED OPERATION detected by " + checkName); 41 | manager.getStdErr().println("[!] Blazer will shutdown all Java processes to prevent a potentially dangerous operation"); 42 | for(int i=10; i>=0; i=i-1){ 43 | manager.issueAlert("[Blazer] Shutdown in " + i); 44 | manager.getStdErr().println("[!] Shutdown in " + i); 45 | try { 46 | Thread.sleep(1000); 47 | } catch (InterruptedException ex) { 48 | System.exit(-1); //Emergency shutdown 49 | } 50 | } 51 | System.exit(-1); //Emergency shutdown 52 | } 53 | } 54 | } 55 | 56 | public void detectException(String checkName, Permission perm) { 57 | for (StackTraceElement elem : Thread.currentThread().getStackTrace()) { 58 | if ("com.mtso.blazer.ObjectGenerator".equals(elem.getClassName()) && "generate".equals(elem.getMethodName())) { 59 | manager.getStdOut().println("[*] BlazerSecurityManager permissions monitor --> " + perm.toString()); 60 | } 61 | } 62 | } 63 | 64 | /* 65 | * To customize permissions, please refer to http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/SecurityManager.html 66 | */ 67 | @Override 68 | public void checkPermission(Permission perm) { 69 | detectException("checkPermission", perm); 70 | super.checkPermission(perm); 71 | } 72 | 73 | @Override 74 | public void checkPermission(Permission perm, Object context) { 75 | detectException("checkPermission", perm); 76 | super.checkPermission(perm, context); 77 | } 78 | 79 | @Override 80 | public void checkCreateClassLoader() { 81 | detectException("checkCreateClassLoader"); 82 | super.checkCreateClassLoader(); 83 | } 84 | 85 | @Override 86 | public void checkAccess(Thread t) { 87 | super.checkAccess(t); 88 | } 89 | 90 | @Override 91 | public void checkAccess(ThreadGroup g) { 92 | super.checkAccess(g); 93 | } 94 | 95 | @Override 96 | public void checkExit(int status) { 97 | super.checkExit(status); 98 | } 99 | 100 | @Override 101 | public void checkExec(String cmd) { 102 | detectException("checkExec"); 103 | super.checkExec(cmd); 104 | } 105 | 106 | @Override 107 | public void checkLink(String lib) { 108 | detectException("checkLink"); 109 | super.checkLink(lib); 110 | } 111 | 112 | @Override 113 | public void checkRead(FileDescriptor fd) { 114 | super.checkRead(fd); 115 | } 116 | 117 | @Override 118 | public void checkRead(String file) { 119 | super.checkRead(file); 120 | } 121 | 122 | @Override 123 | public void checkRead(String file, Object context) { 124 | super.checkRead(file, context); 125 | } 126 | 127 | @Override 128 | public void checkWrite(FileDescriptor fd) { 129 | detectException("checkWrite"); 130 | super.checkWrite(fd); 131 | } 132 | 133 | @Override 134 | public void checkWrite(String file) { 135 | detectException("checkWrite"); 136 | super.checkWrite(file); 137 | } 138 | 139 | @Override 140 | public void checkDelete(String file) { 141 | detectException("checkDelete"); 142 | super.checkDelete(file); 143 | } 144 | 145 | @Override 146 | public void checkConnect(String host, int port) { 147 | detectException("checkConnect"); 148 | super.checkConnect(host, port); 149 | } 150 | 151 | @Override 152 | public void checkConnect(String host, int port, Object context) { 153 | detectException("checkConnect"); 154 | super.checkConnect(host, port, context); 155 | } 156 | 157 | @Override 158 | public void checkListen(int port) { 159 | detectException("checkListen"); 160 | super.checkListen(port); 161 | } 162 | 163 | @Override 164 | public void checkAccept(String host, int port) { 165 | detectException("checkAccept"); 166 | super.checkAccept(host, port); 167 | } 168 | 169 | @Override 170 | public void checkMulticast(InetAddress maddr) { 171 | detectException("checkMulticast"); 172 | super.checkMulticast(maddr); 173 | } 174 | 175 | @Override 176 | public void checkPropertiesAccess() { 177 | detectException("checkPropertiesAccess"); 178 | super.checkPropertiesAccess(); 179 | } 180 | 181 | @Override 182 | public void checkPropertyAccess(String key) { 183 | super.checkPropertyAccess(key); 184 | } 185 | 186 | @Override 187 | public boolean checkTopLevelWindow(Object window) { 188 | return super.checkTopLevelWindow(window); 189 | } 190 | 191 | @Override 192 | public void checkPrintJobAccess() { 193 | super.checkPrintJobAccess(); 194 | } 195 | 196 | @Override 197 | public void checkSystemClipboardAccess() { 198 | super.checkSystemClipboardAccess(); 199 | } 200 | 201 | @Override 202 | public void checkAwtEventQueueAccess() { 203 | super.checkAwtEventQueueAccess(); 204 | } 205 | 206 | @Override 207 | public void checkPackageAccess(String pkg) { 208 | super.checkPackageAccess(pkg); 209 | } 210 | 211 | @Override 212 | public void checkPackageDefinition(String pkg) { 213 | super.checkPackageDefinition(pkg); 214 | } 215 | 216 | @Override 217 | public void checkSetFactory() { 218 | detectException("checkSetFactory"); 219 | super.checkSetFactory(); 220 | } 221 | 222 | @Override 223 | public void checkMemberAccess(Class clazz, int which) { 224 | super.checkMemberAccess(clazz, which); 225 | } 226 | 227 | @Override 228 | public void checkSecurityAccess(String target) { 229 | detectException("checkSecurityAccess"); 230 | super.checkSecurityAccess(target); 231 | } 232 | } 233 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/MessageGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * MessageGenerator.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import com.thoughtworks.xstream.XStream; 18 | import flex.messaging.io.ArrayCollection; 19 | import flex.messaging.io.amf.client.AMFConnection; 20 | import flex.messaging.io.amf.client.exceptions.ClientStatusException; 21 | import flex.messaging.io.amf.client.exceptions.ServerStatusException; 22 | import flex.messaging.messages.RemotingMessage; 23 | import java.io.PrintWriter; 24 | import java.net.InetSocketAddress; 25 | import java.net.Proxy; 26 | import java.security.KeyManagementException; 27 | import java.security.NoSuchAlgorithmException; 28 | import javax.net.ssl.HostnameVerifier; 29 | import javax.net.ssl.HttpsURLConnection; 30 | import javax.net.ssl.SSLContext; 31 | import javax.net.ssl.SSLSession; 32 | import javax.net.ssl.TrustManager; 33 | import javax.net.ssl.X509TrustManager; 34 | import java.security.cert.X509Certificate; 35 | import java.util.Iterator; 36 | 37 | /* 38 | * This class is used to craft and send AMF requests 39 | */ 40 | public class MessageGenerator { 41 | 42 | /* Proxy settings */ 43 | private boolean proxyEnabled; 44 | private String proxyHost; 45 | private String proxyPort; 46 | private String endpoint; 47 | private String cookies; 48 | private AMFConnection amfConnection; 49 | private PrintWriter stdOut; 50 | private PrintWriter stdErr; 51 | private XStream xstream; 52 | 53 | public MessageGenerator(String proxyHost, String proxyPort, String endpoint, String cookies, PrintWriter stdOut, PrintWriter stdErr) { 54 | this.proxyHost = proxyHost; 55 | this.proxyPort = proxyPort; 56 | this.endpoint = endpoint; 57 | this.cookies = cookies; 58 | this.stdOut = stdOut; 59 | this.stdErr = stdErr; 60 | this.xstream = new XStream(); 61 | 62 | // Setup proxy and SSL checks 63 | amfConnection = new AMFConnection(); 64 | proxyEnabled = proxySetup(amfConnection); 65 | 66 | //Initialize AMF connection 67 | try { 68 | amfConnection.connect(endpoint); 69 | } catch (ClientStatusException eClient) { 70 | stdErr.println("[!] ClientStatusException - Connection: " + eClient.toString().trim()); 71 | } 72 | 73 | amfConnection.addHttpRequestHeader("Content-type", "application/x-amf"); 74 | if (cookies == null ? "" != null : !cookies.equals("")) { 75 | amfConnection.addHttpRequestHeader("Cookie", cookies); 76 | } 77 | 78 | AMFConnection.registerAlias("DSA", flex.messaging.messages.AsyncMessageExt.class.getName()); 79 | AMFConnection.registerAlias("DSK", flex.messaging.messages.AcknowledgeMessageExt.class.getName()); 80 | AMFConnection.registerAlias("DSC", flex.messaging.messages.CommandMessageExt.class.getName()); 81 | 82 | //AMF v3 83 | AMFConnection.setDefaultObjectEncoding(3); 84 | 85 | //no-check-certificate 86 | try { 87 | noCheckCertConnection(); 88 | } catch (NoSuchAlgorithmException ex) { 89 | stdErr.println("[!] NoSuchAlgorithmException: " + ex.toString().trim()); 90 | } catch (KeyManagementException ex) { 91 | stdErr.println("[!] KeyManagementException: " + ex.toString().trim()); 92 | } 93 | } 94 | 95 | public boolean isProxyEnabled() { 96 | return this.proxyEnabled; 97 | } 98 | 99 | /* 100 | * Configure the HTTP/HTTPS proxy in order to tunnel all Blazer connections. 101 | * By default, it is the local instance of Burp 102 | */ 103 | private boolean proxySetup(AMFConnection amfConn) { 104 | if (proxyHost != null && proxyPort != null) { 105 | amfConn.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)))); 106 | //Using older Adobe Flex libraries, this seems required 107 | System.setProperty("https.proxyHost", proxyHost); 108 | System.setProperty("http.proxyHost", proxyHost); 109 | System.setProperty("https.proxyPort", proxyPort); 110 | System.setProperty("http.proxyPort", proxyPort); 111 | return true; 112 | } else { 113 | return false; 114 | } 115 | } 116 | 117 | //no-check-certificate equivalent 118 | private void noCheckCertConnection() throws NoSuchAlgorithmException, KeyManagementException { 119 | 120 | TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() { 121 | public java.security.cert.X509Certificate[] getAcceptedIssuers() { 122 | return null; 123 | } 124 | 125 | public void checkClientTrusted(X509Certificate[] certs, String authType) { 126 | } 127 | 128 | public void checkServerTrusted(X509Certificate[] certs, String authType) { 129 | } 130 | }}; 131 | SSLContext sc = SSLContext.getInstance("SSL"); 132 | sc.init(null, trustAllCerts, new java.security.SecureRandom()); 133 | HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory()); 134 | HostnameVerifier allHostsValid = new HostnameVerifier() { 135 | public boolean verify(String hostname, SSLSession session) { 136 | return true; 137 | } 138 | }; 139 | HttpsURLConnection.setDefaultHostnameVerifier(allHostsValid); 140 | } 141 | 142 | public void send(MessageSkeleton packet) { 143 | 144 | Object response = null; 145 | 146 | amfConnection.addHttpRequestHeader("Blazer", packet.getPacketString()); 147 | 148 | RemotingMessage message = new RemotingMessage(); 149 | message.setMessageId(flex.messaging.util.UUIDUtils.createUUID()); 150 | 151 | /* 152 | * IMPORTANT! 153 | * If your application uses customized invocation objects, modify the code below 154 | */ 155 | message.setDestination(packet.getDestination()); 156 | message.setOperation(packet.getOperation()); 157 | 158 | ArrayCollection arguments = new ArrayCollection(); 159 | Iterator parsIt = packet.getPars().iterator(); 160 | while (parsIt.hasNext()) { 161 | arguments.add(parsIt.next()); 162 | } 163 | 164 | message.setBody(arguments); 165 | 166 | stdOut.println("[*] Sending AMF message with signature --> " + packet.getPacketString()); 167 | 168 | try { 169 | response = amfConnection.call(packet.getDestination() + "." + packet.getOperation(), message); 170 | 171 | } catch (ClientStatusException eClient) { 172 | // Older versions of Adobe Flex libraries may return this client-side exception 173 | stdErr.println("[!] ClientStatusException: " + eClient.toString().trim()); 174 | } catch (ServerStatusException eServer) { 175 | stdErr.println("[!] ServerStatusException: " + eServer.toString().trim()); 176 | } catch (Exception eGeneric) { 177 | stdErr.println("[!] Generic Exception: " + eGeneric.toString().trim()); 178 | } finally { 179 | //In any case, dump the response 180 | if (response != null) { 181 | stdOut.println("\n[*] ---------------------------------------------------------"); 182 | stdOut.println(xstream.toXML(response)); 183 | stdOut.println("[*] ---------------------------------------------------------\n"); 184 | } 185 | } 186 | } 187 | 188 | public void disconnectAll() { 189 | amfConnection.close(); 190 | } 191 | 192 | public String getCookies() { 193 | return cookies; 194 | } 195 | 196 | public String getEndpoint() { 197 | return endpoint; 198 | } 199 | } 200 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/TaskSpecification.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TaskSpecification.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import java.io.File; 18 | import java.io.PrintWriter; 19 | import java.util.ArrayList; 20 | 21 | /* 22 | * This class represents the gray-box testing task, containing all configurations and status 23 | */ 24 | class TaskSpecification { 25 | 26 | /* Status attributes */ 27 | static final int STARTED = 1; 28 | static final int PAUSED = 2; 29 | static final int STOPPED = 3; 30 | private int status; 31 | 32 | /* Configuration attributes */ 33 | private String proxyHost = ""; 34 | private String proxyPort = ""; 35 | private ArrayList libraries; 36 | private ArrayList signatures; 37 | private boolean fuzzing = false; 38 | private int threads = 1; 39 | private int permutations = 5; 40 | private float vectorsLikelihood = 50; 41 | private ArrayList vectors; 42 | // Data pools for primitive types 43 | private ArrayList bytePool; 44 | private ArrayList shortPool; 45 | private ArrayList intPool; 46 | private ArrayList longPool; 47 | private ArrayList floatPool; 48 | private ArrayList doublePool; 49 | private ArrayList booleanPool; 50 | private ArrayList charPool; 51 | private ArrayList stringPool; 52 | 53 | /* Request attributes*/ 54 | private String cookies = ""; 55 | private String endpoint = ""; 56 | 57 | /* Standard output/error attributes*/ 58 | private PrintWriter stdOut; 59 | private PrintWriter stdErr; 60 | 61 | protected TaskSpecification(PrintWriter stdOut, PrintWriter stdErr) { 62 | this.stdOut = stdOut; 63 | this.stdErr = stdErr; 64 | libraries = new ArrayList(); 65 | signatures = new ArrayList(); 66 | proxyHost = ""; 67 | proxyPort = ""; 68 | vectors = new ArrayList(); 69 | vectors.add(""); //bogus value for generation only 70 | bytePool = new ArrayList(); 71 | shortPool = new ArrayList(); 72 | intPool = new ArrayList(); 73 | longPool = new ArrayList(); 74 | floatPool = new ArrayList(); 75 | doublePool = new ArrayList(); 76 | booleanPool = new ArrayList(); 77 | charPool = new ArrayList(); 78 | stringPool = new ArrayList(); 79 | this.status = STOPPED; 80 | } 81 | 82 | protected void setStatus(int status) { 83 | this.status = status; 84 | } 85 | 86 | protected int getStatus() { 87 | return status; 88 | } 89 | 90 | protected void setLibraries(final File resource) { 91 | if (!libraries.contains(resource)) { 92 | libraries.add(resource); 93 | 94 | if (resource.getName().endsWith(".jar")) { 95 | try { 96 | addSignatures(JavaUtil.retrieveSignaturesFromJAR(resource, signatures.size())); 97 | } catch (Exception ex) { 98 | stdErr.println("[!] Blazer TaskSpecification retrieveSignaturesFromJAR Exception: " + ex.toString().trim()); 99 | } 100 | } else if (resource.getName().endsWith(".class")) { 101 | try { 102 | addSignatures(JavaUtil.retrieveSignaturesFromClass(resource, signatures.size())); 103 | } catch (Exception ex) { 104 | stdErr.println("[!] Blazer TaskSpecification retrieveSignaturesFromClass Exception: " + ex.toString().trim());; 105 | } 106 | } else if (resource.getName().endsWith(".java")) { 107 | try { 108 | addSignatures(JavaUtil.retrieveSignaturesFromSrc(resource, signatures.size())); 109 | } catch (Exception ex) { 110 | stdErr.println("[!] Blazer TaskSpecification retrieveSignaturesFromSrc Exception: " + ex.toString().trim());; 111 | } 112 | } 113 | } 114 | } 115 | 116 | protected ArrayList getLibraries() { 117 | return libraries; 118 | } 119 | 120 | protected void resetLibraries() { 121 | libraries = new ArrayList(); 122 | } 123 | 124 | protected void resetSignatures() { 125 | signatures = new ArrayList(); 126 | } 127 | 128 | protected void resetVectors() { 129 | vectors = new ArrayList(); 130 | } 131 | 132 | protected void setSignatures(ArrayList signatures) { 133 | this.signatures = signatures; 134 | } 135 | 136 | protected void addSignatures(ArrayList signatures) { 137 | this.signatures.addAll(signatures); 138 | } 139 | 140 | protected ArrayList getSignatures() { 141 | return signatures; 142 | } 143 | 144 | protected void setThreads(int threads) { 145 | this.threads = threads; 146 | } 147 | 148 | protected int getThreads() { 149 | return threads; 150 | } 151 | 152 | protected void setPermutations(int permutations) { 153 | this.permutations = permutations; 154 | } 155 | 156 | protected int getPermutations() { 157 | return permutations; 158 | } 159 | 160 | protected void setProxyHost(String proxyHost) { 161 | this.proxyHost = proxyHost; 162 | } 163 | 164 | protected String getProxyHost() { 165 | return proxyHost; 166 | } 167 | 168 | protected void setProxyPort(String proxyPort) { 169 | this.proxyPort = proxyPort; 170 | } 171 | 172 | protected String getProxyPort() { 173 | return proxyPort; 174 | } 175 | 176 | protected void setCookies(String cookies) { 177 | this.cookies = cookies; 178 | } 179 | 180 | protected String getCookies() { 181 | return cookies; 182 | } 183 | 184 | protected void setEndpoint(String endpoint) { 185 | this.endpoint = endpoint; 186 | } 187 | 188 | protected String getEndpoint() { 189 | return endpoint; 190 | } 191 | 192 | protected void setVectorsLikehood(int vectorsLikelihood) { 193 | this.vectorsLikelihood = vectorsLikelihood; 194 | } 195 | 196 | protected float getVectorsLikehood() { 197 | return vectorsLikelihood; 198 | } 199 | 200 | protected void setVectors(ArrayList vectors) { 201 | this.vectors = vectors; 202 | } 203 | 204 | protected ArrayList getVectors() { 205 | return vectors; 206 | } 207 | 208 | protected void setFuzzing(boolean fuzzing) { 209 | this.fuzzing = fuzzing; 210 | } 211 | 212 | protected boolean doFuzzing() { 213 | return fuzzing; 214 | } 215 | 216 | protected void setBytePool(ArrayList bytePool) { 217 | this.bytePool = bytePool; 218 | } 219 | 220 | protected ArrayList getBytePool() { 221 | return bytePool; 222 | } 223 | 224 | protected void setShortPool(ArrayList shortPool) { 225 | this.shortPool = shortPool; 226 | } 227 | 228 | protected ArrayList getShortPool() { 229 | return shortPool; 230 | } 231 | 232 | protected void setIntPool(ArrayList intPool) { 233 | this.intPool = intPool; 234 | } 235 | 236 | protected ArrayList getIntPool() { 237 | return intPool; 238 | } 239 | 240 | protected void setLongPool(ArrayList longPool) { 241 | this.longPool = longPool; 242 | } 243 | 244 | protected ArrayList getLongPool() { 245 | return longPool; 246 | } 247 | 248 | protected void setFloatPool(ArrayList floatPool) { 249 | this.floatPool = floatPool; 250 | } 251 | 252 | protected ArrayList getFloatPool() { 253 | return floatPool; 254 | } 255 | 256 | protected void setDoublePool(ArrayList doublePool) { 257 | this.doublePool = doublePool; 258 | } 259 | 260 | protected ArrayList getDoublePool() { 261 | return doublePool; 262 | } 263 | 264 | protected void setBooleanPool(ArrayList booleanPool) { 265 | this.booleanPool = booleanPool; 266 | } 267 | 268 | protected ArrayList getBooleanPool() { 269 | return booleanPool; 270 | } 271 | 272 | protected void setCharPool(ArrayList charPool) { 273 | this.charPool = charPool; 274 | } 275 | 276 | protected ArrayList getCharPool() { 277 | return charPool; 278 | } 279 | 280 | protected void setStringPool(ArrayList stringPool) { 281 | this.stringPool = stringPool; 282 | } 283 | 284 | protected ArrayList getStringPool() { 285 | return stringPool; 286 | } 287 | } 288 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/TaskManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * TaskManager.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import burp.BurpExtender; 18 | import burp.IBurpExtenderCallbacks; 19 | import burp.IHttpRequestResponse; 20 | import java.beans.PropertyChangeSupport; 21 | import java.io.PrintWriter; 22 | import java.util.ArrayList; 23 | import java.util.Arrays; 24 | import java.util.Iterator; 25 | 26 | /* 27 | * This class is the core component of Blazer. 28 | * It creates and validates testing tasks. Also, it is responsible for starting 29 | * and monitoring task instances. 30 | */ 31 | public class TaskManager implements ThreadCompleteListener { 32 | 33 | private IBurpExtenderCallbacks burpCallbacks; 34 | private IHttpRequestResponse requestResponse; 35 | private IHttpRequestResponse[] itemsUserSelection; 36 | private TaskSpecification currentTask; 37 | private MessageTask[] threadsContainer; 38 | private int threadsTracker = 0; 39 | private static PropertyChangeSupport pcs; 40 | //Custom stdOut and stdErr used by PrintWriter 41 | private PrintWriter stdout; 42 | private PrintWriter stderr; 43 | 44 | /* Runtime metrics */ 45 | private static int requestsDone = 0; 46 | private long startTime = 0; 47 | 48 | public TaskManager(IBurpExtenderCallbacks burpCallbacks, IHttpRequestResponse[] requestResponse) throws Exception { 49 | 50 | Float majorVer = new Float(burpCallbacks.getBurpVersion()[1]); 51 | Float minorVer = new Float(0); 52 | if (burpCallbacks.getBurpVersion()[2] != null && !burpCallbacks.getBurpVersion()[2].isEmpty()) { 53 | minorVer = new Float(burpCallbacks.getBurpVersion()[2]); 54 | } 55 | 56 | //If running Burp Suite >= [Burp Suite Professional][1.5].[01], enable custom Stdout and Stderr 57 | if (majorVer >= 1.5 && minorVer >= 1.0) { 58 | //new registerExtenderCallbacks interface 59 | burpCallbacks.setExtensionName(BurpExtender.getBanner()); 60 | stdout = new PrintWriter(burpCallbacks.getStdout(), true); 61 | stderr = new PrintWriter(burpCallbacks.getStderr(), true); 62 | } else { 63 | //old registerExtenderCallbacks interface 64 | stdout = new PrintWriter(System.out, true); 65 | stderr = new PrintWriter(System.err, true); 66 | } 67 | 68 | this.burpCallbacks = burpCallbacks; 69 | this.itemsUserSelection = requestResponse; 70 | this.requestResponse = requestResponse[0]; //for generation/fuzzing, we use the first selected request to retrieve endpoint, cookies, ... 71 | 72 | pcs = new PropertyChangeSupport(this); 73 | 74 | currentTask = new TaskSpecification(this.getStdOut(), this.getStdErr()); 75 | String[] proxySettings = GenericUtil.burpProxySettings(burpCallbacks.saveConfig()).split(":"); 76 | currentTask.setProxyHost(proxySettings[0]); 77 | currentTask.setProxyPort(proxySettings[1]); 78 | currentTask.setCookies(GenericUtil.getCookies(this.requestResponse.getRequest())); 79 | currentTask.setEndpoint(this.burpCallbacks.getHelpers().analyzeRequest(this.requestResponse).getUrl().toString()); 80 | } 81 | 82 | public PrintWriter getStdOut() { 83 | return stdout; 84 | } 85 | 86 | public PrintWriter getStdErr() { 87 | return stderr; 88 | } 89 | 90 | public void issueAlert(String msg) { 91 | burpCallbacks.issueAlert(msg); 92 | } 93 | 94 | protected TaskSpecification getTask() { 95 | return currentTask; 96 | } 97 | 98 | protected PropertyChangeSupport getPropertyChangeSupport() { 99 | return pcs; 100 | } 101 | 102 | protected void startCurrentTask() throws InterruptedException { 103 | 104 | if (!currentTask.doFuzzing()) { 105 | burpCallbacks.issueAlert("[Blazer] Starting current task (generation only)"); 106 | } else { 107 | burpCallbacks.issueAlert("[Blazer] Starting current task (fuzzing)"); 108 | } 109 | currentTask.setStatus(TaskSpecification.STARTED); 110 | //Reset metrics 111 | startTime = System.currentTimeMillis(); 112 | requestsDone = 0; 113 | 114 | ArrayList listAttack = currentTask.getVectors(); 115 | ArrayList listSign = currentTask.getSignatures(); 116 | 117 | // Create the threads container with the minimum number of elements 118 | threadsContainer = new MessageTask[Math.min(currentTask.getThreads(), listAttack.size() * getSignaturesSelectedCounter())]; 119 | 120 | for (int aCont = 0; aCont < listAttack.size(); aCont++) { //For all attack vectors. Bogus value in case of a generation task. 121 | ObjectGenerator testCaseObj = null; 122 | if (!currentTask.doFuzzing()) { 123 | testCaseObj = new ObjectGenerator(currentTask, null, this.getStdOut(), this.getStdErr()); 124 | } else { 125 | testCaseObj = new ObjectGenerator(currentTask, (String) listAttack.get(aCont), this.getStdOut(), this.getStdErr()); 126 | } 127 | 128 | for (int sCont = 0; sCont < listSign.size(); sCont++) { // For all destinations/operations 129 | if (currentTask.getStatus() == TaskSpecification.STARTED) { 130 | Object[] row = (Object[]) listSign.get(sCont); 131 | Boolean row0 = (Boolean) row[0]; 132 | if (row0.booleanValue()) { // Choose selected signatures only 133 | if (threadsTracker < currentTask.getThreads()) { 134 | 135 | MessageGenerator mGen = new MessageGenerator(currentTask.getProxyHost(), currentTask.getProxyPort(), currentTask.getEndpoint(), currentTask.getCookies(), this.getStdOut(), this.getStdErr()); 136 | MessageSkeleton mSpec = new MessageSkeleton((String) row[3], (String) row[4], (String) row[5]); 137 | 138 | threadsContainer[threadsTracker] = new MessageTask(testCaseObj, currentTask.getPermutations(), mSpec, mGen); 139 | threadsContainer[threadsTracker].addListener(this); 140 | threadsContainer[threadsTracker].start(); 141 | threadsContainer[threadsTracker].setName(String.valueOf(threadsContainer[threadsTracker].getId())); 142 | threadsTracker++; 143 | } else { 144 | Thread.sleep(4000); 145 | sCont--; //no threads available, repeat the same item 146 | } 147 | } 148 | } 149 | } 150 | } 151 | } 152 | 153 | public void notifyOfThreadComplete(Thread thread) { 154 | //First, reorder the threads container 155 | thread.setName(String.valueOf(Long.MAX_VALUE)); 156 | Arrays.sort(threadsContainer); 157 | threadsTracker--; 158 | 159 | if (threadsTracker == 0 && requestsDone == getRequestsTot()) { 160 | //All thread finished 161 | currentTask.setStatus(TaskSpecification.STOPPED); 162 | pcs.firePropertyChange("taskStopped", null, null); 163 | } 164 | } 165 | 166 | protected void pauseCurrentTask() { 167 | burpCallbacks.issueAlert("[Blazer] Pausing current task"); 168 | currentTask.setStatus(TaskSpecification.PAUSED); 169 | 170 | for (int threadsCont = 0; threadsCont < threadsContainer.length; threadsCont++) { 171 | if (threadsContainer[threadsCont] != null) { 172 | synchronized (threadsContainer[threadsCont]) { 173 | threadsContainer[threadsCont].pauseThread(); 174 | } 175 | } 176 | } 177 | } 178 | 179 | protected void resumeCurrentTask() { 180 | burpCallbacks.issueAlert("[Blazer] Resuming current task"); 181 | currentTask.setStatus(TaskSpecification.STARTED); 182 | 183 | for (int threadsCont = 0; threadsCont < threadsContainer.length; threadsCont++) { 184 | if (threadsContainer[threadsCont] != null) { 185 | synchronized (threadsContainer[threadsCont]) { 186 | threadsContainer[threadsCont].resumeThread(); 187 | threadsContainer[threadsCont].notify(); 188 | } 189 | } 190 | } 191 | } 192 | 193 | protected void stopCurrentTask() { 194 | burpCallbacks.issueAlert("[Blazer] Stopping current task"); 195 | currentTask.setStatus(TaskSpecification.STOPPED); 196 | 197 | for (int threadsCont = 0; threadsCont < threadsContainer.length; threadsCont++) { 198 | if (threadsContainer[threadsCont] != null) { 199 | synchronized (threadsContainer[threadsCont]) { 200 | threadsContainer[threadsCont].stopThread(); 201 | } 202 | } 203 | } 204 | 205 | pcs.firePropertyChange("taskStopped", null, null); 206 | try { 207 | Thread.sleep(1000); 208 | } catch (InterruptedException ie) { 209 | this.getStdErr().println("[!] InterruptedException - Connection: " + ie.toString().trim()); 210 | } 211 | //reset all TaskManager variables 212 | threadsTracker = 0; 213 | requestsDone = 0; 214 | startTime = 0; 215 | } 216 | 217 | protected static void oneMoreDone() { 218 | requestsDone = requestsDone + 1; 219 | pcs.firePropertyChange("requestsDone", null, null); 220 | } 221 | 222 | protected int getRequestsDone() { 223 | return requestsDone; 224 | } 225 | 226 | protected int getRequestsTot() { 227 | if (currentTask.getVectors() != null) { 228 | return (currentTask.getVectors().size() * getSignaturesSelectedCounter() * currentTask.getPermutations()); 229 | }else{ 230 | return 0; 231 | } 232 | } 233 | 234 | protected float getAverageSpeed() { 235 | if (getOverallTime() > 2) { //wait first 2 seconds to a get better estimate 236 | return (getRequestsDone() / getOverallTime()); 237 | } 238 | return 0; 239 | } 240 | 241 | protected float getOverallTime() { 242 | float diffTime = System.currentTimeMillis() - startTime; 243 | return (diffTime / 1000); 244 | } 245 | 246 | protected float getTimeToFinish() { 247 | int diffReq = getRequestsTot() - getRequestsDone(); 248 | if (getAverageSpeed() != 0) { 249 | return (float) (diffReq / (Math.round(getAverageSpeed()) + 0.1)); 250 | } 251 | return 0; 252 | } 253 | 254 | protected boolean isReady() { 255 | 256 | if (!currentTask.getLibraries().isEmpty() && !currentTask.getSignatures().isEmpty() 257 | && !currentTask.getProxyHost().isEmpty() && !currentTask.getProxyPort().isEmpty() 258 | && currentTask.getThreads() >= 1 && currentTask.getPermutations() >= 1 259 | && currentTask.getVectorsLikehood() >= 1 && !currentTask.getVectors().isEmpty() 260 | && !currentTask.getBytePool().isEmpty() && !currentTask.getShortPool().isEmpty() 261 | && !currentTask.getIntPool().isEmpty() && !currentTask.getLongPool().isEmpty() 262 | && !currentTask.getFloatPool().isEmpty() && !currentTask.getDoublePool().isEmpty() 263 | && !currentTask.getBooleanPool().isEmpty() && !currentTask.getCharPool().isEmpty() 264 | && !currentTask.getStringPool().isEmpty() && !currentTask.getEndpoint().isEmpty()) { 265 | 266 | //At least a signature should be selected 267 | if (getSignaturesSelectedCounter() != 0) { 268 | return true; 269 | } else { 270 | return false; 271 | } 272 | } else { 273 | return false; 274 | } 275 | } 276 | 277 | protected int getSignaturesSelectedCounter() { 278 | int cont = 0; 279 | Iterator listSign = currentTask.getSignatures().iterator(); 280 | while (listSign.hasNext()) { 281 | Boolean row = (Boolean) ((Object[]) listSign.next())[0]; 282 | if (row.booleanValue()) { 283 | cont = cont + 1; 284 | } 285 | } 286 | return cont; 287 | } 288 | 289 | protected IHttpRequestResponse[] getItemsUserSelection() { 290 | return itemsUserSelection; 291 | } 292 | } 293 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/JavaUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * JavaUtil.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import com.github.javaparser.JavaParser; 18 | import com.github.javaparser.ast.CompilationUnit; 19 | import com.github.javaparser.ast.ImportDeclaration; 20 | import com.github.javaparser.ast.body.BodyDeclaration; 21 | import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration; 22 | import com.github.javaparser.ast.body.MethodDeclaration; 23 | import com.github.javaparser.ast.body.ModifierSet; 24 | import com.github.javaparser.ast.body.Parameter; 25 | import com.github.javaparser.ast.body.TypeDeclaration; 26 | import java.io.File; 27 | import java.io.FileInputStream; 28 | import java.io.FileNotFoundException; 29 | import java.io.IOException; 30 | import java.io.InputStream; 31 | import java.io.PrintWriter; 32 | import java.lang.reflect.Array; 33 | import java.lang.reflect.Field; 34 | import java.lang.reflect.InvocationTargetException; 35 | import java.lang.reflect.Method; 36 | import java.net.URL; 37 | import java.net.URLClassLoader; 38 | import java.util.ArrayList; 39 | import java.util.Enumeration; 40 | import java.util.HashMap; 41 | import java.util.Iterator; 42 | import java.util.List; 43 | import java.util.jar.JarEntry; 44 | import java.util.jar.JarFile; 45 | import org.objectweb.asm.ClassReader; 46 | import org.objectweb.asm.ClassVisitor; 47 | import org.objectweb.asm.Opcodes; 48 | import org.objectweb.asm.Type; 49 | import org.objectweb.asm.tree.AnnotationNode; 50 | import org.objectweb.asm.tree.ClassNode; 51 | import org.objectweb.asm.tree.MethodNode; 52 | 53 | /* 54 | * This class implements multiple Java auxiliary utils 55 | */ 56 | public class JavaUtil { 57 | 58 | /* 59 | * Signature reference {Boolean, Integer, String, String, String, String, String} 60 | * [0] Boolean (used for table selection) 61 | * [1] Integer - signature's ID 62 | * [2] String - type (interface or class) 63 | * [3] String - class name 64 | * [4] String - method name 65 | * [5] String - method parameters 66 | * [6] String - method annotations 67 | */ 68 | /* 69 | * Retrieve all public method signatures from a given Java file 70 | */ 71 | public static ArrayList retrieveSignaturesFromSrc(File srcFile) throws Exception { 72 | return JavaUtil.retrieveSignaturesFromSrc(srcFile, 0); 73 | } 74 | 75 | public static ArrayList retrieveSignaturesFromSrc(File srcFile, int signId) throws Exception { 76 | 77 | ArrayList signatures = new ArrayList(); 78 | Object[] signature = new Object[7]; 79 | int methoCnt = signId; 80 | 81 | signature[0] = new Boolean(false); //used for signature selection 82 | 83 | CompilationUnit cu; 84 | cu = JavaParser.parse(srcFile); 85 | 86 | //Populate lookup table for classes/packages 87 | HashMap hmPck = new HashMap(); 88 | //Primite types 89 | hmPck.put("byte", "byte"); 90 | hmPck.put("short", "short"); 91 | hmPck.put("int", "int"); 92 | hmPck.put("long", "long"); 93 | hmPck.put("float", "float"); 94 | hmPck.put("double", "double"); 95 | hmPck.put("boolean", "boolean"); 96 | hmPck.put("char", "char"); 97 | hmPck.put("String", "java.lang.String"); 98 | hmPck.put("Boolean", "java.lang.Boolean"); 99 | hmPck.put("Integer", "java.lang.Integer"); 100 | hmPck.put("Byte", "java.lang.Byte"); 101 | hmPck.put("Short", "java.lang.Short"); 102 | hmPck.put("Long", "java.lang.Long"); 103 | hmPck.put("Float", "java.lang.Float"); 104 | hmPck.put("Double", "java.lang.Double"); 105 | hmPck.put("Character", "java.lang.Character"); 106 | hmPck.put("byte[]", "byte[]"); 107 | hmPck.put("short[]", "short[]"); 108 | hmPck.put("int[]", "int[]"); 109 | hmPck.put("long[]", "long[]"); 110 | hmPck.put("float[]", "float[]"); 111 | hmPck.put("double[]", "double[]"); 112 | hmPck.put("boolean[]", "boolean[]"); 113 | hmPck.put("char[]", "char[]"); 114 | hmPck.put("String[]", "java.lang.String[]"); 115 | hmPck.put("Boolean[]", "java.lang.Boolean[]"); 116 | hmPck.put("Integer[]", "java.lang.Integer[]"); 117 | hmPck.put("Byte[]", "java.lang.Byte[]"); 118 | hmPck.put("Short[]", "java.lang.Short[]"); 119 | hmPck.put("Long[]", "java.lang.Long[]"); 120 | hmPck.put("Float[]", "java.lang.Float[]"); 121 | hmPck.put("Double[]", "java.lang.Double[]"); 122 | hmPck.put("Character[]", "java.lang.Character[]"); 123 | //Declared imports 124 | List imports = cu.getImports(); 125 | if (imports != null && !imports.isEmpty()) { 126 | for (ImportDeclaration imp : imports) { 127 | hmPck.put(imp.getName().getName(), imp.getName().toString()); 128 | } 129 | } 130 | 131 | List types = cu.getTypes(); 132 | for (TypeDeclaration type : types) { 133 | if (type instanceof ClassOrInterfaceDeclaration) { 134 | //We are either in a class or in an interface 135 | ClassOrInterfaceDeclaration classDec = (ClassOrInterfaceDeclaration) type; 136 | if (classDec.getModifiers() == ModifierSet.PUBLIC) { 137 | //The class or interface is public 138 | if (classDec.isInterface()) { 139 | signature[2] = "Interface"; //interface 140 | } else { 141 | signature[2] = "Class"; //class 142 | } 143 | //convert to javaCase 144 | signature[3] = classDec.getName().substring(0, 1).toLowerCase() + classDec.getName().substring(1); 145 | } 146 | 147 | List members = type.getMembers(); 148 | for (BodyDeclaration member : members) { 149 | if (member instanceof MethodDeclaration) { 150 | //We are in a method 151 | MethodDeclaration methoDec = (MethodDeclaration) member; 152 | if (methoDec.getModifiers() == ModifierSet.PUBLIC) { 153 | //the method is public 154 | signature[1] = new Integer(methoCnt); 155 | methoCnt++; //increment the signature's ID 156 | signature[4] = methoDec.getName(); 157 | 158 | //retrieve method's pars 159 | List pars = methoDec.getParameters(); 160 | if (pars != null) { 161 | StringBuilder parsStr = new StringBuilder(); 162 | 163 | for (int i = 0; i < pars.size(); i++) { 164 | if (i > 0) { 165 | parsStr.append(", "); 166 | } 167 | Parameter sPar = (Parameter) pars.get(i); 168 | 169 | String sParCleaned = sPar.getType().toString(); 170 | //remove Java generics definition, if present 171 | if (sPar.getType().toString().contains("<")) { 172 | sParCleaned = sParCleaned.substring(0, sParCleaned.indexOf("<")); 173 | } 174 | //before appending the parameter type, retrieve the package-class name from our lookup table 175 | if (hmPck.containsKey(sParCleaned)) { 176 | parsStr.append(hmPck.get(sParCleaned)); 177 | } else { 178 | parsStr.append("NotFound"); //this prevents null values 179 | } 180 | } 181 | signature[5] = parsStr.toString(); 182 | } else { 183 | //method with no parameter 184 | signature[5] = ""; 185 | } 186 | 187 | //retrieve method's annotations 188 | List anns = methoDec.getAnnotations(); 189 | 190 | if (anns != null) { 191 | StringBuilder annStr = new StringBuilder(); 192 | 193 | for (int i = 0; i < anns.size(); i++) { 194 | if (i > 0) { 195 | annStr.append(", "); 196 | } 197 | annStr.append(anns.get(i)); 198 | } 199 | 200 | signature[6] = annStr.toString(); 201 | } else { 202 | //method with no annotations 203 | signature[6] = ""; 204 | } 205 | 206 | //add signature[] to master signatures[] 207 | signatures.add(signature.clone()); 208 | signature[4] = ""; 209 | signature[5] = ""; 210 | signature[6] = ""; 211 | } 212 | } 213 | } 214 | } else { 215 | //bogus signature, no classes found - this is just to prevent GUI crashes 216 | signature[1] = new Integer(methoCnt); 217 | signature[2] = ""; 218 | signature[3] = ""; 219 | signature[4] = ""; 220 | signature[5] = ""; 221 | signature[6] = ""; 222 | } 223 | } 224 | return signatures; 225 | } 226 | 227 | /* 228 | * Retrieve full class name, including package with dot notation 229 | */ 230 | public static String retrieveCanonicalNameFromClass(File classFile) throws FileNotFoundException, IOException { 231 | 232 | ClassNode classNode = new ClassNode(); 233 | InputStream classFileInputStream = new FileInputStream(classFile); 234 | try { 235 | ClassReader classReader = new ClassReader(classFileInputStream); 236 | classReader.accept((ClassVisitor) classNode, 0); 237 | } finally { 238 | classFileInputStream.close(); 239 | } 240 | 241 | Type classType = Type.getObjectType(classNode.name); 242 | return classType.getClassName(); 243 | } 244 | 245 | 246 | /* 247 | * Retrieve all public method signatures from a given Class file 248 | */ 249 | public static ArrayList retrieveSignaturesFromClass(File classFile) throws Exception { 250 | return JavaUtil.retrieveSignaturesFromClass(new FileInputStream(classFile), 0); 251 | } 252 | 253 | public static ArrayList retrieveSignaturesFromClass(InputStream classFileIS) throws Exception { 254 | return JavaUtil.retrieveSignaturesFromClass(classFileIS, 0); 255 | } 256 | 257 | public static ArrayList retrieveSignaturesFromClass(File classFile, int signId) throws Exception { 258 | return retrieveSignaturesFromClass(new FileInputStream(classFile), signId); 259 | } 260 | 261 | public static ArrayList retrieveSignaturesFromClass(InputStream classFileIS, int signId) throws Exception { 262 | 263 | /* 264 | * Dynamic array containing multiple signatures arrays 265 | */ 266 | ArrayList signatures = new ArrayList(); 267 | 268 | Object[] signature = new Object[7]; 269 | signature[0] = new Boolean(false); //used for signature selection 270 | 271 | ClassNode classNode = new ClassNode(); 272 | InputStream classFileInputStream = classFileIS; 273 | try { 274 | ClassReader classReader = new ClassReader(classFileInputStream); 275 | classReader.accept((ClassVisitor) classNode, 0); 276 | } finally { 277 | classFileInputStream.close(); 278 | } 279 | 280 | Type classType = Type.getObjectType(classNode.name); 281 | 282 | if ((classNode.access & Opcodes.ACC_PUBLIC) != 0) { 283 | 284 | if ((classNode.access & Opcodes.ACC_INTERFACE) != 0) { 285 | signature[2] = "Interface"; //interface 286 | } else { 287 | signature[2] = "Class"; //class 288 | } 289 | 290 | String name = classType.getClassName(); 291 | name = name.substring(name.lastIndexOf('.') + 1); //packages are not required 292 | signature[3] = name.substring(0, 1).toLowerCase() + name.substring(1); //convert to javaCase 293 | @SuppressWarnings("unchecked") 294 | List methodNodes = classNode.methods; 295 | 296 | for (MethodNode methodNode : methodNodes) { 297 | 298 | Type[] argumentTypes = Type.getArgumentTypes(methodNode.desc); 299 | 300 | if ((methodNode.access & Opcodes.ACC_PUBLIC) != 0) { 301 | 302 | signature[4] = methodNode.name; 303 | 304 | if (methodNode.visibleAnnotations != null) { 305 | 306 | Iterator c = methodNode.visibleAnnotations.iterator(); 307 | while (c.hasNext()) { 308 | AnnotationNode anode = (AnnotationNode) c.next(); 309 | String annotations = anode.desc; 310 | annotations = annotations.substring(annotations.lastIndexOf('/') + 1, annotations.lastIndexOf(';')); 311 | signature[6] = "@".concat(annotations); //convert to standard format 312 | } 313 | } 314 | 315 | StringBuilder pars = new StringBuilder(); 316 | 317 | for (int i = 0; i < argumentTypes.length; i++) { 318 | 319 | Type argumentType = argumentTypes[i]; 320 | if (i > 0) { 321 | pars.append(", "); 322 | } 323 | pars.append(argumentType.getClassName()); 324 | } 325 | 326 | signature[5] = pars.toString(); 327 | 328 | /* list here all exceptions */ 329 | if (!signature[4].equals("")) { 330 | signature[1] = new Integer(signId); 331 | signatures.add(signature.clone()); 332 | signId++; 333 | } 334 | signature[5] = ""; 335 | } 336 | signature[4] = ""; 337 | signature[6] = ""; 338 | } 339 | } 340 | return signatures; 341 | } 342 | 343 | /* 344 | * Retrieve all public method signatures from a given JAR 345 | */ 346 | public static ArrayList retrieveSignaturesFromJAR(File jarFile) throws Exception { 347 | return JavaUtil.retrieveSignaturesFromJAR(jarFile, 0); 348 | } 349 | 350 | public static ArrayList retrieveSignaturesFromJAR(File jarFile, int signId) throws Exception { 351 | 352 | /* 353 | * Dynamic array containing multiple signatures arrays 354 | */ 355 | ArrayList signaturesGl = new ArrayList(); 356 | int signIdGlobal = signId; 357 | 358 | JarFile myJar = new JarFile(jarFile); 359 | 360 | Enumeration entries = myJar.entries(); 361 | while (entries.hasMoreElements()) { 362 | 363 | JarEntry entry = entries.nextElement(); 364 | String entryName = entry.getName(); 365 | 366 | if (entryName.endsWith(".class")) { 367 | ArrayList res = retrieveSignaturesFromClass(myJar.getInputStream(entry), signIdGlobal); 368 | signaturesGl.addAll(res); 369 | signIdGlobal = signIdGlobal + res.size(); 370 | } 371 | } 372 | return signaturesGl; 373 | } 374 | 375 | 376 | /* 377 | * Recursively traverse a directory looking for .jar/.class/.java files 378 | */ 379 | public static void findAllLibs(File root, List toBuildUp) { 380 | 381 | if (!root.isDirectory() && (root.getName().endsWith(".java") || root.getName().endsWith(".jar") || root.getName().endsWith(".class"))) { 382 | toBuildUp.add(root); 383 | } else if (root.isDirectory()) { 384 | for (File f : root.listFiles()) { 385 | findAllLibs(f, toBuildUp); 386 | } 387 | } else { 388 | return; 389 | } 390 | } 391 | 392 | /* 393 | * Include custom resources into the SystemClassLoader at runtime 394 | * Hack: this code is probably unreliable and may not work on all JVMs 395 | */ 396 | public static void addURLs(URL[] urls, PrintWriter stdOut, PrintWriter stdErr) throws NoSuchMethodException, IllegalAccessException, IllegalArgumentException, InvocationTargetException { 397 | ClassLoader cl = ClassLoader.getSystemClassLoader(); 398 | if (cl instanceof URLClassLoader) { 399 | URLClassLoader ul = (URLClassLoader) cl; 400 | Class[] paraTypes = new Class[1]; 401 | paraTypes[0] = URL.class; 402 | Method method = URLClassLoader.class.getDeclaredMethod("addURL", paraTypes); 403 | method.setAccessible(true); 404 | Object[] args = new Object[1]; 405 | for (int i = 0; i < urls.length; i++) { 406 | args[0] = urls[i]; 407 | method.invoke(ul, args); 408 | } 409 | } else { 410 | stdErr.println("[!] \"SystemClassLoader\" is not instance of \"URLClassLoader\""); 411 | stdErr.println("[!] Some functionalities may not work as expected (e.g. Export AMF2XML)"); 412 | } 413 | } 414 | } 415 | -------------------------------------------------------------------------------- /src/com/mtso/blazer/ObjectGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * ObjectGenerator.java 3 | * 4 | * Copyright (c) 2012 Luca Carettoni 5 | * 6 | * This file is part of Blazer, a Burp extension to perform gray-box AMF Testing. 7 | * 8 | * This program is free software: you can redistribute it and/or modify 9 | * it under the terms of the GNU General Public License as published by 10 | * the Free Software Foundation, either version 3 of the License, or 11 | * (at your option) any later version. This program is distributed in the 12 | * hope that it will be useful, but WITHOUT ANY WARRANTY. 13 | * 14 | */ 15 | package com.mtso.blazer; 16 | 17 | import java.io.File; 18 | import java.io.IOException; 19 | import java.io.PrintWriter; 20 | import java.lang.reflect.Constructor; 21 | import java.lang.reflect.InvocationTargetException; 22 | import java.lang.reflect.Method; 23 | import java.net.MalformedURLException; 24 | import java.net.URL; 25 | import java.net.URLClassLoader; 26 | import java.security.SecureRandom; 27 | import java.util.ArrayList; 28 | import java.util.Arrays; 29 | import java.util.Collections; 30 | import java.util.Random; 31 | import java.util.regex.Pattern; 32 | 33 | /* 34 | * This class generates Java Objects from signatures 35 | */ 36 | public class ObjectGenerator { 37 | 38 | private TaskSpecification task = null; 39 | private Object artifact = null; 40 | private SecureRandom rnd = null; 41 | private ArrayList pool = null; 42 | private PrintWriter stdOut; 43 | private PrintWriter stdErr; 44 | private URLClassLoader ucl = null; 45 | 46 | /* 47 | * Construct an object generator given a specific task, containing attack vectors and likelihood factor. 48 | * 49 | * In case of generation tasks, the 'vectors' ArrayList should be empty. The 'vectorLikelihood' is the 50 | * percentuage of attack vectors in the String pool, used to unbalance the selection of samples 51 | */ 52 | protected ObjectGenerator(TaskSpecification task, String attackVector, PrintWriter stdOut, PrintWriter stdErr) { 53 | 54 | this.stdOut = stdOut; 55 | this.stdErr = stdErr; 56 | this.task = task; 57 | rnd = new SecureRandom(); 58 | pool = (ArrayList) task.getStringPool().clone(); 59 | 60 | 61 | if (!task.doFuzzing()) { 62 | //Generation only - do nothing 63 | } else { 64 | //Fuzzing - unbalance the String pool adding % attack vectors 65 | float poolSize = pool.size(); 66 | int addCounter = StrictMath.abs(StrictMath.round(((poolSize / ((100 - task.getVectorsLikehood()) / 100)) - poolSize))); 67 | for (int i = 0; i < addCounter; i++) { 68 | pool.add(attackVector); 69 | } 70 | } 71 | 72 | try { 73 | //Load application libraries at runtime 74 | Object[] applicationLibs = task.getLibraries().toArray(); 75 | URL[] classUrls = new URL[applicationLibs.length]; 76 | for (int lCont = 0; lCont < applicationLibs.length; lCont++) { 77 | String absoluteVodka = ((File) applicationLibs[lCont]).getCanonicalPath(); 78 | if (absoluteVodka.endsWith(".jar")) { 79 | classUrls[lCont] = (new File(absoluteVodka)).toURI().toURL(); //loading JARs 80 | } else if (absoluteVodka.endsWith(".class")) { 81 | String classPathName = JavaUtil.retrieveCanonicalNameFromClass(((File) applicationLibs[lCont])); 82 | if (File.separator.equalsIgnoreCase("/")) { 83 | classPathName = classPathName.replaceAll("\\.", "/") + ".class"; 84 | } else { 85 | classPathName = classPathName.replaceAll("\\.", "\\\\") + ".class"; 86 | } 87 | absoluteVodka = absoluteVodka.replaceAll(Pattern.quote(classPathName), ""); 88 | classUrls[lCont] = (new File(absoluteVodka)).toURI().toURL(); //loading top directory containing selected classes 89 | } 90 | } 91 | 92 | ClassLoader cl = ClassLoader.getSystemClassLoader(); 93 | if (cl instanceof URLClassLoader) { 94 | JavaUtil.addURLs(classUrls, stdOut, stdErr); 95 | ucl = (URLClassLoader) cl; 96 | } else { 97 | stdErr.println("[!] \"SystemClassLoader\" is not instance of \"URLClassLoader\""); 98 | stdErr.println("[!] BlazerSecurityManager won't work..."); 99 | ucl = new URLClassLoader(classUrls); 100 | } 101 | } catch (MalformedURLException ex) { 102 | stdErr.println("[!] ObjectGenerator MalformedURLException: " + ex.toString().trim()); 103 | } catch (NoSuchMethodException ex) { 104 | stdErr.println("[!] ObjectGenerator NoSuchMethodException: " + ex.toString().trim()); 105 | } catch (IllegalArgumentException ex) { 106 | stdErr.println("[!] ObjectGenerator IllegalArgumentException: " + ex.toString().trim()); 107 | } catch (IllegalAccessException ex) { 108 | stdErr.println("[!] ObjectGenerator IllegalAccessException: " + ex.toString().trim()); 109 | } catch (InvocationTargetException ex) { 110 | stdErr.println("[!] ObjectGenerator InvocationTargetException: " + ex.toString().trim()); 111 | } catch (IOException ex) { 112 | stdErr.println("[!] ObjectGenerator IOException: " + ex.toString().trim()); 113 | } 114 | } 115 | 116 | protected Object generate(String signature) { 117 | 118 | artifact = null; 119 | Random methodRnd = new Random(); 120 | 121 | if (signature.equals("boolean")) { 122 | artifact = task.getBooleanPool().get(rnd.nextInt(task.getBooleanPool().size())); 123 | } else if (signature.equals("boolean[]")) { 124 | boolean[] atemp = new boolean[rnd.nextInt(10)]; 125 | for (int i = 0; i < atemp.length; i++) { 126 | atemp[i] = ((Boolean) task.getBooleanPool().get(rnd.nextInt(task.getBooleanPool().size()))).booleanValue(); 127 | } 128 | artifact = atemp; 129 | } else if (signature.equals("java.lang.Boolean")) { 130 | artifact = (Boolean) task.getBooleanPool().get(rnd.nextInt(task.getBooleanPool().size())); 131 | } else if (signature.equals("java.lang.Boolean[]")) { 132 | Boolean[] atemp = new Boolean[rnd.nextInt(10)]; 133 | for (int i = 0; i < atemp.length; i++) { 134 | atemp[i] = (Boolean) task.getBooleanPool().get(rnd.nextInt(task.getBooleanPool().size())); 135 | } 136 | artifact = atemp; 137 | } else if (signature.equals("int")) { 138 | artifact = task.getIntPool().get(rnd.nextInt(task.getIntPool().size())); 139 | } else if (signature.equals("int[]")) { 140 | int[] atemp = new int[rnd.nextInt(10)]; 141 | for (int i = 0; i < atemp.length; i++) { 142 | atemp[i] = ((Integer) task.getIntPool().get(rnd.nextInt(task.getIntPool().size()))).intValue(); 143 | } 144 | artifact = atemp; 145 | } else if (signature.equals("java.lang.Integer")) { 146 | artifact = (Integer) task.getIntPool().get(rnd.nextInt(task.getIntPool().size())); 147 | } else if (signature.equals("java.lang.Integer[]")) { 148 | Integer[] atemp = new Integer[rnd.nextInt(10)]; 149 | for (int i = 0; i < atemp.length; i++) { 150 | atemp[i] = (Integer) task.getIntPool().get(rnd.nextInt(task.getIntPool().size())); 151 | } 152 | artifact = atemp; 153 | } else if (signature.equalsIgnoreCase("java.lang.String") || (signature.equalsIgnoreCase("java.lang.Object"))) { //In case of Object, handle as String 154 | artifact = pool.get(rnd.nextInt(pool.size())); 155 | } else if (signature.equalsIgnoreCase("java.lang.String[]") || (signature.equalsIgnoreCase("java.lang.Object[]"))) { //In case of Object, handle as String 156 | String[] atemp = new String[rnd.nextInt(10)]; 157 | for (int i = 0; i < atemp.length; i++) { 158 | atemp[i] = (String) pool.get(rnd.nextInt(pool.size())); 159 | } 160 | artifact = atemp; 161 | } else if (signature.equals("byte")) { 162 | artifact = task.getBytePool().get(rnd.nextInt(task.getBytePool().size())); 163 | } else if (signature.equals("byte[]")) { 164 | byte[] atemp = new byte[rnd.nextInt(10)]; 165 | for (int i = 0; i < atemp.length; i++) { 166 | atemp[i] = ((Byte) task.getBytePool().get(rnd.nextInt(task.getBytePool().size()))).byteValue(); 167 | } 168 | artifact = atemp; 169 | } else if (signature.equals("java.lang.Byte")) { 170 | artifact = (Byte) task.getBytePool().get(rnd.nextInt(task.getBytePool().size())); 171 | } else if (signature.equals("java.lang.Byte[]")) { 172 | Byte[] atemp = new Byte[rnd.nextInt(10)]; 173 | for (int i = 0; i < atemp.length; i++) { 174 | atemp[i] = (Byte) task.getBytePool().get(rnd.nextInt(task.getBytePool().size())); 175 | } 176 | artifact = atemp; 177 | } else if (signature.equals("short")) { 178 | artifact = task.getShortPool().get(rnd.nextInt(task.getShortPool().size())); 179 | } else if (signature.equals("short[]")) { 180 | short[] atemp = new short[rnd.nextInt(10)]; 181 | for (int i = 0; i < atemp.length; i++) { 182 | atemp[i] = ((Short) task.getShortPool().get(rnd.nextInt(task.getShortPool().size()))).shortValue(); 183 | } 184 | artifact = atemp; 185 | } else if (signature.equals("java.lang.Short")) { 186 | artifact = (Short) task.getShortPool().get(rnd.nextInt(task.getShortPool().size())); 187 | } else if (signature.equals("java.lang.Short[]")) { 188 | Short[] atemp = new Short[rnd.nextInt(10)]; 189 | for (int i = 0; i < atemp.length; i++) { 190 | atemp[i] = (Short) task.getShortPool().get(rnd.nextInt(task.getShortPool().size())); 191 | } 192 | artifact = atemp; 193 | } else if (signature.equals("long")) { 194 | artifact = task.getLongPool().get(rnd.nextInt(task.getLongPool().size())); 195 | } else if (signature.equals("long[]")) { 196 | long[] atemp = new long[rnd.nextInt(10)]; 197 | for (int i = 0; i < atemp.length; i++) { 198 | atemp[i] = ((Long) task.getLongPool().get(rnd.nextInt(task.getLongPool().size()))).longValue(); 199 | } 200 | artifact = atemp; 201 | } else if (signature.equals("java.lang.Long")) { 202 | artifact = (Long) task.getLongPool().get(rnd.nextInt(task.getLongPool().size())); 203 | } else if (signature.equals("java.lang.Long[]")) { 204 | Long[] atemp = new Long[rnd.nextInt(10)]; 205 | for (int i = 0; i < atemp.length; i++) { 206 | atemp[i] = (Long) task.getLongPool().get(rnd.nextInt(task.getLongPool().size())); 207 | } 208 | artifact = atemp; 209 | } else if (signature.equals("float")) { 210 | artifact = task.getFloatPool().get(rnd.nextInt(task.getFloatPool().size())); 211 | } else if (signature.equals("float[]")) { 212 | float[] atemp = new float[rnd.nextInt(10)]; 213 | for (int i = 0; i < atemp.length; i++) { 214 | atemp[i] = ((Float) task.getFloatPool().get(rnd.nextInt(task.getFloatPool().size()))).floatValue(); 215 | } 216 | artifact = atemp; 217 | } else if (signature.equals("java.lang.Float")) { 218 | artifact = (Float) task.getFloatPool().get(rnd.nextInt(task.getFloatPool().size())); 219 | } else if (signature.equals("java.lang.Float[]")) { 220 | Float[] atemp = new Float[rnd.nextInt(10)]; 221 | for (int i = 0; i < atemp.length; i++) { 222 | atemp[i] = (Float) task.getFloatPool().get(rnd.nextInt(task.getFloatPool().size())); 223 | } 224 | artifact = atemp; 225 | } else if (signature.equals("double")) { 226 | artifact = task.getDoublePool().get(rnd.nextInt(task.getDoublePool().size())); 227 | } else if (signature.equals("double[]")) { 228 | double[] atemp = new double[rnd.nextInt(10)]; 229 | for (int i = 0; i < atemp.length; i++) { 230 | atemp[i] = ((Double) task.getDoublePool().get(rnd.nextInt(task.getDoublePool().size()))).doubleValue(); 231 | } 232 | artifact = atemp; 233 | } else if (signature.equals("java.lang.Double")) { 234 | artifact = (Double) task.getDoublePool().get(rnd.nextInt(task.getDoublePool().size())); 235 | } else if (signature.equals("java.lang.Double[]")) { 236 | Double[] atemp = new Double[rnd.nextInt(10)]; 237 | for (int i = 0; i < atemp.length; i++) { 238 | atemp[i] = (Double) task.getDoublePool().get(rnd.nextInt(task.getDoublePool().size())); 239 | } 240 | artifact = atemp; 241 | } else if (signature.equals("char")) { 242 | artifact = task.getCharPool().get(rnd.nextInt(task.getCharPool().size())); 243 | } else if (signature.equals("char[]")) { 244 | char[] atemp = new char[rnd.nextInt(10)]; 245 | for (int i = 0; i < atemp.length; i++) { 246 | atemp[i] = ((Character) task.getCharPool().get(rnd.nextInt(task.getCharPool().size()))).charValue(); 247 | } 248 | artifact = atemp; 249 | } else if (signature.equals("java.lang.Character")) { 250 | artifact = (Character) task.getCharPool().get(rnd.nextInt(task.getCharPool().size())); 251 | } else if (signature.equals("java.lang.Character[]")) { 252 | Character[] atemp = new Character[rnd.nextInt(10)]; 253 | for (int i = 0; i < atemp.length; i++) { 254 | atemp[i] = (Character) task.getCharPool().get(rnd.nextInt(task.getCharPool().size())); 255 | } 256 | artifact = atemp; 257 | } else if (signature.equalsIgnoreCase("java.lang.Class") 258 | || signature.equalsIgnoreCase("java.lang.Class[]") 259 | || signature.equalsIgnoreCase("") 260 | || signature.isEmpty()) { 261 | artifact = null; //avoid endless loop 262 | } else { 263 | /* Build a custom Object using reflection */ 264 | Class fc = null; 265 | Object newObj = null; 266 | 267 | try { 268 | fc = (Class) ucl.loadClass(signature); //use our custom classloader, containing application libraries 269 | 270 | if (!fc.isInterface() && !fc.isEnum() && !fc.isAnnotation()) { //avoid interfaces 271 | //create an instance of the Object using one of the declared constructor 272 | Constructor cc[] = (fc.getConstructors()); 273 | Collections.shuffle(Arrays.asList(cc)); //fuzzing's magic sauce 274 | building: 275 | for (int cCont = 0; cCont < cc.length; cCont++) { 276 | cc[cCont].setAccessible(true); 277 | Class pcc[] = cc[cCont].getParameterTypes(); 278 | if (pcc.length == 0 || pcc == null) { 279 | //Default constructor with no arguments 280 | newObj = cc[cCont].newInstance(); 281 | break building; 282 | } else { 283 | //Iterate through all arguments for this constructor 284 | Object[] parsInstance = new Object[pcc.length]; 285 | for (int pCont = 0; pCont < pcc.length; pCont++) { 286 | String newSign = pcc[pCont].getCanonicalName(); 287 | if (!newSign.equalsIgnoreCase(signature)) { //Recursion watchdog 288 | parsInstance[pCont] = generate(newSign); 289 | } 290 | } 291 | newObj = cc[cCont].newInstance(parsInstance); 292 | break building; 293 | } 294 | } 295 | //At this point, we need to populate all attributes of an Object 296 | if (newObj != null) { 297 | Method mc[] = fc.getDeclaredMethods(); 298 | Collections.shuffle(Arrays.asList(mc)); //fuzzing's magic sauce 299 | //For all methods 300 | for (int mCont = 0; mCont < mc.length; mCont++) { 301 | //Do not invoke all methods for a specific class 302 | //Soon or later, multiple iterations and randomness should help to build a valid object as required by the remote method 303 | if (methodRnd.nextBoolean()) { 304 | mc[mCont].setAccessible(true); 305 | //For all parameters 306 | Class pvec[] = mc[mCont].getParameterTypes(); 307 | Object[] parsInstance = null; 308 | //Invoke methods (setters) having at least one argument 309 | if (pvec.length > 0) { 310 | parsInstance = new Object[pvec.length]; 311 | for (int pCont = 0; pCont < pvec.length; pCont++) { 312 | String newSign = pvec[pCont].getCanonicalName(); 313 | if (!newSign.equalsIgnoreCase(signature)) { //Recursion watchdog 314 | parsInstance[pCont] = generate(newSign); 315 | } 316 | } 317 | mc[mCont].invoke(newObj, parsInstance); 318 | } 319 | } 320 | } 321 | } 322 | artifact = newObj; 323 | } 324 | } catch (InvocationTargetException ex) { 325 | stdErr.println("[!] InvocationTargetException: " + ex.toString().trim()); 326 | stdErr.println("[!] Using the object built so far..."); 327 | artifact = newObj; 328 | } catch (InstantiationException ex) { 329 | stdErr.println("[!] InstantiationException: " + ex.toString().trim()); 330 | } catch (ClassNotFoundException ex) { 331 | stdErr.println("[!] ClassNotFoundException: " + ex.toString().trim()); 332 | stdErr.println("[!] --> Make sure that you have imported all libraries"); 333 | } catch (IllegalAccessException ex) { 334 | stdErr.println("[!] IllegalAccessException: " + ex.toString().trim()); 335 | } catch (IllegalArgumentException ex) { 336 | stdErr.println("[!] IllegalArgumentException: " + ex.toString().trim()); 337 | } catch (Exception ex) { 338 | stdErr.println("[!] General Exception: " + ex.toString().trim()); 339 | stdErr.println("[!] --> Make sure that you have imported all libraries"); 340 | } 341 | } 342 | return artifact; 343 | } 344 | } 345 | -------------------------------------------------------------------------------- /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 | {one line to give the program's name and a brief idea of what it does.} 635 | Copyright (C) {year} {name of author} 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 | {project} Copyright (C) {year} {fullname} 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 | . --------------------------------------------------------------------------------