use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply in project jargyle by jh3nd3rs0n.
the class ConnectCommandWorker method run.
@Override
public void run() throws IOException {
Socks5Reply socks5Rep = null;
Socket serverFacingSocket = null;
try {
serverFacingSocket = this.newServerFacingSocket();
if (serverFacingSocket == null) {
return;
}
String serverBoundAddress = serverFacingSocket.getInetAddress().getHostAddress();
int serverBoundPort = serverFacingSocket.getPort();
socks5Rep = Socks5Reply.newInstance(Reply.SUCCEEDED, serverBoundAddress, serverBoundPort);
FirewallRule.Context context = new Socks5ReplyFirewallRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), this.methodSubnegotiationResults, this.socks5Request, socks5Rep);
if (!this.commandWorkerContext.canAllowSocks5Reply(this, context, LOGGER)) {
return;
}
if (!this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER)) {
return;
}
RelayServer.Builder builder = new RelayServer.Builder(this.clientFacingSocket, serverFacingSocket);
builder.bufferSize(this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_CONNECT_RELAY_BUFFER_SIZE).intValue());
builder.idleTimeout(this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_CONNECT_RELAY_IDLE_TIMEOUT).intValue());
try {
TcpBasedCommandWorkerHelper.passData(builder);
} catch (IOException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in starting to pass data"), e);
}
} finally {
if (serverFacingSocket != null && !serverFacingSocket.isClosed()) {
serverFacingSocket.close();
}
}
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply in project jargyle by jh3nd3rs0n.
the class ResolveCommandWorker method run.
@Override
public void run() throws IOException {
Socks5Reply socks5Rep = null;
HostResolver hostResolver = this.netObjectFactory.newHostResolver();
InetAddress inetAddress = null;
try {
inetAddress = hostResolver.resolve(this.desiredDestinationAddress);
} catch (UnknownHostException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in resolving the hostname"), e);
socks5Rep = Socks5Reply.newFailureInstance(Reply.HOST_UNREACHABLE);
this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return;
} catch (IOException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in resolving the hostname"), e);
socks5Rep = Socks5Reply.newFailureInstance(Reply.GENERAL_SOCKS_SERVER_FAILURE);
this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return;
}
String serverBoundAddress = inetAddress.getHostAddress();
int serverBoundPort = desiredDestinationPort;
socks5Rep = Socks5Reply.newInstance(Reply.SUCCEEDED, serverBoundAddress, serverBoundPort);
FirewallRule.Context context = new Socks5ReplyFirewallRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), this.methodSubnegotiationResults, this.socks5Request, socks5Rep);
if (!this.commandWorkerContext.canAllowSocks5Reply(this, context, LOGGER)) {
return;
}
this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply in project jargyle by jh3nd3rs0n.
the class Socks5RequestWorkerContext method canAllowSocks5Reply.
public final boolean canAllowSocks5Reply(final Object worker, final FirewallRule.Context context, final Logger logger) {
Socks5ReplyFirewallRules socks5ReplyFirewallRules = this.getSettings().getLastValue(Socks5SettingSpecConstants.SOCKS5_SOCKS5_REPLY_FIREWALL_RULES);
socks5ReplyFirewallRules.applyTo(context);
if (FirewallRuleAction.ALLOW.equals(context.getFirewallRuleAction())) {
return true;
}
Socks5Reply rep = Socks5Reply.newFailureInstance(Reply.CONNECTION_NOT_ALLOWED_BY_RULESET);
this.sendSocks5Reply(worker, rep, logger);
return false;
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply in project jargyle by jh3nd3rs0n.
the class BindCommandWorker method run.
@Override
public void run() throws IOException {
Socks5Reply socks5Rep = null;
ServerSocket listenSocket = null;
Socket inboundSocket = null;
try {
listenSocket = this.netObjectFactory.newServerSocket();
if (!this.configureListenSocket(listenSocket)) {
return;
}
if (!this.bindListenSocket(listenSocket)) {
return;
}
InetAddress inetAddress = listenSocket.getInetAddress();
String serverBoundAddress = inetAddress.getHostAddress();
int serverBoundPort = listenSocket.getLocalPort();
socks5Rep = Socks5Reply.newInstance(Reply.SUCCEEDED, serverBoundAddress, serverBoundPort);
FirewallRule.Context context = new Socks5ReplyFirewallRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), this.methodSubnegotiationResults, this.socks5Request, socks5Rep);
if (!this.commandWorkerContext.canAllowSocks5Reply(this, context, LOGGER)) {
return;
}
if (!this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER)) {
return;
}
inboundSocket = this.acceptInboundSocketFrom(listenSocket);
listenSocket.close();
if (inboundSocket == null) {
return;
}
if (!this.configureInboundSocket(inboundSocket)) {
return;
}
serverBoundAddress = inboundSocket.getInetAddress().getHostAddress();
serverBoundPort = inboundSocket.getLocalPort();
socks5Rep = Socks5Reply.newInstance(Reply.SUCCEEDED, serverBoundAddress, serverBoundPort);
context = new Socks5ReplyFirewallRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), this.methodSubnegotiationResults, this.socks5Request, socks5Rep);
if (!this.canAllowSecondSocks5Reply(context)) {
return;
}
if (!this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER)) {
return;
}
RelayServer.Builder builder = new RelayServer.Builder(this.clientFacingSocket, inboundSocket);
builder.bufferSize(this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_BIND_RELAY_BUFFER_SIZE).intValue());
builder.idleTimeout(this.settings.getLastValue(Socks5SettingSpecConstants.SOCKS5_ON_BIND_RELAY_IDLE_TIMEOUT).intValue());
try {
TcpBasedCommandWorkerHelper.passData(builder);
} catch (IOException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in starting to pass data"), e);
}
} finally {
if (inboundSocket != null && !inboundSocket.isClosed()) {
inboundSocket.close();
}
if (listenSocket != null && !listenSocket.isClosed()) {
listenSocket.close();
}
}
}
use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply in project jargyle by jh3nd3rs0n.
the class BindCommandWorker method bindListenSocket.
private boolean bindListenSocket(final ServerSocket listenSocket) {
Socks5Reply socks5Rep = null;
HostResolver hostResolver = this.netObjectFactory.newHostResolver();
try {
listenSocket.bind(new InetSocketAddress(hostResolver.resolve(this.desiredDestinationAddress), this.desiredDestinationPort));
} catch (IOException e) {
LOGGER.error(ObjectLogMessageHelper.objectLogMessage(this, "Error in binding the listen socket"), e);
socks5Rep = Socks5Reply.newFailureInstance(Reply.GENERAL_SOCKS_SERVER_FAILURE);
this.commandWorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
return false;
}
return true;
}
Aggregations