mirror of
https://github.com/jetty/jetty.project.git
synced 2025-03-04 04:49:12 +00:00
Making DNS Hijacking more evident
This commit is contained in:
parent
c50e547152
commit
c7825731a7
@ -12,15 +12,21 @@ package org.eclipse.jetty.server.handler;
|
|||||||
//You may elect to redistribute this code under either of these licenses.
|
//You may elect to redistribute this code under either of these licenses.
|
||||||
//========================================================================
|
//========================================================================
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import static org.junit.Assume.*;
|
||||||
|
|
||||||
import java.io.BufferedReader;
|
import java.io.BufferedReader;
|
||||||
import java.io.ByteArrayOutputStream;
|
import java.io.ByteArrayOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.InputStreamReader;
|
import java.io.InputStreamReader;
|
||||||
import java.io.OutputStream;
|
import java.io.OutputStream;
|
||||||
|
import java.net.InetAddress;
|
||||||
import java.net.Socket;
|
import java.net.Socket;
|
||||||
|
import java.net.UnknownHostException;
|
||||||
import java.nio.channels.SocketChannel;
|
import java.nio.channels.SocketChannel;
|
||||||
import java.util.concurrent.ConcurrentMap;
|
import java.util.concurrent.ConcurrentMap;
|
||||||
|
|
||||||
import javax.servlet.ServletException;
|
import javax.servlet.ServletException;
|
||||||
import javax.servlet.ServletOutputStream;
|
import javax.servlet.ServletOutputStream;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
@ -31,13 +37,10 @@ import org.eclipse.jetty.io.EndPoint;
|
|||||||
import org.eclipse.jetty.server.Request;
|
import org.eclipse.jetty.server.Request;
|
||||||
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
import org.eclipse.jetty.server.nio.SelectChannelConnector;
|
||||||
import org.eclipse.jetty.toolchain.test.OS;
|
import org.eclipse.jetty.toolchain.test.OS;
|
||||||
import org.eclipse.jetty.util.log.Log;
|
import org.junit.Assert;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assume.assumeTrue;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @version $Revision$ $Date$
|
* @version $Revision$ $Date$
|
||||||
*/
|
*/
|
||||||
@ -120,7 +123,25 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
|||||||
@Test
|
@Test
|
||||||
public void testCONNECTBadHostPort() throws Exception
|
public void testCONNECTBadHostPort() throws Exception
|
||||||
{
|
{
|
||||||
String hostPort = "badlocalhost:" + serverConnector.getLocalPort();
|
String invalidHostname = "AMAZEBALLS_BADHOST.webtide.com";
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
InetAddress addr = InetAddress.getByName(invalidHostname);
|
||||||
|
StringBuilder err = new StringBuilder();
|
||||||
|
err.append("DNS Hijacking detected: ");
|
||||||
|
err.append(invalidHostname).append(" should have not returned a valid IP address [");
|
||||||
|
err.append(addr.getHostAddress()).append("]. ");
|
||||||
|
err.append("Fix your DNS provider to have this test pass.");
|
||||||
|
err.append("\nFor more info see https://en.wikipedia.org/wiki/DNS_hijacking");
|
||||||
|
Assert.assertNull(err.toString(), addr);
|
||||||
|
}
|
||||||
|
catch (UnknownHostException e)
|
||||||
|
{
|
||||||
|
// expected path
|
||||||
|
}
|
||||||
|
|
||||||
|
String hostPort = String.format("%s:%d",invalidHostname,serverConnector.getLocalPort());
|
||||||
String request = "" +
|
String request = "" +
|
||||||
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
|
"CONNECT " + hostPort + " HTTP/1.1\r\n" +
|
||||||
"Host: " + hostPort + "\r\n" +
|
"Host: " + hostPort + "\r\n" +
|
||||||
@ -137,7 +158,7 @@ public class ConnectHandlerTest extends AbstractConnectHandlerTest
|
|||||||
|
|
||||||
// Expect 500 OK from the CONNECT request
|
// Expect 500 OK from the CONNECT request
|
||||||
Response response = readResponse(input);
|
Response response = readResponse(input);
|
||||||
assertEquals("500", response.getCode());
|
assertEquals("Response Code", "500", response.getCode());
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user