Skip to content

Commit 4eb5b8a

Browse files
committed
Add socks 5 env & other settings
1 parent 6e16c21 commit 4eb5b8a

3 files changed

Lines changed: 93 additions & 21 deletions

File tree

README renamed to README.md

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
ProxyBound v4.7
1+
ProxyBound v4.9
22
===============
33

44
ProxyBound is a UNIX program, that hooks network-related libc functions
55
in dynamically linked programs via a preloaded DLL and redirects the
66
connections through SOCKS4a/5 or HTTP proxies.
77

8-
It's based on proxychains-ng by rofl0r
8+
It's based on proxychains-ng by rofl0r & proxychains by haad
99

1010
How it works:
1111
=============
@@ -16,6 +16,16 @@ How it works:
1616
why ? because in order to hook to libc functions like
1717
connect(), dynamic loader facilities are used, namely
1818
dl_sym() and LD_PRELOAD.
19+
20+
Used environment variable:
21+
==========================
22+
23+
- PROXYBOUND_CONF_FILE: Path to config file
24+
- PROXYBOUND_QUIET_MODE: Quiet mode (1 or 0)
25+
- PROXYBOUND_SOCKS5_HOST: Specify unique socks 5 proxy to use
26+
- PROXYBOUND_SOCKS5_PORT: Socks 5 port
27+
- PROXYBOUND_FORCE_DNS: Force dns requests through (1 or 0)
28+
- PROXYBOUND_ALLOW_LEAKS: Not yet implemented (Allow unproxyfied protocols "UDP/ICMP/RAW")
1929

2030
Install:
2131
========
@@ -30,6 +40,12 @@ Install:
3040
Changelog:
3141
==========
3242

43+
Version 4.9:
44+
- Import simple SOCKS5 proxy mode from https://github.com/haad/proxychains
45+
46+
Version 4.8:
47+
- Updates with some features from https://github.com/haad/proxychains
48+
3349
Version 4.7:
3450
- Fix chrome compatibility
3551

@@ -56,18 +72,22 @@ Configuration:
5672
Usage Example:
5773
==============
5874

75+
$ export PROXYBOUND_QUIET_MODE="1"
76+
$ export LD_PRELOAD=/usr/local/lib/libproxybound.so
77+
$ export PROXYBOUND_CONF_FILE=/etc/proxybound.conf
78+
$ telnet targethost.com
79+
80+
In this example it will run telnet through proxy without using proxybound binary
81+
5982
$ proxybound telnet targethost.com
6083

61-
in this example it will run telnet through proxy(or chained proxies)
62-
specified by proxybound.conf
84+
In this example it will run telnet through proxy(or chained proxies) specified by proxybound.conf
6385

6486
$ proxybound -f /etc/proxybound-other.conf targethost2.com
6587

66-
in this example it will use different configuration file then proxybound.conf
67-
to connect to targethost2.com host.
88+
In this example it will use different configuration file then proxybound.conf to connect to targethost2.com host.
6889

6990
$ proxyresolv targethost.com
7091

71-
in this example it will resolve targethost.com through proxy(or chained proxies)
72-
specified by proxybound.conf
92+
In this example it will resolve targethost.com through proxy(or chained proxies) specified by proxybound.conf
7393

src/common.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
#define PROXYBOUND_CONF_FILE_ENV_VAR "PROXYBOUND_CONF_FILE"
22
#define PROXYBOUND_QUIET_MODE_ENV_VAR "PROXYBOUND_QUIET_MODE"
3+
#define PROXYBOUND_SOCKS5_HOST_ENV_VAR "PROXYBOUND_SOCKS5_HOST"
4+
#define PROXYBOUND_SOCKS5_PORT_ENV_VAR "PROXYBOUND_SOCKS5_PORT"
5+
#define PROXYBOUND_FORCE_DNS_ENV_VAR "PROXYBOUND_FORCE_DNS"
6+
#define PROXYBOUND_ALLOW_LEAKS_ENV_VAR "PROXYBOUND_ALLOW_LEAKS"
37
#define PROXYBOUND_CONF_FILE "proxybound.conf"
48
#define LOG_PREFIX "[Proxybound] "
59
#ifndef SYSCONFDIR

src/libproxybound.c

Lines changed: 61 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
/***************************************************************************
22
libproxybound.c
33
---------------
4-
begin : Tue May 14 2002
5-
copyright : netcreature (C) 2002
6-
email : netcreature@users.sourceforge.net
4+
5+
copyright: intika (C) 2019 intika@librefox.org
6+
copyright: rofl0r (C) 2012 https://github.com/rofl0r
7+
copyright: haad (C) 2012 https://github.com/haad
8+
copyright: netcreature (C) 2002 netcreature@users.sourceforge.net
9+
710
***************************************************************************
8-
* GPL *
11+
* GPL *
912
***************************************************************************
1013
* *
1114
* This program is free software; you can redistribute it and/or modify *
@@ -32,7 +35,6 @@
3235
#include <fcntl.h>
3336
#include <dlfcn.h>
3437

35-
3638
#include "core.h"
3739
#include "common.h"
3840

@@ -62,14 +64,18 @@ int proxybound_resolver = 0;
6264
localaddr_arg localnet_addr[MAX_LOCALNET];
6365
size_t num_localnet_addr = 0;
6466
unsigned int remote_dns_subnet = 224;
65-
6667
#ifdef THREAD_SAFE
6768
pthread_once_t init_once = PTHREAD_ONCE_INIT;
6869
#endif
70+
6971
static int init_l = 0;
7072

73+
static void init_additional_settings(chain_type *ct);
74+
7175
static inline void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
7276

77+
static void manual_socks5_env(proxy_data * pd, unsigned int *proxy_count, chain_type * ct);
78+
7379
static void* load_sym(char* symname, void* proxyfunc) {
7480

7581
void *funcptr = dlsym(RTLD_NEXT, symname);
@@ -94,6 +100,10 @@ static void* load_sym(char* symname, void* proxyfunc) {
94100
static void do_init(void) {
95101
MUTEX_INIT(&internal_ips_lock, NULL);
96102
MUTEX_INIT(&hostdb_lock, NULL);
103+
104+
/* check for simple SOCKS5 proxy setup */
105+
manual_socks5_env(proxybound_pd, &proxybound_proxy_count, &proxybound_ct);
106+
97107
/* read the config file */
98108
get_chain_data(proxybound_pd, &proxybound_proxy_count, &proxybound_ct);
99109

@@ -135,6 +145,18 @@ static void gcc_init(void) {
135145
}
136146
#endif
137147

148+
static void init_additional_settings(chain_type *ct) {
149+
char *env;
150+
151+
tcp_read_time_out = 4 * 1000;
152+
tcp_connect_time_out = 10 * 1000;
153+
*ct = DYNAMIC_TYPE;
154+
155+
env = getenv(PROXYBOUND_QUIET_MODE_ENV_VAR);
156+
if(env && *env == '1')
157+
proxybound_quiet_mode = 1;
158+
}
159+
138160
/* get configuration from config file */
139161
static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_type * ct) {
140162
int count = 0, port_n = 0, list = 0;
@@ -148,17 +170,11 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
148170
return;
149171

150172
//Some defaults
151-
tcp_read_time_out = 4 * 1000;
152-
tcp_connect_time_out = 10 * 1000;
153-
*ct = DYNAMIC_TYPE;
173+
init_additional_settings(ct);
154174

155175
env = get_config_path(getenv(PROXYBOUND_CONF_FILE_ENV_VAR), buff, sizeof(buff));
156176
file = fopen(env, "r");
157177

158-
env = getenv(PROXYBOUND_QUIET_MODE_ENV_VAR);
159-
if(env && *env == '1')
160-
proxybound_quiet_mode = 1;
161-
162178
while(fgets(buff, sizeof(buff), file)) {
163179
if(buff[0] != '\n' && buff[strspn(buff, " ")] != '#') {
164180
/* proxylist has to come last */
@@ -267,6 +283,38 @@ static void get_chain_data(proxy_data * pd, unsigned int *proxy_count, chain_typ
267283
proxybound_got_chain_data = 1;
268284
}
269285

286+
static void manual_socks5_env(proxy_data *pd, unsigned int *proxy_count, chain_type *ct) {
287+
char *port_string;
288+
char *host_string;
289+
290+
if(proxybound_got_chain_data)
291+
return;
292+
293+
init_additional_settings(ct);
294+
295+
port_string = getenv(PROXYBOUND_SOCKS5_PORT_ENV_VAR);
296+
if(!port_string)
297+
return;
298+
299+
host_string = getenv(PROXYBOUND_SOCKS5_HOST_ENV_VAR);
300+
if(!host_string)
301+
host_string = "127.0.0.1";
302+
303+
memset(pd, 0, sizeof(proxy_data));
304+
305+
pd[0].ps = PLAY_STATE;
306+
pd[0].ip.as_int = (uint32_t) inet_addr(host_string);
307+
pd[0].port = htons((unsigned short) strtol(port_string, NULL, 0));
308+
pd[0].pt = SOCKS5_TYPE;
309+
proxybound_max_chain = 1;
310+
311+
if(getenv(PROXYBOUND_FORCE_DNS_ENV_VAR) && (*getenv(PROXYBOUND_FORCE_DNS_ENV_VAR) == '1'))
312+
proxybound_resolver = 1;
313+
314+
*proxy_count = 1;
315+
proxybound_got_chain_data = 1;
316+
}
317+
270318
/******* HOOK FUNCTIONS *******/
271319

272320
int connect(int sock, const struct sockaddr *addr, socklen_t len) {

0 commit comments

Comments
 (0)