Commit Graph

345 Commits

Author SHA1 Message Date
tom gilon
bf2ef2ce38 dnat: add rule precedence logic 2020-07-08 19:35:18 +03:00
tom gilon
de31961349 Add option to change tcp destination port and ip before sending to proxy server 2020-05-06 01:07:57 +03:00
Solar Flare
b8fa2a7405 get own_dir by using dladdr() instead of argv[0] 2019-11-27 00:32:08 +08:00
Solar Flare
0a8663c845 fix a buffer overflow bug 2019-11-12 10:40:33 +08:00
rofl0r
86408cd806 add libc gethostbyname test 2019-09-07 15:23:02 +01:00
rofl0r
ea187938e1 test_gethostent: improve compileability 2019-09-07 15:22:41 +01:00
rofl0r
962373e5c6 getaddrinfo: fix behaviour when node is null and !passive
according to the spec, if these 2 conditions hold, the name shall
resolve to localhost.

closes #292
2019-07-21 14:27:55 +01:00
rofl0r
de4460fbd1 proxy_getaddrinfo: don't use sizeof(struct sockaddr_storage) for addr_len
this should fix an issue which seems to be mac's bind() only accepting
sizeof(struct sockaddr_in) for AF_INET.

ref: https://github.com/rofl0r/microsocks/issues/19
2019-05-25 02:23:38 +01:00
rofl0r
5ad7c2a183 proxy_getaddrinfo: implement support for numeric ipv6
closes #282
2019-04-25 14:36:08 +01:00
rofl0r
067885694d proxy url parser: look for @ from the right side
fixes usernames with @ in them.
this is only relevant for support of new url-style proxy addresses.
2019-04-21 01:48:38 +01:00
rofl0r
e895fb713a release 4.14 2019-03-16 23:04:10 +00:00
rofl0r
b8cdfe842c allow non-numeric proxy ips under certain circumstances
conditions that need to be met are:
1) chaintype strict
2) proxy_dns on
3) not the first proxy in the list

if these conditions are met, the dns name can be passed to be
receiving proxy and be resolved there.

addressing https://github.com/rofl0r/proxychains-ng/issues/246#issuecomment-468222637
2019-02-28 14:07:08 +00:00
rofl0r
9f17774b99 allocator_thread.c: whitespace cleanup 2019-02-28 13:32:57 +00:00
rofl0r
dbec605e2c get_chain_data(): no need for inline 2019-02-28 13:28:10 +00:00
rofl0r
5c8f9a2922 shrink huge log buffer 2019-02-28 13:22:13 +00:00
rofl0r
50c079d4b4 don't try to connect to null-routed ips 2019-02-28 13:08:02 +00:00
Tom Li
11988579f5 allocator_thread.c: set O_CLOEXEC/FD_CLOEXEC for pipes, fix #273.
In proxychains, we create pipes and use them internally.
If exec() is called by the program we run, the pipes opened
previously are never closed, causing a file descriptor leak
may eventually crash the program.

This commit calls fcntl() to set FD_CLOEXEC flags on pipes.
AFAIK there's no race condition on pipe creation, but we still
prefer to call the newer pipe2() with O_CLOEXEC if it's supported
by the system, due to its advantage of atomic operation, which
prevents potential race conditions in the future.

Signed-off-by: Tom Li <tomli@tomli.me>
2018-12-25 18:03:39 +00:00
Tom Li
db5cd6b699 configure: define HAVE_PIPE2 if we have pipe2() and O_CLOEXEC.
This commit adds a new run for pipe2() and O_CLOEXEC. If a program
can be executed, define HAVE_PIPE2.

Signed-off-by: Tom Li <tomli@tomli.me>
2018-12-25 18:03:39 +00:00
rofl0r
a6959ee715 configure: force check_compile() to link an executable
by using -c (which just creates an object file), we don't catch implicit
function declarations as an error (see discussion of #274).
2018-12-25 18:01:26 +00:00
rofl0r
49bf4ba772 replace getservbyname_r ifdef hacks with configure check
this should make it work automatically on any new platform without
having to add yet another ifdef hack.
should fix issues with android (#265).
additionally the code for the systems lacking GNU-compatible getservbyname_r()
is now guarded with a mutex, which prevents possible races, therefore
resolving the ancient "TODO" item.
2018-12-02 13:48:43 +00:00
rofl0r
2213afb6f0 debug mode: display whether proxy_dns is on or off 2018-12-02 13:46:55 +00:00
rofl0r
bd7e8a1da1 test_getaddrinfo.c: add check for service argument 2018-12-02 13:45:35 +00:00
rofl0r
416d481ac9 test_getaddrinfo.c: whitespace cleanup 2018-12-02 13:27:22 +00:00
amyangfei
eb36238c8a remove unused variable 2018-08-26 06:18:20 +01:00
amyangfei
275e64499e Fix select_proxy dead loop in round_roubin_chain
Fix issue #147.
If all proxies are in DOWN_STATE or BUSY_STATE state, select_proxy will run
forever in an infinite loop. When all proxies are not available, we wait some
intervals and retry. The wait time starts with 10 milliseconds and is
increased by 10 milliiseconds in each loop. 14 loops sums up with 1.05 second.
2018-08-23 12:40:27 +01:00
rofl0r
1c8f8e4e7e alternatively allow specifying proxy addresses via URL-style strings
e.g. socks5://user:pass@ip:port

code taken from my library "rocksock"[0].

[0]: https://github.com/rofl0r/rocksock
2018-07-26 23:13:15 +01:00
rofl0r
d21af711d8 release 4.13 2018-06-25 00:26:05 +01:00
rofl0r
49d8ac9338 accept proper RFC1929 auth subnegotiation version field
this was wrongly fixed in 06c20ed394

instead of reverting we now accept the correct version
(version field containing 1) plus the incorrect version (5) given by some
proxyservers in the wild. curl accepts both forms too.

closing #224
addressing #221
2018-05-29 18:59:30 +01:00
rofl0r
bb30d867fe configure: prevent bug overwriting config.mak on OpenBSD
the command writing the openbsd line was using >> before the call
which was meant to initialize config.mak using >.

closes #228
2018-04-12 07:13:26 +01:00
rofl0r
06c20ed394 fix socks5 username/password auth
the version field in the auth check needs to be 5, not 1.

closes #221
2018-02-11 14:59:27 +00:00
rofl0r
831df039bd print usage info on --help too 2018-02-11 14:58:26 +00:00
rofl0r
1a62ec60af support solaris X/Open connect call too
solaris curiously defines connect to point to __xnet_connect when
_XOPEN_SOURCE is defined 600.
that means some programs use the real connect symbol, while others
use __xnet_connect.

thanks to @Low-power for testing.

https://github.com/nxmirrors/onnv/blob/master/usr/src/lib/libsocket/socket/socket.c
https://github.com/nxmirrors/onnv/blob/master/usr/src/uts/common/sys/socket.h#L486
2018-01-10 17:36:39 +00:00
WHR
35a674bdbc configure: Solaris detection, ld 'soname' option auto detection; other Solaris related fixes 2018-01-11 00:45:40 +08:00
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
b299193d13 configure: remove bogus uname platform checks
calling uname in a configure script is entirely bogus, as it will return
wrong results in crosscompilation scenarios. the only sensible way to
detect the target platform's peculiarities is to test the preprocessor
for macros defining the target.
2018-01-09 13:50:11 +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
7a233fb1f0 release 4.12
the xmas release.
2016-12-24 13:14:08 +00:00
rofl0r
cd4ced1d52 Revert "Makefile: suppress pedantic warnings in user CFLAGS"
This reverts commit 6ae959e051.

It appears as if -pedantic is special in that there is no option
to disable it.
2016-12-24 12:49:14 +00:00
rofl0r
cb70ab5f8f configure: use quotes for echo calls 2016-12-24 12:48:41 +00:00
Jatin Rungta
c91e6a09ef Fix configure so the right CC gets picked up
unlike one would expect, setting `CC?=gcc -m32` in config.mak did not actually
lead to `gcc -m32` being used as compiler when running make, even though CC
was not declared anywhere else.
it appears as if the CC variable is implicitly defined by GNU make, so using
the ?= assignment (meaning "assign only if not already assigned") did not have
an effect.
when this configure script and Makefile here were written, they were modeled
after the interface provided by GNU autoconf (so there are no surprises for the
user). the assumption was that environment variables passed during configure
are usually stored and used for the compile, but can be overridden when running
make by exporting the variables again.
in reality though they can not be overridden by environment when running make,
as tests showed.
because of that, the other user-supplied variables will now be hard-assigned as
well.

closes #152

commit message by @rofl0r.
2016-12-24 12:36:42 +00:00
rofl0r
bf6eeff75a check snprintf return value for error 2016-12-20 22:18:21 +00:00
rofl0r
6ae959e051 Makefile: suppress pedantic warnings in user CFLAGS 2016-12-13 20:42:50 +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