diff --git a/NonHTTPProxy/src/josh/nonHttp/PythonMangler.java b/NonHTTPProxy/src/josh/nonHttp/PythonMangler.java index 37b29cf..64e6d7a 100644 --- a/NonHTTPProxy/src/josh/nonHttp/PythonMangler.java +++ b/NonHTTPProxy/src/josh/nonHttp/PythonMangler.java @@ -16,6 +16,7 @@ import java.util.List; import java.util.Properties; + import org.python.core.PyBoolean; import org.python.core.PyByteArray; import org.python.core.PyObject; @@ -25,6 +26,7 @@ import josh.utils.events.PythonOutputEvent; import josh.utils.events.PythonOutputEventListener; + public class PythonMangler { private String pyCode; private PythonInterpreter interpreter; @@ -168,7 +170,30 @@ public String setPyCode(String code){ return this.pyCode; } - public byte [] preIntercept(byte [] input, boolean isC2S){ + public byte [] formatOnly(byte [] input, boolean isC2S){ + + byte[]original = input; + try{ + PyObject someFunc = interpreter.get("formatOnly"); + + //this means that the pre Intercept feature has not been implemented. + if(someFunc == null) + return input; + PyObject result = someFunc.__call__(new PyByteArray(input), new PyBoolean(isC2S)); + PyByteArray array = (PyByteArray) result.__tojava__(Object.class); + + byte[] out = new byte [array.__len__()]; + for(int i=0; i < array.__len__(); i++){ + out[i] = (byte)array.get(i).__tojava__(Byte.class); + } + + return out; + }catch(Exception ex){ + System.out.println(ex); + return original; + } + } + public byte [] preIntercept(byte [] input, boolean isC2S){ byte[]original = input; try{ @@ -187,7 +212,7 @@ public String setPyCode(String code){ return out; }catch(Exception ex){ - ex.printStackTrace(); + System.out.println(ex); return original; } } @@ -208,7 +233,7 @@ public String setPyCode(String code){ } return out; }catch(Exception ex){ - ex.printStackTrace(); + System.out.println(ex); return original; } diff --git a/NonHTTPProxy/src/josh/nonHttp/SendData.java b/NonHTTPProxy/src/josh/nonHttp/SendData.java index 8018da5..1288877 100755 --- a/NonHTTPProxy/src/josh/nonHttp/SendData.java +++ b/NonHTTPProxy/src/josh/nonHttp/SendData.java @@ -27,6 +27,7 @@ import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLSocket; + import org.xbill.DNS.A6Record; import josh.nonHttp.events.ProxyEvent; @@ -37,6 +38,7 @@ import josh.utils.events.SendClosedEvent; import josh.utils.events.SendClosedEventListener; + public class SendData implements Runnable { public InputStream in; public DataOutputStream out; @@ -273,10 +275,13 @@ public void run() { tmp = pm.mangle(tmp, isC2S); SendPyOutput(pm); // Check if we updated the data - if (!Arrays.equals(tmp, original)) - this.Name = this.Name + " - Updated by Python (mangle)"; - else + if (!Arrays.equals(tmp, original)){ + if(!this.Name.contains("mangle")){ + this.Name = this.Name + " - Updated by Python (mangle)"; + } + }else{ this.Name = this.Name.replace(" - Updated by Python (mangle)", ""); + } } else { List mtch = regexMatch(); @@ -316,9 +321,11 @@ public void run() { tmp = this.replace(tmp, match, replace); } } - if (!Arrays.equals(tmp, original)) - this.Name = this.Name + " - Updated by Match And Replace Rules"; - else + if (!Arrays.equals(tmp, original)){ + if(!this.Name.contains("Match")){ + this.Name = this.Name + " - Updated by Match And Replace Rules"; + } + }else this.Name = this.Name.replace(" - Updated by Match And Replace Rules", ""); } } @@ -334,9 +341,11 @@ public void run() { SendPyOutput(pm); } //TODO: This logic is not totally right. The data could be altered by other tools before this step. - if (!Arrays.equals(tmp, original)) - this.Name = this.Name + " - Formated by Python"; - else + if (!Arrays.equals(tmp, original)){ + if(!this.Name.contains("Formated")){ + this.Name = this.Name + " - Formated by Python"; + } + }else this.Name = this.Name.replace(" - Formated by Python", ""); // This will block until the the request if forwarded by the user from the // interceptor @@ -357,11 +366,21 @@ public void run() { } else { // Data was not manually intercepted so we treat it like a normal event. - NewDataEvent(tmp, original, this.Name); + if (SERVER.isPythonOn()) { + byte [] updated = pm.formatOnly(original, isC2S); + NewDataEvent(updated, original, this.Name); + }else{ + NewDataEvent(tmp, original, this.Name); + } } } else { // Manual Intercepts was not enabled so we treat it like a normal event. - NewDataEvent(tmp, original, this.Name); + if (SERVER.isPythonOn()) { + byte [] updated = pm.formatOnly(original, isC2S); + NewDataEvent(updated, original, this.Name); + }else{ + NewDataEvent(tmp, original, this.Name); + } } // Write the data back to the socket