Overview Visão geral
Socket hijacking allows you to override a server socket opened on the same port by a different process. Socket seqüestro lhe permite sobrescrever um servidor socket aberto sobre o mesmo porto por um processo diferente. There are several good uses of socket hijacking like developing a Há vários bons usos do socket como o desenvolvimento de um seqüestro port blocker application Port bloqueador candidatura (poor man’s firewall) and some bad uses too. (pobre do homem firewall) e também algumas más utilizações.

Normally the operating system doesn’t allow you to open a server socket on a port which is already opened by another (or even the same) application. Normalmente o sistema operacional não permite que você abra um servidor socket em uma porta que já está aberto por outro (ou até mesmo a) requerimento. However there is an exception and an exception to the exception. No entanto, há uma exceção e uma excepção à excepção.

What and how of socket hijacking O que e como seqüestro de soquete
Often a ServerSocket is opened without specifying a particular IP address to bind to. Muitas vezes um ServerSocket é aberta sem especificar um endereço IP especial para o efeito de vincular. So the socket essentially binds to all available IP address of the machine. Portanto, o soquete liga essencialmente disponível para todos os endereços IP da máquina. This is simple for the programmer. Isto é simples para o programador. However it introduces a security hole. No entanto, introduz-se uma falha de segurança. Any application can bind to a specific IP address of the same machine and on the same port. Qualquer aplicação pode vincular a um determinado endereço IP da máquina, e mesmo sobre o mesmo porto. The original server socket still binds on the remaining port. O original server socket liga ainda sobre as restantes portos. In essence the port has been hijacked by the new application for a specific IP address. Na sua essência o porto tem sido invadida pelo novo pedido de um endereço IP específico. This is socket hijacking. Esta é socket seqüestro.

Java support for socket hijacking Java suporte para socket seqüestro
Starting with JDK 1.4 Java supports the method ServerSocket.setReuseAddress(boolean). Começando com JDK 1,4 Java apoia o método ServerSocket.setReuseAddress (boolean). It allows you to hijack a port for a particular IP address as described above. Ela permite que você roubar uma porta para um determinado endereço IP, como descrito acima. Here is a sample code which allows you to hijack a server socket. Aqui está uma amostra código que permite a adulteração um servidor socket.

Code Código
ServerSocket ssock = new ServerSocket(); ServerSocket ssock = new ServerSocket ();
ssock.setReuseAddress(true); // The magic ssock.setReuseAddress (true); / / O mágico
ssock.bind(new InetSocketAddress(addr, i)); // addr = IP, i = port ssock.bind (novo InetSocketAddress (addr, i)) / / addr = IP, i = porto
Socket sock = ssock.accept(); Socket palmilha ssock.accept = ();
// Do your thing with the accepted connection / / Do seu coisa com o aceite conexão
sock.close(); sock.close ();