How To: Server Socket Hijacking in Java
By Angsuman Chakraborty, Gaea News NetworkTuesday, June 6, 2006
Overview
Socket hijacking allows you to override a server socket opened on the same port by a different process. There are several good uses of socket hijacking like developing a port blocker application (poor man’s firewall) and some bad uses too.
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. However there is an exception and an exception to the exception.
What and how of socket hijacking
Often a ServerSocket is opened without specifying a particular IP address to bind to. So the socket essentially binds to all available IP address of the machine. This is simple for the programmer. However it introduces a security hole. Any application can bind to a specific IP address of the same machine and on the same port. The original server socket still binds on the remaining port. In essence the port has been hijacked by the new application for a specific IP address. This is socket hijacking.
Java support for socket hijacking
Starting with JDK 1.4 Java supports the method ServerSocket.setReuseAddress(boolean). It allows you to hijack a port for a particular IP address as described above. Here is a sample code which allows you to hijack a server socket.
Code
ServerSocket ssock = new ServerSocket();
ssock.setReuseAddress(true); // The magic
ssock.bind(new InetSocketAddress(addr, i)); // addr = IP, i = port
Socket sock = ssock.accept();
// Do your thing with the accepted connection
sock.close();
January 6, 2010: 10:39 pm
This is getting a bit more subjective, but I much prefer the Zune Marketplace. The interface is colorful, has more flair, and some cool features like ‘Mixview’ that let you quickly see related albums, songs, or other users related to what you’re listening to. Clicking on one of those will center on that item, and another set of “neighbors” will come into view, allowing you to navigate around exploring by similar artists, songs, or users. Speaking of users, the Zune “Social” is also great fun, letting you find others with shared tastes and becoming friends with them. You then can listen to a playlist created based on an amalgamation of what all your friends are listening to, which is also enjoyable. Those concerned with privacy will be relieved to know you can prevent the public from seeing your personal listening habits if you so choose. |
ami ku4 |
December 16, 2009: 2:15 pm
will this server socket implementation block access to all other services trying to use this port? |
arun |
Jame |
Jame |
November 18, 2007: 6:54 am
Does your computer (on which you are running this program) have this IP address? Can you ping it? |
Tero Lehtinen |
November 16, 2007: 4:22 pm
I tried this hijacking, but did not get it work. |
Tyson F. Gautreaux