Standard Socks5 Server implementation in Java
- TCP Streaming, Bind
- Username/Password Authentication
- Intercept/Monitor incoming clients and connections
- Reverse Proxy
Written in pure Java, no additional libraries, requires Java >= 8
<dependency>
<groupId>space.themelon</groupId>
<artifactId>KSocks5</artifactId>
<version>1.1</version>
</dependency>
implementation("space.themelon:KSocks5:1.1")
- Spawn a simple open proxy server
ProxyServer server = new ProxyServer.Builder(port).build();
...
server.close();
- Create a proxy server with Username / Password Authentication
AuthMode userPassAuth = new AuthMode((username, password) ->
username.equals("secureusername") && password.equals("securepassword"));
ProxyServer proxy = new ProxyServer.Builder(port)
.auth(userPassAuth)
.build();
- Monitor incoming client connections (
clientMonitor
)
ClientCallback monitor = address -> {
System.out.println("New client " + address);
return true; // approve client
};
ProxyServer server = new ProxyServer.Builder(port)
.clientMonitor(monitor)
.build();
- Monitor outgoing connection requests (
connectionMonitor
)
ConnectionCallback monitor = (client, destination, port) -> {
if (isBlacklisted(destination)) {
System.out.println("Blocking connection to " + destination);
return false;
}
return true;
};
ProxyServer server = new ProxyServer.Builder(port)
.connectionMonitor(monitor)
.build();
- Create a reverse proxy to outside, rather than awaiting connection
ProxyServer server = new ProxyServer.Builder(remoteHost, remotePort)
.reverseProxy()
.build();