How To: Server Socket Hijacking in Java HOW TO :在服務器插座劫持在Java
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 是什麼,以及如何的Socket劫持
Often a ServerSocket is opened without specifying a particular IP address to bind to.往往是一個serversocket是開而不指明特定IP地址綁定到。 So the socket essentially binds to all available IP address of the machine.因此,插座基本上綁定到所有可用的IP地址,該機器。 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.任何應用程序可以綁定到一個特定的IP地址在同一台機器上,並在同一港口。 The original server socket still binds on the remaining port.原來的服務器的Socket仍然具有約束力,對其餘的港口。 In essence the port has been hijacked by the new application for a specific IP address.在本質上的港口已被劫持,新申請一個特定的IP地址。 This is socket hijacking.這是插座劫持。
Java support for socket hijacking Java支持插座劫持
Starting with JDK 1.4 Java supports the method ServerSocket.setReuseAddress(boolean).開始的JDK 1.4的Java支持方法serversocket.setreuseaddress (布爾) 。 It allows you to hijack a port for a particular IP address as described above.它可以讓您劫持港口為某一特定的IP地址如上文所述。 Here is a sample code which allows you to hijack a server socket.這裡是一個範例程式碼,它可以讓您劫持的服務器套接字。
Code 代碼
ServerSocket ssock = new ServerSocket(); serversocket ssock =新serversocket ( ) ;
ssock.setReuseAddress(true); // The magic ssock.setreuseaddress (真實) ; / /魔術
ssock.bind(new InetSocketAddress(addr, i)); // addr = IP, i = port ssock.bind (新inetsocketaddress (地址,我) ) ; / / =的IP地址,我=港口
Socket sock = ssock.accept();插座襪子= ssock.accept ( ) ;
// Do your thing with the accepted connection / /你的事,與接受連線
sock.close(); sock.close ( ) ;
Filed under提起下 Headline News頭條新聞 , , How To如何 , , Java Software Java軟件 , , Tech Note技術說明 | |
| |
RSS 2.0 2.0 | |
Trackback Trackback跟踪 this Article |此文章|
Email this Article電子郵件此文章
You may also like to read您也可以想讀 |




November 16th, 2007 at 4:22 pm 2007年11月16日在下午4時22分
I tried this hijacking, but did not get it work.我想這劫機,但沒有得到它的工作。
Only IP address I could bind to was localhost.只有IP地址,我可以被綁定到本地。
All other IP’s throw java.net.BindException: Cannot assign requested address: JVM_Bind?所有其他IP的投擲java.net.bindexception :不能分配要求地址: jvm_bind ?
November 18th, 2007 at 6:54 am 2007年11月18日在上午06時54分
Does your computer (on which you are running this program) have this IP address?請問您的計算機(上,您正在運行此程序)有這個IP地址是什麼?
Can you ping it?你能平嗎?