rofl0r / microsocks

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

Resolving hostname with microsocks. #37

Closed hongyi-zhao closed 3 years ago

hongyi-zhao commented 3 years ago

I'm not sure whether microsocks supports the socks5h protocol, that is, the hostname is resolved remotely on the socks5 server instead of the client.

Any hints will be highly appreciated.

Regards, HY

srd424 commented 3 years ago

Yes, I'm using it in that mode.

rofl0r commented 3 years ago

https://github.com/rofl0r/microsocks/blob/c4b927bd2f9f7444f65d64f93c356b79f1c6d3e8/sockssrv.c#L129-L135

hongyi-zhao commented 3 years ago

I checked the corresponding code snippet, and it seems that it's the default and only supported work manner to resolve hostname with microsocks remotely. Is my understanding correct?

Regards, HY

srd424 commented 3 years ago

It seems to work in both - looking at code, I guess the client tags the connect request with a type flag to say whether it's supply an IP address or a hostname.

hongyi-zhao commented 3 years ago

It seems to work in both - looking at code,

Can you tell me the specific code snippet? To be frank, I'm a newbie in C language.

I guess the client tags the connect request with a type flag to say whether it's supply an IP address or a hostname.

Do you mean that the working mechanism of microsocks is like the following?

This will trigger the local DNS resolution, i.e., by the DNS server set up on the computer where the curl command issues:

$ curl -4 -x socks5://microsocks-server:1080 URL

This will result in remote DNS resolution, that is, by the DNS server set up on the computer where microsocks resides:

$ curl -4 -x socks5h://microsocks-server:1080 URL

rofl0r commented 3 years ago

try it out and use wireshark to see what's happening.

hongyi-zhao commented 3 years ago

Thank you very much for your suggestion. I confirmed the above conclusion with the following testings. For my case, the microsocks is runing on a remote machine with the FQDN pve.hyddns.xyz and listening on port 21080.

On the local machine runs the following:

werner@X10DAi:~$ curl -Iv -4 -x socks5h://pve.hyddns.xyz:21080 www.xpc.edu.cn

At the same time, on the remote computer running microsocks, issue the following command to check the progress of the dns query as noted here:

werner@M4600t:~$ sudo tshark -n  -f 'src port 53' -Y 'dns.qry.name contains "xpc.edu.cn"'
Running as user "root" and group "root". This could be dangerous.
Capturing on 'enp2s0'
    1 0.000000000  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xe697 A www.xpc.edu.cn A 10.8.10.4
    2 0.000027925  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x7d4f A www.xpc.edu.cn A 10.8.10.4
    3 0.004064578  10.8.10.244 → 192.168.1.100 DNS 102 Standard query response 0x04f4 AAAA www.xpc.edu.cn AAAA 240c:c0a8:2043:0:3c06:fea9::
    4 0.004093167  10.8.10.244 → 192.168.1.100 DNS 102 Standard query response 0x0b39 AAAA www.xpc.edu.cn AAAA 240c:c0a8:2043:0:3c06:fea9::
    5 0.004631451  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x4971 A www.xpc.edu.cn A 10.8.10.4
    6 0.006908930  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x70d1 A www.xpc.edu.cn A 10.8.10.4
    7 0.009648804  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x0e0e A www.xpc.edu.cn A 10.8.10.4
    8 0.012232869  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x03f6 A www.xpc.edu.cn A 10.8.10.4
    9 0.015005062  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xdb35 A www.xpc.edu.cn A 10.8.10.4
   10 0.017864612  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x035c A www.xpc.edu.cn A 10.8.10.4
   11 0.020866015  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x835f A www.xpc.edu.cn A 10.8.10.4
   12 0.023223518  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x5d75 A www.xpc.edu.cn A 10.8.10.4
   13 0.026063040  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x4e64 A www.xpc.edu.cn A 10.8.10.4
   14 0.029325483  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xad19 A www.xpc.edu.cn A 10.8.10.4
   15 0.032002892  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x4b24 A www.xpc.edu.cn A 10.8.10.4
   16 0.034743264  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x3107 A www.xpc.edu.cn A 10.8.10.4
   17 0.037462266  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xd3c0 A www.xpc.edu.cn A 10.8.10.4
   18 0.040122251  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x62f5 A www.xpc.edu.cn A 10.8.10.4
   19 0.043142885  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x9e45 A www.xpc.edu.cn A 10.8.10.4
   20 0.045292150  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x1204 A www.xpc.edu.cn A 10.8.10.4
   21 0.048582120  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xec09 A www.xpc.edu.cn A 10.8.10.4
   22 0.051130221  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x808b A www.xpc.edu.cn A 10.8.10.4
   23 0.054182229  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xc77f A www.xpc.edu.cn A 10.8.10.4
   24 0.056801180  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xe322 A www.xpc.edu.cn A 10.8.10.4
   25 0.060044573  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x22b5 A www.xpc.edu.cn A 10.8.10.4
   26 0.062758908  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x5a2e A www.xpc.edu.cn A 10.8.10.4
   27 0.065553641  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xd140 A www.xpc.edu.cn A 10.8.10.4
   28 0.068102505  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x1540 A www.xpc.edu.cn A 10.8.10.4
   29 0.070882644  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xc391 A www.xpc.edu.cn A 10.8.10.4
   30 0.073441378  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x5cff A www.xpc.edu.cn A 10.8.10.4
   31 0.077982558  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xfc4b A www.xpc.edu.cn A 10.8.10.4
   32 0.079565513  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x5e5c A www.xpc.edu.cn A 10.8.10.4
   33 0.081762394  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xf98a A www.xpc.edu.cn A 10.8.10.4
   34 0.084944696  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xa01a A www.xpc.edu.cn A 10.8.10.4
   35 0.087843132  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xc629 A www.xpc.edu.cn A 10.8.10.4
   36 0.090423306  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x6462 A www.xpc.edu.cn A 10.8.10.4
   37 0.093243495  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x46c7 A www.xpc.edu.cn A 10.8.10.4
   38 0.095705434  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x34fc A www.xpc.edu.cn A 10.8.10.4
   39 0.098526758  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x8b21 A www.xpc.edu.cn A 10.8.10.4
   40 0.101364186  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x9392 A www.xpc.edu.cn A 10.8.10.4
   41 0.103836608  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xb096 A www.xpc.edu.cn A 10.8.10.4
   42 0.106576904  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xabee A www.xpc.edu.cn A 10.8.10.4
   43 0.109804577  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x24ab A www.xpc.edu.cn A 10.8.10.4
   44 0.112679493  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x971a A www.xpc.edu.cn A 10.8.10.4
   45 0.115525409  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x2f6c A www.xpc.edu.cn A 10.8.10.4
   46 0.118266322  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0xd233 A www.xpc.edu.cn A 10.8.10.4
   47 0.120683031  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x507e A www.xpc.edu.cn A 10.8.10.4
   48 0.123660276  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x59e1 A www.xpc.edu.cn A 10.8.10.4
   49 0.126224437  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x0248 A www.xpc.edu.cn A 10.8.10.4
   50 0.128875924  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x5592 A www.xpc.edu.cn A 10.8.10.4
   51 5.000219565  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x8053 A www.xpc.edu.cn A 10.8.10.4
   52 5.000243913  10.8.10.244 → 192.168.1.100 DNS 90 Standard query response 0x24c4 A www.xpc.edu.cn A 10.8.10.4