diff --git a/NonHTTPProxy/src/josh/dao/HibHelper.java b/NonHTTPProxy/src/josh/dao/HibHelper.java index 61a8b28..a042902 100755 --- a/NonHTTPProxy/src/josh/dao/HibHelper.java +++ b/NonHTTPProxy/src/josh/dao/HibHelper.java @@ -9,14 +9,11 @@ public class HibHelper { - private static SessionFactory sessionFactory = buildSessionFactory(); private static SessionFactory buildSessionFactory() { System.out.println("Built new session factory"); - //java.util.logging.Logger.getLogger("org.hibernate").setLevel(java.util.logging.Level.OFF); - //java.util.logging.Logger.getLogger("com.mchange").setLevel(java.util.logging.Level.OFF); try { String path = System.getProperty("user.home"); String resultFile = path + "/.NoPEProxy/requests.sqlite"; @@ -25,7 +22,6 @@ private static SessionFactory buildSessionFactory() { Properties prop= new Properties(); prop.setProperty("hibernate.dialect", "josh.dao.SQLiteDialect"); - //prop.setProperty("hibernate.dialect", "org.hibernate.dialect.MySQLDialect"); prop.setProperty("hibernate.connection.driver_class", "org.sqlite.JDBC"); prop.setProperty("hibernate.show_sql", "false"); prop.setProperty("hibernate.hbm2ddl.auto", "update"); diff --git a/NonHTTPProxy/src/josh/dao/ListenerSetting.java b/NonHTTPProxy/src/josh/dao/ListenerSetting.java index adb3b0c..4f4f09c 100644 --- a/NonHTTPProxy/src/josh/dao/ListenerSetting.java +++ b/NonHTTPProxy/src/josh/dao/ListenerSetting.java @@ -24,15 +24,18 @@ public class ListenerSetting { private String cert; @Column(name = "ssl") private boolean ssl; + @Column(name = "udp") + private Boolean udp; public ListenerSetting(){} - public ListenerSetting(int lport, int sport, String sip, String cert, boolean ssl){ + public ListenerSetting(int lport, int sport, String sip, String cert, boolean ssl, Boolean udp){ this.lport = lport; this.sport = sport; this.sip = sip; this.cert = cert; this.ssl = ssl; + this.udp = udp; } public int getId() { return id; @@ -70,6 +73,20 @@ public boolean isSsl() { public void setSsl(boolean ssl) { this.ssl = ssl; } + public Boolean isUdp() { + if(this.udp == null){ + return false; + }else{ + return udp; + } + } + public void setUdp(Boolean udp) { + if(udp == null){ + this.udp = false; + }else{ + this.udp = udp; + } + } } diff --git a/NonHTTPProxy/src/josh/dao/Requests.java b/NonHTTPProxy/src/josh/dao/Requests.java index 5acd690..fa4f7c8 100755 --- a/NonHTTPProxy/src/josh/dao/Requests.java +++ b/NonHTTPProxy/src/josh/dao/Requests.java @@ -40,11 +40,13 @@ public class Requests { private String data_str; @Column(name = "original_str") private String original_str; + @Column(name = "protocol") + private String protocol; public Requests(){}; - public Requests(int Index, byte[] requestResponse, byte[] original, String SrcIp,int SrcPort, String DstIP, int DstPort, String Direction, Long time, int bytes){ + public Requests(int Index, byte[] requestResponse, byte[] original, String SrcIp,int SrcPort, String DstIP, int DstPort, String Direction, Long time, int bytes, String protocol){ this.alt_id = Index; this.data = Base64.getEncoder().encodeToString(requestResponse); this.original = Base64.getEncoder().encodeToString(original); @@ -57,6 +59,7 @@ public Requests(int Index, byte[] requestResponse, byte[] original, String SrcIp this.bytes = original.length; this.original_str = new String(original); //.replaceAll("[^a-zA-Z0-9~!@#$%^&*()_+`\\-=,./<>?\\s]", ""); this.data_str = new String(requestResponse);//.replaceAll("[^a-zA-Z0-9~!@#$%^&*()_+`\\-=,./<>?\\s]", ""); + this.protocol = protocol; } @@ -171,6 +174,22 @@ public String getOriginal_str() { public void setOriginal_str(String original_str) { this.original_str = original_str; } + + public String getProtocol(){ + if(this.protocol == null){ + return "TCP"; + }else{ + return this.protocol; + } + } + + public void setProtocol(String protocol){ + if(protocol == null){ + this.protocol = "TCP"; + }else{ + this.protocol = protocol; + } + } diff --git a/NonHTTPProxy/src/josh/dao/UpdateDBTask.java b/NonHTTPProxy/src/josh/dao/UpdateDBTask.java index 261d67d..159c781 100755 --- a/NonHTTPProxy/src/josh/dao/UpdateDBTask.java +++ b/NonHTTPProxy/src/josh/dao/UpdateDBTask.java @@ -58,7 +58,7 @@ public void run() { List updated = new ArrayList(); session.getTransaction().begin(); while((le = queue.poll())!= null){ - Requests dao = new Requests(0, le.requestResponse, le.original, le.SrcIP, le.SrcPort, le.DstIP, le.DstPort, le.Direction, le.time.getTime(), le.Bytes); + Requests dao = new Requests(0, le.requestResponse, le.original, le.SrcIP, le.SrcPort, le.DstIP, le.DstPort, le.Direction, le.time.getTime(), le.Bytes, le.protocol); session.saveOrUpdate(dao); le.Index =(long)dao.getId(); updated.add(le); diff --git a/NonHTTPProxy/src/josh/nonHttp/GenericMiTMServer.java b/NonHTTPProxy/src/josh/nonHttp/GenericMiTMServer.java index 017cefd..525afac 100755 --- a/NonHTTPProxy/src/josh/nonHttp/GenericMiTMServer.java +++ b/NonHTTPProxy/src/josh/nonHttp/GenericMiTMServer.java @@ -96,19 +96,12 @@ public static boolean available(int port) { } ServerSocket ss = null; - DatagramSocket ds = null; try { ss = new ServerSocket(port); ss.setReuseAddress(true); - ds = new DatagramSocket(port); - ds.setReuseAddress(true); return true; } catch (IOException e) { } finally { - if (ds != null) { - ds.close(); - } - if (ss != null) { try { ss.close(); @@ -169,7 +162,7 @@ public boolean isPythonOn() { return this.MangleWithPython; } - public void setPythonMange(boolean mangle) { + public void setPythonMangle(boolean mangle) { this.MangleWithPython = mangle; } diff --git a/NonHTTPProxy/src/josh/nonHttp/GenericUDPMiTMServer.java b/NonHTTPProxy/src/josh/nonHttp/GenericUDPMiTMServer.java index d330b41..1ad3a81 100644 --- a/NonHTTPProxy/src/josh/nonHttp/GenericUDPMiTMServer.java +++ b/NonHTTPProxy/src/josh/nonHttp/GenericUDPMiTMServer.java @@ -1,30 +1,17 @@ package josh.nonHttp; // -import java.io.DataOutputStream; -import java.io.FileInputStream; import java.io.IOException; -import java.io.InputStream; import java.net.ConnectException; import java.net.DatagramPacket; import java.net.DatagramSocket; -import java.net.ServerSocket; -import java.net.Socket; -import java.net.SocketException; -import java.security.KeyStore; -import java.security.cert.X509Certificate; +import java.net.InetAddress; import java.util.ArrayList; -import java.util.HashMap; import java.util.Iterator; import java.util.List; -import java.util.Vector; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLServerSocket; -import javax.net.ssl.SSLServerSocketFactory; -import javax.net.ssl.SSLSocket; -import javax.net.ssl.SSLSocketFactory; +import java.util.regex.Matcher; +import java.util.regex.Pattern; import burp.IBurpExtenderCallbacks; import josh.nonHttp.events.ProxyEvent; @@ -35,443 +22,233 @@ import josh.utils.events.SendClosedEvent; import josh.utils.events.SendClosedEventListener; -public class GenericUDPMiTMServer implements Runnable, ProxyEventListener, PythonOutputEventListener, SendClosedEventListener{ - - +public class GenericUDPMiTMServer + implements Runnable, ProxyEventListener, PythonOutputEventListener, SendClosedEventListener { + public int ListenPort; public int ServerPort; public String ServerAddress; public String ServerHostandIP; - public String CertHostName; - private boolean killme=false; - protected boolean isInterceptOn=false; - private int interceptType=0; // 0=both, 1=c2s, 2=s2c + private boolean killme = false; + protected boolean isInterceptOn = false; public InterceptData interceptc2s; public InterceptData intercepts2c; - Object svrSock; - //SSLServerSocket sslSvrSock; - Socket connectionSocket; - Object cltSock; - Vector threads = new Vector(); - Vector sends = new Vector(); - HashMap pairs = new HashMap(); - HashMaptreads2 = new HashMap(); - boolean isSSL = false; - boolean isRunning=false; - public final int INTERCEPT_C2S=1; - public final int INTERCEPT_S2C=2; - public final int INTERCEPT_BOTH=0; - private int IntercetpDirection=0; + public DatagramSocket udpServerSocket = null; + public final int INTERCEPT_C2S = 1; + public final int INTERCEPT_S2C = 2; + public final int INTERCEPT_BOTH = 0; + private int IntercetpDirection = 0; private IBurpExtenderCallbacks Callbacks; private boolean MangleWithPython = false; - //SendData send; - //SendData getD; - - - - public GenericUDPMiTMServer(boolean isSSL, IBurpExtenderCallbacks Callbacks){ + + public GenericUDPMiTMServer(boolean isSSL, IBurpExtenderCallbacks Callbacks) { this.interceptc2s = new InterceptData(null); this.intercepts2c = new InterceptData(null); - this.isSSL = isSSL; this.Callbacks = Callbacks; } - + public static boolean available(int port) { - if (port < 1 || port > 65535) { - return false; - } - - ServerSocket ss = null; - DatagramSocket ds = null; - try { - ss = new ServerSocket(port); - ss.setReuseAddress(true); - ds = new DatagramSocket(port); - ds.setReuseAddress(true); - return true; - } catch (IOException e) { - } finally { - if (ds != null) { - ds.close(); - } - - if (ss != null) { - try { - ss.close(); - } catch (IOException e) { - - } - } - } - - return false; + if (port < 1 || port > 65535) { + return false; + } + + DatagramSocket udpSocket = null; + try { + udpSocket = new DatagramSocket(port); + udpSocket.setReuseAddress(true); + return true; + } catch (IOException e) { + } finally { + if (udpSocket != null) { + udpSocket.close(); + } + } + System.out.println("Port " + port + " is in use."); + return false; } - + private List _listeners = new ArrayList(); private List _pylisteners = new ArrayList(); - public synchronized void addEventListener(ProxyEventListener listener) { + + public synchronized void addEventListener(ProxyEventListener listener) { _listeners.add(listener); } - public synchronized void removeEventListener(ProxyEventListener listener) { + + public synchronized void removeEventListener(ProxyEventListener listener) { _listeners.remove(listener); } - public synchronized void addPyEventListener(PythonOutputEventListener listener) { + + public synchronized void addPyEventListener(PythonOutputEventListener listener) { _pylisteners.add(listener); } - public synchronized void removePyEventListener(PythonOutputEventListener listener) { + + public synchronized void removePyEventListener(PythonOutputEventListener listener) { _pylisteners.remove(listener); } - private synchronized void NewDataEvent(ProxyEvent e) { + + private synchronized void NewDataEvent(ProxyEvent e) { + System.out.println(e); ProxyEvent event = e; Iterator i = _listeners.iterator(); - while(i.hasNext()) { + while (i.hasNext()) { ((ProxyEventListener) i.next()).DataReceived(event); } } - - public synchronized void SendPyOutput(PythonOutputEvent event){ + + public synchronized void SendPyOutput(PythonOutputEvent event) { Iterator i = _pylisteners.iterator(); - while(i.hasNext()) { + while (i.hasNext()) { ((PythonOutputEventListener) i.next()).PythonMessages(event); } } - - private synchronized void InterceptedEvent(ProxyEvent e, boolean isC2S) { + + private synchronized void InterceptedEvent(ProxyEvent e, boolean isC2S) { ProxyEvent event = e; event.setMtm(this); Iterator i = _listeners.iterator(); - while(i.hasNext()) { + while (i.hasNext()) { ((ProxyEventListener) i.next()).Intercepted(event, isC2S); } - + } - public boolean isPythonOn(){ + + public boolean isPythonOn() { return this.MangleWithPython; } - public void setPythonMange(boolean mangle){ + + public void setPythonMangle(boolean mangle) { this.MangleWithPython = mangle; } - - public void KillThreads(){ - - - //System.out.println("Number of Data buffer threads is: " + threads.size()); - for(int i=0; imtch = regexMatch(); - if(mtch != null){ - - for(String line : mtch){ - - //System.out.println(tmpStr); - String []kv = line.split("\\|\\|"); - // Check for direction specific options - String option = "both"; - if(kv.length == 3){ - option = kv[2]; - } - if(option.equals("both")){ - //Do nothing and let the rest process - }else if(option.equals("c2sOnly") && this.isC2S){ - //Do nothing and let the rest process - }else if(option.equals("s2cOnly") && !this.isC2S){ - //Do nothing and let the rest process - }else{ - // return to for loop - continue; - } - - if(kv[0].startsWith("#")){ - //do nothing this is a comment - } - else if(kv[0].startsWith("0x")){ - // This indicates we are doing hex replacement - byte [] match = new BigInteger(kv[0].replace("0x", ""),16).toByteArray(); - byte [] replace = new BigInteger(kv[1].replace("0x", ""),16).toByteArray(); - tmp = this.replace(tmp, match, replace); - }else{ - // this will be just a basic string replacement - byte [] match = kv[0].getBytes(); - byte [] replace = kv[1].getBytes(); - tmp = this.replace(tmp, match, replace); - } - } - if(!Arrays.equals(tmp,original)) - this.Name = this.Name + " - Updated by Match And Replace Rules"; - else - this.Name = this.Name.replace(" - Updated by Match And Replace Rules", ""); - } - } - - // Send things to the interceptor if it is enabled - if(SERVER.isInterceptOn()){ - if(SERVER.getIntercetpDir() == SERVER.INTERCEPT_BOTH || - (this.Name.equals("c2s") && SERVER.getIntercetpDir() == SERVER.INTERCEPT_C2S) || - (this.Name.equals("s2c") && SERVER.getIntercetpDir() == SERVER.INTERCEPT_S2C) - ){ - // Here we format the data before sending it to the interceptor - if(SERVER.isPythonOn()){ - tmp = pm.preIntercept(tmp, isC2S); - SendPyOutput(pm); - } - if(!Arrays.equals(tmp,original)) - 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 - // This function also handles the events that send the informatoin to the UI and logs. - Send2Interceptor(tmp, this.Name, isC2S); - - if(isC2S) - tmp=SERVER.interceptc2s.getData(); - else - tmp=SERVER.intercepts2c.getData(); - - // Here we format the data back before sending it back - if(SERVER.isPythonOn()){ - tmp = pm.postIntercept(tmp, isC2S); - SendPyOutput(pm); - } - - }else{ - // Data was not manually intercepted so we treat it like a normal event. - NewDataEvent(tmp, original, this.Name); - } - }else{ - // Manual Intercepts was not enabled so we treat it like a normal event. - NewDataEvent(tmp, original, this.Name); - } - - //Write the data back to the socket - out.write(tmp); - - - - }catch(SocketTimeoutException Ex){ - }catch(SSLHandshakeException Ex){ - //System.out.println(Ex.getMessage()); - }catch(SSLException Ex){ - //System.out.println(Ex.getMessage()); - } - catch(Exception Ex){ - //System.out.println("Error in: " + this.Name); - //Ex.printStackTrace(); - break; - - - } - - } - //System.out.println(this.Name + " - Connection Has Closed."); - this.SendClosedEventTrigger(); - //System.out.println("Socket Closed."); - - - } - - - ////Fun Functions - private String getHostandIP(Object Socket, boolean isSSL){ - String SourceInfo=""; - if(isSSL){ - SourceInfo = ((SSLSocket)Socket).getRemoteSocketAddress().toString(); - }else - SourceInfo = ((Socket)Socket).getRemoteSocketAddress().toString(); - - - if(SourceInfo != null && SourceInfo.indexOf(":") != -1 && !this.isIPV6(SourceInfo)){ - - SourceInfo = SourceInfo.split(":")[0]; - if(SourceInfo.indexOf('/')==0){ - SourceInfo = SourceInfo.split("/")[1]; - } - }else{ - if(isSSL){ - SourceInfo = ((SSLSocket)Socket).getInetAddress().getHostAddress(); - }else - SourceInfo = ((Socket)Socket).getInetAddress().getHostAddress(); - } - - return SourceInfo; - } - - private boolean isIPV6(String addr){ - if(countchars(addr, ':') > 1) - return true; - else - return false; - } - - private int countchars(String arg, char c){ - int count = 0; - for(int i = 0; i< arg.length(); i++){ - if( arg.charAt(i) == c){ - count++; - } - } - return count; - } - - private List regexMatch(){ - List tmp = new ArrayList(); - /*String fs = System.getProperty("file.separator"); - String file = System.getProperty("user.dir") + fs + "nonHTTPmatch.txt";*/ - String path = System.getProperty("user.home"); - String file = path + "/.NoPEProxy/nonHTTPmatch.txt"; - File f = new File(file); - if(!f.exists()){ - System.out.println("missing nonHTTPmatch.txt"); - return new ArrayList(); - } - Path p = Paths.get(file); - //if(isC2S){ - Charset charset = Charset.forName("UTF-8"); - try (BufferedReader reader = Files.newBufferedReader(p, charset)) { - String line = null; - while ((line = reader.readLine()) != null) { - tmp.add(line); - } - } catch (IOException x) { - System.err.format("IOException: %s%n", x); - } - //} - return tmp; - } - - private byte [] replace(byte[] input, byte [] match, byte [] replace) throws IOException{ - ByteArrayOutputStream bos = new ByteArrayOutputStream( ); - byte [] tmp = input; - int length = tmp.length; - int offset=0; - for(int i=0;i regexMatch() { + List tmp = new ArrayList(); + /* + * String fs = System.getProperty("file.separator"); + * String file = System.getProperty("user.dir") + fs + "nonHTTPmatch.txt"; + */ + String path = System.getProperty("user.home"); + String file = path + "/.NoPEProxy/nonHTTPmatch.txt"; + File f = new File(file); + if (!f.exists()) { + System.out.println("missing nonHTTPmatch.txt"); + return new ArrayList(); + } + Path p = Paths.get(file); + // if(isC2S){ + Charset charset = Charset.forName("UTF-8"); + try (BufferedReader reader = Files.newBufferedReader(p, charset)) { + String line = null; + while ((line = reader.readLine()) != null) { + tmp.add(line); + } + } catch (IOException x) { + System.err.format("IOException: %s%n", x); + } + // } + return tmp; + } + + private void updateBuffersWithRegEx(){ + try{ + List mtch = regexMatch(); + if (mtch != null) { + + for (String line : mtch) { + + String[] kv = line.split("\\|\\|"); + // Check for direction specific options + String option = "both"; + if (kv.length == 3) { + option = kv[2]; + } + if (option.equals("both")) { + // Do nothing and let the rest process + } else if (option.equals("c2sOnly") && this.isC2S) { + // Do nothing and let the rest process + } else if (option.equals("s2cOnly") && !this.isC2S) { + // Do nothing and let the rest process + } else { + // return to for loop + continue; + } + + if (kv[0].startsWith("#")) { + // do nothing this is a comment + } else if (kv[0].startsWith("0x")) { + // This indicates we are doing hex replacement + byte[] match = new BigInteger(kv[0].replace("0x", ""), 16).toByteArray(); + byte[] replace = new BigInteger(kv[1].replace("0x", ""), 16).toByteArray(); + this.modifiedBuffer = this.replace(this.modifiedBuffer, match, replace); + } else { + // this will be just a basic string replacement + byte[] match = kv[0].getBytes(); + byte[] replace = kv[1].getBytes(); + this.modifiedBuffer = this.replace(this.modifiedBuffer, match, replace); + } + } + if (!Arrays.equals(this.modifiedBuffer, this.originalBuffer)){ + 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", ""); + } + }catch(IOException ex){ + System.out.println(ex); + } + } + + private byte[] replace(byte[] input, byte[] match, byte[] replace) throws IOException { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + byte[] tmp = input; + int length = tmp.length; + int offset = 0; + for (int i = 0; i < length; i++) { + if (lookahead(i, tmp, match)) { + // bos.write(tmp, offset, i-offset); + bos.write(replace); + offset = i + match.length; + i = i + match.length - 1; + } else { + bos.write(tmp[i]); + } + } + return bos.toByteArray(); + + } + + private boolean lookahead(int index, byte[] input, byte[] match) { + int j = 0; + for (int i = index; i < input.length && j < match.length; i++) { + if (input[i] != match[j++]) { + return false; + } + } + if (j == match.length) + return true; + else + return false; + } + + /// All Event Stuff + + public synchronized void addEventListener(ProxyEventListener listener) { + _listeners.add(listener); + } + + public synchronized void removeEventListener(ProxyEventListener listener) { + _listeners.remove(listener); + } + + public synchronized void addPyEventListener(PythonOutputEventListener listener) { + _pylisteners.add(listener); + } + + public synchronized void removePyEventListener(PythonOutputEventListener listener) { + _pylisteners.remove(listener); + } + + public synchronized void addSendClosedEventListener(SendClosedEventListener listener) { + _sclisteners.add(listener); + } + + public synchronized void removeSendClosedEventListener(SendClosedEventListener listener) { + _sclisteners.remove(listener); + } + + public synchronized void SendClosedEventTrigger() { + SendClosedEvent event = new SendClosedEvent(this); + event.setDirection(this.Name); + Iterator i = _sclisteners.iterator(); + while (i.hasNext()) { + ((SendClosedEventListener) i.next()).Closed(event); + } + + } + + public synchronized void SendPyOutput(PythonMangler pm) { + String output = pm.getOutput(); + String error = pm.getError(); + if (!output.equals("") || !error.equals("")) { + PythonOutputEvent event = new PythonOutputEvent(this); + event.setMessage(output); + event.setError(error); + if (isC2S) { + event.setDirection("Client-To-Server"); + } else { + event.setDirection("Server-To-Client"); + } + Iterator i = _pylisteners.iterator(); + while (i.hasNext()) { + ((PythonOutputEventListener) i.next()).PythonMessages(event); + } + } + } + + private synchronized void NewDataEvent(byte[] modified) { + ProxyEvent event = new ProxyEvent(this); + event.setProtocl("UDP"); + event.setData(modified); + event.setOriginalData(this.originalBuffer); + event.setDirection(this.Name); + event.setSrcIP(this.srcIPString); + event.setSrcPort(this.srcPort); + event.setDstIP(this.dstIPString); + event.setDstPort(this.dstPort); + Iterator i = _listeners.iterator(); + while (i.hasNext()) { + ((ProxyEventListener) i.next()).DataReceived(event); + } + } + + private synchronized void Send2Interceptor(byte[] data) { + ProxyEvent event = new ProxyEvent(this); + event.setProtocl("UDP"); + event.setData(data); + event.setDirection(this.Name); + event.setSrcIP(this.srcIPString); + event.setSrcPort(this.srcPort); + event.setDstIP(this.dstIPString); + event.setDstPort(this.dstPort); + Iterator i = _listeners.iterator(); + while (i.hasNext()) { + ((ProxyEventListener) i.next()).Intercepted(event, this.isC2S); + } + } + +} diff --git a/NonHTTPProxy/src/josh/nonHttp/events/ProxyEvent.java b/NonHTTPProxy/src/josh/nonHttp/events/ProxyEvent.java index 4a8261d..f1a8b05 100755 --- a/NonHTTPProxy/src/josh/nonHttp/events/ProxyEvent.java +++ b/NonHTTPProxy/src/josh/nonHttp/events/ProxyEvent.java @@ -15,7 +15,7 @@ public class ProxyEvent extends EventObject { private String SrcIP; private String DstIP; private Object mtm; - private GenericUDPMiTMServer mtmUDP; + private String protocol; public ProxyEvent(Object arg0) { super(arg0); @@ -68,13 +68,6 @@ public GenericMiTMServer getTCPMtm(){ public void setMtm(Object mtm) { this.mtm = mtm; } - /*public GenericUDPMiTMServer getUDPMtm() { - return mtmUDP; - } - - public void setUDPMtm(GenericUDPMiTMServer mtm) { - this.mtmUDP = mtm; - }*/ public int getSrcPort() { return SrcPort; @@ -115,6 +108,13 @@ public byte[] getOriginalData() { public void setOriginalData(byte[] originalData) { OriginalData = originalData; } + + public String getProtocol(){ + return this.protocol; + } + public void setProtocl(String protocol){ + this.protocol = protocol; + } diff --git a/NonHTTPProxy/src/josh/ui/NonHttpUI.java b/NonHTTPProxy/src/josh/ui/NonHttpUI.java index 9c30404..41a397d 100755 --- a/NonHTTPProxy/src/josh/ui/NonHttpUI.java +++ b/NonHTTPProxy/src/josh/ui/NonHttpUI.java @@ -1,11 +1,7 @@ package josh.ui; - - - import javax.swing.JPanel; - import javax.swing.border.LineBorder; import javax.swing.ImageIcon; import java.awt.Color; @@ -77,7 +73,6 @@ import org.fife.ui.rsyntaxtextarea.SyntaxConstants; import org.fife.ui.rsyntaxtextarea.SyntaxScheme; import org.fife.ui.rsyntaxtextarea.Token; -import org.hibernate.Session; import org.json.simple.JSONArray; import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; @@ -87,10 +82,10 @@ import josh.dao.ListenerSetting; import josh.dao.UpdateDBTask; import josh.nonHttp.GenericMiTMServer; +import josh.nonHttp.GenericUDPMiTMServer; import josh.nonHttp.PythonMangler; import josh.nonHttp.events.ProxyEvent; import josh.nonHttp.events.ProxyEventListener; -import josh.ui.utils.ColoredTableCellRenderer; import josh.ui.utils.ListenerDB; import josh.ui.utils.LogEntry; import josh.ui.utils.NonHTTPTableModel; @@ -102,10 +97,10 @@ import josh.utils.events.DNSEvent; import josh.utils.events.DNSTableEvent; import josh.utils.events.DNSTableEventListener; +import josh.utils.events.PortConnectEvt; import josh.utils.events.PythonOutputEvent; import josh.utils.events.PythonOutputEventListener; -import josh.utils.events.TCPConnectionAttemptListener; -import josh.utils.events.TCPPacketEvt; +import josh.utils.events.ConnectionAttemptListener; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; @@ -128,7 +123,6 @@ import javax.swing.JRadioButton; import java.awt.GridLayout; import javax.swing.UIManager; -import javax.swing.UnsupportedLookAndFeelException; import javax.swing.border.TitledBorder; import javax.swing.border.EtchedBorder; import java.awt.GridBagLayout; @@ -147,20 +141,14 @@ import java.awt.Dimension; import java.awt.FileDialog; import javax.swing.ListSelectionModel; -import javax.swing.LookAndFeel; -import javax.swing.SwingUtilities; -import javax.swing.UIDefaults; - -import java.awt.FlowLayout; import javax.swing.JEditorPane; import javax.swing.JTextPane; import javax.swing.JComboBox; import javax.swing.Box; import javax.swing.BoxLayout; - @SuppressWarnings("serial") -public class NonHttpUI extends JPanel implements ProxyEventListener, DNSTableEventListener, PythonOutputEventListener{ +public class NonHttpUI extends JPanel implements ProxyEventListener, DNSTableEventListener, PythonOutputEventListener { public IBurpExtenderCallbacks Callbacks; public IExtensionHelpers Helpers; @@ -173,8 +161,10 @@ public class NonHttpUI extends JPanel implements ProxyEventListener, DNSTableEve JLabel lblCurrentIpAddress = new JLabel("Current Ip Address: "); JCheckBox isSSL; public DefaultTableModel tbm; - private HashMap threads = new HashMap(); - //private HashMap threads = new HashMap(); + private HashMap threads = new HashMap(); + private HashMap udpThreads = new HashMap(); + // private HashMap threads = new + // HashMap(); public NonHTTPTableModel ntbm; private JTabbedPane BurpTabs; public NonHTTPTableModel intbm; @@ -182,7 +172,7 @@ public class NonHttpUI extends JPanel implements ProxyEventListener, DNSTableEve JRadioButton isBoth; JRadioButton isC2S; JRadioButton isS2C; - Boolean EnableTCPDump=true; + Boolean EnableTCPDump = true; private JTable DnsListTable; public DefaultTableModel dnstTbm; private JLabel errorMsg; @@ -203,23 +193,20 @@ public class NonHttpUI extends JPanel implements ProxyEventListener, DNSTableEve private Queue queue = new LinkedList(); private Timer timer; private JEditorPane PythonConsole; - - public boolean useDefault= false; + + public boolean useDefault = false; public IMessageEditor repeater; - - - private Color NopeGreen = new Color(0x2e,0x7d,0x32); //135, 211, 124); + + private Color NopeGreen = new Color(0x2e, 0x7d, 0x32); // 135, 211, 124); private Color NopeRed = new Color(214, 69, 65); - private Color NopePurple = new Color(142, 68, 173); + private Color NopePurple = new Color(142, 68, 173); private Color NopeBlue = new Color(65, 131, 215); private Color NopeOrange = new Color(249, 191, 59); - private Color NopePink = new Color(0xc2,0x18,0x5b); - private Color NopeGrey = new Color(0x26,0x32,0x38); + private Color NopePink = new Color(0xc2, 0x18, 0x5b); + private Color NopeGrey = new Color(0x26, 0x32, 0x38); private Lister lister; - - - //GenericMiTMServer mtm; + // GenericMiTMServer mtm; /** * Create the frame. @@ -228,36 +215,38 @@ public NonHttpUI(IBurpExtenderCallbacks Callbacks, IExtensionHelpers Helpers, Sh setLayout(new GridLayout(0, 1, 0, 0)); this.Callbacks = Callbacks; this.Helpers = Helpers; - //##################################################################################### + // ##################################################################################### // Regiser Custom Fonts IconFontSwing.register(Elusive.getIconFont()); IconFontSwing.register(FontAwesome.getIconFont()); IconFontSwing.register(GoogleMaterialDesignIcons.getIconFont()); - - //##################################################################################### + + // ##################################################################################### // Setup Saved Configs AUTOSTART = Boolean.parseBoolean(this.getProperties("autoStart", "false")); - IFNUM = Integer.parseInt(this.getProperties("interface","0")); - - //##################################################################################### - // Create the 3 tabs + IFNUM = Integer.parseInt(this.getProperties("interface", "0")); + + // ##################################################################################### + // Create the 3 tabs BurpTabs = new JTabbedPane(); Intercept = new JPanel(); - JScrollPane History = new JScrollPane(); + JScrollPane History = new JScrollPane(); JPanel Options = new JPanel(); this.setBorder(null); GridBagLayout gbl_Options = new GridBagLayout(); - gbl_Options.columnWidths = new int[]{1067, 0}; - gbl_Options.rowHeights = new int[]{423, 220, 0}; - gbl_Options.columnWeights = new double[]{0.0, Double.MIN_VALUE}; - gbl_Options.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; + gbl_Options.columnWidths = new int[] { 1067, 0 }; + gbl_Options.rowHeights = new int[] { 423, 220, 0 }; + gbl_Options.columnWeights = new double[] { 0.0, Double.MIN_VALUE }; + gbl_Options.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; Options.setLayout(gbl_Options); - String local="---"; + String local = "---"; String tmpPort = this.getProperties("dnsport"); - if(tmpPort == null || tmpPort.equals("")) - tmpPort="5353"; + if (tmpPort == null || tmpPort.equals("")) + tmpPort = "5353"; JPanel panel_2 = new JPanel(); - panel_2.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "DNS Settings", TitledBorder.LEADING, TitledBorder.TOP, null, UIManager.getColor("CheckBoxMenuItem.selectionBackground"))); + panel_2.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "DNS Settings", + TitledBorder.LEADING, TitledBorder.TOP, null, + UIManager.getColor("CheckBoxMenuItem.selectionBackground"))); GridBagConstraints gbc_panel_2 = new GridBagConstraints(); gbc_panel_2.fill = GridBagConstraints.BOTH; gbc_panel_2.insets = new Insets(0, 0, 5, 0); @@ -265,14 +254,14 @@ public NonHttpUI(IBurpExtenderCallbacks Callbacks, IExtensionHelpers Helpers, Sh gbc_panel_2.gridy = 0; Options.add(panel_2, gbc_panel_2); GridBagLayout gbl_panel_2 = new GridBagLayout(); - gbl_panel_2.columnWidths = new int[]{42, 290, 242, 0, 0}; - gbl_panel_2.rowHeights = new int[]{110, 27, 0, 223, 0}; - gbl_panel_2.columnWeights = new double[]{0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE}; - gbl_panel_2.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE}; + gbl_panel_2.columnWidths = new int[] { 42, 290, 242, 0, 0 }; + gbl_panel_2.rowHeights = new int[] { 110, 27, 0, 223, 0 }; + gbl_panel_2.columnWeights = new double[] { 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE }; + gbl_panel_2.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE }; panel_2.setLayout(gbl_panel_2); - - //##################################################################################### - // DNS Controls for Options tab + + // ##################################################################################### + // DNS Controls for Options tab JPanel panel = new JPanel(); GridBagConstraints gbc_panel = new GridBagConstraints(); gbc_panel.fill = GridBagConstraints.BOTH; @@ -283,27 +272,26 @@ public NonHttpUI(IBurpExtenderCallbacks Callbacks, IExtensionHelpers Helpers, Sh panel_2.add(panel, gbc_panel); panel.setBorder(null); GridBagLayout gbl_panel = new GridBagLayout(); - gbl_panel.columnWidths = new int[]{0, 61, 59, 73, 130, 0}; - gbl_panel.rowHeights = new int[]{30, 33, 23, 0}; - gbl_panel.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE}; - gbl_panel.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE}; + gbl_panel.columnWidths = new int[] { 0, 61, 59, 73, 130, 0 }; + gbl_panel.rowHeights = new int[] { 30, 33, 23, 0 }; + gbl_panel.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE }; + gbl_panel.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; panel.setLayout(gbl_panel); - btnStartDns = new JButton(""); //Start DNS - btnStartDns.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY,40)); - btnStartDns.setBackground(NopeGreen);//green + btnStartDns = new JButton(""); // Start DNS + btnStartDns.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY, 40)); + btnStartDns.setBackground(NopeGreen);// green btnStartDns.setToolTipText("Start and Stop DNS Server"); btnStartDns.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - ToggleDNS( dnsIpTxt.getText() ,Integer.parseInt(txtDNSPort.getText())); - if(isDNSRunning){ + ToggleDNS(dnsIpTxt.getText(), Integer.parseInt(txtDNSPort.getText())); + if (isDNSRunning) { - - }else{ - btnStartDns.setBackground(NopeRed); //red - btnStartDns.setIcon(IconFontSwing.buildIcon(FontAwesome.STOP,40)); + } else { + btnStartDns.setBackground(NopeRed); // red + btnStartDns.setIcon(IconFontSwing.buildIcon(FontAwesome.STOP, 40)); btnStartDns.setText("");// Stop DNS isDNSRunning = true; - //lblStatusDNS.setText("DNS ON"); + // lblStatusDNS.setText("DNS ON"); } } @@ -323,16 +311,15 @@ public void actionPerformed(ActionEvent e) { gbc_lblDnsIp.gridx = 3; gbc_lblDnsIp.gridy = 0; panel.add(lblDnsIp, gbc_lblDnsIp); - dnsIpTxt = new JTextField(); dnsIpTxt.setToolTipText("Must restart the DNS server when the DNS IP is changed."); dnsIpTxt.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { - if(dnsIpTxt.getText().matches("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$")){ + if (dnsIpTxt.getText().matches("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$")) { DNSIP = dnsIpTxt.getText(); - Callbacks.printOutput("DNSIP Changed to : " + DNSIP); + Callbacks.printOutput("DNSIP Changed to : " + DNSIP); } } }); @@ -346,7 +333,7 @@ public void keyReleased(KeyEvent e) { dnsIpTxt.setColumns(10); dnsIpTxt.setText(local); DNSIP = dnsIpTxt.getText(); - + JLabel lblDnsport = new JLabel("DNS Listener Port:"); GridBagConstraints gbc_lblDnsport = new GridBagConstraints(); gbc_lblDnsport.fill = GridBagConstraints.HORIZONTAL; @@ -354,20 +341,20 @@ public void keyReleased(KeyEvent e) { gbc_lblDnsport.gridx = 3; gbc_lblDnsport.gridy = 1; panel.add(lblDnsport, gbc_lblDnsport); - + final JCheckBox chckbxStartDnsOn = new JCheckBox("Start DNS on Start Up"); chckbxStartDnsOn.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { updateAutoStart(chckbxStartDnsOn.isSelected()); } }); - + txtDNSPort = new JTextField(); txtDNSPort.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { DNSPort = Integer.parseInt(txtDNSPort.getText()); - updateProperties("dnsport", ""+DNSPort); + updateProperties("dnsport", "" + DNSPort); } }); txtDNSPort.addPropertyChangeListener(new PropertyChangeListener() { @@ -383,31 +370,30 @@ public void propertyChange(PropertyChangeEvent evt) { gbc_txtDNSPort.gridy = 1; panel.add(txtDNSPort, gbc_txtDNSPort); txtDNSPort.setColumns(10); - - //##################################################################################### - // Network Interfaces Information for Options tab + + // ##################################################################################### + // Network Interfaces Information for Options tab IfTxtBox = new JTextField(); IfTxtBox.addKeyListener(new KeyAdapter() { @Override public void keyReleased(KeyEvent evt) { - if(IfTxtBox.getText().matches("^[0-9]{1,3}$")){ + if (IfTxtBox.getText().matches("^[0-9]{1,3}$")) { updateInterface(IfTxtBox.getText()); - updateInterfaceInformation(); + updateInterfaceInformation(); } } }); - - JLabel lblInterface = new JLabel("Interface:"); - GridBagConstraints gbc_lblInterface = new GridBagConstraints(); - gbc_lblInterface.anchor = GridBagConstraints.WEST; - gbc_lblInterface.insets = new Insets(0, 0, 0, 5); - gbc_lblInterface.gridx = 1; - gbc_lblInterface.gridy = 2; - panel.add(lblInterface, gbc_lblInterface); - - + + JLabel lblInterface = new JLabel("Interface:"); + GridBagConstraints gbc_lblInterface = new GridBagConstraints(); + gbc_lblInterface.anchor = GridBagConstraints.WEST; + gbc_lblInterface.insets = new Insets(0, 0, 0, 5); + gbc_lblInterface.gridx = 1; + gbc_lblInterface.gridy = 2; + panel.add(lblInterface, gbc_lblInterface); + IfTxtBox.setToolTipText("The interface number from the list below."); - IfTxtBox.setText(""+IFNUM); + IfTxtBox.setText("" + IFNUM); GridBagConstraints gbc_IfTxtBox = new GridBagConstraints(); gbc_IfTxtBox.fill = GridBagConstraints.HORIZONTAL; gbc_IfTxtBox.anchor = GridBagConstraints.SOUTH; @@ -415,15 +401,16 @@ public void keyReleased(KeyEvent evt) { gbc_IfTxtBox.gridx = 2; gbc_IfTxtBox.gridy = 2; panel.add(IfTxtBox, gbc_IfTxtBox); - //IfTxtBox.setColumns(10); + // IfTxtBox.setColumns(10); GridBagConstraints gbc_chckbxStartDnsOn = new GridBagConstraints(); gbc_chckbxStartDnsOn.anchor = GridBagConstraints.WEST; gbc_chckbxStartDnsOn.fill = GridBagConstraints.VERTICAL; gbc_chckbxStartDnsOn.gridx = 4; gbc_chckbxStartDnsOn.gridy = 2; panel.add(chckbxStartDnsOn, gbc_chckbxStartDnsOn); - - useDefaultIp = new JCheckBox("Use the above 'DNS Response IP' for all DNS responses excluding host entries below. "); + + useDefaultIp = new JCheckBox( + "Use the above 'DNS Response IP' for all DNS responses excluding host entries below. "); useDefaultIp.addChangeListener(new ChangeListener() { public void stateChanged(ChangeEvent arg0) { sb.setDefault(useDefaultIp.isSelected()); @@ -436,37 +423,34 @@ public void stateChanged(ChangeEvent arg0) { gbc_useDefaultIp.gridx = 2; gbc_useDefaultIp.gridy = 1; panel_2.add(useDefaultIp, gbc_useDefaultIp); - - - lblCurrentIpAddress.setToolTipText("Double Click to add IP address to DNS Config"); - lblCurrentIpAddress.addMouseListener(new MouseAdapter() { - @Override - public void mouseClicked(MouseEvent arg0) { - //Check for double click - if(arg0.getClickCount()==2){ - String [] theSplits = lblCurrentIpAddress.getText().split(":"); - String ip = theSplits[1]; - if(ip!=null){ - ip=ip.trim(); - dnsIpTxt.setText(ip); - } - - - } + + lblCurrentIpAddress.setToolTipText("Double Click to add IP address to DNS Config"); + lblCurrentIpAddress.addMouseListener(new MouseAdapter() { + @Override + public void mouseClicked(MouseEvent arg0) { + // Check for double click + if (arg0.getClickCount() == 2) { + String[] theSplits = lblCurrentIpAddress.getText().split(":"); + String ip = theSplits[1]; + if (ip != null) { + ip = ip.trim(); + dnsIpTxt.setText(ip); } - }); - GridBagConstraints gbc_lblCurrentIpAddress = new GridBagConstraints(); - gbc_lblCurrentIpAddress.anchor = GridBagConstraints.NORTH; - gbc_lblCurrentIpAddress.fill = GridBagConstraints.HORIZONTAL; - gbc_lblCurrentIpAddress.insets = new Insets(0, 0, 5, 5); - gbc_lblCurrentIpAddress.gridx = 1; - gbc_lblCurrentIpAddress.gridy = 2; - panel_2.add(lblCurrentIpAddress, gbc_lblCurrentIpAddress); - - - lblCurrentIpAddress.setForeground(Color.BLUE); - lblCurrentIpAddress.setText("Current Ip Address: " + local ); - + + } + } + }); + GridBagConstraints gbc_lblCurrentIpAddress = new GridBagConstraints(); + gbc_lblCurrentIpAddress.anchor = GridBagConstraints.NORTH; + gbc_lblCurrentIpAddress.fill = GridBagConstraints.HORIZONTAL; + gbc_lblCurrentIpAddress.insets = new Insets(0, 0, 5, 5); + gbc_lblCurrentIpAddress.gridx = 1; + gbc_lblCurrentIpAddress.gridy = 2; + panel_2.add(lblCurrentIpAddress, gbc_lblCurrentIpAddress); + + lblCurrentIpAddress.setForeground(Color.BLUE); + lblCurrentIpAddress.setText("Current Ip Address: " + local); + JLabel lblNewLabel_1 = new JLabel(" Left unchecked the real IP address will be used instead."); GridBagConstraints gbc_lblNewLabel_1 = new GridBagConstraints(); gbc_lblNewLabel_1.anchor = GridBagConstraints.WEST; @@ -474,7 +458,7 @@ public void mouseClicked(MouseEvent arg0) { gbc_lblNewLabel_1.gridx = 2; gbc_lblNewLabel_1.gridy = 2; panel_2.add(lblNewLabel_1, gbc_lblNewLabel_1); - + JTextArea txtIfList = new JTextArea(); GridBagConstraints gbc_txtIfList = new GridBagConstraints(); gbc_txtIfList.insets = new Insets(0, 0, 0, 5); @@ -485,9 +469,10 @@ public void mouseClicked(MouseEvent arg0) { txtIfList.setEditable(false); txtIfList.setWrapStyleWord(true); txtIfList.setText(getInterfaceList()); - + JPanel panel_4 = new JPanel(); - panel_4.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Custom Hosts file", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(59, 59, 59))); + panel_4.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Custom Hosts file", + TitledBorder.LEADING, TitledBorder.TOP, null, new Color(59, 59, 59))); GridBagConstraints gbc_panel_4 = new GridBagConstraints(); gbc_panel_4.insets = new Insets(0, 0, 0, 5); gbc_panel_4.fill = GridBagConstraints.BOTH; @@ -495,12 +480,12 @@ public void mouseClicked(MouseEvent arg0) { gbc_panel_4.gridy = 3; panel_2.add(panel_4, gbc_panel_4); GridBagLayout gbl_panel_4 = new GridBagLayout(); - gbl_panel_4.columnWidths = new int[]{12, 0}; - gbl_panel_4.rowHeights = new int[]{28, 0}; - gbl_panel_4.columnWeights = new double[]{1.0, Double.MIN_VALUE}; - gbl_panel_4.rowWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_panel_4.columnWidths = new int[] { 12, 0 }; + gbl_panel_4.rowHeights = new int[] { 28, 0 }; + gbl_panel_4.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; + gbl_panel_4.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; panel_4.setLayout(gbl_panel_4); - + JTextArea dnsHosts = new JTextArea(); dnsHosts.setText(this.readHosts()); dnsHosts.addKeyListener(new KeyAdapter() { @@ -514,127 +499,181 @@ public void keyReleased(KeyEvent arg0) { gbc_dnsHosts.gridx = 0; gbc_dnsHosts.gridy = 0; panel_4.add(dnsHosts, gbc_dnsHosts); - - //tbm = (DefaultTableModel)ListTable.getModel(); - tbm = new DefaultTableModel(){ - @Override - public boolean isCellEditable(int row, int column) { - if(column == 0){ - int port = Integer.parseInt(""+tbm.getValueAt(row,1)); - for(int i=0; i< tbm.getRowCount(); i++){ - if(i == row) - continue; - else if(port == Integer.parseInt(""+tbm.getValueAt(i,1)) && (boolean)tbm.getValueAt(i,0)) - return false; - } - return true; - }else if((boolean)tbm.getValueAt(row,0) && column == 5) - return false; - else if(!(boolean)tbm.getValueAt(row,0) && column == 5) - return true; - else - return false; - } - + + // tbm = (DefaultTableModel)ListTable.getModel(); + tbm = new DefaultTableModel() { + @Override + public boolean isCellEditable(int row, int column) { + if (column == 0) { + int port = Integer.parseInt("" + tbm.getValueAt(row, 1)); + for (int i = 0; i < tbm.getRowCount(); i++) { + if (i == row) + continue; + else if (port == Integer.parseInt("" + tbm.getValueAt(i, 1)) && (boolean) tbm.getValueAt(i, 0)) + return false; + } + return true; + } else if ((boolean) tbm.getValueAt(row, 0) && column == 5) + return false; + else if (!(boolean) tbm.getValueAt(row, 0) && column == 5) + return true; + else if ((boolean) tbm.getValueAt(row, 0) && column == 6) + return false; + else if (!(boolean) tbm.getValueAt(row, 0) && column == 6) + return true; + else + return false; + } + }; - - String header[] = new String[]{"Enable","Listener","Server Address", "Server Port","Cert Host","SSL"}; + + String header[] = new String[] { "Enable", "Listener", "Server Address", "Server Port", "Cert Host", "SSL", + "UDP" }; tbm.setColumnIdentifiers(header); - + tbm.addTableModelListener(new TableModelListener() { @SuppressWarnings("static-access") @Override public void tableChanged(TableModelEvent e) { - ///OK something changed in the table... it could be a new row added or - - - if(e.getType()==e.UPDATE && e.getColumn() == 0){ + if (e.getType() == e.UPDATE && e.getColumn() == 0) { int rowid = ListTable.getSelectedRow(); - //System.out.println("Updated Table"); - //update create - if(((Boolean)tbm.getValueAt(rowid, 0))){ - //Check if the port is in use - int listport = Integer.parseInt(""+tbm.getValueAt(rowid, 1)); - if(!GenericMiTMServer.available(listport)){ + if (((Boolean) tbm.getValueAt(rowid, 0))) { + // Check if the port is in use + int listport = Integer.parseInt("" + tbm.getValueAt(rowid, 1)); + Boolean isUDP = (Boolean) tbm.getValueAt(rowid, 6); + if (isUDP == null) + isUDP = false; + System.out.println("UDP is: " + isUDP); + if (!isUDP && !GenericMiTMServer.available(listport)) { + tbm.setValueAt(false, rowid, 0); + Callbacks.printOutput("Port is already in use or port is outside range."); + } else if (isUDP && !GenericUDPMiTMServer.available(listport)) { tbm.setValueAt(false, rowid, 0); Callbacks.printOutput("Port is already in use or port is outside range."); - }else if((Boolean)tbm.getValueAt(rowid, 5) && !checkCert()){ + } else if (!isUDP && (Boolean) tbm.getValueAt(rowid, 5) && !checkCert()) { tbm.setValueAt(false, rowid, 0); Callbacks.printOutput("SSL Cert is not installed correctly"); - isSSL.setForeground(Color.red); + isSSL.setForeground(Color.red); lblNewLabel.setForeground(Color.red); Timer timer = new Timer(); timer.schedule(new TimerTask() { - @Override - public void run() { - isSSL.setForeground(Color.black); - lblNewLabel.setForeground(Color.black); - } - }, 3*1000); - - }else{ - ///isSSL.setBackground(); - GenericMiTMServer mtm = new GenericMiTMServer((Boolean)tbm.getValueAt(rowid, 5), Callbacks); - //GenericUDPMiTMServer mtm = new GenericUDPMiTMServer((Boolean)tbm.getValueAt(rowid, 5), Callbacks); - //TODO: Add validation + @Override + public void run() { + isSSL.setForeground(Color.black); + lblNewLabel.setForeground(Color.black); + } + }, 3 * 1000); + + } else if (!isUDP) { + GenericMiTMServer mtm = new GenericMiTMServer((Boolean) tbm.getValueAt(rowid, 5), + Callbacks); mtm.ListenPort = listport; mtm.ServerPort = Integer.parseInt("" + tbm.getValueAt(rowid, 3)); - mtm.CertHostName = (String)tbm.getValueAt(rowid, 4); + mtm.CertHostName = (String) tbm.getValueAt(rowid, 4); mtm.ServerAddress = (String) tbm.getValueAt(rowid, 2); - mtm.setPythonMange( chckbxEnablePythonMangler.isSelected() ); + mtm.setPythonMangle(chckbxEnablePythonMangler.isSelected()); mtm.addEventListener(NonHttpUI.this); mtm.addPyEventListener(NonHttpUI.this); - if(btnIntercept.getText().endsWith("ON")) + if (btnIntercept.getText().endsWith("ON")) mtm.setIntercept(true); - - if(isC2S.isSelected()) + + if (isC2S.isSelected()) mtm.setInterceptDir(mtm.INTERCEPT_C2S); - else if(isS2C.isSelected()) + else if (isS2C.isSelected()) mtm.setInterceptDir(mtm.INTERCEPT_S2C); - else if(isBoth.isSelected()) + else if (isBoth.isSelected()) mtm.setInterceptDir(mtm.INTERCEPT_BOTH); - - //threads.put(mtm.ListenPort, mtm); /// track threads by the listening port + + // threads.put(mtm.ListenPort, mtm); /// track threads by the listening port threads.put(listport, mtm); /// track threads by the rowid Thread t = new Thread(mtm); t.start(); - currentListeners.addItem(listport + " - " + mtm.ServerAddress +":"+mtm.ServerPort); - - + currentListeners.addItem(listport + " - " + mtm.ServerAddress + ":" + mtm.ServerPort); + + } else { + GenericUDPMiTMServer mtm = new GenericUDPMiTMServer((Boolean) tbm.getValueAt(rowid, 5), + Callbacks); + mtm.ListenPort = listport; + mtm.ServerPort = Integer.parseInt("" + tbm.getValueAt(rowid, 3)); + mtm.ServerAddress = (String) tbm.getValueAt(rowid, 2); + mtm.setPythonMangle(chckbxEnablePythonMangler.isSelected()); + mtm.addEventListener(NonHttpUI.this); + mtm.addPyEventListener(NonHttpUI.this); + if (btnIntercept.getText().endsWith("ON")) + mtm.setIntercept(true); + + if (isC2S.isSelected()) + mtm.setInterceptDir(mtm.INTERCEPT_C2S); + else if (isS2C.isSelected()) + mtm.setInterceptDir(mtm.INTERCEPT_S2C); + else if (isBoth.isSelected()) + mtm.setInterceptDir(mtm.INTERCEPT_BOTH); + udpThreads.put(listport, mtm); + Thread t = new Thread(mtm); + t.start(); + currentListeners.addItem(listport + " - " + mtm.ServerAddress + ":" + mtm.ServerPort); + } - }else if (e.getColumn() == 0){ //delete a server thread - int lPort = Integer.parseInt(""+tbm.getValueAt(rowid, 1)); - GenericMiTMServer mtm = ((GenericMiTMServer)threads.get(lPort)); - //GenericUDPMiTMServer mtm = ((GenericUDPMiTMServer)threads.get(lPort)); - //GenericMiTMServer mtm = ((GenericMiTMServer)threads.get(rowid)); - if(mtm != null){ + } else if (e.getColumn() == 0) { // delete a server thread + int lPort = Integer.parseInt("" + tbm.getValueAt(rowid, 1)); + Boolean isUDP = (Boolean) tbm.getValueAt(rowid, 6); + if (isUDP == null) + isUDP = false; + + GenericUDPMiTMServer udpMtm = ((GenericUDPMiTMServer) udpThreads.get(lPort)); + GenericMiTMServer mtm = ((GenericMiTMServer) threads.get(rowid)); + if (mtm != null && !isUDP) { mtm.KillThreads(); threads.remove(lPort); - currentListeners.removeItem(mtm.ListenPort + " - " + mtm.ServerAddress +":"+mtm.ServerPort); + currentListeners + .removeItem(mtm.ListenPort + " - " + mtm.ServerAddress + ":" + mtm.ServerPort); + } else if (udpMtm != null) { + udpMtm.KillThreads(); + udpThreads.remove(lPort); + currentListeners.removeItem( + udpMtm.ListenPort + " - " + udpMtm.ServerAddress + ":" + udpMtm.ServerPort); } } - }else if(e.getType()==e.UPDATE && e.getColumn() == 5){ + } else if (e.getType() == e.UPDATE && e.getColumn() == 5) { int rowid = ListTable.getSelectedRow(); - int lport = Integer.parseInt("" +tbm.getValueAt(rowid, 1)); - int sport = Integer.parseInt("" +tbm.getValueAt(rowid, 3)); - String cert = (String)tbm.getValueAt(rowid, 4); - String sip = (String)tbm.getValueAt(rowid, 2); - boolean ssl = (boolean)tbm.getValueAt(rowid, 5); - ListenerSetting ls = new ListenerSetting(lport, sport, sip, cert, !ssl); + int lport = Integer.parseInt("" + tbm.getValueAt(rowid, 1)); + int sport = Integer.parseInt("" + tbm.getValueAt(rowid, 3)); + String cert = (String) tbm.getValueAt(rowid, 4); + String sip = (String) tbm.getValueAt(rowid, 2); + Boolean ssl = (Boolean) tbm.getValueAt(rowid, 5); + Boolean udp = (Boolean) tbm.getValueAt(rowid, 6); + if(udp == null) + udp = false; + else if(udp && ssl){ + ssl=false; + tbm.setValueAt(false, rowid,5); + } + ListenerSetting ls = new ListenerSetting(lport, sport, sip, cert, !ssl, udp); ListenerDB.updateSSL(ls, ssl); + } else if (e.getType() == e.UPDATE && e.getColumn() == 6) { + int rowid = ListTable.getSelectedRow(); + int lport = Integer.parseInt("" + tbm.getValueAt(rowid, 1)); + int sport = Integer.parseInt("" + tbm.getValueAt(rowid, 3)); + String cert = (String) tbm.getValueAt(rowid, 4); + String sip = (String) tbm.getValueAt(rowid, 2); + Boolean ssl = (Boolean) tbm.getValueAt(rowid, 5); + Boolean upd = (Boolean) tbm.getValueAt(rowid, 6); + if (upd == null || upd){ + ssl = false; + tbm.setValueAt(false, rowid,5); + } + ListenerSetting ls = new ListenerSetting(lport, sport, sip, cert, ssl, !upd); + ListenerDB.updateUDP(ls, upd); } } }); - - - - - //##################################################################################### - // Match and replace rules for Options tab + + // ##################################################################################### + // Match and replace rules for Options tab String rules = getMatchRules(); - if(rules.equals("")){ + if (rules.equals("")) { rules = "# '#' will comment out the line\r\n" + "# Normal String replace rules are in the following format:\r\n" + "#\r\n" @@ -649,22 +688,22 @@ else if(isBoth.isSelected()) + "#\r\n" + "# For example to modify only client to server traffic\r\n" + "# * 0x11223344||0x556677||c2sOnly"; - + } - + Callbacks.customizeUiComponent(Options); - //##################################################################################### - // SetUp table TCP Log History Tab + // ##################################################################################### + // SetUp table TCP Log History Tab ntbm = new NonHTTPTableModel(); ntbm.initDB(); - ntbm.requestViewer = Callbacks.createMessageEditor(ntbm,false); - ntbm.originalViewer = Callbacks.createMessageEditor(ntbm,false); + ntbm.requestViewer = Callbacks.createMessageEditor(ntbm, false); + ntbm.originalViewer = Callbacks.createMessageEditor(ntbm, false); GridBagLayout gbl_Intercept = new GridBagLayout(); - gbl_Intercept.columnWidths = new int[]{122, 0}; - gbl_Intercept.rowHeights = new int[]{29, 0, 0}; - gbl_Intercept.columnWeights = new double[]{1.0, Double.MIN_VALUE}; - gbl_Intercept.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; + gbl_Intercept.columnWidths = new int[] { 122, 0 }; + gbl_Intercept.rowHeights = new int[] { 29, 0, 0 }; + gbl_Intercept.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; + gbl_Intercept.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; Intercept.setLayout(gbl_Intercept); JPanel panel_3 = new JPanel(); @@ -675,38 +714,51 @@ else if(isBoth.isSelected()) gbc_panel_3.gridy = 0; Intercept.add(panel_3, gbc_panel_3); GridBagLayout gbl_panel_3 = new GridBagLayout(); - gbl_panel_3.columnWidths = new int[]{122, 56, 56, 60, 0, 0, 0, 0, 0, 0, 0, 0}; - gbl_panel_3.rowHeights = new int[]{29, 0}; - gbl_panel_3.columnWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE}; - gbl_panel_3.rowWeights = new double[]{0.0, Double.MIN_VALUE}; + gbl_panel_3.columnWidths = new int[] { 122, 56, 56, 60, 0, 0, 0, 0, 0, 0, 0, 0 }; + gbl_panel_3.rowHeights = new int[] { 29, 0 }; + gbl_panel_3.columnWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 1.0, + Double.MIN_VALUE }; + gbl_panel_3.rowWeights = new double[] { 0.0, Double.MIN_VALUE }; panel_3.setLayout(gbl_panel_3); - + JSplitPane splitPane = new JSplitPane(); splitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); splitPane.setBounds(6, 238, 989, 462); logTable = new Table(ntbm); - //ColoredTableCellRenderer ctcr = new ColoredTableCellRenderer(); - //logTable.setDefaultRenderer(String.class, ctcr); + // ColoredTableCellRenderer ctcr = new ColoredTableCellRenderer(); + // logTable.setDefaultRenderer(String.class, ctcr); logTable.setCellSelectionEnabled(true); logTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); logTable.setFont(new Font("SansSerif", Font.PLAIN, 16)); logTable.setBackground(SystemColor.text); logTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); - logTable.getColumnModel().getColumn(0).setPreferredWidth(50);//index - logTable.getColumnModel().getColumn(1).setPreferredWidth(160);//Time - logTable.getColumnModel().getColumn(2).setPreferredWidth(550);//Direction - - logTable.getColumnModel().getColumn(3).setPreferredWidth(150);//Sip - logTable.getColumnModel().getColumn(4).setPreferredWidth(60);//Sport - logTable.getColumnModel().getColumn(5).setPreferredWidth(150);//dip - logTable.getColumnModel().getColumn(6).setPreferredWidth(60);//dport - logTable.getColumnModel().getColumn(6).setPreferredWidth(50);//bytes - - + logTable.getColumnModel().getColumn(0).setPreferredWidth(60);// index + logTable.getColumnModel().getColumn(0).setMaxWidth(75);// index + + logTable.getColumnModel().getColumn(1).setPreferredWidth(200);// Time + logTable.getColumnModel().getColumn(1).setMaxWidth(200);// Time + + logTable.getColumnModel().getColumn(2).setPreferredWidth(50);// Protocol + logTable.getColumnModel().getColumn(2).setMaxWidth(50); + + logTable.getColumnModel().getColumn(3).setPreferredWidth(550);// Direction + logTable.getColumnModel().getColumn(4).setPreferredWidth(550);// Direction + logTable.getColumnModel().getColumn(5).setPreferredWidth(150);// Sip + + logTable.getColumnModel().getColumn(6).setPreferredWidth(60);// Sport + logTable.getColumnModel().getColumn(6).setMaxWidth(70);// Sport + + logTable.getColumnModel().getColumn(7).setPreferredWidth(150);// dip + + logTable.getColumnModel().getColumn(8).setPreferredWidth(60);// dport + logTable.getColumnModel().getColumn(8).setMaxWidth(70);// Sport + + logTable.getColumnModel().getColumn(9).setPreferredWidth(100);// bytes + logTable.getColumnModel().getColumn(9).setMaxWidth(100);// bytes + JScrollPane logscrollPane = new JScrollPane(logTable); splitPane.setLeftComponent(logscrollPane); - - + JPopupMenu jpm = new JPopupMenu(); JMenuItem menuItem = new JMenuItem("Send To Comparer"); menuItem.addActionListener(new ActionListener() { @@ -715,31 +767,29 @@ public void actionPerformed(ActionEvent e) { } }); jpm.add(menuItem); - - JPanel panel_5 = new JPanel(); panel_5.setBorder(null); splitPane.setRightComponent(panel_5); GridBagLayout gbl_panel_5 = new GridBagLayout(); - gbl_panel_5.columnWidths = new int[]{115, 658, 0, 0, 0}; - gbl_panel_5.rowHeights = new int[]{35, 123, 0}; - gbl_panel_5.columnWeights = new double[]{0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE}; - gbl_panel_5.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; + gbl_panel_5.columnWidths = new int[] { 115, 658, 0, 0, 0 }; + gbl_panel_5.rowHeights = new int[] { 35, 123, 0 }; + gbl_panel_5.columnWeights = new double[] { 0.0, 1.0, 0.0, 1.0, Double.MIN_VALUE }; + gbl_panel_5.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; panel_5.setLayout(gbl_panel_5); - + // This button even will set focus on the currently selected tcp message. // This is usefull when several messages scroll across the table. It becomes // easy to loose your place. JButton btnGoBack = new JButton("Go To Selected"); - btnGoBack.setIcon(IconFontSwing.buildIcon(FontAwesome.LOCATION_ARROW,16)); + btnGoBack.setIcon(IconFontSwing.buildIcon(FontAwesome.LOCATION_ARROW, 16)); btnGoBack.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - Long index = logTable.getSelectedIndex(); + Long index = logTable.getSelectedIndex(); System.out.println(index); int selectedRow = logTable.getSelectedRow(); logTable.requestFocus(); - logTable.changeSelection(selectedRow,0,false, false); + logTable.changeSelection(selectedRow, 0, false, false); } }); GridBagConstraints gbc_btnGoBack = new GridBagConstraints(); @@ -749,7 +799,7 @@ public void actionPerformed(ActionEvent e) { gbc_btnGoBack.gridx = 0; gbc_btnGoBack.gridy = 0; panel_5.add(btnGoBack, gbc_btnGoBack); - + // UI Element to display the current selection in the tcp log lblSelected = new JLabel("Selected"); GridBagConstraints gbc_lblSelected = new GridBagConstraints(); @@ -758,53 +808,54 @@ public void actionPerformed(ActionEvent e) { gbc_lblSelected.gridx = 1; gbc_lblSelected.gridy = 0; panel_5.add(lblSelected, gbc_lblSelected); - //This allows the table model to update the label text when an element is selected. + // This allows the table model to update the label text when an element is + // selected. ntbm.label = lblSelected; - - JLabel lblSearch = new JLabel("");//Search - lblSearch.setIcon(IconFontSwing.buildIcon(FontAwesome.SEARCH,16, NopeOrange)); + + JLabel lblSearch = new JLabel("");// Search + lblSearch.setIcon(IconFontSwing.buildIcon(FontAwesome.SEARCH, 16, NopeOrange)); GridBagConstraints gbc_lblSearch = new GridBagConstraints(); gbc_lblSearch.anchor = GridBagConstraints.EAST; gbc_lblSearch.insets = new Insets(0, 0, 5, 5); gbc_lblSearch.gridx = 2; gbc_lblSearch.gridy = 0; panel_5.add(lblSearch, gbc_lblSearch); - + searchDb = new JTextField(); - + searchDb.addKeyListener(new KeyAdapter() { @Override public void keyPressed(KeyEvent arg0) { - if(arg0.getKeyCode() == arg0.VK_ENTER){ - if(!searchDb.getText().equals("")){ - int rowCount=ntbm.getRowCount(); - if(rowCount >0 ){ - for (int i=rowCount -1; i>=0; i--) { + if (arg0.getKeyCode() == arg0.VK_ENTER) { + if (!searchDb.getText().equals("")) { + int rowCount = ntbm.getRowCount(); + if (rowCount > 0) { + for (int i = rowCount - 1; i >= 0; i--) { ntbm.log.remove(i); // } } - //ntbm.fireTableRowsDeleted(0, rowCount-1); - //ntbm.fireTableDataChanged(); + // ntbm.fireTableRowsDeleted(0, rowCount-1); + // ntbm.fireTableDataChanged(); LinkedList list = LogEntry.searchDB(searchDb.getText().trim()); - for(LogEntry le : list){ + for (LogEntry le : list) { ntbm.log.add(le); } ntbm.fireTableDataChanged(); - }else{ - int rowCount=ntbm.getRowCount(); - if(rowCount >0 ){ - for (int i=rowCount -1; i>=0; i--) { + } else { + int rowCount = ntbm.getRowCount(); + if (rowCount > 0) { + for (int i = rowCount - 1; i >= 0; i--) { ntbm.log.remove(i); } } LinkedList list = LogEntry.restoreDB(); - for(LogEntry le : list){ + for (LogEntry le : list) { ntbm.log.add(le); - + } ntbm.fireTableDataChanged(); - + } } } @@ -816,7 +867,7 @@ public void keyPressed(KeyEvent arg0) { gbc_searchDb.gridy = 0; panel_5.add(searchDb, gbc_searchDb); searchDb.setColumns(10); - + JTabbedPane tabs = new JTabbedPane(); GridBagConstraints gbc_tabs = new GridBagConstraints(); gbc_tabs.anchor = GridBagConstraints.WEST; @@ -826,26 +877,17 @@ public void keyPressed(KeyEvent arg0) { gbc_tabs.gridx = 0; gbc_tabs.gridy = 1; panel_5.add(tabs, gbc_tabs); - - - //Decorate Tabs to match Burp message editor + // Decorate Tabs to match Burp message editor tabs.addTab("Message", ntbm.requestViewer.getComponent()); tabs.addTab("Original", ntbm.originalViewer.getComponent()); - - - - + Callbacks.customizeUiComponent(History); - - - - - - //##################################################################################### - // SetUp UI for Interceptor tab + + // ##################################################################################### + // SetUp UI for Interceptor tab btnIntercept = new JButton("Intercept is OFF"); - btnIntercept.setIcon(IconFontSwing.buildIcon(FontAwesome.EYE_SLASH,16, NopeRed)); + btnIntercept.setIcon(IconFontSwing.buildIcon(FontAwesome.EYE_SLASH, 16, NopeRed)); GridBagConstraints gbc_btnIntercept = new GridBagConstraints(); gbc_btnIntercept.anchor = GridBagConstraints.NORTHWEST; gbc_btnIntercept.insets = new Insets(0, 0, 0, 5); @@ -854,36 +896,38 @@ public void keyPressed(KeyEvent arg0) { panel_3.add(btnIntercept, gbc_btnIntercept); btnIntercept.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - boolean toggle=false; - if(btnIntercept.getText().endsWith("OFF")){ + boolean toggle = false; + if (btnIntercept.getText().endsWith("OFF")) { btnIntercept.setText("Intercept is ON"); - btnIntercept.setIcon(IconFontSwing.buildIcon(FontAwesome.EYE,16, NopeGreen)); - toggle=true; - }else{ + btnIntercept.setIcon(IconFontSwing.buildIcon(FontAwesome.EYE, 16, NopeGreen)); + toggle = true; + } else { btnIntercept.setText("Intercept is OFF"); - btnIntercept.setIcon(IconFontSwing.buildIcon(FontAwesome.EYE_SLASH,16, NopeRed)); - toggle=false; + btnIntercept.setIcon(IconFontSwing.buildIcon(FontAwesome.EYE_SLASH, 16, NopeRed)); + toggle = false; } - for(GenericMiTMServer svr : threads.values()){ + for (GenericMiTMServer svr : threads.values()) { svr.setIntercept(toggle); } - /*for(GenericUDPMiTMServer svr : threads.values()){ - svr.setIntercept(toggle); - }*/ + for(GenericUDPMiTMServer svr : udpThreads.values()){ + svr.setIntercept(toggle); + } + } }); btnIntercept.setBounds(878, 205, 117, 29); - JButton btnForward = new JButton("");//Forward - btnForward.setIcon(IconFontSwing.buildIcon(FontAwesome.FORWARD,16)); - //btnForward.setBackground(NopeGreen); + JButton btnForward = new JButton("");// Forward + btnForward.setIcon(IconFontSwing.buildIcon(FontAwesome.FORWARD, 16)); + // btnForward.setBackground(NopeGreen); btnForward.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { synchronized (intbm) { - isC2S.setBackground(UIManager.getColor("CheckBoxMenuItem.selectionBackground")); - isS2C.setBackground(UIManager.getColor("CheckBoxMenuItem.selectionBackground")); + //was selctionBackground + isC2S.setBackground(UIManager.getColor("CheckBoxMenuItem.background")); + isS2C.setBackground(UIManager.getColor("CheckBoxMenuItem.background")); intbm.notify(); } @@ -900,12 +944,12 @@ public void actionPerformed(ActionEvent arg0) { isC2S.setBackground(UIManager.getColor("InternalFrame.paletteBackground")); isC2S.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - for(GenericMiTMServer svr : threads.values()){ + for (GenericMiTMServer svr : threads.values()) { svr.setInterceptDir(svr.INTERCEPT_C2S); } - /*for(GenericUDPMiTMServer svr : threads.values()){ - svr.setInterceptDir(svr.INTERCEPT_C2S); - }*/ + for(GenericUDPMiTMServer svr : udpThreads.values()){ + svr.setInterceptDir(svr.INTERCEPT_C2S); + } } }); @@ -922,12 +966,12 @@ public void actionPerformed(ActionEvent e) { isS2C.setFont(new Font("Lucida Grande", Font.PLAIN, 13)); isS2C.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - for(GenericMiTMServer svr : threads.values()){ + for (GenericMiTMServer svr : threads.values()) { svr.setInterceptDir(svr.INTERCEPT_S2C); } - /*for(GenericUDPMiTMServer svr : threads.values()){ - svr.setInterceptDir(svr.INTERCEPT_S2C); - }*/ + for(GenericUDPMiTMServer svr : udpThreads.values()){ + svr.setInterceptDir(svr.INTERCEPT_S2C); + } } }); buttonGroup.add(isS2C); @@ -943,12 +987,12 @@ public void actionPerformed(ActionEvent e) { isBoth.setFont(new Font("Lucida Grande", Font.PLAIN, 14)); isBoth.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - for(GenericMiTMServer svr : threads.values()){ + for (GenericMiTMServer svr : threads.values()) { svr.setInterceptDir(svr.INTERCEPT_BOTH); } - /*for(GenericUDPMiTMServer svr : threads.values()){ - svr.setInterceptDir(svr.INTERCEPT_BOTH); - }*/ + for(GenericUDPMiTMServer svr : udpThreads.values()){ + svr.setInterceptDir(svr.INTERCEPT_BOTH); + } } }); buttonGroup.add(isBoth); @@ -960,14 +1004,14 @@ public void actionPerformed(ActionEvent e) { panel_3.add(isBoth, gbc_isBoth); isBoth.setSelected(true); isBoth.setBounds(800, 206, 66, 23); - + Component rigidArea = Box.createRigidArea(new Dimension(20, 20)); GridBagConstraints gbc_rigidArea = new GridBagConstraints(); gbc_rigidArea.insets = new Insets(0, 0, 0, 5); gbc_rigidArea.gridx = 6; gbc_rigidArea.gridy = 0; panel_3.add(rigidArea, gbc_rigidArea); - + Component rigidArea_2 = Box.createRigidArea(new Dimension(20, 20)); GridBagConstraints gbc_rigidArea_2 = new GridBagConstraints(); gbc_rigidArea_2.insets = new Insets(0, 0, 0, 5); @@ -982,93 +1026,87 @@ public void actionPerformed(ActionEvent e) { gbc_interceptInfo.gridx = 10; gbc_interceptInfo.gridy = 0; panel_3.add(interceptInfo, gbc_interceptInfo); - - + JTabbedPane interceptPane = new JTabbedPane(JTabbedPane.TOP); GridBagConstraints gbc_repeaterPane = new GridBagConstraints(); gbc_repeaterPane.fill = GridBagConstraints.BOTH; gbc_repeaterPane.gridx = 0; gbc_repeaterPane.gridy = 1; intbm = new NonHTTPTableModel(); - intbm.requestViewer = Callbacks.createMessageEditor(intbm,true); - - //This decorates the intercept tabs to be like brup message tables + intbm.requestViewer = Callbacks.createMessageEditor(intbm, true); + + // This decorates the intercept tabs to be like brup message tables interceptPane.addTab("Message", intbm.requestViewer.getComponent()); Intercept.add(interceptPane, gbc_repeaterPane); - + Callbacks.customizeUiComponent(Intercept); - - - - - //##################################################################################### + // ##################################################################################### // Finalizing Setup functions - - - if(AUTOSTART){ + + if (AUTOSTART) { btnStartDns.setText(""); // Stop DNS - btnStartDns.setIcon(IconFontSwing.buildIcon(FontAwesome.STOP,40)); - btnStartDns.setBackground(NopeGreen); ///Green + btnStartDns.setIcon(IconFontSwing.buildIcon(FontAwesome.STOP, 40)); + btnStartDns.setBackground(NopeGreen); /// Green isDNSRunning = true; - //lblStatusDNS.setText("DNS ON"); + // lblStatusDNS.setText("DNS ON"); } - if(this.getProperties("autostart","false").equals("true")) + if (this.getProperties("autostart", "false").equals("true")) chckbxStartDnsOn.setSelected(true); else chckbxStartDnsOn.setSelected(false); - + // Update the network interface information updateInterfaceInformation(); // order the tabs BurpTabs.addTab("TCP Intercept ", Intercept); BurpTabs.addTab("TCP History ", splitPane); - //BurpTabs.setIconAt(4,IconFontSwing.buildIcon(FontAwesome.HISTORY,20, NopeOrange)); - + // BurpTabs.setIconAt(4,IconFontSwing.buildIcon(FontAwesome.HISTORY,20, + // NopeOrange)); + JSplitPane RepeaterPanel = new JSplitPane(); RepeaterPanel.setOrientation(JSplitPane.VERTICAL_SPLIT); BurpTabs.addTab("TCP Repeater ", null, RepeaterPanel, null); - + JPanel Repeater = new JPanel(); RepeaterPanel.setLeftComponent(Repeater); - - - //BurpTabs.addTab("TCP Repeater ", null, Repeater, null); - //BurpTabs.setIconAt(2,IconFontSwing.buildIcon(FontAwesome.RECYCLE,20, NopePink)); + // BurpTabs.addTab("TCP Repeater ", null, Repeater, null); + // BurpTabs.setIconAt(2,IconFontSwing.buildIcon(FontAwesome.RECYCLE,20, + // NopePink)); GridBagLayout gbl_Repeater = new GridBagLayout(); - gbl_Repeater.columnWidths = new int[]{0, 492, 12, 90, 0, 0}; - gbl_Repeater.rowHeights = new int[]{28, 0, 0, 0, 0}; - gbl_Repeater.columnWeights = new double[]{1.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; - gbl_Repeater.rowWeights = new double[]{0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE}; + gbl_Repeater.columnWidths = new int[] { 0, 492, 12, 90, 0, 0 }; + gbl_Repeater.rowHeights = new int[] { 28, 0, 0, 0, 0 }; + gbl_Repeater.columnWeights = new double[] { 1.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; + gbl_Repeater.rowWeights = new double[] { 0.0, 0.0, 1.0, 0.0, Double.MIN_VALUE }; Repeater.setLayout(gbl_Repeater); - + JButton btnNewButton = new JButton("");// btnNewButton.setLayout(new BoxLayout(btnNewButton, BoxLayout.X_AXIS)); JLabel serverIconLabel = new JLabel(); - serverIconLabel.setIcon(IconFontSwing.buildIcon(FontAwesome.SERVER,18, NopePink)); + serverIconLabel.setIcon(IconFontSwing.buildIcon(FontAwesome.SERVER, 18, NopePink)); JLabel directionIconLabel = new JLabel(); - directionIconLabel.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_RIGHT,18, NopePink)); + directionIconLabel.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_RIGHT, 18, NopePink)); JLabel toSeverText = new JLabel(" To Server"); btnNewButton.add(directionIconLabel); btnNewButton.add(serverIconLabel); btnNewButton.add(toSeverText); - - + btnNewButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - if(currentListeners.getSelectedItem() != null){ - String selected = ""+currentListeners.getSelectedItem(); + if (currentListeners.getSelectedItem() != null) { + String selected = "" + currentListeners.getSelectedItem(); String portStr = selected.split("-")[0]; int port = Integer.parseInt(portStr.trim()); GenericMiTMServer x = threads.get(port); - //TODO: I need to match ephemeral ports here because there can be several threads on the same server. + // TODO: I need to match ephemeral ports here because there can be several + // threads on the same server. x.repeatToServer(repeater.getMessage(), port); } - + } }); - + JLabel lblClientAndServer = new JLabel("Client and Server must be connected for this to function properly"); lblClientAndServer.setFont(new Font("SansSerif", Font.ITALIC, 12)); GridBagConstraints gbc_lblClientAndServer = new GridBagConstraints(); @@ -1082,7 +1120,7 @@ public void actionPerformed(ActionEvent arg0) { gbc_btnNewButton.gridx = 3; gbc_btnNewButton.gridy = 0; Repeater.add(btnNewButton, gbc_btnNewButton); - + JLabel lblSelectAStream = new JLabel("Select A Stream to Repeat Request:"); lblSelectAStream.setFont(new Font("SansSerif", Font.BOLD, 12)); GridBagConstraints gbc_lblSelectAStream = new GridBagConstraints(); @@ -1091,7 +1129,7 @@ public void actionPerformed(ActionEvent arg0) { gbc_lblSelectAStream.gridx = 0; gbc_lblSelectAStream.gridy = 1; Repeater.add(lblSelectAStream, gbc_lblSelectAStream); - + currentListeners = new JComboBox(); GridBagConstraints gbc_currentListeners = new GridBagConstraints(); gbc_currentListeners.insets = new Insets(0, 0, 5, 5); @@ -1099,25 +1137,25 @@ public void actionPerformed(ActionEvent arg0) { gbc_currentListeners.gridx = 1; gbc_currentListeners.gridy = 1; Repeater.add(currentListeners, gbc_currentListeners); - + JButton btnSendToClient = new JButton("");/// Send to Client btnSendToClient.setLayout(new BoxLayout(btnSendToClient, BoxLayout.X_AXIS)); JLabel clientIconLabel = new JLabel(); - clientIconLabel.setIcon(IconFontSwing.buildIcon(GoogleMaterialDesignIcons.COMPUTER,18, NopeBlue)); + clientIconLabel.setIcon(IconFontSwing.buildIcon(GoogleMaterialDesignIcons.COMPUTER, 18, NopeBlue)); JLabel clientDirIconLabel = new JLabel(); - clientDirIconLabel.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_LEFT,18, NopeBlue)); + clientDirIconLabel.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_LEFT, 18, NopeBlue)); JLabel toClientText = new JLabel(" To Client"); btnSendToClient.add(clientIconLabel); btnSendToClient.add(clientDirIconLabel); btnSendToClient.add(toClientText); btnSendToClient.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - if(currentListeners.getSelectedItem() != null){ - String selected = ""+currentListeners.getSelectedItem(); + if (currentListeners.getSelectedItem() != null) { + String selected = "" + currentListeners.getSelectedItem(); String portStr = selected.split("-")[0]; int port = Integer.parseInt(portStr.trim()); GenericMiTMServer x = threads.get(port); - x.repeatToClient(repeater.getMessage(),port); + x.repeatToClient(repeater.getMessage(), port); } } }); @@ -1127,7 +1165,7 @@ public void actionPerformed(ActionEvent arg0) { gbc_btnSendToClient.gridx = 3; gbc_btnSendToClient.gridy = 1; Repeater.add(btnSendToClient, gbc_btnSendToClient); - + repeaterPane = new JTabbedPane(JTabbedPane.TOP); GridBagConstraints gbc_repeaterPane2 = new GridBagConstraints(); gbc_repeaterPane2.gridwidth = 2; @@ -1138,9 +1176,9 @@ public void actionPerformed(ActionEvent arg0) { RepeaterJPane repeaterJPane = new RepeaterJPane(); repeater = Callbacks.createMessageEditor(repeaterJPane, true); Repeater.add(repeaterPane, gbc_repeaterPane2); - + repeaterPane.addTab("Message", repeater.getComponent()); - + Component rigidArea_1 = Box.createRigidArea(new Dimension(20, 20)); GridBagConstraints gbc_rigidArea_1 = new GridBagConstraints(); gbc_rigidArea_1.fill = GridBagConstraints.VERTICAL; @@ -1148,16 +1186,16 @@ public void actionPerformed(ActionEvent arg0) { gbc_rigidArea_1.gridx = 4; gbc_rigidArea_1.gridy = 2; Repeater.add(rigidArea_1, gbc_rigidArea_1); - + JPanel genCodePanel = new JPanel(); RepeaterPanel.setRightComponent(genCodePanel); GridBagLayout gbl_genCodePanel = new GridBagLayout(); - gbl_genCodePanel.columnWidths = new int[]{0, 0, 0, 0}; - gbl_genCodePanel.rowHeights = new int[]{0, 0, 0, 0, 0}; - gbl_genCodePanel.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE}; - gbl_genCodePanel.rowWeights = new double[]{0.0, 0.0, 1.0, 1.0, Double.MIN_VALUE}; + gbl_genCodePanel.columnWidths = new int[] { 0, 0, 0, 0 }; + gbl_genCodePanel.rowHeights = new int[] { 0, 0, 0, 0, 0 }; + gbl_genCodePanel.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE }; + gbl_genCodePanel.rowWeights = new double[] { 0.0, 0.0, 1.0, 1.0, Double.MIN_VALUE }; genCodePanel.setLayout(gbl_genCodePanel); - + RSyntaxTextArea pyRepeaterCode = new RSyntaxTextArea(); pyRepeaterCode.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON); pyRepeaterCode.setCodeFoldingEnabled(true); @@ -1168,9 +1206,9 @@ public void actionPerformed(ActionEvent arg0) { ptscheme.getStyle(Token.FUNCTION).foreground = new Color(135, 211, 124); pyRepeaterCode.setHighlightCurrentLine(false); pyRepeaterCode.revalidate(); - + JLabel repeaterCodeLabel = new JLabel("Code Playground"); - repeaterCodeLabel.setIcon(IconFontSwing.buildIcon(FontAwesome.CODE,18, NopeGreen)); + repeaterCodeLabel.setIcon(IconFontSwing.buildIcon(FontAwesome.CODE, 18, NopeGreen)); GridBagConstraints gbc_repeaterCodeLabel = new GridBagConstraints(); gbc_repeaterCodeLabel.anchor = GridBagConstraints.WEST; gbc_repeaterCodeLabel.insets = new Insets(0, 0, 5, 5); @@ -1179,14 +1217,14 @@ public void actionPerformed(ActionEvent arg0) { genCodePanel.add(repeaterCodeLabel, gbc_repeaterCodeLabel); pyRepeaterCode.setBackground(new Color(44, 62, 80)); pyRepeaterCode.setForeground(Color.WHITE); - + GridBagConstraints gbc_pyRepeaterCode = new GridBagConstraints(); gbc_pyRepeaterCode.insets = new Insets(0, 0, 5, 5); gbc_pyRepeaterCode.fill = GridBagConstraints.BOTH; gbc_pyRepeaterCode.gridx = 1; gbc_pyRepeaterCode.gridy = 2; genCodePanel.add(pyRepeaterCode, gbc_pyRepeaterCode); - + JPanel panel_7 = new JPanel(); GridBagConstraints gbc_panel_7 = new GridBagConstraints(); gbc_panel_7.insets = new Insets(0, 0, 5, 0); @@ -1196,66 +1234,61 @@ public void actionPerformed(ActionEvent arg0) { gbc_panel_7.gridy = 2; genCodePanel.add(panel_7, gbc_panel_7); GridBagLayout gbl_panel_7 = new GridBagLayout(); - gbl_panel_7.columnWidths = new int[]{0, 0}; - gbl_panel_7.rowHeights = new int[]{0, 0, 0, 0}; - gbl_panel_7.columnWeights = new double[]{0.0, Double.MIN_VALUE}; - gbl_panel_7.rowWeights = new double[]{0.0, 0.0, 0.0, Double.MIN_VALUE}; + gbl_panel_7.columnWidths = new int[] { 0, 0 }; + gbl_panel_7.rowHeights = new int[] { 0, 0, 0, 0 }; + gbl_panel_7.columnWeights = new double[] { 0.0, Double.MIN_VALUE }; + gbl_panel_7.rowWeights = new double[] { 0.0, 0.0, 0.0, Double.MIN_VALUE }; panel_7.setLayout(gbl_panel_7); - + JButton rptGenCode = new JButton("Gen Code"); - rptGenCode.setIcon(IconFontSwing.buildIcon(FontAwesome.CODE,18, NopeGreen)); + rptGenCode.setIcon(IconFontSwing.buildIcon(FontAwesome.CODE, 18, NopeGreen)); GridBagConstraints gbc_rptGenCode = new GridBagConstraints(); gbc_rptGenCode.fill = GridBagConstraints.HORIZONTAL; gbc_rptGenCode.insets = new Insets(0, 0, 5, 0); gbc_rptGenCode.gridx = 0; gbc_rptGenCode.gridy = 0; panel_7.add(rptGenCode, gbc_rptGenCode); - - - - - + JButton btnServerCode = new JButton(""); // Repeater Code to Server btnServerCode.setLayout(new BoxLayout(btnServerCode, BoxLayout.X_AXIS)); JLabel serverIconLabel1 = new JLabel(); - serverIconLabel1.setIcon(IconFontSwing.buildIcon(FontAwesome.SERVER,18, NopePink)); + serverIconLabel1.setIcon(IconFontSwing.buildIcon(FontAwesome.SERVER, 18, NopePink)); JLabel directionIconLabel1 = new JLabel(); - directionIconLabel1.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_RIGHT,18, NopePink)); + directionIconLabel1.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_RIGHT, 18, NopePink)); JLabel toSeverText1 = new JLabel(" To Server"); btnServerCode.add(directionIconLabel1); btnServerCode.add(serverIconLabel1); btnServerCode.add(toSeverText1); - + btnServerCode.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { String code = pyRepeaterCode.getText(); - try{ + try { HashMap out = PythonMangler.runRepeaterCode(code); - if(out != null){ - byte [] bytes = (byte []) out.get("out"); + if (out != null) { + byte[] bytes = (byte[]) out.get("out"); repCodeOutput.setText(""); - if(currentListeners.getSelectedItem() != null && bytes != null){ - String selected = ""+currentListeners.getSelectedItem(); + if (currentListeners.getSelectedItem() != null && bytes != null) { + String selected = "" + currentListeners.getSelectedItem(); String portStr = selected.split("-")[0]; int port = Integer.parseInt(portStr.trim()); GenericMiTMServer x = threads.get(port); x.repeatToServer(bytes, port); } - String stdout = ""+out.get("stdout"); - String stderr = ""+out.get("stderr"); + String stdout = "" + out.get("stdout"); + String stderr = "" + out.get("stderr"); repCodeOutput.setText("###Standard Out: \n" + stdout + "\n\n###Standard Error:\n" + stderr); - }else{ + } else { repCodeOutput.setText(""); repCodeOutput.setText("Something is wrong with your code. Missing function sendPayload maybe?"); - + } - }catch(Exception ex){ + } catch (Exception ex) { repCodeOutput.setText(""); - repCodeOutput.setText(ex.getMessage()+"\n\nCast exceptions usually are cause becuase you are trying to return something that is not a byte array? \nexample: \n return bytearray('somestring') "); + repCodeOutput.setText(ex.getMessage() + + "\n\nCast exceptions usually are cause becuase you are trying to return something that is not a byte array? \nexample: \n return bytearray('somestring') "); } - - - + } }); GridBagConstraints gbc_btnServerCode = new GridBagConstraints(); @@ -1264,45 +1297,46 @@ public void actionPerformed(ActionEvent e) { gbc_btnServerCode.gridx = 0; gbc_btnServerCode.gridy = 1; panel_7.add(btnServerCode, gbc_btnServerCode); - + JButton btnClientCode = new JButton(""); // repeater code client btnClientCode.setLayout(new BoxLayout(btnClientCode, BoxLayout.X_AXIS)); JLabel clientIconLabel1 = new JLabel(); - clientIconLabel1.setIcon(IconFontSwing.buildIcon(GoogleMaterialDesignIcons.COMPUTER,18, NopeBlue)); + clientIconLabel1.setIcon(IconFontSwing.buildIcon(GoogleMaterialDesignIcons.COMPUTER, 18, NopeBlue)); JLabel clientDirIconLabel1 = new JLabel(); - clientDirIconLabel1.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_LEFT,18, NopeBlue)); + clientDirIconLabel1.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_LEFT, 18, NopeBlue)); JLabel toClientText1 = new JLabel(" To Client"); btnClientCode.add(clientIconLabel1); btnClientCode.add(clientDirIconLabel1); btnClientCode.add(toClientText1); - + btnClientCode.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { String code = pyRepeaterCode.getText(); - - try{ + + try { HashMap out = PythonMangler.runRepeaterCode(code); - if(out != null){ - byte [] bytes = (byte []) out.get("out"); + if (out != null) { + byte[] bytes = (byte[]) out.get("out"); repCodeOutput.setText(""); - if(currentListeners.getSelectedItem() != null && bytes != null){ - String selected = ""+currentListeners.getSelectedItem(); + if (currentListeners.getSelectedItem() != null && bytes != null) { + String selected = "" + currentListeners.getSelectedItem(); String portStr = selected.split("-")[0]; int port = Integer.parseInt(portStr.trim()); GenericMiTMServer x = threads.get(port); x.repeatToClient(bytes, port); } - String stdout = ""+out.get("stdout"); - String stderr = ""+out.get("stderr"); + String stdout = "" + out.get("stdout"); + String stderr = "" + out.get("stderr"); repCodeOutput.setText("###Standard Out: \n" + stdout + "\n\n###Standard Error:\n" + stderr); - }else{ + } else { repCodeOutput.setText(""); repCodeOutput.setText("Something is wrong with your code. Missing function sendPayload maybe?"); - + } - }catch(Exception ex){ + } catch (Exception ex) { repCodeOutput.setText(""); - repCodeOutput.setText(ex.getMessage()+"\n\nCast exceptions usually are cause becuase you are trying to return something that is not a byte array? \nexample: \n return bytearray('somestring') "); + repCodeOutput.setText(ex.getMessage() + + "\n\nCast exceptions usually are cause becuase you are trying to return something that is not a byte array? \nexample: \n return bytearray('somestring') "); } } }); @@ -1311,7 +1345,7 @@ public void actionPerformed(ActionEvent arg0) { gbc_btnClientCode.gridx = 0; gbc_btnClientCode.gridy = 2; panel_7.add(btnClientCode, gbc_btnClientCode); - + repCodeOutput = new RSyntaxTextArea(); repCodeOutput.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON); GridBagConstraints gbc_repCodeOutput = new GridBagConstraints(); @@ -1323,35 +1357,36 @@ public void actionPerformed(ActionEvent arg0) { repCodeOutput.setColumns(10); rptGenCode.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - if(repeater.getMessage() != null){ + if (repeater.getMessage() != null) { String code = PayloadAnalysis.createPyCode(repeater.getMessage()); - if(pyRepeaterCode.getText() == null || pyRepeaterCode.getText().trim().equals("")){ - code +="\n\n\ndef sendPayload():\n"; - code +=" return bytearray(payload)\n\n"; + if (pyRepeaterCode.getText() == null || pyRepeaterCode.getText().trim().equals("")) { + code += "\n\n\ndef sendPayload():\n"; + code += " return bytearray(payload)\n\n"; pyRepeaterCode.setText(code); - }else{ + } else { String currentCode = pyRepeaterCode.getText(); String newCode = currentCode.replaceFirst("^payload='.*'", code); pyRepeaterCode.setText(newCode); } } - + } }); - - + JPanel Automation = new JPanel(); BurpTabs.addTab("Automation ", null, Automation, null); - //BurpTabs.setIconAt(3,IconFontSwing.buildIcon(FontAwesome.CODE,20, NopeGreen)); - Automation.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Match and Replace Rules", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); + // BurpTabs.setIconAt(3,IconFontSwing.buildIcon(FontAwesome.CODE,20, + // NopeGreen)); + Automation.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), + "Match and Replace Rules", TitledBorder.LEADING, TitledBorder.TOP, null, new Color(0, 0, 0))); GridBagLayout gbl_Automation = new GridBagLayout(); - gbl_Automation.columnWidths = new int[]{472, 0}; - gbl_Automation.rowHeights = new int[]{0, 0}; - gbl_Automation.columnWeights = new double[]{1.0, Double.MIN_VALUE}; - gbl_Automation.rowWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_Automation.columnWidths = new int[] { 472, 0 }; + gbl_Automation.rowHeights = new int[] { 0, 0 }; + gbl_Automation.columnWeights = new double[] { 1.0, Double.MIN_VALUE }; + gbl_Automation.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; Automation.setLayout(gbl_Automation); PythonMangler pm = new PythonMangler(); - + JSplitPane splitPane_1 = new JSplitPane(); splitPane_1.setResizeWeight(0.5); splitPane_1.setOneTouchExpandable(true); @@ -1361,42 +1396,42 @@ public void actionPerformed(ActionEvent e) { gbc_splitPane_1.gridx = 0; gbc_splitPane_1.gridy = 0; Automation.add(splitPane_1, gbc_splitPane_1); - + JPanel panel_8 = new JPanel(); splitPane_1.setRightComponent(panel_8); GridBagLayout gbl_panel_8 = new GridBagLayout(); - gbl_panel_8.columnWidths = new int[]{0, 0, 0, 0, 0}; - gbl_panel_8.rowHeights = new int[]{0, 0, 0}; - gbl_panel_8.columnWeights = new double[]{0.0, 0.0, 1.0, 1.0, Double.MIN_VALUE}; - gbl_panel_8.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; + gbl_panel_8.columnWidths = new int[] { 0, 0, 0, 0, 0 }; + gbl_panel_8.rowHeights = new int[] { 0, 0, 0 }; + gbl_panel_8.columnWeights = new double[] { 0.0, 0.0, 1.0, 1.0, Double.MIN_VALUE }; + gbl_panel_8.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; panel_8.setLayout(gbl_panel_8); - + chckbxEnablePythonMangler = new JCheckBox("Enable Python Mangler"); GridBagConstraints gbc_chckbxEnablePythonMangler = new GridBagConstraints(); gbc_chckbxEnablePythonMangler.insets = new Insets(0, 0, 5, 5); gbc_chckbxEnablePythonMangler.gridx = 0; gbc_chckbxEnablePythonMangler.gridy = 0; panel_8.add(chckbxEnablePythonMangler, gbc_chckbxEnablePythonMangler); - + JButton btnImportPython = new JButton("Import Python"); - btnImportPython.setIcon(IconFontSwing.buildIcon(FontAwesome.FILE_CODE_O,16, NopeGreen)); + btnImportPython.setIcon(IconFontSwing.buildIcon(FontAwesome.FILE_CODE_O, 16, NopeGreen)); GridBagConstraints gbc_btnImportPython = new GridBagConstraints(); gbc_btnImportPython.insets = new Insets(0, 0, 5, 5); gbc_btnImportPython.gridx = 1; gbc_btnImportPython.gridy = 0; panel_8.add(btnImportPython, gbc_btnImportPython); - + JButton btnExportPython = new JButton("Export Python"); - btnExportPython.setIcon(IconFontSwing.buildIcon(FontAwesome.FILE_CODE_O,16, NopeBlue)); + btnExportPython.setIcon(IconFontSwing.buildIcon(FontAwesome.FILE_CODE_O, 16, NopeBlue)); GridBagConstraints gbc_btnExportPython = new GridBagConstraints(); gbc_btnExportPython.anchor = GridBagConstraints.WEST; gbc_btnExportPython.insets = new Insets(0, 0, 5, 5); gbc_btnExportPython.gridx = 2; gbc_btnExportPython.gridy = 0; panel_8.add(btnExportPython, gbc_btnExportPython); - + JButton btnClearConsole = new JButton("Clear Console"); - btnClearConsole.setIcon(IconFontSwing.buildIcon(FontAwesome.BAN,20, NopeRed)); + btnClearConsole.setIcon(IconFontSwing.buildIcon(FontAwesome.BAN, 20, NopeRed)); btnClearConsole.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { PythonConsole.setText(""); @@ -1408,7 +1443,7 @@ public void actionPerformed(ActionEvent arg0) { gbc_btnClearConsole.gridx = 3; gbc_btnClearConsole.gridy = 0; panel_8.add(btnClearConsole, gbc_btnClearConsole); - + JSplitPane splitPane_2 = new JSplitPane(); splitPane_2.setResizeWeight(0.5); GridBagConstraints gbc_splitPane_2 = new GridBagConstraints(); @@ -1417,15 +1452,13 @@ public void actionPerformed(ActionEvent arg0) { gbc_splitPane_2.gridx = 0; gbc_splitPane_2.gridy = 1; panel_8.add(splitPane_2, gbc_splitPane_2); - + JScrollPane scrollPane_2 = new JScrollPane(); splitPane_2.setLeftComponent(scrollPane_2); - - - + pythonText = new RSyntaxTextArea(); pythonText.setText(pm.getPyCode()); - //pythonText = new JEditorPane(); + // pythonText = new JEditorPane(); pythonText.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON); pythonText.setCodeFoldingEnabled(true); SyntaxScheme scheme = pythonText.getSyntaxScheme(); @@ -1433,11 +1466,9 @@ public void actionPerformed(ActionEvent arg0) { scheme.getStyle(Token.LITERAL_STRING_DOUBLE_QUOTE).foreground = new Color(253, 227, 167); scheme.getStyle(Token.OPERATOR).foreground = new Color(137, 196, 244); scheme.getStyle(Token.FUNCTION).foreground = new Color(135, 211, 124); - - pythonText.setHighlightCurrentLine(false); - + pythonText.revalidate(); pythonText.setBackground(new Color(44, 62, 80)); pythonText.setForeground(Color.WHITE); @@ -1450,28 +1481,27 @@ public void keyReleased(KeyEvent arg0) { pm.reload(); } }); - + scrollPane_2.setViewportView(pythonText); - - + JScrollPane scrollPane_3 = new JScrollPane(); splitPane_2.setRightComponent(scrollPane_3); - + PythonConsole = new JEditorPane(); PythonConsole.setEditable(false); PythonConsole.setContentType("text/html"); - + scrollPane_3.setViewportView(PythonConsole); - + JPanel panel_6 = new JPanel(); splitPane_1.setLeftComponent(panel_6); GridBagLayout gbl_panel_6 = new GridBagLayout(); - gbl_panel_6.columnWidths = new int[]{44, 12, 0}; - gbl_panel_6.rowHeights = new int[]{0, 0, 0}; - gbl_panel_6.columnWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; - gbl_panel_6.rowWeights = new double[]{0.0, 1.0, Double.MIN_VALUE}; + gbl_panel_6.columnWidths = new int[] { 44, 12, 0 }; + gbl_panel_6.rowHeights = new int[] { 0, 0, 0 }; + gbl_panel_6.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; + gbl_panel_6.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE }; panel_6.setLayout(gbl_panel_6); - + errorMsg = new JLabel(""); GridBagConstraints gbc_errorMsg = new GridBagConstraints(); gbc_errorMsg.fill = GridBagConstraints.HORIZONTAL; @@ -1480,7 +1510,7 @@ public void keyReleased(KeyEvent arg0) { gbc_errorMsg.gridy = 0; panel_6.add(errorMsg, gbc_errorMsg); errorMsg.setForeground(Color.RED); - + JScrollPane scrollPane = new JScrollPane(); GridBagConstraints gbc_scrollPane = new GridBagConstraints(); gbc_scrollPane.fill = GridBagConstraints.BOTH; @@ -1488,7 +1518,7 @@ public void keyReleased(KeyEvent arg0) { gbc_scrollPane.gridx = 0; gbc_scrollPane.gridy = 1; panel_6.add(scrollPane, gbc_scrollPane); - + txtRules = new RSyntaxTextArea(); txtRules.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_PYTHON); SyntaxScheme matchScheme = txtRules.getSyntaxScheme(); @@ -1497,10 +1527,9 @@ public void keyReleased(KeyEvent arg0) { matchScheme.getStyle(Token.OPERATOR).foreground = new Color(137, 196, 244); matchScheme.getStyle(Token.FUNCTION).foreground = new Color(135, 211, 124); txtRules.revalidate(); - pythonText.setHighlightCurrentLine(false); - + pythonText.revalidate(); txtRules.setTabSize(3); scrollPane.setViewportView(txtRules); @@ -1508,7 +1537,7 @@ public void keyReleased(KeyEvent arg0) { @Override public void keyReleased(KeyEvent e) { updateMatchRules(); - + } }); txtRules.setText(rules); @@ -1516,16 +1545,16 @@ public void keyReleased(KeyEvent e) { public void actionPerformed(ActionEvent arg0) { FileDialog fileDialog = new FileDialog(new Frame(), "Save", FileDialog.SAVE); fileDialog.setFilenameFilter(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".py"); - } + public boolean accept(File dir, String name) { + return name.endsWith(".py"); + } }); fileDialog.setVisible(true); - + String filename = fileDialog.getDirectory() + fileDialog.getFile(); - if(filename != null){ + if (filename != null) { File f = new File(filename); - if(!f.exists()){ + if (!f.exists()) { try { f.createNewFile(); } catch (IOException e) { @@ -1537,7 +1566,7 @@ public boolean accept(File dir, String name) { Charset charset = Charset.forName("UTF-8"); try (BufferedWriter writer = Files.newBufferedWriter(p, charset)) { writer.write(pythonText.getText()); - }catch(Exception ex){ + } catch (Exception ex) { ex.printStackTrace(); } } @@ -1547,61 +1576,60 @@ public boolean accept(File dir, String name) { public void actionPerformed(ActionEvent arg0) { FileDialog fileDialog = new FileDialog(new Frame(), "Import", FileDialog.LOAD); fileDialog.setFilenameFilter(new FilenameFilter() { - public boolean accept(File dir, String name) { - return name.endsWith(".py"); - } + public boolean accept(File dir, String name) { + return name.endsWith(".py"); + } }); fileDialog.setVisible(true); String filename = fileDialog.getDirectory() + fileDialog.getFile(); - if(filename != null){ + if (filename != null) { Path p = Paths.get(filename); - + try (BufferedReader reader = Files.newBufferedReader(p)) { String line = ""; - String code=""; - - while( (line = reader.readLine()) != null ){ + String code = ""; + + while ((line = reader.readLine()) != null) { code += line + "\r\n"; } pythonText.setText(code); PythonMangler pm = new PythonMangler(); pm.setPyCode(code); pm.reload(); - - - }catch(Exception ex){ + + } catch (Exception ex) { ex.printStackTrace(); } } - + } }); chckbxEnablePythonMangler.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { - for(GenericMiTMServer svr : threads.values()){ - svr.setPythonMange(chckbxEnablePythonMangler.isSelected()); + for (GenericMiTMServer svr : threads.values()) { + svr.setPythonMangle(chckbxEnablePythonMangler.isSelected()); pm.reload(); } - /*for(GenericUDPMiTMServer svr : threads.values()){ - svr.setPythonMange(chckbxEnablePythonMangler.isSelected()); - }*/ + + for (GenericUDPMiTMServer svr : udpThreads.values()) { + svr.setPythonMangle(chckbxEnablePythonMangler.isSelected()); + } + } }); - - - - //##################################################################################### + + // ##################################################################################### // Setup UI for DNS log JPanel DNSPanel = new JPanel(); GridBagLayout gbl_DNSPanel = new GridBagLayout(); - gbl_DNSPanel.columnWidths = new int[]{456, 0, 0, 0}; - gbl_DNSPanel.rowHeights = new int[]{406, 0}; - gbl_DNSPanel.columnWeights = new double[]{1.0, 0.0, 1.0, Double.MIN_VALUE}; - gbl_DNSPanel.rowWeights = new double[]{1.0, Double.MIN_VALUE}; + gbl_DNSPanel.columnWidths = new int[] { 456, 0, 0, 0 }; + gbl_DNSPanel.rowHeights = new int[] { 406, 0 }; + gbl_DNSPanel.columnWeights = new double[] { 1.0, 0.0, 1.0, Double.MIN_VALUE }; + gbl_DNSPanel.rowWeights = new double[] { 1.0, Double.MIN_VALUE }; DNSPanel.setLayout(gbl_DNSPanel); BurpTabs.addTab("DNS History ", null, DNSPanel, null); - //BurpTabs.setIconAt(0,IconFontSwing.buildIcon(FontAwesome.EYE,20, NopeBlue)); - + // BurpTabs.setIconAt(0,IconFontSwing.buildIcon(FontAwesome.EYE,20, NopeBlue)); + JScrollPane DNSRequests = new JScrollPane(); GridBagConstraints gbc_DNSRequests = new GridBagConstraints(); gbc_DNSRequests.fill = GridBagConstraints.BOTH; @@ -1609,611 +1637,631 @@ public void actionPerformed(ActionEvent arg0) { gbc_DNSRequests.gridx = 0; gbc_DNSRequests.gridy = 0; DNSPanel.add(DNSRequests, gbc_DNSRequests); - DnsListTable = new JTable(){ + DnsListTable = new JTable() { @Override public Class getColumnClass(int column) { switch (column) { - case 0: - return String.class; - case 1: - return String.class; - default: - return String.class; + case 0: + return String.class; + case 1: + return String.class; + default: + return String.class; } } }; DnsListTable.setFont(new Font("SansSerif", Font.PLAIN, 16)); - - DNSRequests.setViewportView(DnsListTable); - - Component rigidArea_3 = Box.createRigidArea(new Dimension(20, 20)); - GridBagConstraints gbc_rigidArea_3 = new GridBagConstraints(); - gbc_rigidArea_3.fill = GridBagConstraints.VERTICAL; - gbc_rigidArea_3.insets = new Insets(0, 0, 0, 5); - gbc_rigidArea_3.gridx = 1; - gbc_rigidArea_3.gridy = 0; - DNSPanel.add(rigidArea_3, gbc_rigidArea_3); - - JPanel panel_9 = new JPanel(); - GridBagConstraints gbc_panel_9 = new GridBagConstraints(); - gbc_panel_9.fill = GridBagConstraints.BOTH; - gbc_panel_9.gridx = 2; - gbc_panel_9.gridy = 0; - DNSPanel.add(panel_9, gbc_panel_9); - GridBagLayout gbl_panel_9 = new GridBagLayout(); - gbl_panel_9.columnWidths = new int[]{0, 0, 0}; - gbl_panel_9.rowHeights = new int[]{0, 0, 0, 0, 0}; - gbl_panel_9.columnWeights = new double[]{1.0, 0.0, Double.MIN_VALUE}; - gbl_panel_9.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE}; - panel_9.setLayout(gbl_panel_9); - - JButton btnPortMonitor = new JButton(""); - btnPortMonitor.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY,20)); - btnPortMonitor.setBackground(NopeGreen); - btnPortMonitor.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - if(lister == null){ - btnPortMonitor.setBackground(NopeRed); - btnPortMonitor.setIcon(IconFontSwing.buildIcon(FontAwesome.STOP,20)); - lister = new Lister( dnsIpTxt.getText()); - lister.addEventListener(new TCPConnectionAttemptListener(){ - DefaultTableModel model = (DefaultTableModel) portTable.getModel(); - - + + DNSRequests.setViewportView(DnsListTable); + + Component rigidArea_3 = Box.createRigidArea(new Dimension(20, 20)); + GridBagConstraints gbc_rigidArea_3 = new GridBagConstraints(); + gbc_rigidArea_3.fill = GridBagConstraints.VERTICAL; + gbc_rigidArea_3.insets = new Insets(0, 0, 0, 5); + gbc_rigidArea_3.gridx = 1; + gbc_rigidArea_3.gridy = 0; + DNSPanel.add(rigidArea_3, gbc_rigidArea_3); + + JPanel panel_9 = new JPanel(); + GridBagConstraints gbc_panel_9 = new GridBagConstraints(); + gbc_panel_9.fill = GridBagConstraints.BOTH; + gbc_panel_9.gridx = 2; + gbc_panel_9.gridy = 0; + DNSPanel.add(panel_9, gbc_panel_9); + GridBagLayout gbl_panel_9 = new GridBagLayout(); + gbl_panel_9.columnWidths = new int[] { 0, 0, 0 }; + gbl_panel_9.rowHeights = new int[] { 0, 0, 0, 0, 0 }; + gbl_panel_9.columnWeights = new double[] { 1.0, 0.0, Double.MIN_VALUE }; + gbl_panel_9.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE }; + panel_9.setLayout(gbl_panel_9); + + JButton btnPortMonitor = new JButton(""); + btnPortMonitor.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY, 20)); + btnPortMonitor.setBackground(NopeGreen); + btnPortMonitor.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + if (lister == null) { + btnPortMonitor.setBackground(NopeRed); + btnPortMonitor.setIcon(IconFontSwing.buildIcon(FontAwesome.STOP, 20)); + lister = new Lister(dnsIpTxt.getText()); + lister.addEventListener(new ConnectionAttemptListener() { + DefaultTableModel model = (DefaultTableModel) portTable.getModel(); + + @Override + public void ConnectAttempt(PortConnectEvt pkt) { + BurpTabs.setIconAt(4, + IconFontSwing.buildIcon(GoogleMaterialDesignIcons.PUBLIC, 20, NopeRed)); + Vector vec = new Vector(); + + vec.add(model.getRowCount()); + vec.add(1, pkt.getTime()); + vec.add(2, pkt.getSip()); + vec.add(3, pkt.getDport()); + vec.add(4, pkt.getProto()); + vec.add(5, pkt.getService()); + model.insertRow(0, vec); + Timer t = new Timer(); + t.schedule(new TimerTask() { @Override - public void TcpConnAttempt(TCPPacketEvt pkt) { - BurpTabs.setIconAt(4,IconFontSwing.buildIcon(GoogleMaterialDesignIcons.PUBLIC,20, NopeRed)); - Vector vec = new Vector(); - - vec.add(model.getRowCount()); - vec.add(1, pkt.getTime()); - vec.add(2, pkt.getSip()); - vec.add(3, pkt.getDport()); - vec.add(4, pkt.getService()); - model.addRow(vec); - Timer t = new Timer(); - t.schedule(new TimerTask() { - @Override - public void run() { - BurpTabs.setIconAt(4,IconFontSwing.buildIcon(GoogleMaterialDesignIcons.PUBLIC,20, NopePurple)); - } - }, 2*1000); - - + public void run() { + BurpTabs.setIconAt(4, + IconFontSwing.buildIcon(GoogleMaterialDesignIcons.PUBLIC, 20, NopePurple)); } - - }); - Thread listerThread = new Thread(lister); - listerThread.start(); - }else{ - lister.kill(); - lister = null; - btnPortMonitor.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY,20)); - - btnPortMonitor.setBackground(NopeGreen); + }, 2 * 1000); + } - } - }); - - JLabel lblPortMonitor = new JLabel("Port Monitor"); - Font portFont = UIManager.getFont("Label.font").deriveFont(Font.BOLD); - lblPortMonitor.setFont(portFont); - GridBagConstraints gbc_lblPortMonitor = new GridBagConstraints(); - gbc_lblPortMonitor.fill = GridBagConstraints.HORIZONTAL; - gbc_lblPortMonitor.insets = new Insets(0, 0, 5, 0); - gbc_lblPortMonitor.gridx = 1; - gbc_lblPortMonitor.gridy = 0; - panel_9.add(lblPortMonitor, gbc_lblPortMonitor); - - JLabel lblNewLabel_2 = new JLabel("Ensure you have libpcap or winpcap installed ."); - GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints(); - gbc_lblNewLabel_2.fill = GridBagConstraints.HORIZONTAL; - gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5); - gbc_lblNewLabel_2.gridx = 0; - gbc_lblNewLabel_2.gridy = 1; - panel_9.add(lblNewLabel_2, gbc_lblNewLabel_2); - GridBagConstraints gbc_btnPortMonitor = new GridBagConstraints(); - gbc_btnPortMonitor.fill = GridBagConstraints.HORIZONTAL; - gbc_btnPortMonitor.insets = new Insets(0, 0, 5, 0); - gbc_btnPortMonitor.gridx = 1; - gbc_btnPortMonitor.gridy = 1; - panel_9.add(btnPortMonitor, gbc_btnPortMonitor); - - JScrollPane scrollPane_4 = new JScrollPane(); - GridBagConstraints gbc_scrollPane_4 = new GridBagConstraints(); - gbc_scrollPane_4.gridwidth = 2; - gbc_scrollPane_4.fill = GridBagConstraints.BOTH; - gbc_scrollPane_4.gridx = 0; - gbc_scrollPane_4.gridy = 3; - panel_9.add(scrollPane_4, gbc_scrollPane_4); - - portTable = new JTable(); - portTable.setModel(new DefaultTableModel( - new Object[][] { - }, - new String[] { - "#", "Time", "Source IP", "Port", "Service" - } - )); - portTable.getColumnModel().getColumn(0).setMaxWidth(50); - portTable.setFont(new Font("SansSerif", Font.PLAIN, 16)); - scrollPane_4.setViewportView(portTable); - - dnstTbm = (DefaultTableModel)DnsListTable.getModel(); - String DNSheader[] = new String[]{"Time","Domain","Resolved Ip", "Client Address", "Client Name"}; - dnstTbm.setColumnIdentifiers(DNSheader); - - //BurpTabs.addTab("DNS History ", null, DNSRequests, null); - //BurpTabs.setIconAt(4,IconFontSwing.buildIcon(GoogleMaterialDesignIcons.PUBLIC,20, NopePurple)); + + }); + Thread listerThread = new Thread(lister); + listerThread.start(); + } else { + lister.kill(); + lister = null; + btnPortMonitor.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY, 20)); + + btnPortMonitor.setBackground(NopeGreen); + } + } + }); + + JLabel lblPortMonitor = new JLabel("Port Monitor"); + Font portFont = UIManager.getFont("Label.font").deriveFont(Font.BOLD); + lblPortMonitor.setFont(portFont); + GridBagConstraints gbc_lblPortMonitor = new GridBagConstraints(); + gbc_lblPortMonitor.fill = GridBagConstraints.HORIZONTAL; + gbc_lblPortMonitor.insets = new Insets(0, 0, 5, 0); + gbc_lblPortMonitor.gridx = 1; + gbc_lblPortMonitor.gridy = 0; + panel_9.add(lblPortMonitor, gbc_lblPortMonitor); + + JLabel lblNewLabel_2 = new JLabel("Ensure you have libpcap or winpcap installed ."); + GridBagConstraints gbc_lblNewLabel_2 = new GridBagConstraints(); + gbc_lblNewLabel_2.fill = GridBagConstraints.HORIZONTAL; + gbc_lblNewLabel_2.insets = new Insets(0, 0, 5, 5); + gbc_lblNewLabel_2.gridx = 0; + gbc_lblNewLabel_2.gridy = 1; + panel_9.add(lblNewLabel_2, gbc_lblNewLabel_2); + GridBagConstraints gbc_btnPortMonitor = new GridBagConstraints(); + gbc_btnPortMonitor.fill = GridBagConstraints.HORIZONTAL; + gbc_btnPortMonitor.insets = new Insets(0, 0, 5, 0); + gbc_btnPortMonitor.gridx = 1; + gbc_btnPortMonitor.gridy = 1; + panel_9.add(btnPortMonitor, gbc_btnPortMonitor); + + JScrollPane scrollPane_4 = new JScrollPane(); + GridBagConstraints gbc_scrollPane_4 = new GridBagConstraints(); + gbc_scrollPane_4.gridwidth = 2; + gbc_scrollPane_4.fill = GridBagConstraints.BOTH; + gbc_scrollPane_4.gridx = 0; + gbc_scrollPane_4.gridy = 3; + panel_9.add(scrollPane_4, gbc_scrollPane_4); + + portTable = new JTable(); + portTable.setModel(new DefaultTableModel( + new Object[][] { + }, + new String[] { + "#", "Time", "Source IP", "Port", "Proto", "Service" + })); + portTable.getColumnModel().getColumn(0).setMaxWidth(50); + portTable.setFont(new Font("SansSerif", Font.PLAIN, 16)); + scrollPane_4.setViewportView(portTable); + + dnstTbm = (DefaultTableModel) DnsListTable.getModel(); + String DNSheader[] = new String[] { "Time", "Domain", "Resolved Ip", "Client Address", "Client Name" }; + dnstTbm.setColumnIdentifiers(DNSheader); + + // BurpTabs.addTab("DNS History ", null, DNSRequests, null); + // BurpTabs.setIconAt(4,IconFontSwing.buildIcon(GoogleMaterialDesignIcons.PUBLIC,20, + // NopePurple)); BurpTabs.add("Server Config ", Options); - //BurpTabs.setIconAt(5,IconFontSwing.buildIcon(FontAwesome.COGS,20, NopePink)); - - //##################################################################################### - // Mitm Listner tables and controls for Options tab + // BurpTabs.setIconAt(5,IconFontSwing.buildIcon(FontAwesome.COGS,20, NopePink)); + + // ##################################################################################### + // Mitm Listner tables and controls for Options tab JPanel panel_1 = new JPanel(); - panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), "Non HTTP Proxy Settings", TitledBorder.LEADING, TitledBorder.TOP, null, UIManager.getColor("CheckBoxMenuItem.selectionBackground"))); + panel_1.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED, null, null), + "Non HTTP Proxy Settings", TitledBorder.LEADING, TitledBorder.TOP, null, + UIManager.getColor("CheckBoxMenuItem.selectionBackground"))); GridBagConstraints gbc_panel_1 = new GridBagConstraints(); gbc_panel_1.fill = GridBagConstraints.BOTH; gbc_panel_1.gridx = 0; gbc_panel_1.gridy = 1; Options.add(panel_1, gbc_panel_1); - GridBagLayout gbl_panel_1 = new GridBagLayout(); - gbl_panel_1.columnWidths = new int[]{85, 157, 141, 83, 75, 40, 133, 117, 117, 0}; - gbl_panel_1.rowHeights = new int[]{22, 28, 29, 0, 0}; - gbl_panel_1.columnWeights = new double[]{0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; - gbl_panel_1.rowWeights = new double[]{0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE}; - panel_1.setLayout(gbl_panel_1); - - /// Buttons for Clear History, export database, import database, add proxy, remove proxy - JButton btnAdd = new JButton("");//ADD Listener - btnAdd.setIcon(IconFontSwing.buildIcon(FontAwesome.PLUS_CIRCLE, 50, NopeGreen)); //Greeen - GridBagConstraints gbc_btnAdd = new GridBagConstraints(); - gbc_btnAdd.fill = GridBagConstraints.BOTH; - gbc_btnAdd.insets = new Insets(0, 0, 5, 5); - gbc_btnAdd.gridheight = 2; - gbc_btnAdd.gridx = 0; - gbc_btnAdd.gridy = 0; - panel_1.add(btnAdd, gbc_btnAdd); - btnAdd.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - int lPort = Integer.parseInt(LstnPort.getText()); - /*if(threads.containsKey(lPort)) - Callbacks.printOutput("Listener Already Exits"); - else{*/ - Vector vec = new Vector(); - - vec.add(false); - vec.add(LstnPort.getText()); - vec.add(SvrAddr.getText()); - vec.add(SvrPort.getText()); - vec.add(certName.getText()); - if(isSSL.isSelected()) - vec.add(true); - else - vec.add(false); - - tbm.addRow(vec); - int rowInserted=tbm.getRowCount()-1; - tbm.fireTableRowsInserted(rowInserted,rowInserted); - ListenerSetting ls = new ListenerSetting(Integer.parseInt(LstnPort.getText()), - Integer.parseInt(SvrPort.getText()), - SvrAddr.getText(), - certName.getText(), - isSSL.isSelected()); - - ListenerDB.add(ls); - - - - //} + GridBagLayout gbl_panel_1 = new GridBagLayout(); + gbl_panel_1.columnWidths = new int[] { 85, 157, 141, 83, 75, 40, 133, 117, 117, 0 }; + gbl_panel_1.rowHeights = new int[] { 22, 28, 29, 0, 0 }; + gbl_panel_1.columnWeights = new double[] { 0.0, 1.0, 1.0, 1.0, 1.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; + gbl_panel_1.rowWeights = new double[] { 0.0, 0.0, 0.0, 1.0, Double.MIN_VALUE }; + panel_1.setLayout(gbl_panel_1); + + /// Buttons for Clear History, export database, import database, add proxy, + /// remove proxy + JButton btnAdd = new JButton("");// ADD Listener + btnAdd.setIcon(IconFontSwing.buildIcon(FontAwesome.PLUS_CIRCLE, 50, NopeGreen)); // Greeen + GridBagConstraints gbc_btnAdd = new GridBagConstraints(); + gbc_btnAdd.fill = GridBagConstraints.BOTH; + gbc_btnAdd.insets = new Insets(0, 0, 5, 5); + gbc_btnAdd.gridheight = 2; + gbc_btnAdd.gridx = 0; + gbc_btnAdd.gridy = 0; + panel_1.add(btnAdd, gbc_btnAdd); + btnAdd.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + int lPort = Integer.parseInt(LstnPort.getText()); + /* + * if(threads.containsKey(lPort)) + * Callbacks.printOutput("Listener Already Exits"); + * else{ + */ + Vector vec = new Vector(); + + vec.add(false); // add Enabled + vec.add(LstnPort.getText()); + vec.add(SvrAddr.getText()); + vec.add(SvrPort.getText()); + vec.add(certName.getText()); + if (isSSL.isSelected()) + vec.add(true); + else + vec.add(false); + vec.add(false); // add isUDP + + tbm.addRow(vec); + int rowInserted = tbm.getRowCount() - 1; + tbm.fireTableRowsInserted(rowInserted, rowInserted); + ListenerSetting ls = new ListenerSetting( + Integer.parseInt(LstnPort.getText()), + Integer.parseInt(SvrPort.getText()), + SvrAddr.getText(), + certName.getText(), + isSSL.isSelected(), + false); + + ListenerDB.add(ls); + + // } + + } + + }); + + JLabel lblcertName = new JLabel("Certificate HostName:"); + GridBagConstraints gbc_lblcertName = new GridBagConstraints(); + gbc_lblcertName.anchor = GridBagConstraints.SOUTH; + gbc_lblcertName.fill = GridBagConstraints.HORIZONTAL; + gbc_lblcertName.insets = new Insets(0, 0, 5, 5); + gbc_lblcertName.gridx = 1; + gbc_lblcertName.gridy = 0; + panel_1.add(lblcertName, gbc_lblcertName); + + JLabel lblAddress = new JLabel("Server Address:"); + GridBagConstraints gbc_lblAddress = new GridBagConstraints(); + gbc_lblAddress.anchor = GridBagConstraints.SOUTHWEST; + gbc_lblAddress.insets = new Insets(0, 0, 5, 5); + gbc_lblAddress.gridx = 2; + gbc_lblAddress.gridy = 0; + panel_1.add(lblAddress, gbc_lblAddress); + + JLabel lblLstnPort = new JLabel("Server Port:"); + GridBagConstraints gbc_lblLstnPort = new GridBagConstraints(); + gbc_lblLstnPort.anchor = GridBagConstraints.SOUTH; + gbc_lblLstnPort.fill = GridBagConstraints.HORIZONTAL; + gbc_lblLstnPort.insets = new Insets(0, 0, 5, 5); + gbc_lblLstnPort.gridx = 3; + gbc_lblLstnPort.gridy = 0; + panel_1.add(lblLstnPort, gbc_lblLstnPort); + + JLabel lblPort = new JLabel("Listen Port:"); + GridBagConstraints gbc_lblPort = new GridBagConstraints(); + gbc_lblPort.anchor = GridBagConstraints.SOUTH; + gbc_lblPort.fill = GridBagConstraints.HORIZONTAL; + gbc_lblPort.insets = new Insets(0, 0, 5, 5); + gbc_lblPort.gridwidth = 2; + gbc_lblPort.gridx = 4; + gbc_lblPort.gridy = 0; + panel_1.add(lblPort, gbc_lblPort); + + isSSL = new JCheckBox("SSL - (Export Burp's CACert as pkcs12 with password 'changeit'. "); + // isSSL.setIcon(IconFontSwing.buildIcon(Elusive.LOCK_ALT,16)); + isSSL.setBackground(UIManager.getColor("ArrowButton.background")); + GridBagConstraints gbc_isSSL = new GridBagConstraints(); + gbc_isSSL.anchor = GridBagConstraints.NORTH; + gbc_isSSL.fill = GridBagConstraints.HORIZONTAL; + gbc_isSSL.insets = new Insets(0, 0, 5, 0); + gbc_isSSL.gridheight = 2; + gbc_isSSL.gridwidth = 4; + gbc_isSSL.gridx = 5; + gbc_isSSL.gridy = 0; + panel_1.add(isSSL, gbc_isSSL); + + certName = new JTextField(); + certName.setText("www.example.com"); + GridBagConstraints gbc_certName = new GridBagConstraints(); + gbc_certName.anchor = GridBagConstraints.NORTH; + gbc_certName.fill = GridBagConstraints.HORIZONTAL; + gbc_certName.insets = new Insets(0, 0, 5, 5); + gbc_certName.gridx = 1; + gbc_certName.gridy = 1; + panel_1.add(certName, gbc_certName); + certName.setColumns(10); + SvrAddr = new JTextField(); + SvrAddr.setText("127.0.0.1"); + GridBagConstraints gbc_SvrAddr = new GridBagConstraints(); + gbc_SvrAddr.anchor = GridBagConstraints.NORTH; + gbc_SvrAddr.fill = GridBagConstraints.HORIZONTAL; + gbc_SvrAddr.insets = new Insets(0, 0, 5, 5); + gbc_SvrAddr.gridx = 2; + gbc_SvrAddr.gridy = 1; + panel_1.add(SvrAddr, gbc_SvrAddr); + SvrAddr.setColumns(10); + + JButton btnImportHistory = new JButton("Import History"); + btnImportHistory.setIcon(IconFontSwing.buildIcon(FontAwesome.DATABASE, 16, NopeOrange)); + btnImportHistory.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + // String fs = System.getProperty("file.separator"); + // String resultFile = System.getProperty("user.dir") + fs +"requests.sqlite"; + String path = System.getProperty("user.home"); + String resultFile = path + "/.NoPEProxy/requests.sqlite"; + Frame fr = new Frame(); + FileDialog fd = new FileDialog(fr, "Import Database", FileDialog.LOAD); + fd.setVisible(true); + + String imported = fd.getDirectory() + fd.getFile(); + Path impPath = Paths.get(imported); + Path localPath = Paths.get(resultFile); + try { + HibHelper.getSessionFactory().close(); + Thread.sleep(2000); // wait for the threads to close + + Files.copy(impPath, localPath, StandardCopyOption.REPLACE_EXISTING); + // Delete The current table; + int rowCount = ntbm.getRowCount(); + if (rowCount > 0) { + for (int i = rowCount - 1; i >= 0; i--) { + ntbm.log.remove(i); + // ntbm.fireTableRowsDeleted(i, i); + } + } + int lrowCount = tbm.getRowCount(); + if (rowCount > 0) { + for (int i = lrowCount - 1; i >= 0; i--) { + tbm.removeRow(i); + + } + } + tbm.fireTableDataChanged(); + + HibHelper.renew(); + LinkedList list = LogEntry.restoreDB(); + for (LogEntry le : list) { + ntbm.log.add(le); + } + ntbm.fireTableDataChanged(); + + /// Restore Listener Settings + List settings = ListenerDB.restoreDB(); + for (ListenerSetting ls : settings) { + Vector vec = new Vector(); + vec.addElement(false); + vec.add(ls.getLport()); + vec.add(ls.getSip()); + vec.add(ls.getSport()); + vec.add(ls.getCert()); + vec.add(ls.isSsl()); + vec.add(ls.isUdp()); + tbm.addRow(vec); + + } + tbm.fireTableDataChanged(); + + } catch (IOException e1) { + Callbacks.printError(e1.getMessage()); + } catch (InterruptedException e1) { + // TODO Auto-generated catch block + e1.printStackTrace(); + } + + } + }); + + JButton btnRemoveProxy = new JButton("Remove Proxy"); + btnRemoveProxy.setIcon(IconFontSwing.buildIcon(FontAwesome.MINUS_CIRCLE, 23, NopeRed)); // red + + btnRemoveProxy.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + if (ListTable.getSelectedRow() != -1) { + int rowid = ListTable.getSelectedRow(); + int lPort = Integer.parseInt("" + tbm.getValueAt(rowid, 1)); + int sport = Integer.parseInt("" + tbm.getValueAt(rowid, 3)); + String cert = (String) tbm.getValueAt(rowid, 4); + String sip = (String) tbm.getValueAt(rowid, 2); + boolean ssl = (boolean) tbm.getValueAt(rowid, 5); + Boolean udp = (Boolean) tbm.getValueAt(rowid, 6); + if(udp == null){ + udp=false; + } + ListenerSetting ls = new ListenerSetting(lPort, sport, sip, cert, ssl, udp); + ListenerDB.remove(ls); + if (udp) { + GenericUDPMiTMServer mtm = ((GenericUDPMiTMServer) udpThreads.get(lPort)); + // GenericUDPMiTMServer mtm = ((GenericUDPMiTMServer)threads.get(lPort)); + if (mtm != null) { + mtm.KillThreads(); + udpThreads.remove(lPort); + } + + } else { + GenericMiTMServer mtm = ((GenericMiTMServer) threads.get(lPort)); + // GenericUDPMiTMServer mtm = ((GenericUDPMiTMServer)threads.get(lPort)); + if (mtm != null) { + mtm.KillThreads(); + threads.remove(lPort); + } + } + tbm.removeRow(rowid); + tbm.fireTableRowsDeleted(rowid, rowid); + + } + + } + }); + + SvrPort = new JTextField(); + SvrPort.setText("1001"); + GridBagConstraints gbc_SvrPort = new GridBagConstraints(); + gbc_SvrPort.anchor = GridBagConstraints.NORTH; + gbc_SvrPort.fill = GridBagConstraints.HORIZONTAL; + gbc_SvrPort.insets = new Insets(0, 0, 5, 5); + gbc_SvrPort.gridx = 3; + gbc_SvrPort.gridy = 1; + panel_1.add(SvrPort, gbc_SvrPort); + SvrPort.setColumns(10); + + LstnPort = new JTextField(); + LstnPort.setText("1000"); + GridBagConstraints gbc_LstnPort = new GridBagConstraints(); + gbc_LstnPort.anchor = GridBagConstraints.NORTH; + gbc_LstnPort.fill = GridBagConstraints.HORIZONTAL; + gbc_LstnPort.insets = new Insets(0, 0, 5, 5); + gbc_LstnPort.gridx = 4; + gbc_LstnPort.gridy = 1; + panel_1.add(LstnPort, gbc_LstnPort); + LstnPort.setColumns(10); + + lblNewLabel = new JLabel("Name the cert 'burpca.p12' in Burp's installation folder)"); + GridBagConstraints gbc_lblNewLabel = new GridBagConstraints(); + gbc_lblNewLabel.anchor = GridBagConstraints.NORTH; + gbc_lblNewLabel.fill = GridBagConstraints.HORIZONTAL; + gbc_lblNewLabel.insets = new Insets(0, 0, 5, 0); + gbc_lblNewLabel.gridwidth = 3; + gbc_lblNewLabel.gridx = 6; + gbc_lblNewLabel.gridy = 1; + panel_1.add(lblNewLabel, gbc_lblNewLabel); + GridBagConstraints gbc_btnRemoveProxy = new GridBagConstraints(); + gbc_btnRemoveProxy.anchor = GridBagConstraints.WEST; + gbc_btnRemoveProxy.fill = GridBagConstraints.VERTICAL; + gbc_btnRemoveProxy.insets = new Insets(0, 0, 5, 5); + gbc_btnRemoveProxy.gridwidth = 2; + gbc_btnRemoveProxy.gridx = 0; + gbc_btnRemoveProxy.gridy = 2; + panel_1.add(btnRemoveProxy, gbc_btnRemoveProxy); + + JButton btnAdd_1 = new JButton("Add 80 & 443 to Burp"); + btnAdd_1.setIcon(IconFontSwing.buildIcon(FontAwesome.COGS, 16, NopeOrange)); + btnAdd_1.setToolTipText("This addes invisible proxy listeners to Burp's normal HTTP proxy configureation."); + btnAdd_1.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent arg0) { + // This is used to automagicaly add 80 and 443 invisible proxy listeners to + // burp's normal HTTP traffic listernes. + // These ports are used with the DNS server to proxy HTTP requests normally + // through burp. + String config = Callbacks.saveConfigAsJson("proxy.request_listeners"); + JSONParser parser = new JSONParser(); + try { + JSONObject jsonObject = (JSONObject) parser.parse(config); + JSONArray listeners = (JSONArray) ((JSONObject) jsonObject.get("proxy")).get("request_listeners"); + JSONObject list80 = new JSONObject(); + list80.put("certificate_mode", "per_host"); + list80.put("running", true); + list80.put("support_invisible_proxying", true); + list80.put("listen_mode", "all_interfaces"); + list80.put("listener_port", 80); + JSONObject list443 = (JSONObject) parser.parse(list80.toJSONString()); + list443.put("listener_port", 443); + listeners.add(list80); + listeners.add(list443); + Callbacks.loadConfigFromJson(jsonObject.toJSONString()); + + } catch (ParseException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + // Callbacks.loadConfigFromJson(arg0); + + } + }); + GridBagConstraints gbc_btnAdd_1 = new GridBagConstraints(); + gbc_btnAdd_1.fill = GridBagConstraints.VERTICAL; + gbc_btnAdd_1.anchor = GridBagConstraints.EAST; + gbc_btnAdd_1.gridwidth = 2; + gbc_btnAdd_1.insets = new Insets(0, 0, 5, 5); + gbc_btnAdd_1.gridx = 3; + gbc_btnAdd_1.gridy = 2; + panel_1.add(btnAdd_1, gbc_btnAdd_1); + GridBagConstraints gbc_btnImportHistory = new GridBagConstraints(); + gbc_btnImportHistory.anchor = GridBagConstraints.EAST; + gbc_btnImportHistory.fill = GridBagConstraints.VERTICAL; + gbc_btnImportHistory.insets = new Insets(0, 0, 5, 5); + gbc_btnImportHistory.gridx = 6; + gbc_btnImportHistory.gridy = 2; + panel_1.add(btnImportHistory, gbc_btnImportHistory); + + JButton btnSaveHistory = new JButton("Export History"); + btnSaveHistory.setIcon(IconFontSwing.buildIcon(FontAwesome.DATABASE, 16, NopeBlue)); + btnSaveHistory.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + // String fs = System.getProperty("file.separator"); + // String file = System.getProperty("user.dir") + fs +"requests.sqlite"; + String path = System.getProperty("user.home"); + String file = path + "/.NoPEProxy/requests.sqlite"; + Frame fr = new Frame(); + FileDialog fd = new FileDialog(fr, "Export File", FileDialog.SAVE); + fd.setVisible(true); + + String exported = fd.getDirectory() + fd.getFile(); + Path old = Paths.get(file); + Path newFile = Paths.get(exported); + try { + Files.copy(old, newFile, StandardCopyOption.REPLACE_EXISTING); + } catch (IOException e1) { + Callbacks.printError(e1.getMessage()); + } + + } + }); + GridBagConstraints gbc_btnSaveHistory = new GridBagConstraints(); + gbc_btnSaveHistory.fill = GridBagConstraints.BOTH; + gbc_btnSaveHistory.insets = new Insets(0, 0, 5, 5); + gbc_btnSaveHistory.gridx = 7; + gbc_btnSaveHistory.gridy = 2; + panel_1.add(btnSaveHistory, gbc_btnSaveHistory); + + JButton btnClearHistory = new JButton("Clear History"); + btnClearHistory.setIcon(IconFontSwing.buildIcon(FontAwesome.DATABASE, 16, NopeRed)); + btnClearHistory.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + int rowCount = ntbm.getRowCount(); + if (rowCount <= 0) + return; + + for (int i = rowCount - 1; i >= 0; i--) { + ntbm.log.remove(i); + // ntbm.fireTableRowsDeleted(i, i); + } + LogEntry.clearTable(); + + } + }); + GridBagConstraints gbc_btnClearHistory = new GridBagConstraints(); + gbc_btnClearHistory.insets = new Insets(0, 0, 5, 0); + gbc_btnClearHistory.fill = GridBagConstraints.BOTH; + gbc_btnClearHistory.gridx = 8; + gbc_btnClearHistory.gridy = 2; + panel_1.add(btnClearHistory, gbc_btnClearHistory); + + JScrollPane scrollPane_1 = new JScrollPane(); + GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints(); + gbc_scrollPane_1.fill = GridBagConstraints.BOTH; + gbc_scrollPane_1.gridwidth = 9; + gbc_scrollPane_1.gridx = 0; + gbc_scrollPane_1.gridy = 3; + panel_1.add(scrollPane_1, gbc_scrollPane_1); + // Create the listener table and add it to the above scroll pane + ListTable = new JTable() { + @Override + public Class getColumnClass(int column) { + switch (column) { + case 0: + return Boolean.class; + case 1: + return Integer.class; + case 2: + return Integer.class; + case 3: + return String.class; + case 4: + return String.class; + case 5: + return Boolean.class; + case 6: + return Boolean.class; + default: + return String.class; + } + } + }; + ListTable.setFont(new Font("SansSerif", Font.PLAIN, 16)); + ListTable.setRowHeight(ListTable.getRowHeight() + 50); + scrollPane_1.setViewportView(ListTable); + ListTable.setModel(tbm); + ListTable.getColumnModel().getColumn(0).setMaxWidth(50);// enable + ListTable.getColumnModel().getColumn(1).setMaxWidth(100);// listener port + ListTable.getColumnModel().getColumn(3).setMaxWidth(100);// server port + ListTable.getColumnModel().getColumn(5).setMaxWidth(50);// ssl + ListTable.getColumnModel().getColumn(6).setMaxWidth(50);// ssl + + /// Restore Settings + List settings = ListenerDB.restoreDB(); + for (ListenerSetting ls : settings) { + Vector vec = new Vector(); + vec.addElement(false); + vec.add(ls.getLport()); + vec.add(ls.getSip()); + vec.add(ls.getSport()); + vec.add(ls.getCert()); + vec.add(ls.isSsl()); + vec.add(ls.isUdp()); + tbm.addRow(vec); + + } + tbm.fireTableDataChanged(); - } - - }); - - JLabel lblcertName = new JLabel("Certificate HostName:"); - GridBagConstraints gbc_lblcertName = new GridBagConstraints(); - gbc_lblcertName.anchor = GridBagConstraints.SOUTH; - gbc_lblcertName.fill = GridBagConstraints.HORIZONTAL; - gbc_lblcertName.insets = new Insets(0, 0, 5, 5); - gbc_lblcertName.gridx = 1; - gbc_lblcertName.gridy = 0; - panel_1.add(lblcertName, gbc_lblcertName); - - - - JLabel lblAddress = new JLabel("Server Address:"); - GridBagConstraints gbc_lblAddress = new GridBagConstraints(); - gbc_lblAddress.anchor = GridBagConstraints.SOUTHWEST; - gbc_lblAddress.insets = new Insets(0, 0, 5, 5); - gbc_lblAddress.gridx = 2; - gbc_lblAddress.gridy = 0; - panel_1.add(lblAddress, gbc_lblAddress); - - JLabel lblLstnPort = new JLabel("Server Port:"); - GridBagConstraints gbc_lblLstnPort = new GridBagConstraints(); - gbc_lblLstnPort.anchor = GridBagConstraints.SOUTH; - gbc_lblLstnPort.fill = GridBagConstraints.HORIZONTAL; - gbc_lblLstnPort.insets = new Insets(0, 0, 5, 5); - gbc_lblLstnPort.gridx = 3; - gbc_lblLstnPort.gridy = 0; - panel_1.add(lblLstnPort, gbc_lblLstnPort); - - JLabel lblPort = new JLabel("Listen Port:"); - GridBagConstraints gbc_lblPort = new GridBagConstraints(); - gbc_lblPort.anchor = GridBagConstraints.SOUTH; - gbc_lblPort.fill = GridBagConstraints.HORIZONTAL; - gbc_lblPort.insets = new Insets(0, 0, 5, 5); - gbc_lblPort.gridwidth = 2; - gbc_lblPort.gridx = 4; - gbc_lblPort.gridy = 0; - panel_1.add(lblPort, gbc_lblPort); - - isSSL = new JCheckBox("SSL - (Export Burp's CACert as pkcs12 with password 'changeit'. "); - //isSSL.setIcon(IconFontSwing.buildIcon(Elusive.LOCK_ALT,16)); - isSSL.setBackground(UIManager.getColor("ArrowButton.background")); - GridBagConstraints gbc_isSSL = new GridBagConstraints(); - gbc_isSSL.anchor = GridBagConstraints.NORTH; - gbc_isSSL.fill = GridBagConstraints.HORIZONTAL; - gbc_isSSL.insets = new Insets(0, 0, 5, 0); - gbc_isSSL.gridheight = 2; - gbc_isSSL.gridwidth = 4; - gbc_isSSL.gridx = 5; - gbc_isSSL.gridy = 0; - panel_1.add(isSSL, gbc_isSSL); - - certName = new JTextField(); - certName.setText("www.example.com"); - GridBagConstraints gbc_certName = new GridBagConstraints(); - gbc_certName.anchor = GridBagConstraints.NORTH; - gbc_certName.fill = GridBagConstraints.HORIZONTAL; - gbc_certName.insets = new Insets(0, 0, 5, 5); - gbc_certName.gridx = 1; - gbc_certName.gridy = 1; - panel_1.add(certName, gbc_certName); - certName.setColumns(10); - SvrAddr = new JTextField(); - SvrAddr.setText("127.0.0.1"); - GridBagConstraints gbc_SvrAddr = new GridBagConstraints(); - gbc_SvrAddr.anchor = GridBagConstraints.NORTH; - gbc_SvrAddr.fill = GridBagConstraints.HORIZONTAL; - gbc_SvrAddr.insets = new Insets(0, 0, 5, 5); - gbc_SvrAddr.gridx = 2; - gbc_SvrAddr.gridy = 1; - panel_1.add(SvrAddr, gbc_SvrAddr); - SvrAddr.setColumns(10); - - JButton btnImportHistory = new JButton("Import History"); - btnImportHistory.setIcon(IconFontSwing.buildIcon(FontAwesome.DATABASE,16, NopeOrange)); - btnImportHistory.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - //String fs = System.getProperty("file.separator"); - //String resultFile = System.getProperty("user.dir") + fs +"requests.sqlite"; - String path = System.getProperty("user.home"); - String resultFile = path + "/.NoPEProxy/requests.sqlite"; - Frame fr = new Frame(); - FileDialog fd = new FileDialog(fr,"Import Database", FileDialog.LOAD); - fd.setVisible(true); - - String imported = fd.getDirectory() + fd.getFile(); - Path impPath = Paths.get(imported); - Path localPath = Paths.get(resultFile); - try { - HibHelper.getSessionFactory().close(); - Thread.sleep(2000); // wait for the threads to close - - Files.copy(impPath, localPath, StandardCopyOption.REPLACE_EXISTING); - //Delete The current table; - int rowCount=ntbm.getRowCount(); - if(rowCount >0 ){ - for (int i=rowCount -1; i>=0; i--) { - ntbm.log.remove(i); - //ntbm.fireTableRowsDeleted(i, i); - } - } - int lrowCount = tbm.getRowCount(); - if(rowCount > 0){ - for (int i=lrowCount -1; i>=0; i--) { - tbm.removeRow(i); - - } - } - tbm.fireTableDataChanged(); - - HibHelper.renew(); - LinkedList list = LogEntry.restoreDB(); - for(LogEntry le : list){ - ntbm.log.add(le); - } - ntbm.fireTableDataChanged(); - - ///Restore Listener Settings - List settings = ListenerDB.restoreDB(); - for(ListenerSetting ls : settings){ - Vector vec = new Vector(); - vec.addElement(false); - vec.add(ls.getLport()); - vec.add(ls.getSip()); - vec.add(ls.getSport()); - vec.add(ls.getCert()); - vec.add(ls.isSsl()); - tbm.addRow(vec); - - } - tbm.fireTableDataChanged(); - - - - } catch (IOException e1) { - Callbacks.printError(e1.getMessage()); - } catch (InterruptedException e1) { - // TODO Auto-generated catch block - e1.printStackTrace(); - } - - } - }); - - JButton btnRemoveProxy = new JButton("Remove Proxy"); - btnRemoveProxy.setIcon(IconFontSwing.buildIcon(FontAwesome.MINUS_CIRCLE, 23, NopeRed)); //red - - btnRemoveProxy.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - if(ListTable.getSelectedRow() != -1){ - int rowid = ListTable.getSelectedRow(); - int lPort = Integer.parseInt("" + tbm.getValueAt(rowid, 1)); - int sport = Integer.parseInt("" + tbm.getValueAt(rowid, 3)); - String cert = (String)tbm.getValueAt(rowid, 4); - String sip = (String)tbm.getValueAt(rowid, 2); - boolean ssl = (boolean)tbm.getValueAt(rowid, 5); - ListenerSetting ls = new ListenerSetting(lPort, sport, sip, cert, ssl); - ListenerDB.remove(ls); - GenericMiTMServer mtm = ((GenericMiTMServer)threads.get(lPort)); - //GenericUDPMiTMServer mtm = ((GenericUDPMiTMServer)threads.get(lPort)); - if(mtm != null){ - mtm.KillThreads(); - threads.remove(lPort); - } - tbm.removeRow(rowid); - tbm.fireTableRowsDeleted(rowid, rowid); - - } - - } - }); - - SvrPort = new JTextField(); - SvrPort.setText("1001"); - GridBagConstraints gbc_SvrPort = new GridBagConstraints(); - gbc_SvrPort.anchor = GridBagConstraints.NORTH; - gbc_SvrPort.fill = GridBagConstraints.HORIZONTAL; - gbc_SvrPort.insets = new Insets(0, 0, 5, 5); - gbc_SvrPort.gridx = 3; - gbc_SvrPort.gridy = 1; - panel_1.add(SvrPort, gbc_SvrPort); - SvrPort.setColumns(10); - - LstnPort = new JTextField(); - LstnPort.setText("1000"); - GridBagConstraints gbc_LstnPort = new GridBagConstraints(); - gbc_LstnPort.anchor = GridBagConstraints.NORTH; - gbc_LstnPort.fill = GridBagConstraints.HORIZONTAL; - gbc_LstnPort.insets = new Insets(0, 0, 5, 5); - gbc_LstnPort.gridx = 4; - gbc_LstnPort.gridy = 1; - panel_1.add(LstnPort, gbc_LstnPort); - LstnPort.setColumns(10); - - lblNewLabel = new JLabel("Name the cert 'burpca.p12' in Burp's installation folder)"); - GridBagConstraints gbc_lblNewLabel = new GridBagConstraints(); - gbc_lblNewLabel.anchor = GridBagConstraints.NORTH; - gbc_lblNewLabel.fill = GridBagConstraints.HORIZONTAL; - gbc_lblNewLabel.insets = new Insets(0, 0, 5, 0); - gbc_lblNewLabel.gridwidth = 3; - gbc_lblNewLabel.gridx = 6; - gbc_lblNewLabel.gridy = 1; - panel_1.add(lblNewLabel, gbc_lblNewLabel); - GridBagConstraints gbc_btnRemoveProxy = new GridBagConstraints(); - gbc_btnRemoveProxy.anchor = GridBagConstraints.WEST; - gbc_btnRemoveProxy.fill = GridBagConstraints.VERTICAL; - gbc_btnRemoveProxy.insets = new Insets(0, 0, 5, 5); - gbc_btnRemoveProxy.gridwidth = 2; - gbc_btnRemoveProxy.gridx = 0; - gbc_btnRemoveProxy.gridy = 2; - panel_1.add(btnRemoveProxy, gbc_btnRemoveProxy); - - JButton btnAdd_1 = new JButton("Add 80 & 443 to Burp"); - btnAdd_1.setIcon(IconFontSwing.buildIcon(FontAwesome.COGS,16, NopeOrange)); - btnAdd_1.setToolTipText("This addes invisible proxy listeners to Burp's normal HTTP proxy configureation."); - btnAdd_1.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent arg0) { - //This is used to automagicaly add 80 and 443 invisible proxy listeners to burp's normal HTTP traffic listernes. - // These ports are used with the DNS server to proxy HTTP requests normally through burp. - String config = Callbacks.saveConfigAsJson("proxy.request_listeners"); - JSONParser parser = new JSONParser(); - try { - JSONObject jsonObject = (JSONObject) parser.parse(config); - JSONArray listeners = (JSONArray)((JSONObject)jsonObject.get("proxy")).get("request_listeners"); - JSONObject list80 = new JSONObject(); - list80.put("certificate_mode", "per_host"); - list80.put("running", true); - list80.put("support_invisible_proxying", true); - list80.put("listen_mode", "all_interfaces"); - list80.put("listener_port", 80); - JSONObject list443 = (JSONObject) parser.parse(list80.toJSONString()); - list443.put("listener_port", 443); - listeners.add(list80); - listeners.add(list443); - Callbacks.loadConfigFromJson(jsonObject.toJSONString()); - - - } catch (ParseException e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - - //Callbacks.loadConfigFromJson(arg0); - - } - }); - GridBagConstraints gbc_btnAdd_1 = new GridBagConstraints(); - gbc_btnAdd_1.fill = GridBagConstraints.VERTICAL; - gbc_btnAdd_1.anchor = GridBagConstraints.EAST; - gbc_btnAdd_1.gridwidth = 2; - gbc_btnAdd_1.insets = new Insets(0, 0, 5, 5); - gbc_btnAdd_1.gridx = 3; - gbc_btnAdd_1.gridy = 2; - panel_1.add(btnAdd_1, gbc_btnAdd_1); - GridBagConstraints gbc_btnImportHistory = new GridBagConstraints(); - gbc_btnImportHistory.anchor = GridBagConstraints.EAST; - gbc_btnImportHistory.fill = GridBagConstraints.VERTICAL; - gbc_btnImportHistory.insets = new Insets(0, 0, 5, 5); - gbc_btnImportHistory.gridx = 6; - gbc_btnImportHistory.gridy = 2; - panel_1.add(btnImportHistory, gbc_btnImportHistory); - - JButton btnSaveHistory = new JButton("Export History"); - btnSaveHistory.setIcon(IconFontSwing.buildIcon(FontAwesome.DATABASE,16, NopeBlue)); - btnSaveHistory.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - //String fs = System.getProperty("file.separator"); - //String file = System.getProperty("user.dir") + fs +"requests.sqlite"; - String path = System.getProperty("user.home"); - String file = path + "/.NoPEProxy/requests.sqlite"; - Frame fr = new Frame(); - FileDialog fd = new FileDialog(fr,"Export File", FileDialog.SAVE); - fd.setVisible(true); - - String exported = fd.getDirectory() + fd.getFile(); - Path old = Paths.get(file); - Path newFile = Paths.get(exported); - try { - Files.copy(old, newFile, StandardCopyOption.REPLACE_EXISTING); - } catch (IOException e1) { - Callbacks.printError(e1.getMessage()); - } - - - - } - }); - GridBagConstraints gbc_btnSaveHistory = new GridBagConstraints(); - gbc_btnSaveHistory.fill = GridBagConstraints.BOTH; - gbc_btnSaveHistory.insets = new Insets(0, 0, 5, 5); - gbc_btnSaveHistory.gridx = 7; - gbc_btnSaveHistory.gridy = 2; - panel_1.add(btnSaveHistory, gbc_btnSaveHistory); - - JButton btnClearHistory = new JButton("Clear History"); - btnClearHistory.setIcon(IconFontSwing.buildIcon(FontAwesome.DATABASE,16, NopeRed)); - btnClearHistory.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - int rowCount=ntbm.getRowCount(); - if(rowCount <=0) - return; - - for (int i=rowCount -1; i>=0; i--) { - ntbm.log.remove(i); - //ntbm.fireTableRowsDeleted(i, i); - } - LogEntry.clearTable(); - - } - }); - GridBagConstraints gbc_btnClearHistory = new GridBagConstraints(); - gbc_btnClearHistory.insets = new Insets(0, 0, 5, 0); - gbc_btnClearHistory.fill = GridBagConstraints.BOTH; - gbc_btnClearHistory.gridx = 8; - gbc_btnClearHistory.gridy = 2; - panel_1.add(btnClearHistory, gbc_btnClearHistory); - - JScrollPane scrollPane_1 = new JScrollPane(); - GridBagConstraints gbc_scrollPane_1 = new GridBagConstraints(); - gbc_scrollPane_1.fill = GridBagConstraints.BOTH; - gbc_scrollPane_1.gridwidth = 9; - gbc_scrollPane_1.gridx = 0; - gbc_scrollPane_1.gridy = 3; - panel_1.add(scrollPane_1, gbc_scrollPane_1); - // Create the listener table and add it to the above scroll pane - ListTable = new JTable(){ - @Override - public Class getColumnClass(int column) { - switch (column) { - case 0: - return Boolean.class; - case 1: - return Integer.class; - case 2: - return Integer.class; - case 3: - return String.class; - case 4: - return String.class; - case 5: - return Boolean.class; - default: - return String.class; - } - } - }; - ListTable.setFont(new Font("SansSerif", Font.PLAIN, 16)); - ListTable.setRowHeight(ListTable.getRowHeight()+50); - scrollPane_1.setViewportView(ListTable); - ListTable.setModel(tbm); - ListTable.getColumnModel().getColumn(0).setMaxWidth(50);//enable - ListTable.getColumnModel().getColumn(1).setMaxWidth(100);//listener port - ListTable.getColumnModel().getColumn(3).setMaxWidth(100);//server port - ListTable.getColumnModel().getColumn(5).setMaxWidth(50);//ssl - - ///Restore Settings - List settings = ListenerDB.restoreDB(); - for(ListenerSetting ls : settings){ - Vector vec = new Vector(); - vec.addElement(false); - vec.add(ls.getLport()); - vec.add(ls.getSip()); - vec.add(ls.getSport()); - vec.add(ls.getCert()); - vec.add(ls.isSsl()); - tbm.addRow(vec); - - } - tbm.fireTableDataChanged(); - - - JPanel About = new JPanel(); - BurpTabs.addTab("About ", IconFontSwing.buildIcon(FontAwesome.INFO,16, NopeGrey), About, null); + BurpTabs.addTab("About ", IconFontSwing.buildIcon(FontAwesome.INFO, 16, NopeGrey), About, null); GridBagLayout gbl_About = new GridBagLayout(); - gbl_About.columnWidths = new int[]{0, 0, 0, 0}; - gbl_About.rowHeights = new int[]{0, 0, 0, 0, 0, 0, 0, 0}; - gbl_About.columnWeights = new double[]{0.0, 1.0, 0.0, Double.MIN_VALUE}; - gbl_About.rowWeights = new double[]{0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE}; + gbl_About.columnWidths = new int[] { 0, 0, 0, 0 }; + gbl_About.rowHeights = new int[] { 0, 0, 0, 0, 0, 0, 0, 0 }; + gbl_About.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE }; + gbl_About.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, Double.MIN_VALUE }; About.setLayout(gbl_About); - + JLabel lblNopeProxy = new JLabel("NOn Http Protocol Extending (NoPE) Proxy"); GridBagConstraints gbc_lblNopeProxy = new GridBagConstraints(); gbc_lblNopeProxy.insets = new Insets(0, 0, 5, 5); gbc_lblNopeProxy.gridx = 1; gbc_lblNopeProxy.gridy = 1; About.add(lblNopeProxy, gbc_lblNopeProxy); - + JLabel lblVersion = new JLabel("Version 1.5.2"); GridBagConstraints gbc_lblVersion = new GridBagConstraints(); gbc_lblVersion.insets = new Insets(0, 0, 5, 5); gbc_lblVersion.gridx = 1; gbc_lblVersion.gridy = 2; About.add(lblVersion, gbc_lblVersion); - - JLabel lblDevelopedByJosh = new JLabel("Developed By: Josh Summitt - @Null0perat0r@defcon.social - josh@factionsecurity.com"); + + JLabel lblDevelopedByJosh = new JLabel( + "Developed By: Josh Summitt - @Null0perat0r@defcon.social - josh@factionsecurity.com"); lblDevelopedByJosh.addMouseListener(new MouseListener() { - + @Override public void mouseReleased(MouseEvent e) { // TODO Auto-generated method stub - + } - + @Override public void mousePressed(MouseEvent evt) { try { @@ -2225,25 +2273,25 @@ public void mousePressed(MouseEvent evt) { // TODO Auto-generated catch block e.printStackTrace(); } - + } - + @Override public void mouseExited(MouseEvent e) { // TODO Auto-generated method stub - + } - + @Override public void mouseEntered(MouseEvent e) { // TODO Auto-generated method stub - + } - + @Override public void mouseClicked(MouseEvent e) { // TODO Auto-generated method stub - + } }); GridBagConstraints gbc_lblDevelopedByJosh = new GridBagConstraints(); @@ -2251,7 +2299,7 @@ public void mouseClicked(MouseEvent e) { gbc_lblDevelopedByJosh.gridx = 1; gbc_lblDevelopedByJosh.gridy = 4; About.add(lblDevelopedByJosh, gbc_lblDevelopedByJosh); - + JButton btnHttpgithubcomsummitt = new JButton("https://github.com/summitt"); Icon ghicon = IconFontSwing.buildIcon(Elusive.GITHUB, 23); btnHttpgithubcomsummitt.setIcon(ghicon); @@ -2273,41 +2321,37 @@ public void actionPerformed(ActionEvent arg0) { gbc_btnHttpgithubcomsummitt.gridx = 1; gbc_btnHttpgithubcomsummitt.gridy = 6; About.add(btnHttpgithubcomsummitt, gbc_btnHttpgithubcomsummitt); - - BurpTabs.setIconAt(0,IconFontSwing.buildIcon(FontAwesome.EYE,20, NopeBlue)); - BurpTabs.setIconAt(1,IconFontSwing.buildIcon(FontAwesome.HISTORY,20, NopeOrange)); - BurpTabs.setIconAt(2,IconFontSwing.buildIcon(FontAwesome.RECYCLE,20, NopePink)); - BurpTabs.setIconAt(3,IconFontSwing.buildIcon(FontAwesome.CODE,20, NopeGreen)); - BurpTabs.setIconAt(4,IconFontSwing.buildIcon(GoogleMaterialDesignIcons.PUBLIC,20, NopePurple)); - BurpTabs.setIconAt(5,IconFontSwing.buildIcon(FontAwesome.COGS,20, NopeRed)); - BurpTabs.setIconAt(6,IconFontSwing.buildIcon(FontAwesome.INFO,20, NopeGrey)); - - + + BurpTabs.setIconAt(0, IconFontSwing.buildIcon(FontAwesome.EYE, 20, NopeBlue)); + BurpTabs.setIconAt(1, IconFontSwing.buildIcon(FontAwesome.HISTORY, 20, NopeOrange)); + BurpTabs.setIconAt(2, IconFontSwing.buildIcon(FontAwesome.RECYCLE, 20, NopePink)); + BurpTabs.setIconAt(3, IconFontSwing.buildIcon(FontAwesome.CODE, 20, NopeGreen)); + BurpTabs.setIconAt(4, IconFontSwing.buildIcon(GoogleMaterialDesignIcons.PUBLIC, 20, NopePurple)); + BurpTabs.setIconAt(5, IconFontSwing.buildIcon(FontAwesome.COGS, 20, NopeRed)); + BurpTabs.setIconAt(6, IconFontSwing.buildIcon(FontAwesome.INFO, 20, NopeGrey)); + // Add Tabs to main component add(BurpTabs); Callbacks.customizeUiComponent(BurpTabs); - - //Set DataUpdate Timer + + // Set DataUpdate Timer timer = new Timer(); - timer.scheduleAtFixedRate(new UpdateDBTask(queue,ntbm, searchDb, BurpTabs), 0, 1*1500); - - - //timer.schedule(new UpdateDBTask(queue,ntbm), 2 * 1000); - - + timer.scheduleAtFixedRate(new UpdateDBTask(queue, ntbm, searchDb, BurpTabs), 0, 1 * 1500); + // timer.schedule(new UpdateDBTask(queue,ntbm), 2 * 1000); } -//############################################################################################################################ -// Supporting Functions -//############################################################################################################################ - private boolean checkCert(){ + + // ############################################################################################################################ + // Supporting Functions + // ############################################################################################################################ + private boolean checkCert() { File f = new File("./burpca.p12"); - if(f.exists()){ + if (f.exists()) { try { - KeyStore keyStoreFile = KeyStore.getInstance("PKCS12"); - keyStoreFile.load(new FileInputStream("./burpca.p12"),"changeit".toCharArray()); - return true; + KeyStore keyStoreFile = KeyStore.getInstance("PKCS12"); + keyStoreFile.load(new FileInputStream("./burpca.p12"), "changeit".toCharArray()); + return true; } catch (KeyStoreException e) { // TODO Auto-generated catch block e.printStackTrace(); @@ -2323,20 +2367,23 @@ private boolean checkCert(){ } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); - } + } return false; - }else{ + } else { return false; } } - private void saveHosts(String hosts){ - - /*String fs = System.getProperty("file.separator"); - String file = System.getProperty("user.dir") + fs + "hosts.txt";*/ + + private void saveHosts(String hosts) { + + /* + * String fs = System.getProperty("file.separator"); + * String file = System.getProperty("user.dir") + fs + "hosts.txt"; + */ String path = System.getProperty("user.home"); String file = path + "/.NoPEProxy/hosts.txt"; File f = new File(file); - if(!f.exists()){ + if (!f.exists()) { Callbacks.printOutput("missing hosts.txt.. creating it."); try { f.createNewFile(); @@ -2347,7 +2394,7 @@ private void saveHosts(String hosts){ return; } Path p = Paths.get(file); - + Charset charset = Charset.forName("UTF-8"); try (BufferedWriter writer = Files.newBufferedWriter(p, charset)) { writer.write(hosts); @@ -2355,45 +2402,46 @@ private void saveHosts(String hosts){ // TODO Auto-generated catch block e.printStackTrace(); } - - + } - private String readHosts(){ - - //String fs = System.getProperty("file.separator"); - //String file = System.getProperty("user.dir") + fs + "hosts.txt"; + + private String readHosts() { + + // String fs = System.getProperty("file.separator"); + // String file = System.getProperty("user.dir") + fs + "hosts.txt"; String path = System.getProperty("user.home"); String file = path + "/.NoPEProxy/hosts.txt"; File f = new File(file); - if(!f.exists()){ + if (!f.exists()) { return ""; } Path p = Paths.get(file); - + BufferedReader reader; - String out=""; + String out = ""; try { reader = Files.newBufferedReader(p); - - String line=""; + + String line = ""; while ((line = reader.readLine()) != null) { - out+=line+"\r\n"; + out += line + "\r\n"; } } catch (IOException e) { - out=""; + out = ""; e.printStackTrace(); } - + return out; } - private void updateMatchRules(){ - - //String fs = System.getProperty("file.separator"); - //String file = System.getProperty("user.dir") + fs + "nonHTTPmatch.txt"; + + private void updateMatchRules() { + + // String fs = System.getProperty("file.separator"); + // String file = System.getProperty("user.dir") + fs + "nonHTTPmatch.txt"; String path = System.getProperty("user.home"); String file = path + "/.NoPEProxy/nonHTTPmatch.txt"; File f = new File(file); - if(!f.exists()){ + if (!f.exists()) { Callbacks.printOutput("missing nonHTTPsmatch.txt.. creating it."); try { f.createNewFile(); @@ -2404,49 +2452,48 @@ private void updateMatchRules(){ return; } Path p = Paths.get(file); - + Charset charset = Charset.forName("UTF-8"); try (BufferedWriter writer = Files.newBufferedWriter(p, charset)) { - String rules= this.getTxtRules().getText(); - String [] rs = rules.split("\n"); - String error=""; - - for(String r : rs){ - if(r.trim().equals("")){ // blank line + String rules = this.getTxtRules().getText(); + String[] rs = rules.split("\n"); + String error = ""; + + for (String r : rs) { + if (r.trim().equals("")) { // blank line writer.write(""); - }else if (r.startsWith("#")){ // a comment + } else if (r.startsWith("#")) { // a comment writer.write(r + "\n"); - }else if (r.contains("||") && r.split("\\|\\|").length ==2){ // 2 argument match + } else if (r.contains("||") && r.split("\\|\\|").length == 2) { // 2 argument match writer.write(r + "\n"); - }else if (r.contains("||") && r.split("\\|\\|").length ==3 && r.split("\\|\\|")[2].matches("(both|c2sOnly|s2cOnly)")){ // 3 argument match + } else if (r.contains("||") && r.split("\\|\\|").length == 3 + && r.split("\\|\\|")[2].matches("(both|c2sOnly|s2cOnly)")) { // 3 argument match writer.write(r + "\n"); - }else if (r.contains("||") && r.split("\\|\\|").length ==3){ + } else if (r.contains("||") && r.split("\\|\\|").length == 3) { error = "3rd Argument must be 'both', 'c2sOnly', or 's2cOnly'"; - }else{ + } else { error = "Rules Are Not Valid. Format: matchStr||replaceStr or 0x121212||0x131313"; - + } } - + errorMsg.setText(error); - - - + } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } - - + } - private String getMatchRules(){ + + private String getMatchRules() { String out = ""; - //String fs = System.getProperty("file.separator"); - //String file = System.getProperty("user.dir") + fs + "nonHTTPmatch.txt"; + // String fs = System.getProperty("file.separator"); + // String file = System.getProperty("user.dir") + fs + "nonHTTPmatch.txt"; String path = System.getProperty("user.home"); String file = path + "/.NoPEProxy/nonHTTPmatch.txt"; File f = new File(file); - if(!f.exists()){ + if (!f.exists()) { try { f.createNewFile(); } catch (IOException e) { @@ -2456,67 +2503,67 @@ private String getMatchRules(){ return ""; } Path p = Paths.get(file); - + Charset charset = Charset.forName("UTF-8"); try (BufferedReader reader = Files.newBufferedReader(p, charset)) { - String line = null; - while ((line = reader.readLine()) != null) { - out += line + "\r\n"; - } + String line = null; + while ((line = reader.readLine()) != null) { + out += line + "\r\n"; + } } catch (IOException x) { - System.err.format("IOException: %s%n", x); + System.err.format("IOException: %s%n", x); } return out; - + } - - private String getInterfaceList(){ - String out=""; + + private String getInterfaceList() { + String out = ""; Enumeration e; try { e = NetworkInterface.getNetworkInterfaces(); - int ifCount =0; - while(e.hasMoreElements()) - { - NetworkInterface n = (NetworkInterface) e.nextElement(); - Enumeration ee = n.getInetAddresses(); - while (ee.hasMoreElements()) - { - InetAddress i = (InetAddress) ee.nextElement(); - if(i.getHostAddress().matches("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$")){ - out += ifCount++ +") " + n.getName() + " : " + i.getHostAddress() + " : " + (n.getHardwareAddress() != null ? Hex.toHexString(n.getHardwareAddress()) : "") + "\n"; - - - } - - } - ifCount++; + int ifCount = 0; + while (e.hasMoreElements()) { + NetworkInterface n = (NetworkInterface) e.nextElement(); + Enumeration ee = n.getInetAddresses(); + while (ee.hasMoreElements()) { + InetAddress i = (InetAddress) ee.nextElement(); + if (i.getHostAddress().matches("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$")) { + out += ifCount++ + ") " + n.getName() + " : " + i.getHostAddress() + " : " + + (n.getHardwareAddress() != null ? Hex.toHexString(n.getHardwareAddress()) : "") + + "\n"; + + } + + } + ifCount++; } } catch (SocketException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } return out; - + } - private void updateInterface(String state){ - this.updateProperties("interface", state); + private void updateInterface(String state) { + this.updateProperties("interface", state); } - private void updateProperties(String key, String value){ + + private void updateProperties(String key, String value) { Properties config = new Properties(); try { - //config.load(ClassLoader.getSystemResourceAsStream("dns.properties")); + // config.load(ClassLoader.getSystemResourceAsStream("dns.properties")); String path = System.getProperty("user.home"); File f = new File(path + "/.NoPEProxy/dns.properties"); - if(f.exists()){ - config.load( new FileInputStream(f)); - }else{ - //config.load(ClassLoader.getSystemResourceAsStream("dns.properties")); + if (f.exists()) { + config.load(new FileInputStream(f)); + } else { + // config.load(ClassLoader.getSystemResourceAsStream("dns.properties")); File p = new File(path + "/.NoPEProxy"); - if(!p.exists()) + if (!p.exists()) p.mkdir(); f.createNewFile(); } @@ -2531,29 +2578,29 @@ private void updateProperties(String key, String value){ e1.printStackTrace(); } - + } - - private String getProperties(String key){ - return this.getProperties(key,""); + + private String getProperties(String key) { + return this.getProperties(key, ""); } - private String getProperties(String key, String defaultValue){ + + private String getProperties(String key, String defaultValue) { Properties config = new Properties(); try { - //config.load(ClassLoader.getSystemResourceAsStream("dns.properties")); + // config.load(ClassLoader.getSystemResourceAsStream("dns.properties")); String path = System.getProperty("user.home"); File f = new File(path + "/.NoPEProxy/dns.properties"); - if(f.exists()){ - config.load( new FileInputStream(f)); - }else{ - //config.load(ClassLoader.getSystemResourceAsStream("dns.properties")); + if (f.exists()) { + config.load(new FileInputStream(f)); + } else { + // config.load(ClassLoader.getSystemResourceAsStream("dns.properties")); File p = new File(path + "/.NoPEProxy"); - if(!p.exists()) + if (!p.exists()) p.mkdir(); f.createNewFile(); } return config.getProperty(key, defaultValue); - } catch (FileNotFoundException e1) { @@ -2563,74 +2610,71 @@ private String getProperties(String key, String defaultValue){ e1.printStackTrace(); } return ""; - + } - private void updateAutoStart(boolean state){ - - if(state) + private void updateAutoStart(boolean state) { + + if (state) this.updateProperties("autoStart", "true"); else this.updateProperties("autoStart", "false"); - } - - public boolean getAutoStart(){ + public boolean getAutoStart() { return AUTOSTART; } - public void DNSStopped(){ - btnStartDns.setText("");//Start DNS - btnStartDns.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY,40)); - btnStartDns.setBackground(NopeGreen);//red + public void DNSStopped() { + btnStartDns.setText("");// Start DNS + btnStartDns.setIcon(IconFontSwing.buildIcon(FontAwesome.PLAY, 40)); + btnStartDns.setBackground(NopeGreen);// red isDNSRunning = false; - //lblStatusDNS.setText("DNS OFF"); - + // lblStatusDNS.setText("DNS OFF"); } - public int getInterfaceNumber(){ + public int getInterfaceNumber() { return IFNUM; } - private void updateInterfaceInformation(){ + + private void updateInterfaceInformation() { Enumeration e; try { e = NetworkInterface.getNetworkInterfaces(); - int ifCount =0; - while(e.hasMoreElements()) - { - NetworkInterface n = (NetworkInterface) e.nextElement(); - Enumeration ee = n.getInetAddresses(); - while (ee.hasMoreElements()) - { - InetAddress i = (InetAddress) ee.nextElement(); - if(i.getHostAddress().matches("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$")){ - Callbacks.printOutput(ifCount + ") " + n.getName() + " : " + i.getHostAddress() + " : " + (n.getHardwareAddress() != null ? Hex.toHexString(n.getHardwareAddress()) : "")); - if(Integer.parseInt(IfTxtBox.getText()) == ifCount++){ - lblCurrentIpAddress.setText("Current Ip Address: " + i.getHostAddress()); - dnsIpTxt.setText(i.getHostAddress()); - - break; - } - - } - - } - ifCount++; + int ifCount = 0; + while (e.hasMoreElements()) { + NetworkInterface n = (NetworkInterface) e.nextElement(); + Enumeration ee = n.getInetAddresses(); + while (ee.hasMoreElements()) { + InetAddress i = (InetAddress) ee.nextElement(); + if (i.getHostAddress().matches("^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$")) { + Callbacks.printOutput(ifCount + ") " + n.getName() + " : " + i.getHostAddress() + " : " + + (n.getHardwareAddress() != null ? Hex.toHexString(n.getHardwareAddress()) : "")); + if (Integer.parseInt(IfTxtBox.getText()) == ifCount++) { + lblCurrentIpAddress.setText("Current Ip Address: " + i.getHostAddress()); + dnsIpTxt.setText(i.getHostAddress()); + + break; + } + + } + + } + ifCount++; } } catch (SocketException e1) { Callbacks.printError(e1.getMessage()); } } -//######################################################################################################################################################################## -/// Event Stuff here + // ######################################################################################################################################################################## + /// Event Stuff here private List _listeners = new ArrayList(); private JCheckBox useDefaultIp; private RSyntaxTextArea pythonText; - //private JEditorPane pythonText; + // private JEditorPane pythonText; private JCheckBox chckbxEnablePythonMangler; private JLabel lblNewLabel; private JTabbedPane repeaterPane; @@ -2639,83 +2683,88 @@ private void updateInterfaceInformation(){ private JPanel Intercept; private RSyntaxTextArea repCodeOutput; private JTable portTable; - - public synchronized void addEventListener(DNSConfigListener listener) { + + public synchronized void addEventListener(DNSConfigListener listener) { _listeners.add(listener); } - public synchronized void removeEventListener(DNSConfigListener listener) { + + public synchronized void removeEventListener(DNSConfigListener listener) { _listeners.remove(listener); } @SuppressWarnings("rawtypes") - private synchronized void ToggleDNS(String Address, Integer Port){ + private synchronized void ToggleDNS(String Address, Integer Port) { Iterator i = _listeners.iterator(); - - while(i.hasNext()) { + + while (i.hasNext()) { DNSEvent evt = new DNSEvent(this); evt.setAddress(Address); evt.setPort(Port); ((DNSConfigListener) i.next()).DNSToggle(evt); } - + } - public synchronized void addEventListener(ProxyEventListener listener) { + public synchronized void addEventListener(ProxyEventListener listener) { _listeners.add(listener); - //_listeners.remove(listener); + // _listeners.remove(listener); } - public synchronized void removeEventListener(ProxyEventListener listener) { + + public synchronized void removeEventListener(ProxyEventListener listener) { _listeners.remove(listener); } + @Override public void DataReceived(ProxyEvent evt) { // Network data to the queue. // timer will process this every 2 seconds and add them to the log. - queue.add(new LogEntry(evt.getData(),evt.getOriginalData(), evt.getSrcIP(), evt.getSrcPort(), evt.getDstIP(), evt.getDstPort(), evt.getDirection())); - + queue.add(new LogEntry(evt.getData(), evt.getOriginalData(), evt.getSrcIP(), evt.getSrcPort(), evt.getDstIP(), + evt.getDstPort(), evt.getDirection(), evt.getProtocol())); } + @Override public void Intercepted(ProxyEvent evt, boolean isC2S) { - + BurpTabs.setSelectedIndex(0); - byte [] origReq = evt.getData(); + byte[] origReq = evt.getData(); intbm.requestViewer.setMessage(evt.getData(), true); - if(isC2S){ + if (isC2S) { this.isC2S.setForeground(NopeBlue); this.isC2S.setFont(new Font("Lucida Grande", Font.BOLD, 13)); - - + interceptInfo.removeAll(); interceptInfo.setLayout(new BoxLayout(interceptInfo, BoxLayout.X_AXIS)); JLabel srcLabel = new JLabel(evt.getSrcIP() + ":" + evt.getSrcPort() + " "); srcLabel.setForeground(NopeBlue); interceptInfo.add(srcLabel); JLabel iconRight = new JLabel(); - iconRight.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_RIGHT,16, NopeBlue)); + iconRight.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_RIGHT, 16, NopeBlue)); interceptInfo.add(iconRight); JLabel dstLabel = new JLabel(evt.getDstIP() + ":" + evt.getDstPort() + " "); dstLabel.setForeground(NopeBlue); interceptInfo.add(dstLabel); interceptInfo.setText(" "); interceptInfo.setForeground(Color.blue); - } - else { + } else { this.isS2C.setForeground(NopeRed); this.isS2C.setFont(new Font("Lucida Grande", Font.BOLD, 13)); - /*interceptInfo.setText(evt.getDstIP() + ":"+evt.getDstPort() + " <<== " + evt.getSrcIP() + ":" + evt.getSrcPort()); - interceptInfo.setForeground(new Color(0xE4, 0x31, 0x17));*/ - + /* + * interceptInfo.setText(evt.getDstIP() + ":"+evt.getDstPort() + " <<== " + + * evt.getSrcIP() + ":" + evt.getSrcPort()); + * interceptInfo.setForeground(new Color(0xE4, 0x31, 0x17)); + */ + interceptInfo.removeAll(); interceptInfo.setLayout(new BoxLayout(interceptInfo, BoxLayout.X_AXIS)); - JLabel dstLabel = new JLabel(evt.getDstIP() + ":"+evt.getDstPort() + " "); + JLabel dstLabel = new JLabel(evt.getDstIP() + ":" + evt.getDstPort() + " "); dstLabel.setForeground(NopeRed); interceptInfo.add(dstLabel); JLabel iconRight = new JLabel(); - iconRight.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_LEFT,16, NopeRed)); + iconRight.setIcon(IconFontSwing.buildIcon(Elusive.ARROW_LEFT, 16, NopeRed)); iconRight.setForeground(NopeRed); interceptInfo.add(iconRight); - JLabel srcLabel = new JLabel(" " + evt.getSrcIP() + ":" + evt.getSrcPort()); + JLabel srcLabel = new JLabel(" " + evt.getSrcIP() + ":" + evt.getSrcPort()); srcLabel.setForeground(NopeRed); interceptInfo.add(srcLabel); interceptInfo.setText(" "); @@ -2724,27 +2773,33 @@ public void Intercepted(ProxyEvent evt, boolean isC2S) { synchronized (intbm) { try { - + intbm.wait(); - - if(isC2S){ - if(evt.isTCPMtm()) + + if (isC2S) { + if (evt.isTCPMtm()) evt.getTCPMtm().forwardC2SRequest(intbm.requestViewer.getMessage()); - /*else - evt.getUDPMtm().forwardC2SRequest(intbm.requestViewer.getMessage());*/ - }else{ - if(evt.isTCPMtm()) + + else + evt.getUDPMtm().forwardC2SRequest(intbm.requestViewer.getMessage()); + + } else { + if (evt.isTCPMtm()) evt.getTCPMtm().forwardS2CRequest(intbm.requestViewer.getMessage()); - /*else - evt.getUDPMtm().forwardS2CRequest(intbm.requestViewer.getMessage());*/ + + else + evt.getUDPMtm().forwardS2CRequest(intbm.requestViewer.getMessage()); + } - if(intbm.requestViewer.getMessage() == origReq) - queue.add(new LogEntry(intbm.requestViewer.getMessage(), origReq, evt.getSrcIP(), evt.getSrcPort(), evt.getDstIP(), evt.getDstPort(), evt.getDirection()/*+" - Intercepted - Not Changed"*/)); + if (intbm.requestViewer.getMessage() == origReq) + queue.add(new LogEntry(intbm.requestViewer.getMessage(), origReq, evt.getSrcIP(), evt.getSrcPort(), + evt.getDstIP(), evt.getDstPort(), evt.getDirection(), evt.getProtocol())); else - queue.add(new LogEntry(intbm.requestViewer.getMessage(),origReq, evt.getSrcIP(), evt.getSrcPort(), evt.getDstIP(), evt.getDstPort(), "** "+evt.getDirection()+" ** - Edited")); - - //ntbm.fireTableRowsInserted(0, 0); - intbm.requestViewer.setMessage(new byte[]{}, true); + queue.add(new LogEntry(intbm.requestViewer.getMessage(), origReq, evt.getSrcIP(), evt.getSrcPort(), + evt.getDstIP(), evt.getDstPort(), "** " + evt.getDirection() + " ** - Edited", evt.getProtocol())); + + // ntbm.fireTableRowsInserted(0, 0); + intbm.requestViewer.setMessage(new byte[] {}, true); interceptInfo.setText(""); this.isC2S.setForeground(Color.black); this.isS2C.setForeground(Color.black); @@ -2756,17 +2811,17 @@ public void Intercepted(ProxyEvent evt, boolean isC2S) { } } - - } + @Override public void NewDomainRequest(DNSTableEvent e) { - //This may be fucking up the interface - //BurpTabs.setIconAt(4,IconFontSwing.buildIcon(GoogleMaterialDesignIcons.INFO_OUTLINE,20, NopeRed)); + // This may be fucking up the interface + // BurpTabs.setIconAt(4,IconFontSwing.buildIcon(GoogleMaterialDesignIcons.INFO_OUTLINE,20, + // NopeRed)); String Domain = e.getDomain(); String ClientIp = e.getClientIP(); Vector vec = new Vector(); - //SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd hh:mm:ss"); + // SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd hh:mm:ss"); SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss"); vec.add(sdf.format(new Date())); vec.add(Domain); @@ -2774,54 +2829,60 @@ public void NewDomainRequest(DNSTableEvent e) { vec.add(ClientIp); vec.add(e.getHostName()); int N = dnstTbm.getRowCount(); - for(int i=0; i< N; i++){ + for (int i = 0; i < N; i++) { String dname = dnstTbm.getValueAt(i, 1).toString(); String ip = dnstTbm.getValueAt(i, 3).toString(); - if(ip.equals(ClientIp) && dname.equals(Domain)){ + if (ip.equals(ClientIp) && dname.equals(Domain)) { dnstTbm.removeRow(i); break; } } - + dnstTbm.insertRow(0, vec); - /*Timer t = new Timer(); - t.schedule(new TimerTask() { - @Override - public void run() { - BurpTabs.setIconAt(4,IconFontSwing.buildIcon(GoogleMaterialDesignIcons.PUBLIC,20, NopePurple)); - } - }, 2*1000); - */ - + /* + * Timer t = new Timer(); + * t.schedule(new TimerTask() { + * + * @Override + * public void run() { + * BurpTabs.setIconAt(4,IconFontSwing.buildIcon(GoogleMaterialDesignIcons.PUBLIC + * ,20, NopePurple)); + * } + * }, 2*1000); + */ + } + @Override public void PythonMessages(PythonOutputEvent e) { - + String Output = ""; - if(e.getDirection().startsWith("Client")) + if (e.getDirection().startsWith("Client")) Output += "
"; else Output += "
"; - Output +="Direction: " + e.getDirection() + " : " + new Date() + "
"; - if(!e.getMessage().equals("")){ + Output += "Direction: " + e.getDirection() + " : " + new Date() + "
"; + if (!e.getMessage().equals("")) { Output += "
"; Output += "###Messages:
"; - Output += e.getMessage().replace(" ", " ").replace("<", "<").replace(">", ">").replace("\n", "
"); + Output += e.getMessage().replace(" ", " ").replace("<", "<").replace(">", ">").replace("\n", + "
"); Output += "

"; - + } - - if(!e.getError().equals("")){ + + if (!e.getError().equals("")) { Output += "
"; Output += "###Errors:
"; - Output += "
" + e.getError().replace(" ", " ").replace("<", "<").replace(">", ">").replace("\n", "
"); + Output += "
" + e.getError().replace(" ", " ").replace("<", "<").replace(">", ">") + .replace("\n", "
"); Output += "

"; } - Output+="
"; - //this.PythonConsole.setText(this.PythonConsole.getText() + "\n" +Output); - HTMLDocument doc = (HTMLDocument)PythonConsole.getDocument(); - HTMLEditorKit editorKit = (HTMLEditorKit)PythonConsole.getEditorKit(); - + Output += "
"; + // this.PythonConsole.setText(this.PythonConsole.getText() + "\n" +Output); + HTMLDocument doc = (HTMLDocument) PythonConsole.getDocument(); + HTMLEditorKit editorKit = (HTMLEditorKit) PythonConsole.getEditorKit(); + try { editorKit.insertHTML(doc, doc.getLength(), Output, 0, 0, null); } catch (BadLocationException e1) { @@ -2831,37 +2892,41 @@ public void PythonMessages(PythonOutputEvent e) { // TODO Auto-generated catch block e1.printStackTrace(); } - + System.out.println(e.getError()); System.out.println(e.getMessage()); - + } + public JTextArea getTxtRules() { return txtRules; } - + public JTextField getTxtDNSPort() { return txtDNSPort; } + public JLabel getLblSelected() { return lblSelected; } + public JCheckBox getChckbxUseAboveIp() { return useDefaultIp; } + public JCheckBox getChckbxEnablePythonMangler() { return chckbxEnablePythonMangler; } - protected JLabel getLblNewLabel() { return lblNewLabel; } + protected JTabbedPane getRepeaterPane() { return repeaterPane; } - - class RepeaterJPane extends JTextPane implements IMessageEditorController{ + + class RepeaterJPane extends JTextPane implements IMessageEditorController { @Override public IHttpService getHttpService() { @@ -2878,16 +2943,16 @@ public byte[] getResponse() { return null; } - - } protected JComboBox getCurrentListeners() { return currentListeners; } + protected JTextField getSearchDb() { return searchDb; } + protected JPanel getIntercept() { return Intercept; } diff --git a/NonHTTPProxy/src/josh/ui/utils/ListenerDB.java b/NonHTTPProxy/src/josh/ui/utils/ListenerDB.java index c4b8b39..26597e5 100644 --- a/NonHTTPProxy/src/josh/ui/utils/ListenerDB.java +++ b/NonHTTPProxy/src/josh/ui/utils/ListenerDB.java @@ -1,14 +1,11 @@ package josh.ui.utils; -import java.util.Calendar; -import java.util.Date; -import java.util.LinkedList; +import java.awt.SystemColor; import java.util.List; import org.hibernate.Session; import josh.dao.HibHelper; import josh.dao.ListenerSetting; -import josh.dao.Requests; public class ListenerDB { @@ -28,12 +25,13 @@ public static void add(ListenerSetting ls){ public static void updateSSL(ListenerSetting ls, boolean ssl){ Session s = HibHelper.getSessionFactory().openSession(); List list = (List)s - .createQuery("from ListenerSetting where sip = :sip and sport = :sport and lport = :lport and cert = :cert and ssl = :ssl") + .createQuery("from ListenerSetting where sip = :sip and sport = :sport and lport = :lport and cert = :cert and ssl = :ssl and (udp = :udp or udp IS NULL)") .setParameter("sip", ls.getSip()) .setParameter("sport", ls.getSport()) .setParameter("lport", ls.getLport()) .setParameter("cert", ls.getCert()) .setParameter("ssl", ls.isSsl()) + .setParameter("udp", ls.isUdp()) .list(); if(list.size() >= 1){ s.getTransaction().begin(); @@ -43,16 +41,40 @@ public static void updateSSL(ListenerSetting ls, boolean ssl){ } s.close(); + } + + public static void updateUDP(ListenerSetting ls, boolean udp){ + Session s = HibHelper.getSessionFactory().openSession(); + List list = (List)s + .createQuery("from ListenerSetting where sip = :sip and sport = :sport and lport = :lport and cert = :cert and ssl = :ssl and (udp = :udp or udp IS NULL)") + .setParameter("sip", ls.getSip()) + .setParameter("sport", ls.getSport()) + .setParameter("lport", ls.getLport()) + .setParameter("cert", ls.getCert()) + .setParameter("ssl", ls.isSsl()) + .setParameter("udp", ls.isUdp()) + .list(); + if(list.size() >= 1){ + s.getTransaction().begin(); + list.get(0).setUdp(udp); + s.update(list.get(0)); + s.getTransaction().commit(); + } + s.close(); + } public static void remove(ListenerSetting ls){ + System.out.println("removing"); + System.out.println(ls.isUdp()); Session s = HibHelper.getSessionFactory().openSession(); List list = (List)s - .createQuery("from ListenerSetting where sip = :sip and sport = :sport and lport = :lport and cert = :cert and ssl = :ssl") + .createQuery("from ListenerSetting where sip = :sip and sport = :sport and lport = :lport and cert = :cert and ssl = :ssl and (udp = :udp or udp IS NULL)") .setParameter("sip", ls.getSip()) .setParameter("sport", ls.getSport()) .setParameter("lport", ls.getLport()) .setParameter("cert", ls.getCert()) .setParameter("ssl", ls.isSsl()) + .setParameter("udp", ls.isUdp()) .list(); if(list.size() >= 1){ s.getTransaction().begin(); @@ -69,6 +91,8 @@ public static void remove(ListenerSetting ls){ Session s = HibHelper.getSessionFactory().openSession(); List list = (List)s.createQuery("from ListenerSetting").list(); + System.out.println("Reading DB"); + System.out.println(list.get(0).isUdp()); s.close(); return list; diff --git a/NonHTTPProxy/src/josh/ui/utils/LogEntry.java b/NonHTTPProxy/src/josh/ui/utils/LogEntry.java index fe63d86..01cacb7 100755 --- a/NonHTTPProxy/src/josh/ui/utils/LogEntry.java +++ b/NonHTTPProxy/src/josh/ui/utils/LogEntry.java @@ -21,12 +21,13 @@ public class LogEntry public int Bytes; public Long Index; public byte [] original; + public String protocol = "TCP"; public LogEntry(){ } - public LogEntry(byte[] requestResponse, byte[] original, String SrcIp,int SrcPort, String DstIP, int DstPort, String Direction) + public LogEntry(byte[] requestResponse, byte[] original, String SrcIp,int SrcPort, String DstIP, int DstPort, String Direction, String Protocol) { this.time = Calendar.getInstance().getTime(); @@ -38,11 +39,12 @@ public LogEntry(byte[] requestResponse, byte[] original, String SrcIp,int SrcPor this.DstPort = DstPort; this.Direction = Direction; this.Bytes = original.length; + this.protocol = Protocol; } - public LogEntry(Long Index, String SrcIp,int SrcPort, String DstIP, int DstPort, String Direction, Long time, int bytes) + public LogEntry(Long Index, String SrcIp,int SrcPort, String DstIP, int DstPort, String Direction, Long time, int bytes, String protocol) { this.Index = Index; @@ -53,6 +55,7 @@ public LogEntry(Long Index, String SrcIp,int SrcPort, String DstIP, int DstPort, this.DstPort = DstPort; this.Direction = Direction; this.Bytes = bytes; + this.protocol = protocol; } @@ -68,7 +71,7 @@ else if(new String(original).contains(term.trim())) } public long save(){ Session s = HibHelper.getSessionFactory().openSession(); - Requests dao = new Requests(0, this.requestResponse, this.original, this.SrcIP, this.SrcPort, this.DstIP, this.DstPort, this.Direction, this.time.getTime(), this.Bytes); + Requests dao = new Requests(0, this.requestResponse, this.original, this.SrcIP, this.SrcPort, this.DstIP, this.DstPort, this.Direction, this.time.getTime(), this.Bytes, this.protocol); s.getTransaction().begin(); s.saveOrUpdate(dao); s.getTransaction().commit(); @@ -88,7 +91,7 @@ public void commit(){ session.close(); } public long saveCommitDeferred(LogEntry le){ - Requests dao = new Requests(0, le.requestResponse, le.original, le.SrcIP, le.SrcPort, le.DstIP, le.DstPort, le.Direction, le.time.getTime(), le.Bytes); + Requests dao = new Requests(0, le.requestResponse, le.original, le.SrcIP, le.SrcPort, le.DstIP, le.DstPort, le.Direction, le.time.getTime(), le.Bytes, le.protocol); session.save(dao); this.Index = (long)dao.getId(); return dao.getId(); @@ -130,7 +133,7 @@ public Requests getData(Long index){ List r = (List)s.createQuery("from Requests order by id desc").list(); LinkedList list = new LinkedList(); for(Requests q : r){ - list.add(new LogEntry((long)q.getId(), q.getSrcIp(), q.getSrcPort(), q.getDstIp(), q.getDstPort(), q.getDirection(),q.getDate(), q.getBytes())); + list.add(new LogEntry((long)q.getId(), q.getSrcIp(), q.getSrcPort(), q.getDstIp(), q.getDstPort(), q.getDirection(),q.getDate(), q.getBytes(), q.getProtocol())); //list.add(new LogEntry(q.getData(), q.getOriginal(), (long)q.getId(), q.getSrcIp(), q.getSrcPort(), q.getDstIp(), q.getDstPort(), q.getDirection(),q.getDate(), q.getBytes())); } s.close(); @@ -143,13 +146,21 @@ public Requests getData(Long index){ Session s = HibHelper.getSessionFactory().openSession(); List r = (List)s - .createQuery("from Requests where original_str like :term or data_str like :term2 order by id desc") + .createQuery( + "from Requests where original_str like :term " + + "or data_str like :term2 " + + "or direction like :term " + + "or srcport = :term3 " + + "or dstport = :term3 " + + "or direction like :term2 " + + "or protocol like :term2 order by id desc") .setParameter("term", "%"+query+"%") .setParameter("term2", "%"+query+"%") + .setParameter("term3", query) .list(); LinkedList list = new LinkedList(); for(Requests q : r){ - list.add(new LogEntry((long)q.getId(), q.getSrcIp(), q.getSrcPort(), q.getDstIp(), q.getDstPort(), q.getDirection(),q.getDate(), q.getBytes())); + list.add(new LogEntry((long)q.getId(), q.getSrcIp(), q.getSrcPort(), q.getDstIp(), q.getDstPort(), q.getDirection(),q.getDate(), q.getBytes(), q.getProtocol())); } s.close(); return list; diff --git a/NonHTTPProxy/src/josh/ui/utils/NonHTTPTableModel.java b/NonHTTPProxy/src/josh/ui/utils/NonHTTPTableModel.java index 17d4ad3..9f22c14 100755 --- a/NonHTTPProxy/src/josh/ui/utils/NonHTTPTableModel.java +++ b/NonHTTPProxy/src/josh/ui/utils/NonHTTPTableModel.java @@ -42,7 +42,7 @@ public int getRowCount() @Override public int getColumnCount() { - return 9; + return 10; } @Override @@ -55,16 +55,18 @@ public String getColumnName(int columnIndex) case 1: return "Time"; case 2: - return "Direction - Annotation"; + return "Proto"; case 3: - return "Method"; + return "Direction - Annotation"; case 4: - return "Source IP"; + return "Method"; case 5: - return "Source Port"; + return "Src IP"; case 6: - return "Dst IP"; + return "Src Port"; case 7: + return "Dst IP"; + case 8: return "Dst Port"; default: return "Bytes"; @@ -77,9 +79,9 @@ public Class getColumnClass(int columnIndex) switch (columnIndex) { case 0: return Integer.class; - case 5: return Integer.class; - case 7: return Integer.class; + case 6: return Integer.class; case 8: return Integer.class; + case 9: return Integer.class; default: return String.class; } } @@ -99,8 +101,10 @@ public Object getValueAt(int rowIndex, int columnIndex) case 1: return sdf.format(logEntry.time); case 2: - return logEntry.Direction; + return logEntry.protocol; case 3: + return logEntry.Direction; + case 4: if(logEntry.Direction.contains("Repeater")) return "TCP Repeater"; else if (logEntry.Direction.contains("Match")) @@ -113,19 +117,17 @@ else if (logEntry.Direction.contains("**")) return "Intercept"; else return "Normal"; - case 4: - return logEntry.SrcIP; case 5: - return logEntry.SrcPort; + return logEntry.SrcIP; case 6: - return logEntry.DstIP; + return logEntry.SrcPort; case 7: - return logEntry.DstPort; + return logEntry.DstIP; case 8: + return logEntry.DstPort; + case 9: return logEntry.Bytes; - - default: return null; } }else{ diff --git a/NonHTTPProxy/src/josh/ui/utils/Table.java b/NonHTTPProxy/src/josh/ui/utils/Table.java index 841ebe0..d376d84 100755 --- a/NonHTTPProxy/src/josh/ui/utils/Table.java +++ b/NonHTTPProxy/src/josh/ui/utils/Table.java @@ -12,6 +12,8 @@ import javax.swing.table.TableCellRenderer; import javax.swing.table.TableModel; import org.hibernate.Session; +import org.python.core.packagecache.SysPackageManager; + import burp.IMessageEditor; import jiconfont.icons.Elusive; import jiconfont.swing.IconFontSwing; @@ -103,7 +105,10 @@ public Component prepareRenderer( Border inside = new EmptyBorder(0, 1, 0, 1); Border highlight = new CompoundBorder(outside, inside); JComponent jc = (JComponent)c;*/ - + if(log.size() == 0){ + return c; + } + int r = this.convertRowIndexToModel(row); if( super.isRowSelected(row)){ c.setBackground(new Color(52, 73, 94)); diff --git a/NonHTTPProxy/src/josh/utils/Lister.java b/NonHTTPProxy/src/josh/utils/Lister.java index f2c9988..c79ab63 100644 --- a/NonHTTPProxy/src/josh/utils/Lister.java +++ b/NonHTTPProxy/src/josh/utils/Lister.java @@ -30,29 +30,30 @@ import org.pcap4j.packet.IpV4Packet; import org.pcap4j.packet.Packet; import org.pcap4j.packet.TcpPacket; +import org.pcap4j.packet.UdpPacket; import org.pcap4j.packet.EthernetPacket; import org.pcap4j.util.NifSelector; import josh.utils.events.DNSEvent; import josh.utils.events.DNSTableEventListener; -import josh.utils.events.TCPConnectionAttemptListener; -import josh.utils.events.TCPPacketEvt; +import josh.utils.events.ConnectionAttemptListener; +import josh.utils.events.PortConnectEvt; import josh.utils.events.UDPEventListener; -public class Lister implements Runnable{ +public class Lister implements Runnable { private String IP; private ExecutorService pool; private PcapHandle handle; - private HashMap portsFound = new HashMap(); - - public Lister(String IP){ + private HashMap portsFound = new HashMap(); + + public Lister(String IP) { this.IP = IP; } @Override public void run() { System.out.println("Lister Started"); - try{ + try { InetAddress addr = InetAddress.getByName(this.IP); System.out.println("#### LIST OF DEVS ####"); @@ -63,54 +64,73 @@ public void run() { } System.out.println("###############"); System.out.println(addr); - PcapNetworkInterface nif = Pcaps.getDevByAddress(addr); + PcapNetworkInterface nif = Pcaps.getDevByAddress(addr); - if (nif == null) { + if (nif == null) { System.out.println("No Interface Matches IP"); - return; - } - handle - = nif.openLive(65536, PromiscuousMode.PROMISCUOUS, 10); - handle.setFilter("tcp", BpfCompileMode.OPTIMIZE); - - PacketListener listener - = new PacketListener() { - @Override - public void gotPacket(Packet packet) { - TcpPacket tcp = packet.get(TcpPacket.class); - IpV4Packet ip = packet.get(IpV4Packet.class); - if(tcp == null || ip == null) return; - if(tcp.getHeader().getSyn() && !tcp.getHeader().getAck() ){ //&& !ip.getHeader().getSrcAddr().toString().equals("/"+IP)){ - SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm"); - String time = sdf.format(new Date()); - String key = ip.getHeader().getSrcAddr().getHostAddress() + ":"+ tcp.getHeader().getDstPort().valueAsInt(); - if(portsFound.containsKey(key) && portsFound.get(key).equals(time)) - return; - portsFound.put(key, time); - fireEvent(ip.getHeader().getSrcAddr().getHostAddress(), - tcp.getHeader().getDstPort().name(), - tcp.getHeader().getDstPort().valueAsInt(), - time); - } - - } - }; - - try { - pool = Executors.newCachedThreadPool(); - handle.loop(-1, listener, pool); // This is better than handle.loop(5, listener); - pool.shutdown(); - } catch (InterruptedException e) { - //e.printStackTrace(); - } - - handle.close(); - }catch(Exception ex){ - + return; + } + handle = nif.openLive(65536, PromiscuousMode.PROMISCUOUS, 10); + System.out.println("(tcp or udp) and ip.dst == " + this.IP); + handle.setFilter("(tcp or udp) and dst net " + this.IP, BpfCompileMode.OPTIMIZE); + + PacketListener listener = new PacketListener() { + @Override + public void gotPacket(Packet packet) { + TcpPacket tcp = packet.get(TcpPacket.class); + UdpPacket udp = packet.get(UdpPacket.class); + IpV4Packet ip = packet.get(IpV4Packet.class); + + if ((udp == null && tcp == null) || ip == null) + return; + + SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd hh:mm"); + String time = sdf.format(new Date()); + String key = ip.getHeader().getSrcAddr().getHostAddress() + ":"; + String proto = "TCP"; + String service = ""; + int destPort=-1; + + if (tcp != null && tcp.getHeader().getSyn() && !tcp.getHeader().getAck()) { + key += tcp.getHeader().getDstPort().valueAsInt() + ":" + proto; + service = tcp.getHeader().getDstPort().name(); + destPort = tcp.getHeader().getDstPort().valueAsInt(); + } + else if (udp != null) { + proto= "UDP"; + key += udp.getHeader().getDstPort().valueAsInt() + ":" + proto; + service = udp.getHeader().getDstPort().name(); + destPort = udp.getHeader().getDstPort().valueAsInt(); + } + + if ((portsFound.containsKey(key) && portsFound.get(key).equals(time)) || destPort == -1 ) + return; + portsFound.put(key, time); + fireEvent(ip.getHeader().getSrcAddr().getHostAddress(), + service, + destPort, + time, + proto); + + } + }; + + try { + pool = Executors.newCachedThreadPool(); + handle.loop(-1, listener, pool); // This is better than handle.loop(5, listener); + pool.shutdown(); + } catch (InterruptedException e) { + // e.printStackTrace(); + } + + handle.close(); + } catch (Exception ex) { + } System.out.println("Lister Stopped"); - } - public void kill(){ + } + + public void kill() { try { handle.breakLoop(); pool.shutdown(); @@ -118,52 +138,48 @@ public void kill(){ } catch (NotOpenException e) { e.printStackTrace(); } - + } - - private List _listeners = new ArrayList(); - - public synchronized void addEventListener(TCPConnectionAttemptListener listener) { + + private List _listeners = new ArrayList(); + + public synchronized void addEventListener(ConnectionAttemptListener listener) { _listeners.add(listener); } - public synchronized void removeEventListener(TCPConnectionAttemptListener listener) { + + public synchronized void removeEventListener(ConnectionAttemptListener listener) { _listeners.remove(listener); } - - private void fireEvent(String sip, String service, int dport, String time){ - TCPPacketEvt event = new TCPPacketEvt(this, sip, service, dport, time); - Iterator i = _listeners.iterator(); - while(i.hasNext()) { - i.next().TcpConnAttempt(event); + + private void fireEvent(String sip, String service, int dport, String time, String proto) { + PortConnectEvt event = new PortConnectEvt(this, sip, service, dport, time, proto); + Iterator i = _listeners.iterator(); + while (i.hasNext()) { + i.next().ConnectAttempt(event); } } - - - public static void main(String[] args) throws PcapNativeException, NotOpenException, UnknownHostException { AccessController.doPrivileged(new PrivilegedAction() { - public Object run() { - Lister lister = new Lister("192.168.1.129"); - Thread t = new Thread(lister); - t.start(); - - try { - Thread.sleep(10*1000); + public Object run() { + Lister lister = new Lister("192.168.1.129"); + Thread t = new Thread(lister); + t.start(); + + try { + Thread.sleep(10 * 1000); lister.kill(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } - - - return null; - - } - }); - - } - + + return null; + + } + }); + + } } diff --git a/NonHTTPProxy/src/josh/utils/events/ConnectionAttemptListener.java b/NonHTTPProxy/src/josh/utils/events/ConnectionAttemptListener.java new file mode 100644 index 0000000..f01533c --- /dev/null +++ b/NonHTTPProxy/src/josh/utils/events/ConnectionAttemptListener.java @@ -0,0 +1,9 @@ +package josh.utils.events; + +import java.util.EventListener; + +public interface ConnectionAttemptListener extends EventListener { + + public abstract void ConnectAttempt(PortConnectEvt pkt); + +} diff --git a/NonHTTPProxy/src/josh/utils/events/TCPPacketEvt.java b/NonHTTPProxy/src/josh/utils/events/PortConnectEvt.java similarity index 64% rename from NonHTTPProxy/src/josh/utils/events/TCPPacketEvt.java rename to NonHTTPProxy/src/josh/utils/events/PortConnectEvt.java index 9e6f1d2..fedafe3 100644 --- a/NonHTTPProxy/src/josh/utils/events/TCPPacketEvt.java +++ b/NonHTTPProxy/src/josh/utils/events/PortConnectEvt.java @@ -2,19 +2,21 @@ import java.util.EventObject; -public class TCPPacketEvt extends EventObject { +public class PortConnectEvt extends EventObject { private String sip; private int dport; private String Service; private String time; + private String Proto; - public TCPPacketEvt(Object arg0, String sip, String Service, int dport, String time) { + public PortConnectEvt(Object arg0, String sip, String Service, int dport, String time, String Proto) { super(arg0); this.sip = sip; this.Service = Service; this.dport = dport; this.time = time; + this.Proto = Proto; } public String getSip() { @@ -48,6 +50,13 @@ public String getTime() { public void setTime(String time) { this.time = time; } + + public void setProto(String proto){ + this.Proto = proto; + } + public String getProto(){ + return this.Proto; + } diff --git a/NonHTTPProxy/src/josh/utils/events/TCPConnectionAttemptListener.java b/NonHTTPProxy/src/josh/utils/events/TCPConnectionAttemptListener.java deleted file mode 100644 index 0a29fec..0000000 --- a/NonHTTPProxy/src/josh/utils/events/TCPConnectionAttemptListener.java +++ /dev/null @@ -1,9 +0,0 @@ -package josh.utils.events; - -import java.util.EventListener; - -public interface TCPConnectionAttemptListener extends EventListener { - - public abstract void TcpConnAttempt(TCPPacketEvt pkt); - -}