Commit Graph

212 Commits (v4.15)

Author SHA1 Message Date
papadave a1f7007a46 main.c: fix build error with solaris
sys/feature_tests.h:362:2: error: #error
"Compiler or options invalid for pre-UNIX 03 X/Open applications and pre-2001 POSIX applications"
2018-01-10 16:14:21 +00:00
rofl0r 3366dc3131 allocator_thread.c: fix build on FreeBSD due to MAP_ANON
thx to @Low-power for testing
2018-01-10 16:09:09 +00:00
rofl0r 2f3d33dd47 remove usage of s6_addr16 and s6_addr32
it turns out that those macros are not portable at all. rather than
adding workarounds to make it work for every single platform, just
use plain s6_addr instead.
2018-01-09 13:30:02 +00:00
rofl0r d28f4df8e2 allocator_thread.c: define _DARWIN_C_SOURCE so we get MAP_ANON
https://github.com/nneonneo/osx-10.9-opensource/blob/master/xnu-2422.1.72/bsd/sys/mman.h#L142
https://opensource.apple.com/source/xnu/xnu-344/bsd/sys/mman.h
2017-12-21 16:30:17 +00:00
rofl0r 03880ce695 allocator_thread: add assertion that we get the right response
in order to prevent future bugs like the one fixed in cc7bc891ff
we need to assure that the response is of the same type as the request -
if not, some unexpected race condition happened.
2017-12-19 00:35:01 +00:00
rofl0r cc7bc891ff allocator_thread: fix segfault with weechat 2.0
it was reported that weechat 2.0 on ubuntu 16.04 LTS x86_64 segfaulted like this:

4 0x00007f6bf0e7e0c0 in __stack_chk_fail () at stack_chk_fail.c:28
5 0x00007f6bf2536bce in at_get_ip_for_host (host=0x339c4d0 "abcdefghijklmnop.onion", len=22) at src/allocator_thread.c:290
 readbuf = {octet = "irc.", as_int = 778269289} msg = {msgtype = ATM_GETNAME, datalen = 13}

what happened was that weechat forked, thus got its own private copy of the VM
and thus a private copy of the mutex which should prevent parallel use of
at_get_ip_for_host() & friends. therefore the following race was possible:
- process A writes a message of type ATM_GETIP into the server pipe
- process B writes a message of type ATM_GETNAME into the server pipe
- process A write transaction is finished, and goes into receive mode
- server thread reads process B's message and responds with a ATM_GETNAME msg
- process A reads the response which was intended for process B into the 4 byte
  ip address buffer, but ATM_GETNAME are much larger than ATM_GETIP responses,
  resulting in stack corruption.

to prevent this issue, the storage of the mutex must reside in shared memory,
which we achieve via mmap. alternatively, shm_open() or sysvipc shm stuff could
be used. the former requires the mmap call to happen before the fork, the latter
not, however the shm would require a named object in /dev/shm (which requires
generating a unique name per proxychains instance, and subsequent cleanup).
so in the end, the mmap is easier to deal with, and we can be reasonably
certain that our constructor is being run before the hooked application forks.
2017-12-19 00:29:23 +00:00
rofl0r 3b5f41028b allocator_thread: use bigger stacksize for Mac OS X 2017-12-15 13:15:13 +00:00
Antonio Quartulli 46647bee44 fix memory leak
don't leak variable 'space' when the host is numeric

Signed-off-by: Antonio Quartulli <a@unstable.cc>
2017-08-28 15:19:43 +01:00
rofl0r bb3df1e440 allocator_thread.c: handle EINTR case when reading/writing pipe data
addressing #163
2017-02-23 01:08:24 +00:00
rofl0r bf6eeff75a check snprintf return value for error 2016-12-20 22:18:21 +00:00
Carlos Maddela 5ed5089733 Avoid using %n$ operand number formats to compile cleanly with ISO C. 2016-12-13 20:27:56 +00:00
Carlos Maddela 8ddc8a6da3 Prevent empty translation units to satisfy ISO C compilers. 2016-12-13 20:27:15 +00:00
Carlos Maddela 167780ce36 Fix format ‘%p’ expects argument of type ‘void *’ warning. 2016-12-13 20:12:15 +00:00
Carlos Maddela 4b413c902f Fix format specifier for unsigned int. 2016-12-13 20:11:37 +00:00
Carlos Maddela 6dcaf533d1 Fix grammar in usage message to keep Lintian happy. 2016-12-05 18:37:11 +11:00
Carlos Maddela 0bd2130352 Fix spelling in log message: doesnt -> doesn't 2016-12-05 14:10:09 +11:00
forkbomber cf9a16de06 core.c: add HOST header to each CONNECT request
fixes #92
closes #93
2016-10-16 19:43:00 +00:00
Jay Taylor 0f6b226b15 Fix random_chain on Mac OS X
On Mac OS X, random chain was broken and returned always the last proxy from the
config file.  Use fix as suggested by @ravomavain.

Closes #75.
2016-10-14 21:49:01 +00:00
rofl0r e527b9ee64 print error message instead of segfaulting for invalid chain_len
closes #126
2016-06-23 09:27:15 +01:00
Carlos Maddela 993dfc059d Fix trivial compilation warning
Fix "missing braces around initializer" warning.
2016-06-09 12:09:51 +01:00
rofl0r f1e5f2ba01 don't call dlsym() from close() hook
it turned out that calling dlsym() may call malloc() in turn,
so we end up with the same deadlock described in the latest commit.

we thus now put all the fds passed to close pre-init into a list
and close them at init time.

this may finally fix #119.
2016-05-26 19:11:18 +01:00
rofl0r 8870140ff0 don't call INIT() from close hook
it was observed that it is a bad idea to initialize the entire
infrastructure used by proxychains from the close hook,
because the following scenario will lead to a deadlock:

- it is possible that the dynlinker executes the initializer code of
  other shared libs first
- if that code directly or indirectly calls malloc()
- which calls close() if it decided to use an mmap based allocation
- will now call our close(), which does
- call pthread_once which requires a lock
- creates a thread which calls malloc()
- which in turn calls our close() another time
- and our close is still in locked state.

so it seems the only save thing to do is to just get the address
of the original close function, and call that when we're in a
pre-init state.
this may hold for other functions that do lazy initialization as well,
however for those just calling the original function is probably
undesired since that could result in unproxified connections.
it will be needed to analyze on a per-function basis what the best
thing to do is, and finally rely only on the execution of the init
function from the gcc initializer.

should fix #119
2016-05-26 10:48:32 +01:00
rofl0r b64c89e0e4 add check for broken OpenBSD fclose()
http://marc.info/?l=openbsd-bugs&m=145280872431093&w=2

closes #95
2016-02-04 12:49:49 +00:00
rofl0r a1c31e73b6 improve hostsreader test code 2016-02-04 09:38:16 +00:00
Alexander Batischev f85cecdabe Fix bug in hostsreader
hostsreader_get() used to assign the IP address to both `name` and `ip`
fields in `struct hostsreader`, which led to proxychains effectively
ignoring the contents of /etc/hosts.
2016-02-04 09:37:06 +00:00
rofl0r 672bf7661d getnameinfo: support ipv6 as well 2015-12-06 13:01:56 +00:00
rofl0r 0e0e35927c mute warning in debug mode 2015-12-06 12:57:45 +00:00
rofl0r 205004fa2a factor out setup_hooks() 2015-12-02 12:14:58 +00:00
rofl0r 50c84176da debug.c: fix for ipv6 changes
closes #94
2015-12-01 20:37:27 +00:00
rofl0r 32df7ff152 connect(): handle ipv4-mapped ipv6 addresses
if an ipv4-mapped ipv6 address is detected, the ip is converted
into v4 format because it may actually be one of our remote dns ips.
it was reported that a program called "maven", when getting handed our
fake ips in the remote dns subnet, converts the ip to v6 prior to calling
connect():
[proxychains] Strict chain ... 127.0.0.1:1080 ... ::ffff:224.0.0.1:443
<--socket error or timeout!

fixes #77
2015-09-15 21:19:51 +01:00
rofl0r 2237749567 preliminary ipv6 support
only basic testing was done (with 2 socks5 proxies listening on ::1)
but seems to work as intended.

ipv6 support for the hostsreader (/etc/hosts) is not implemented so far.
2015-08-10 17:00:26 +01:00
rofl0r 9969dd3a22 fix socks5 bug: always requested user auth cap
since "user" always points to a statically allocated string buffer,
the test for if(user)... was bogus.
use ulen instead.

this bug should only be visible on socks servers that require auth
if username was not passed, so it was probably not really an issue.
2015-06-14 12:10:32 +01:00
rofl0r d900b090fe put INIT() call consistently at beginning of hooked funcs 2015-06-14 11:16:59 +01:00
rofl0r afe6171cad clean up some debug ifdefs 2015-06-14 10:53:33 +01:00
rofl0r 51b2eb91ce remove commented-out code [2] 2015-06-14 10:27:41 +01:00
rofl0r ae16ae9fc9 remove commented-out code 2015-06-14 09:57:05 +01:00
rofl0r 338b9ce4e3 whitespace fixes for proxytype switch block 2015-06-13 20:32:15 +01:00
rofl0r c6553c2cc5 replace string manip. in HTTP setup code with single snprintf 2015-06-13 20:21:59 +01:00
rofl0r 49adb6ce29 simplify socks5 buffer setup code 2015-06-13 19:02:11 +01:00
rofl0r c7fa7bf86a simplify start_chain struct setup 2015-06-13 18:37:57 +01:00
rofl0r 2182eff358 fix segfault in DNS mapping lookup code
the allocatorthread got pointers to RAM which were reallocated
behind the back, and if realloc() couldn't grow in-place, lead
to segfaults in applications that do a lot of DNS-lookups such
as webbrowsers.

closes #66
closes #31

thanks to @ravomavain for tracking down the issue.
2015-06-06 11:43:53 +01:00
rofl0r 68e42d59f7 fixup for 9ab7dbe 2015-05-21 14:04:10 +01:00
rofl0r 9ab7dbeb3b fix for CVE-2015-3887
closes #60
2015-05-21 13:46:22 +01:00
rofl0r ba61b48fd7 fix compilation with openbsd
closes #52
2015-04-08 11:09:48 +01:00
Aleksey Filippov 4e986caa2a support MSG_FASTOPEN on old kernels 2015-02-17 15:30:43 +01:00
Aleksey Filippov 8dd08e2cd2 add sendto hook to handle MSG_FASTOPEN flag 2015-01-23 17:14:37 +01:00
rofl0r 25ee4c318d hostsreader: use temporary vars for string manipulation
working directly with the passed variables could lead to bugs when
some lines in the hosts file aren't well-formed and the loop is taken
several times while the buf vars are already modified.
2014-11-14 13:19:06 +01:00
rofl0r 4fb7eb0532 replace problematic hostentdb with hostsreader
the hostentdb introduced between 4.2 and 4.3
(via af5c6f0c6a )
had several issues:
- it caused breakage on FreeBSD and was commented out there
- prevented usage of the hostdb when proxy_dns was turned off
  (issue #42)
- required dynamic memory allocation which was accessed from several
  threads
- wouldnt reflect changes to the hosts file made during program run

the only sensible solution is to remove the hostentdb and replace it
with a home-grown hosts parser (we can't use gethostent() since
that would mess up the gethostent()-state from different threads).

the new parser used here is deliberately held simple and only meant
to provide the user with means to reference hardcoded ipv4 addresses
via his hosts file.

fixes #42
2014-11-14 12:33:58 +01:00
rofl0r cd4aee1997 print proxychains version on DLL init
framework to print version stolen from musl
2014-07-22 14:10:11 +02:00
rofl0r 7852269282 libproxychains.c: whitespace cleanup 2014-07-21 13:18:20 +02:00
rofl0r d3586380bd get_chain_data: reject invalid entries in proxylist section 2014-07-21 13:17:24 +02:00
rofl0r 5168bc4eed bail out when no proxy was configured 2014-07-21 12:37:01 +02:00
rofl0r 82d0b13b8f main.c: remove trailing whitespace noise 2014-07-09 19:16:33 +02:00
rofl0r ed7c89072a main.c: append previously existing LD_PRELOAD contents rather than overwriting
some broken programs like pulseaudio rely on LD_PRELOAD hacks to function,
if we just override the environment variable, those will stop working.

simplified version of patch suggested by @hexchain

closes #35
2014-07-09 19:12:30 +02:00
rofl0r 84d9a97a08 main.c: remove code duplication around LD_PRELOAD 2014-07-09 18:07:24 +02:00
rofl0r f669139c9e common.c: fix trailing whitespace 2014-07-02 10:10:53 +02:00
rofl0r 530fee89ce proxy_getaddrinfo: don't use strncpy
the strncpy function is both dangerous and slow.
dangerous because it doesn't do what the naive programmer expects
(bounded strcpy), and slow because it pads the entire bufsize
with zeroes.
2014-01-22 22:22:24 +01:00
rofl0r b76aa653c9 proxy_getaddrinfo: fix case when func was used in lieu of inet_aton 2014-01-22 16:13:20 +01:00
rofl0r f868928c4b fix incorrect poll.h inclusion
sys/poll.h is a glibc legacy alias for poll.h.
the latter is specified by POSIX, the former not.
on glibc one of them just includes the other so it doesnt hurt.
2014-01-08 14:57:13 +01:00
David ecbd735508 Chromium tried to close our pipes and falls into infinity loop.
If return value of close() is -1, chromium will fall into infinity loop.
2014-01-08 13:38:59 +08:00
rofl0r fa0f355ce8 add missing INIT() to close hook
this caused a crash when the gcc initializer was not called first.
2013-08-30 23:44:27 +02:00
rofl0r 8a84f980bb fix indentation of debug.c 2013-06-26 12:22:12 +02:00
crass 354a4ce4e2 Add round_robin to example config. 2013-06-26 12:22:12 +02:00
crass f603e50cb3 Add support for round robin mode. 2013-06-26 12:22:11 +02:00
crass 5c4c166802 Add DUMP_PROXY_CHAIN for debug builds and debug.c. 2013-06-25 12:56:41 +02:00
rofl0r b9ca1cdefd proxychains.conf: add hint that proxy must be in ipv4 notation 2013-05-02 13:44:49 +02:00
rofl0r 64a7cd26dc fix case where proxy was using a DNS name or non-dotted ipv4
it is generally invalid to use a DNS name since DNS subsystem
is only available once connected to the proxy; because
DNS is done server-side.

closes #19
2013-05-02 13:44:49 +02:00
mancha 2aba83087e libproxychains.c: fix NULL pointer dereference after fopen().
if a configuration file can be accessed by proxychains but there is a
mandatory access control (or other) block on the target appication's
ability to read that file, fopen() creates a NULL pointer that will
cause a segfault in fgets().

closes #17

Signed-off-by: mancha <mancha1@hush.com>
2013-04-30 04:06:36 -04:00
rofl0r f3af1239a9 better regex for obsolete proxyresolv script (thx yhzarcali)
closes #11
2013-01-29 18:43:21 +01:00
rofl0r 1da09e49e5 hook close() to prevent rude programs like ssh to close our pipes
those pipes are needed to talk with the dns-name allocator thread.

closes #9
2013-01-21 01:54:45 +01:00
rofl0r 173b90368e update proxyresolv 2013-01-06 19:20:44 +01:00
rofl0r c8bfdc15e6 remove old proxychains launcher script 2013-01-06 19:12:15 +01:00
rofl0r 5526afb56d FreeBSD support 2012-12-25 19:08:05 +01:00
rofl0r be4efc0fd5 fix no-newline warnings on old compilers 2012-12-25 18:01:11 +01:00
rofl0r 5ecd5ac51d fix compilation on musl libc 2012-12-18 09:38:32 +01:00
rofl0r 1c265b9628 getnameinfo: check size and family of salen 2012-12-17 23:21:58 +01:00
rofl0r 346474a43b getnameinfo: return error if buffers are too small 2012-12-17 22:41:51 +01:00
rofl0r ce655fdac8 fix the never-ending issues with the wrong glibc prototype of getnameinfo
this bug was fixed shortly before 2.14 release, so we checked for that.
however some distros decided to backport this fix to earlier versions,
breaking our compiletime check.

http://sourceware.org/git/?p=glibc.git;a=commitdiff;h=e4ecafe004b3d4270b3a9dace8f970047400ed38

the portable solution is to stick the function into a separate comilation
unit that does not see the glibc prototype.

closes #7
2012-12-17 22:17:04 +01:00
rofl0r af5c6f0c6a replace hostent lookup with better performing in-memory copy.
the central dns resolver function proxy_gethostbyname() used
to iterate over the gethostent() db (/etc/hosts) on each dns
request.
since this is not threadsafe, we synchronized access to it
previously using mutexes. the parsing of this file is slow,
and blocking all threads to do it even moreso.
since gethostent_r() is only available on a few platforms,
i decided to read the hostent db once and then use a quick
in-memory lookup on further usage.

+ some further refactoring.
2012-11-08 01:18:19 +01:00
rofl0r c698d48c03 move stringfromipv4 into common.c 2012-11-07 22:00:03 +01:00
rofl0r 03ee84060e remove THREAD_SAFE ifdefs. from now on, pthreads are required.
additionally we have some explicit init and deinit routines for
core.c now, so that we dont need to share variables with
libproxychains.c.
2012-11-07 21:31:19 +01:00
rofl0r bd07ca49b9 use pipe instead of pipe2 2012-11-07 21:31:18 +01:00
rofl0r f570a66902 use mutexes also to protect the pipe communication
wasn't threadsafe before.
2012-11-07 21:31:18 +01:00
rofl0r d0abc93c74 preliminary first fork-safe version
instead of allocating memory in the child, we now use the allocator
thread to do all the necessary allocations himself.
additionally we provide a clean API to query the ip <-> dns mapping.
these functions connect via a pipe to the allocator thread, and
exchange messages.

further cleanup is needed, but it seems to work so far.
thread-safety is not yet guaranteed.

closes #1
2012-11-07 21:31:11 +01:00
rofl0r 25afe98b20 failed attempt to use shared memory for the ip <-> dns mapping
this is in order to get irssi, which forks for DNS lookups,
and similar programs, to work as intended.

in a previous attempt i learned that shared memory created in a
child process is not visible to the parent;
in this attempt i spin off a thread from the parent which listens
on a pipe and manages the shared memory allocation from the parent
address-space. however this doesnt work as expected:
memory allocated in the parent after the child forked is not visi-
ble to the child as well.

so what happens is: irssi starts a child process, the thread allocs
memory and hands it to the child, the child attempts to write and
segfaults. however irssi doesnt crash. since now the memory is
already allocated, doing the dns lookup again will succeed.

i.e. the dns lookup works now in irssi by luck.
all but the first dns lookups will suceed.

however this is not good enough for me to be satisfied, i commit
this only for documentation purposes.
2012-11-07 16:49:14 +01:00
rofl0r 7bca3ba5ef main.c: fixed forgotten initialization for second loop using i
this caused the combination of -q -f somefile to not find the dll
in the current dir, because it started iterating the directory
list with 2 instead of 0.
2012-11-04 06:14:33 +01:00
rofl0r e05cafc8e2 put a mutex lock around gethostent() usage, to prevent internal
races. the external usage was covered by the latest commit.
2012-11-04 05:23:51 +01:00
rofl0r 2d58820635 proxy_gethostbyname: fix thread safety issues arising from ...
gethostent() usage.

also set hostent.h_aliases member to a valid pointer.
2012-11-04 05:02:57 +01:00
rofl0r b851b39a37 add RcB tags to core.h
this is handy as it allows me to do quick testprograms using my RcB program,
without specifying dozens of things on the command line.
2012-11-04 05:01:38 +01:00
rofl0r e8d49b02e8 gethostbyaddr hook: also set aliases.
i inspected behaviour of libc's and they all seem to set a valid
h_aliases pointer, of which the first one should be NULL, if no
aliases exist.
2012-11-04 04:58:48 +01:00
rofl0r 859dabb302 common.h: supply a default for SYSCONFDIR if not passed via CFLAGS 2012-11-04 04:57:45 +01:00
rofl0r bddb79a286 fix bug which lead to segfault in ubuntu 12.04 telnet
it called gethostbyname and expected that the h->h_name was set.

this code path here which gets only active if the passed name
equals the gethostname() result failed to set a couple of values.

additionally fixed usage of strncpy, which causes the entire
memory buffer to be written, even when the string is much shorter.

a similar bugfix was independently discovered by semion laptev, but my
version is threadsafe - his version introduces a new static buffer,
even though we have plenty of thread-safe space reserved exactly
for this usage case, thus causing a regression.
2012-11-04 01:00:58 +01:00
guanqun bbf8b7aab0 fix typo in help message 2012-08-27 23:30:45 +08:00
rofl0r 01b8c81e90 add some default localnets (commented) to config 2012-08-16 16:44:51 +02:00
rofl0r 923c4f1026 fix core.h to be usable on its own 2012-08-06 01:26:34 +02:00
rofl0r 108610e30e core.c: add getservbyname_r replacement function for mac 2012-08-06 01:26:03 +02:00
rofl0r 0f1bc719fd put base64 variable to the place it gets used 2012-08-04 17:55:37 +02:00
rofl0r 068e088a8b tunnel_to: use better suited type 2012-08-03 10:43:59 +02:00
rofl0r 40bb78b53f fix omission in common.c 2012-07-16 02:42:09 +02:00
rofl0r 80e58726e2 correct copyright of main.c 2012-07-16 02:36:35 +02:00