Skip to content

Support socks server name (FQDN) #604

Description

@hiddenman

Hi.

I wrote a patch for original proxychains (https://proxychains.sourceforge.net/) to support using a SOCKS server's name (FQDN) in the config, not just its IP address.

It works fine and you can use config like:
socks5 your-socks5-server.com 1080 username password

This patch is also backward-compartible so you can still use IP-address like:
socks5 192.168.1.1 1080 username password

Would you mind to port and include this patch to proxychains-ng?

Thank you.

--- a/proxychains/libproxychains.c	2025-07-07 00:44:13.000000000 +0300
+++ b/proxychains/libproxychains.c	2025-07-07 01:06:26.296492985 +0300
@@ -72,6 +72,7 @@
 proxy_data proxychains_pd[MAX_CHAIN];
 int proxychains_proxy_count = 0;
 int proxychains_got_chain_data = 0;
+int proxychains_got_chain_host = 0;
 int proxychains_max_chain = 1;
 int proxychains_quiet_mode = 0;
 int proxychains_resolver = 0;
@@ -98,9 +99,10 @@
 //		" real addr %p  wrapped addr %p\n",
 //		true_connect, connect);
 	}
+	if (!true_gethostbyname) {
 	true_gethostbyname = (gethostbyname_t) 
 		dlsym(RTLD_NEXT, "gethostbyname");
-
+    }
 	if (!true_gethostbyname) {
 		fprintf(stderr, "Cannot load symbol 'gethostbyname' %s\n", 
 				dlerror());
@@ -204,7 +206,29 @@
 				port_n=0;
 				sscanf(buff,"%s %s %d %s %s", type,host,&port_n,
 					pd[count].user,pd[count].pass);
-				pd[count].ip=inet_addr(host);
+                struct in_addr addr;
+                if (inet_aton(host, &addr)) {
+                    pd[count].ip = addr.s_addr;
+                    proxychains_write_log("[+] IP used directly: %s\n", host);
+                } else {
+                    struct hostent *he = gethostbyname(host);
+                    if (!he) {
+                        fprintf(stderr, "[!] gethostbyname failed for host: %s\n", host);
+                        pd[count].ip = 0;
+                    } else if (!he->h_addr_list || !he->h_addr_list[0]) {
+                        fprintf(stderr, "[!] No addresses returned for host: %s\n", host);
+                        pd[count].ip = 0;
+                    } else if (he->h_addrtype != AF_INET || he->h_length != sizeof(struct in_addr)) {
+                        fprintf(stderr, "[!] Unexpected address type or length for host: %s\n", host);
+                        pd[count].ip = 0;
+                    } else {
+                        struct in_addr *addr = (struct in_addr *)he->h_addr_list[0];
+                        pd[count].ip = addr->s_addr;
+
+                        proxychains_write_log("[+] Resolved %s to IP: %s\n", host, inet_ntoa(*addr));
+                    }
+                }
+                
 				pd[count].port=htons((unsigned short)port_n);
 				if(!strcmp(type,"http")) {
 					pd[count].pt=HTTP_TYPE;
@@ -252,6 +276,7 @@
 	fclose(file);
 	*proxy_count=count;
 	proxychains_got_chain_data=1;
+	proxychains_got_chain_host=1;
 }
 
 
@@ -296,13 +321,25 @@
 struct hostent *gethostbyname(const char *name)
 {
 	PDEBUG("gethostbyname: %s\n",name);
+	if(!proxychains_got_chain_host) {
+        if (!true_gethostbyname) {
+    	    true_gethostbyname = (gethostbyname_t) 
+    		dlsym(RTLD_NEXT, "gethostbyname");
+        }
+	    if (!true_gethostbyname) {
+		    fprintf(stderr, "Cannot load symbol 'gethostbyname' %s\n", 
+			    	dlerror());
+		    exit(1);
+	    }
+		return true_gethostbyname(name);
+    } else {
 	if(!init_l)
 		init_lib();
 	if(proxychains_resolver)
 		return proxy_gethostbyname(name);
 	else
 		return true_gethostbyname(name);
-			
+    }		
 	return NULL;
 }
 int getaddrinfo(const char *node, const char *service,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions