rofl0r / rofl0r/proxychains-ng

Support socks server name (FQDN)

Open
#604 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
C
Stars
10.7k
Forks
1.1k
PR merge metrics
No merged PRs in 30d

Description

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,

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in libproxychains.c, reading the configuration parsing and gethostbyname entry points shown in the proposed patch. Verify that SOCKS server FQDNs such as your-socks5-server.com work while numeric IP addresses remain compatible, and inspect the resolver-related paths before deciding how to validate the change.

Written by the indexing model from the issue text.

Assessment

Tech stack
c
Domain
networking
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.