Search in sources :

Example 1 with Socks5Request

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.

the class Socks5ReplyFirewallRule method appliesTo.

@Override
public boolean appliesTo(final Rule.Context context) {
    if (!(context instanceof Context)) {
        return false;
    }
    Context cntxt = (Context) context;
    if (cntxt.getFirewallRuleAction() != null) {
        return false;
    }
    MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
    Socks5Request socks5Req = cntxt.getSocks5Request();
    Socks5Reply socks5Rep = cntxt.getSocks5Reply();
    if (this.clientAddressRange != null && !this.clientAddressRange.contains(cntxt.getClientAddress())) {
        return false;
    }
    if (this.socksServerAddressRange != null && !this.socksServerAddressRange.contains(cntxt.getSocksServerAddress())) {
        return false;
    }
    if (this.method != null && !this.method.equals(methSubnegotiationResults.getMethod())) {
        return false;
    }
    if (this.user != null && !this.user.equals(methSubnegotiationResults.getUser())) {
        return false;
    }
    if (this.command != null && !this.command.equals(socks5Req.getCommand())) {
        return false;
    }
    if (this.desiredDestinationAddressRange != null && !this.desiredDestinationAddressRange.contains(socks5Req.getDesiredDestinationAddress())) {
        return false;
    }
    if (this.desiredDestinationPortRange != null && !this.desiredDestinationPortRange.contains(Port.newInstance(socks5Req.getDesiredDestinationPort()))) {
        return false;
    }
    if (this.serverBoundAddressRange != null && !this.serverBoundAddressRange.contains(socks5Rep.getServerBoundAddress())) {
        return false;
    }
    if (this.serverBoundPortRange != null && !this.serverBoundPortRange.contains(Port.newInstance(socks5Rep.getServerBoundPort()))) {
        return false;
    }
    return true;
}
Also used : Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) MethodSubnegotiationResults(com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)

Example 2 with Socks5Request

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.

the class Socks5RequestFirewallRule method appliesTo.

@Override
public boolean appliesTo(final Rule.Context context) {
    if (!(context instanceof Context)) {
        return false;
    }
    Context cntxt = (Context) context;
    if (cntxt.getFirewallRuleAction() != null) {
        return false;
    }
    MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
    Socks5Request socks5Req = cntxt.getSocks5Request();
    if (this.clientAddressRange != null && !this.clientAddressRange.contains(cntxt.getClientAddress())) {
        return false;
    }
    if (this.socksServerAddressRange != null && !this.socksServerAddressRange.contains(cntxt.getSocksServerAddress())) {
        return false;
    }
    if (this.method != null && !this.method.equals(methSubnegotiationResults.getMethod())) {
        return false;
    }
    if (this.user != null && !this.user.equals(methSubnegotiationResults.getUser())) {
        return false;
    }
    if (this.command != null && !this.command.equals(socks5Req.getCommand())) {
        return false;
    }
    if (this.desiredDestinationAddressRange != null && !this.desiredDestinationAddressRange.contains(socks5Req.getDesiredDestinationAddress())) {
        return false;
    }
    if (this.desiredDestinationPortRange != null && !this.desiredDestinationPortRange.contains(Port.newInstance(socks5Req.getDesiredDestinationPort()))) {
        return false;
    }
    return true;
}
Also used : Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) MethodSubnegotiationResults(com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults)

Example 3 with Socks5Request

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.

the class Socks5Worker method run.

public void run() throws IOException {
    this.clientFacingInputStream = this.clientFacingSocket.getInputStream();
    Method method = this.negotiateMethod();
    if (method == null) {
        return;
    }
    MethodSubnegotiationResults methodSubnegotiationResults = this.doMethodSubnegotiation(method);
    if (methodSubnegotiationResults == null) {
        return;
    }
    Socket socket = methodSubnegotiationResults.getSocket();
    this.clientFacingInputStream = socket.getInputStream();
    this.clientFacingSocket = socket;
    this.socks5WorkerContext = new Socks5WorkerContext(new WorkerContext(this.clientFacingSocket, this.socks5WorkerContext.getConfiguration(), this.socks5WorkerContext.getRoute(), this.socks5WorkerContext.getRoutes(), this.socks5WorkerContext.getClientFacingDtlsDatagramSocketFactory()));
    Socks5Request socks5Request = this.newSocks5Request();
    if (socks5Request == null) {
        return;
    }
    if (!this.canAllowSocks5Request(new Socks5RequestFirewallRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), methodSubnegotiationResults, socks5Request))) {
        return;
    }
    Route route = this.selectRoute(new Socks5RequestRoutingRule.Context(this.clientFacingSocket.getInetAddress().getHostAddress(), this.clientFacingSocket.getLocalAddress().getHostAddress(), methodSubnegotiationResults, socks5Request, this.socks5WorkerContext.getRoutes()));
    if (route == null) {
        return;
    }
    this.socks5WorkerContext = new Socks5WorkerContext(new WorkerContext(this.socks5WorkerContext.getClientFacingSocket(), this.socks5WorkerContext.getConfiguration(), route, this.socks5WorkerContext.getRoutes(), this.socks5WorkerContext.getClientFacingDtlsDatagramSocketFactory()));
    Socks5RequestWorkerContext socks5RequestWorkerContext = new Socks5RequestWorkerContext(this.socks5WorkerContext, methodSubnegotiationResults, socks5Request);
    Socks5RequestWorker socks5RequestWorker = this.newSocks5RequestWorker(socks5RequestWorkerContext);
    socks5RequestWorker.run();
}
Also used : WorkerContext(com.github.jh3nd3rs0n.jargyle.server.WorkerContext) Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) Method(com.github.jh3nd3rs0n.jargyle.transport.socks5.Method) WorkerContext(com.github.jh3nd3rs0n.jargyle.server.WorkerContext) Socks5RequestRoutingRule(com.github.jh3nd3rs0n.jargyle.server.rules.impl.Socks5RequestRoutingRule) Socket(java.net.Socket) Route(com.github.jh3nd3rs0n.jargyle.server.Route)

Example 4 with Socks5Request

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.

the class Socks5Worker method newSocks5Request.

private Socks5Request newSocks5Request() {
    Socks5Request socks5Request = null;
    try {
        socks5Request = Socks5Request.newInstanceFrom(this.clientFacingInputStream);
    } catch (AddressTypeNotSupportedException e) {
        LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Unable to parse the SOCKS5 request"), e);
        Socks5Reply socks5Rep = Socks5Reply.newFailureInstance(Reply.ADDRESS_TYPE_NOT_SUPPORTED);
        this.socks5WorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
        return null;
    } catch (CommandNotSupportedException e) {
        LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Unable to parse the SOCKS5 request"), e);
        Socks5Reply socks5Rep = Socks5Reply.newFailureInstance(Reply.COMMAND_NOT_SUPPORTED);
        this.socks5WorkerContext.sendSocks5Reply(this, socks5Rep, LOGGER);
        return null;
    } catch (IOException e) {
        ClientFacingIOExceptionLoggingHelper.log(LOGGER, ObjectLogMessageHelper.objectLogMessage(this, "Error in parsing the SOCKS5 request"), e);
        return null;
    }
    LOGGER.debug(ObjectLogMessageHelper.objectLogMessage(this, "Received %s", socks5Request.toString()));
    return socks5Request;
}
Also used : Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) Socks5Reply(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply) CommandNotSupportedException(com.github.jh3nd3rs0n.jargyle.transport.socks5.CommandNotSupportedException) IOException(java.io.IOException) AddressTypeNotSupportedException(com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressTypeNotSupportedException)

Example 5 with Socks5Request

use of com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request in project jargyle by jh3nd3rs0n.

the class Socks5RequestRoutingRule method appliesTo.

@Override
public boolean appliesTo(final Rule.Context context) {
    if (!(context instanceof Context)) {
        return false;
    }
    Context cntxt = (Context) context;
    if (cntxt.getRoute() != null) {
        return false;
    }
    MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
    Socks5Request socks5Req = cntxt.getSocks5Request();
    if (this.clientAddressRange != null && !this.clientAddressRange.contains(cntxt.getClientAddress())) {
        return false;
    }
    if (this.socksServerAddressRange != null && !this.socksServerAddressRange.contains(cntxt.getSocksServerAddress())) {
        return false;
    }
    if (this.method != null && !this.method.equals(methSubnegotiationResults.getMethod())) {
        return false;
    }
    if (this.user != null && !this.user.equals(methSubnegotiationResults.getUser())) {
        return false;
    }
    if (this.command != null && !this.command.equals(socks5Req.getCommand())) {
        return false;
    }
    if (this.desiredDestinationAddressRange != null && !this.desiredDestinationAddressRange.contains(socks5Req.getDesiredDestinationAddress())) {
        return false;
    }
    if (this.desiredDestinationPortRange != null && !this.desiredDestinationPortRange.contains(Port.newInstance(socks5Req.getDesiredDestinationPort()))) {
        return false;
    }
    return true;
}
Also used : Socks5Request(com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request) MethodSubnegotiationResults(com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults)

Aggregations

Socks5Request (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request)6 MethodSubnegotiationResults (com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults)3 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)3 Method (com.github.jh3nd3rs0n.jargyle.transport.socks5.Method)2 Socket (java.net.Socket)2 Properties (com.github.jh3nd3rs0n.jargyle.client.Properties)1 Route (com.github.jh3nd3rs0n.jargyle.server.Route)1 WorkerContext (com.github.jh3nd3rs0n.jargyle.server.WorkerContext)1 Socks5RequestRoutingRule (com.github.jh3nd3rs0n.jargyle.server.rules.impl.Socks5RequestRoutingRule)1 AddressType (com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressType)1 AddressTypeNotSupportedException (com.github.jh3nd3rs0n.jargyle.transport.socks5.AddressTypeNotSupportedException)1 CommandNotSupportedException (com.github.jh3nd3rs0n.jargyle.transport.socks5.CommandNotSupportedException)1 MethodEncapsulation (com.github.jh3nd3rs0n.jargyle.transport.socks5.MethodEncapsulation)1 Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Reply)1 IOException (java.io.IOException)1 InetAddress (java.net.InetAddress)1 UnknownHostException (java.net.UnknownHostException)1