Package: proxychains / 3.1-6

100-exclude-localhost.patch Patch series | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
Description: Solve problems with connecting to localhost.
Forwarded: no
Author: Emilio López <turl@tuxfamily.org>
Last-Update: 2009-03-03
--- proxychains-3.1.orig/proxychains/libproxychains.c	2006-03-16 05:16:59.000000000 +1300
+++ proxychains-3.1/proxychains/libproxychains.c	2007-04-18 15:31:24.000000000 +1200
@@ -42,6 +42,30 @@
 #define     SOCKFAMILY(x)     (satosin(x)->sin_family)
 #define     MAX_CHAIN 30*1024
 
+#ifdef PTRUE
+#undef PTRUE
+#endif
+#define PTRUE 1
+
+#ifdef PFALSE
+#undef PFALSE
+#endif
+#define PFALSE 0
+
+/* total number of available slots for subnets */
+#define	    MAX_LOCAL_NETS 20
+
+/* structur for representing networks to be excluded */
+typedef struct 
+{
+    int	valid;
+    unsigned int subnetwork;
+    unsigned int subnetmask;
+} my_network;
+
+my_network localnet[MAX_LOCAL_NETS]; /* array of sub nets */
+
+
 int tcp_read_time_out;
 int tcp_connect_time_out;
 chain_type proxychains_ct;
@@ -55,14 +79,15 @@
 static inline void get_chain_data(
 	proxy_data *pd,
 	unsigned int *proxy_count,
-	chain_type *ct);
+	chain_type *ct,
+	my_network *subnets);
 
 static void init_lib()
 {
 //	proxychains_write_log("ProxyChains-"VERSION
-//			" (http://proxychains.sf.net)\n");
-	
-	get_chain_data(proxychains_pd,&proxychains_proxy_count,&proxychains_ct);
+//			" (http://proxychains.sf.net)\n");	
+	get_chain_data(proxychains_pd,&proxychains_proxy_count,&proxychains_ct,localnet);
+
 	true_connect = (connect_t) dlsym(RTLD_NEXT, "connect");
 
 	if (!true_connect) {
@@ -140,11 +165,12 @@
 static inline void get_chain_data(
 			proxy_data *pd,
 			unsigned int *proxy_count,
-			chain_type *ct)
+			chain_type *ct,
+			my_network *subnets)
 {
 
 
-	int count=0,port_n=0,list=0;
+	int count=0,port_n=0,list=0,subcount=0;
 	char buff[1024],type[1024],host[1024],user[1024];
 	FILE* file;
 
@@ -170,7 +196,11 @@
 		if(buff[strspn(buff," ")]!='#') {
 			if(list) {
 				bzero(&pd[count], sizeof(proxy_data));
-				pd[count].ps=PLAY_STATE;
+				
+				bzero(&subnets[subcount], sizeof(my_network));
+ 			   
+				pd[count].ps=PLAY_STATE;			   
+
 				port_n=0;
 				sscanf(buff,"%s %s %d %s %s", type,host,&port_n,
 					pd[count].user,pd[count].pass);
@@ -182,6 +212,12 @@
 					pd[count].pt=SOCKS4_TYPE;
 				}else if(!strcmp(type,"socks5")) {
 					pd[count].pt=SOCKS5_TYPE;
+				} else if(!strcmp(type,"localnet")) {
+		    		subnets[subcount].subnetwork=inet_addr(host);
+ 			    	subnets[subcount].subnetmask=inet_addr(pd[count].user);
+ 			    	subnets[subcount].valid=PTRUE;
+ 			    	subnets[subcount + 1].valid=PFALSE; 			    	
+	 			    subcount++;
 				}else continue;
 				
 				if( pd[count].ip && pd[count].ip!=-1 && port_n)
@@ -223,13 +259,23 @@
 int connect (int sock, const struct sockaddr *addr, unsigned int len)
 {
 	int socktype=0,optlen=0,flags=0,ret=0;
-
+	int lnnum=0;
 	if(!init_l)
 		init_lib();
 	optlen=sizeof(socktype);
 	getsockopt(sock,SOL_SOCKET,SO_TYPE,&socktype,&optlen);
 	if (! (SOCKFAMILY(*addr)==AF_INET  && socktype==SOCK_STREAM))
 		return true_connect(sock,addr,len);
+
+	get_chain_data(proxychains_pd,&proxychains_proxy_count,&proxychains_ct,localnet);
+	for (lnnum = 0; localnet[lnnum].valid == PTRUE; lnnum++)
+	{
+     	if (( satosin(*addr)->sin_addr.s_addr & localnet[lnnum].subnetmask) == localnet[lnnum].subnetwork)  
+		{
+			return true_connect(sock,addr,len);
+		}
+	}
+
 	flags=fcntl(sock, F_GETFL, 0);
 	if(flags & O_NONBLOCK)
 	fcntl(sock, F_SETFL, !O_NONBLOCK);