rofl0r / microsocks

tiny, portable SOCKS5 server with very moderate resource usage
Other
1.48k stars 266 forks source link

FR: whitelist IP address in parameter #45

Closed mimi89999 closed 2 years ago

mimi89999 commented 2 years ago

Hello, It would be very useful to be able to pass IP addresses that should be whitelisted as arguments.

rofl0r commented 2 years ago

in case you talk about the auth-once mode, you could implement this functionality easily with a tiny shell script wrapper:

/bin/microsocks-authed

#!/bin/sh
MICROSOCKS=microsocks
user=foo
pass=bar
ip=127.0.0.1
port=1081

auth_once_delayed() {
 sleep 1
 curl --socks5 ${user}:${pass}@${ip}:${port} http://ifconfig.me
}

auth_once_delayed &
exec $MICROSOCKS -1 -i $ip -p $port -u "$user" -P "$pass"

if you don't want to hardcode user, pass, etc you could add a small getopt loop that parses same parameter as microsocks

mimi89999 commented 2 years ago

The problem is that I can't run shell scripts on the device. I worked it around by adding

@@ -416,6 +423,9 @@ int main(int argc, char** argv) {
                                return usage();
                }
        }
+       union sockaddr_union whitelist_addr = {.v4.sin_family = AF_UNSPEC};
+       resolve_sa("MY_IP", 0, &whitelist_addr);
+       add_auth_ip(&whitelist_addr);
        if((auth_user && !auth_pass) || (!auth_user && auth_pass)) {
                dprintf(2, "error: user and pass must be used together\n");
                return 1;
rofl0r commented 2 years ago

nice work. the code of microsocks is deliberately kept simple and readable so users can easily change it to suit their specific usecase.

mimi89999 commented 2 years ago

I think that it's a useful feature that could be used by other users

rofl0r commented 2 years ago

maybe. if i get more requests for it in the future i'll consider implementing it. time will tell whether there's a real demand.

Jieiku commented 2 years ago

I see this got added... I am assuming use it like this:

microsocks -1 -i 0.0.0.0 -p 1080 -w 192.168.1.40 -u user -P password

assuming that is correct, can you specify more than one ip for the whitelist parameter?

Thank you for this software!

EDIT: I assumed wrong, I must not be using the -w feature correctly