Search in sources :

Example 1 with MethodSubnegotiationResults

use of com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults 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 MethodSubnegotiationResults

use of com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults 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 MethodSubnegotiationResults

use of com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults 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)

Example 4 with MethodSubnegotiationResults

use of com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults in project jargyle by jh3nd3rs0n.

the class Socks5UdpFirewallRule 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;
    }
    String clientAddress = cntxt.getClientAddress();
    MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
    String peerAddress = cntxt.getPeerAddress();
    if (this.clientAddressRange != null && !this.clientAddressRange.contains(clientAddress)) {
        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.peerAddressRange != null && !this.peerAddressRange.contains(peerAddress)) {
        return false;
    }
    return true;
}
Also used : MethodSubnegotiationResults(com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults)

Example 5 with MethodSubnegotiationResults

use of com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults in project jargyle by jh3nd3rs0n.

the class Socks5ReplyFirewallRule method applyTo.

@Override
public void applyTo(final Rule.Context context) {
    FirewallRuleAction firewallRuleAction = this.getFirewallRuleAction();
    Context cntxt = (Context) context;
    cntxt.setFirewallRuleAction(firewallRuleAction);
    LogAction logAction = this.getLogAction();
    if (logAction == null) {
        return;
    }
    String clientAddress = cntxt.getClientAddress();
    MethodSubnegotiationResults methSubnegotiationResults = cntxt.getMethodSubnegotiationResults();
    String user = methSubnegotiationResults.getUser();
    String possibleUser = (user != null) ? String.format(" (%s)", user) : "";
    if (firewallRuleAction.equals(FirewallRuleAction.ALLOW)) {
        logAction.invoke(String.format("SOCKS5 reply to %s%s is allowed based on the following " + "firewall rule and context: %s, %s", clientAddress, possibleUser, this, context));
    } else if (firewallRuleAction.equals(FirewallRuleAction.DENY)) {
        logAction.invoke(String.format("SOCKS5 reply to %s%s is denied based on the following " + "firewall rule and context: %s, %s", clientAddress, possibleUser, this, context));
    }
}
Also used : LogAction(com.github.jh3nd3rs0n.jargyle.server.LogAction) MethodSubnegotiationResults(com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults)

Aggregations

MethodSubnegotiationResults (com.github.jh3nd3rs0n.jargyle.server.socks5.MethodSubnegotiationResults)8 LogAction (com.github.jh3nd3rs0n.jargyle.server.LogAction)4 Socks5Request (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Request)3 Route (com.github.jh3nd3rs0n.jargyle.server.Route)1 Routes (com.github.jh3nd3rs0n.jargyle.server.Routes)1 Socks5Reply (com.github.jh3nd3rs0n.jargyle.transport.socks5.Socks5Reply)1