From c820bcd5d885837d007e65fa6c842dfc0df5eead Mon Sep 17 00:00:00 2001 From: Nimrod Aviram Date: Fri, 2 Aug 2019 19:20:19 +0300 Subject: [PATCH 1/3] Trying to get SNI to work. --- .gitignore | 2 ++ .../core/config/delegate/ClientDelegate.java | 1 + .../de/rub/nds/tlsattacker/transport/Connection.java | 2 ++ .../transport/TransportHandlerFactory.java | 12 ++++++------ .../transport/tcp/ClientTcpTransportHandler.java | 12 +++++++++++- 5 files changed, 22 insertions(+), 7 deletions(-) diff --git a/.gitignore b/.gitignore index b6ef39ca9c..3509c80c02 100644 --- a/.gitignore +++ b/.gitignore @@ -42,3 +42,5 @@ Utils/.settings/org.eclipse.core.resources.prefs Utils/.settings/org.eclipse.jdt.core.prefs .project test.sh +.settings/ +.classpath diff --git a/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/delegate/ClientDelegate.java b/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/delegate/ClientDelegate.java index f0506f70c7..70a294b815 100644 --- a/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/delegate/ClientDelegate.java +++ b/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/delegate/ClientDelegate.java @@ -77,6 +77,7 @@ public void applyDelegate(Config config) { con.setPort(uri.getPort()); } if (IPAddress.isValid(uri.getHost())) { + System.out.println("Setting IP: " + uri.getHost()); con.setIp(uri.getHost()); if (sniHostname != null) { con.setHostname(sniHostname); diff --git a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java index fec3a70663..270469c97d 100644 --- a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java +++ b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java @@ -57,6 +57,8 @@ public String getIp() { } public void setIp(String ip) { + System.out.println("Setting IP: " + ip); + new Exception().printStackTrace(System.out); this.ip = ip; } diff --git a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/TransportHandlerFactory.java b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/TransportHandlerFactory.java index 6ae98858e3..16b840717f 100644 --- a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/TransportHandlerFactory.java +++ b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/TransportHandlerFactory.java @@ -28,7 +28,7 @@ public static TransportHandler createTransportHandler(Connection con) { switch (con.getTransportHandlerType()) { case TCP: if (localConEndType == ConnectionEndType.CLIENT) { - return new ClientTcpTransportHandler(timeout, con.getHostname(), con.getPort()); + return new ClientTcpTransportHandler(timeout, con.getIp(), con.getPort()); } else { return new ServerTcpTransportHandler(timeout, con.getPort()); } @@ -36,7 +36,7 @@ public static TransportHandler createTransportHandler(Connection con) { throw new UnsupportedOperationException("EAP_TLS is currently not supported"); case UDP: if (localConEndType == ConnectionEndType.CLIENT) { - return new ClientUdpTransportHandler(timeout, con.getHostname(), con.getPort()); + return new ClientUdpTransportHandler(timeout, con.getIp(), con.getPort()); } else { return new ServerUdpTransportHandler(timeout, con.getPort()); } @@ -50,26 +50,26 @@ public static TransportHandler createTransportHandler(Connection con) { throw new UnsupportedOperationException("STREAM TransportHandler can only be created manually"); case TCP_TIMING: if (localConEndType == ConnectionEndType.CLIENT) { - return new TimingClientTcpTransportHandler(timeout, con.getHostname(), con.getPort()); + return new TimingClientTcpTransportHandler(timeout, con.getIp(), con.getPort()); } else { return new TimingServerTcpTransportHandler(timeout, con.getPort()); } case UDP_TIMING: if (localConEndType == ConnectionEndType.CLIENT) { - return new TimingClientUdpTransportHandler(timeout, con.getHostname(), con.getPort()); + return new TimingClientUdpTransportHandler(timeout, con.getIp(), con.getPort()); } else { return new TimingServerUdpTransportHandler(timeout, con.getPort()); } case TCP_PROXY_TIMING: if (localConEndType == ConnectionEndType.CLIENT) { - return new TimingProxyClientTcpTransportHandler(timeout, con.getHostname(), con.getPort()); + return new TimingProxyClientTcpTransportHandler(timeout, con.getIp(), con.getPort()); } else { throw new UnsupportedOperationException( "TCP_PROXY_TIMING for server sockets is currently not supported"); } case TCP_NO_DELAY: if (localConEndType == ConnectionEndType.CLIENT) { - return new ClientTcpNoDelayTransportHandler(timeout, con.getHostname(), con.getPort()); + return new ClientTcpNoDelayTransportHandler(timeout, con.getIp(), con.getPort()); } else { throw new UnsupportedOperationException( "This transport handler type is only supported in client mode"); diff --git a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java index 4e9b707d8f..c3c256e432 100644 --- a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java +++ b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java @@ -29,14 +29,22 @@ public class ClientTcpTransportHandler extends TransportHandler { public ClientTcpTransportHandler(Connection connection) { super(connection.getTimeout(), ConnectionEndType.CLIENT); - this.hostname = connection.getHostname(); + this.hostname = connection.getIp(); + System.out.println("Ctor 1: Got hostname: " + this.hostname); this.port = connection.getPort(); this.connectionTimeout = 60000; } + public ClientTcpTransportHandler(Connection connection, long timeout) { + this(connection); + this.connectionTimeout = timeout; + } + public ClientTcpTransportHandler(long timeout, String hostname, int port) { super(timeout, ConnectionEndType.CLIENT); this.hostname = hostname; + System.out.println("Ctor 2: Got hostname: " + this.hostname); + new Exception().printStackTrace(System.out); this.port = port; this.connectionTimeout = timeout; } @@ -44,6 +52,7 @@ public ClientTcpTransportHandler(long timeout, String hostname, int port) { public ClientTcpTransportHandler(long connectionTimeout, long timeout, String hostname, int port) { super(timeout, ConnectionEndType.CLIENT); this.hostname = hostname; + System.out.println("Ctor 3: Got hostname: " + this.hostname); this.port = port; this.connectionTimeout = connectionTimeout; } @@ -59,6 +68,7 @@ public void closeConnection() throws IOException { @Override public void initialize() throws IOException { socket = new Socket(); + System.out.println("Connecting to " + hostname); socket.connect(new InetSocketAddress(hostname, port), (int) connectionTimeout); if (!socket.isConnected()) { throw new IOException("Could not connect to " + hostname + ":" + "port"); From 84ed6b9bbf112efe0ac3d45d1f8513465fa07e9d Mon Sep 17 00:00:00 2001 From: Nimrod Aviram Date: Fri, 2 Aug 2019 19:36:01 +0300 Subject: [PATCH 2/3] Copying IP in the copy constructor of OutboundConnection. Removed annoying stack traces printing. --- .../rub/nds/tlsattacker/core/connection/OutboundConnection.java | 1 + .../main/java/de/rub/nds/tlsattacker/transport/Connection.java | 1 - .../nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java | 1 - 3 files changed, 1 insertion(+), 2 deletions(-) diff --git a/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/connection/OutboundConnection.java b/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/connection/OutboundConnection.java index 64ff375bc3..16c5ddaeee 100644 --- a/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/connection/OutboundConnection.java +++ b/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/connection/OutboundConnection.java @@ -40,6 +40,7 @@ public OutboundConnection(String alias, Integer port, String hostname) { public OutboundConnection(OutboundConnection other) { this.alias = other.alias; this.hostname = other.hostname; + this.ip = other.ip; this.port = other.port; this.proxyDataHostname = other.proxyDataHostname; this.proxyDataPort = other.proxyDataPort; diff --git a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java index 270469c97d..d6f9b053a8 100644 --- a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java +++ b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java @@ -58,7 +58,6 @@ public String getIp() { public void setIp(String ip) { System.out.println("Setting IP: " + ip); - new Exception().printStackTrace(System.out); this.ip = ip; } diff --git a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java index c3c256e432..735a4faddd 100644 --- a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java +++ b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java @@ -44,7 +44,6 @@ public ClientTcpTransportHandler(long timeout, String hostname, int port) { super(timeout, ConnectionEndType.CLIENT); this.hostname = hostname; System.out.println("Ctor 2: Got hostname: " + this.hostname); - new Exception().printStackTrace(System.out); this.port = port; this.connectionTimeout = timeout; } From 45096ff3f7bba789955ccd8fae887e96ae4cb47c Mon Sep 17 00:00:00 2001 From: Nimrod Aviram Date: Fri, 2 Aug 2019 19:40:13 +0300 Subject: [PATCH 3/3] Removing debug prints. --- .../nds/tlsattacker/core/config/delegate/ClientDelegate.java | 1 - .../java/de/rub/nds/tlsattacker/transport/Connection.java | 1 - .../tlsattacker/transport/tcp/ClientTcpTransportHandler.java | 4 ---- 3 files changed, 6 deletions(-) diff --git a/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/delegate/ClientDelegate.java b/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/delegate/ClientDelegate.java index 70a294b815..f0506f70c7 100644 --- a/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/delegate/ClientDelegate.java +++ b/TLS-Core/src/main/java/de/rub/nds/tlsattacker/core/config/delegate/ClientDelegate.java @@ -77,7 +77,6 @@ public void applyDelegate(Config config) { con.setPort(uri.getPort()); } if (IPAddress.isValid(uri.getHost())) { - System.out.println("Setting IP: " + uri.getHost()); con.setIp(uri.getHost()); if (sniHostname != null) { con.setHostname(sniHostname); diff --git a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java index d6f9b053a8..fec3a70663 100644 --- a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java +++ b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/Connection.java @@ -57,7 +57,6 @@ public String getIp() { } public void setIp(String ip) { - System.out.println("Setting IP: " + ip); this.ip = ip; } diff --git a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java index 735a4faddd..4b15655c50 100644 --- a/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java +++ b/Transport/src/main/java/de/rub/nds/tlsattacker/transport/tcp/ClientTcpTransportHandler.java @@ -30,7 +30,6 @@ public class ClientTcpTransportHandler extends TransportHandler { public ClientTcpTransportHandler(Connection connection) { super(connection.getTimeout(), ConnectionEndType.CLIENT); this.hostname = connection.getIp(); - System.out.println("Ctor 1: Got hostname: " + this.hostname); this.port = connection.getPort(); this.connectionTimeout = 60000; } @@ -43,7 +42,6 @@ public ClientTcpTransportHandler(Connection connection, long timeout) { public ClientTcpTransportHandler(long timeout, String hostname, int port) { super(timeout, ConnectionEndType.CLIENT); this.hostname = hostname; - System.out.println("Ctor 2: Got hostname: " + this.hostname); this.port = port; this.connectionTimeout = timeout; } @@ -51,7 +49,6 @@ public ClientTcpTransportHandler(long timeout, String hostname, int port) { public ClientTcpTransportHandler(long connectionTimeout, long timeout, String hostname, int port) { super(timeout, ConnectionEndType.CLIENT); this.hostname = hostname; - System.out.println("Ctor 3: Got hostname: " + this.hostname); this.port = port; this.connectionTimeout = connectionTimeout; } @@ -67,7 +64,6 @@ public void closeConnection() throws IOException { @Override public void initialize() throws IOException { socket = new Socket(); - System.out.println("Connecting to " + hostname); socket.connect(new InetSocketAddress(hostname, port), (int) connectionTimeout); if (!socket.isConnected()) { throw new IOException("Could not connect to " + hostname + ":" + "port");