java hijack socket possible?

2020-05-03 00:54发布

I suddenly find myself wondering this question, is it possible in java to hijack a socket?

say a server is listening on port 5000, would it be possible to write a java programme to listen on port 5000, and forward the same data to the server via port 5000.

What would be involved in doing this? I feel this involves writing a new network driver that would pass the data to the java prog, which then does some processing and pass it back to the driver before sending it to the server. Of course all this processing could just as well be done in the driver code itself~

And just out of curiosity, how would you approach writing this driver for a windows noob?

3条回答
我欲成王,谁敢阻挡
2楼-- · 2020-05-03 01:23

Or maybe you want to capture the traffic and inject your packets in communication ? If so, then try jpcap

查看更多
甜甜的少女心
3楼-- · 2020-05-03 01:33

Network sockets are managed by the operating system, and the OS will not let you bind to a socket that is already in use. So yes, you would need to do some trickery on the network driver level.

查看更多
Lonely孤独者°
4楼-- · 2020-05-03 01:36

Sounds like you are being naughty. As Thilo said, you can't typically hijack a port. You could proxy for the port, so have clients connect to port 5001, and your program listens on 5001, then forwards to 5000. You could also do the same at the host level - replace host X with host y. Host y runs your program on port 5000 and forwards to host X on port 5000.

查看更多
登录 后发表回答