From 3b02fcecea9f0e1f932bff24316541e2b35a0530 Mon Sep 17 00:00:00 2001 From: root Date: Thu, 4 Jun 2020 14:35:41 +0200 Subject: [PATCH 01/11] Enable multi-line auth headers - first match (BASIC or DIGEST) works --- http-auth.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/http-auth.c b/http-auth.c index c2a353c4..b5a36c66 100644 --- a/http-auth.c +++ b/http-auth.c @@ -285,13 +285,14 @@ char *http_auth_request_header(struct evbuffer *src, struct evbuffer *tee) return NULL; // I'm going up straight to the 403... } } - // FIXME: multi-line headers are not supported if (line == NULL || *line == '\0' || strchr(line, ':') == NULL) { free(line); return NULL; } - if (strncasecmp(line, auth_request_header, strlen(auth_request_header)) == 0) - return line; + if (strncasecmp(line, auth_request_header, strlen(auth_request_header)) == 0) + if (strcasestr(line, "Basic") != NULL || + strcasestr (line, "Digest") != NULL) + return line; free(line); } } From 1ff8787d11beeb8a4ae48324590714c2c69e4e4d Mon Sep 17 00:00:00 2001 From: snorre-k Date: Fri, 5 Jun 2020 14:02:51 +0200 Subject: [PATCH 02/11] Update README.md --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index aba93a78..3b544e3b 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,10 @@ # redsocks – transparent TCP-to-proxy redirector +Adapted by Snorre to have some bugfixes + +* Works with proxies sending multiple authentication requests +* Added RPM spec file + This tool allows you to redirect any TCP connection to SOCKS or HTTPS proxy using your firewall, so redirection may be system-wide or network-wide. From ede4223f8d4fb393c7f8a82cdb575faf4b0dfb96 Mon Sep 17 00:00:00 2001 From: snorre-k Date: Fri, 5 Jun 2020 14:04:20 +0200 Subject: [PATCH 03/11] Bugfix: redsocks does not start, when proxy cannot be resolved --- redsocks.service | 1 + 1 file changed, 1 insertion(+) diff --git a/redsocks.service b/redsocks.service index 2913b7d9..903e601f 100644 --- a/redsocks.service +++ b/redsocks.service @@ -1,5 +1,6 @@ [Unit] Description=Transparent redirector of any TCP connection to proxy using your firewall +After=network.target [Service] Type=forking From 394e304b9cd8addbc85fe57c649eb924ed2a506d Mon Sep 17 00:00:00 2001 From: snorre-k Date: Fri, 5 Jun 2020 14:06:44 +0200 Subject: [PATCH 04/11] Create redsocks.spec --- redsocks.spec | 103 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 redsocks.spec diff --git a/redsocks.spec b/redsocks.spec new file mode 100644 index 00000000..a208a1bc --- /dev/null +++ b/redsocks.spec @@ -0,0 +1,103 @@ +# +# spec file for package +# +# Copyright (c) 2020 SUSE LINUX Products GmbH, Nuernberg, Germany. +# +# All modifications and additions to the file contributed by third parties +# remain the property of their copyright owners, unless otherwise agreed +# upon. The license for this file, and modifications and additions to the +# file, is the same license as for the pristine package itself (unless the +# license for the pristine package is not an Open Source License, in which +# case the license is the MIT License). An "Open Source License" is a +# license that conforms to the Open Source Definition (Version 1.9) +# published by the Open Source Initiative. + +# Please submit bugfixes or comments via http://bugs.opensuse.org/ +# + +%if 0%{!?_fillupdir:1} +# < SLES15 (para SLE15>=, /usr/share/fillup-templates) +%define _fillupdir %{_var}/adm/fillup-templates +%endif + +Name: redsocks +Version: 0.5.1 +Release: 0 +License: Apache-2.0 +Summary: Redirect any TCP connection to a SOCKS or HTTPS proxy server +Url: http://darkk.net.ru/redsocks/ +Group: Productivity/Networking/Other +Source: %{name}-%{version}.tar.gz +Source2: %{name}.sysconfig +BuildRequires: libevent-devel +PreReq: %fillup_prereq +PreReq: /usr/bin/getent +%if 0%{?suse_version} >= 1210 +BuildRequires: systemd +%endif +%{?systemd_requires} + +%description +Redsocks is a daemon running on the local system, that will transparently +tunnel any TCP connection via a remote SOCKS4, SOCKS5 or HTTP proxy server. It +uses the system firewall's redirection facility to intercept TCP connections, +thus the redirection is system-wide, with fine-grained control, and does +not depend on LD_PRELOAD libraries. + +Redsocks supports tunneling TCP connections and UDP packets. It has +authentication support for both, SOCKS and HTTP proxies. + +Also included is a small DNS server returning answers with the "truncated" flag +set for any UDP query, forcing the resolver to use TCP. + +%prep +%setup + +%build +CFLAGS="$RPM_OPT_FLAGS" make %{?_smp_mflags} + +%install +%{__install} -v -D -m 755 %{name} %buildroot/%_prefix/bin/%{name} +%{__install} -D %{name}.service %buildroot/%_unitdir/%{name}.service +sed -i -e 's#EnvironmentFile=.*#EnvironmentFile=%{_sysconfdir}/sysconfig/%{name}#' %buildroot/%_unitdir/%{name}.service +mkdir -p %{buildroot}%{_sbindir} +ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name} +%{__install} -D debian/%{name}.conf %buildroot/%_sysconfdir/%{name}/%{name}.conf +%{__install} -D debian/%{name}.8 %buildroot/%_mandir/man8/%{name}.8 +gzip %buildroot/%_mandir/man8/%{name}.8 +%{__install} -D -m644 %{SOURCE2} %{buildroot}%{_fillupdir}/sysconfig.%{name} +%{__install} -d -m 0755 %{buildroot}%{_tmpfilesdir} +echo "d /var/run/%name 755 %name %name" >%{buildroot}%{_tmpfilesdir}/%{name}.conf + +%pre +%service_add_pre %{name}.service +if ! /usr/bin/getent passwd %name &>/dev/null; then + echo "Creating %name user" + /usr/sbin/useradd -c "RedSocks user" -s /sbin/nologin -r -d /var/run/%name -U %name 2> /dev/null || : +fi + +%post +%fillup_only +%service_add_post %{name}.service +systemd-tmpfiles --create %{_tmpfilesdir}/%{name}.conf + +%preun +%service_del_preun %{name}.service + +%postun +%service_del_postun %{name}.service + +%files +%defattr(-,root,root) +%doc README.md redsocks.conf.example +%doc %attr(644,root,root) %_mandir/*/* +%dir %_sysconfdir/%{name} +%config(noreplace) %attr(644,root,root) %_sysconfdir/%{name}/%{name}.conf +%attr(755,root,root) %{_prefix}/bin/%{name} +%attr(755,root,root) %{_sbindir}/rc%{name} +%attr(644,root,root) %_unitdir/%{name}.service +%{_fillupdir}/sysconfig.%{name} +%{_tmpfilesdir}/%{name}.conf + +%changelog + From 31919d5bc513b766da1e9d8293859764ded7580e Mon Sep 17 00:00:00 2001 From: Norbert Kipp Date: Fri, 5 Jun 2020 15:25:36 +0200 Subject: [PATCH 05/11] prepare for OSB <-> GIT --- redsocks.spec => RPM/redsocks.spec | 3 +-- SuSE/redsocks.sysconfig | 9 +++++++++ 2 files changed, 10 insertions(+), 2 deletions(-) rename redsocks.spec => RPM/redsocks.spec (97%) create mode 100644 SuSE/redsocks.sysconfig diff --git a/redsocks.spec b/RPM/redsocks.spec similarity index 97% rename from redsocks.spec rename to RPM/redsocks.spec index a208a1bc..7dbb92a4 100644 --- a/redsocks.spec +++ b/RPM/redsocks.spec @@ -28,7 +28,6 @@ Summary: Redirect any TCP connection to a SOCKS or HTTPS proxy server Url: http://darkk.net.ru/redsocks/ Group: Productivity/Networking/Other Source: %{name}-%{version}.tar.gz -Source2: %{name}.sysconfig BuildRequires: libevent-devel PreReq: %fillup_prereq PreReq: /usr/bin/getent @@ -65,7 +64,7 @@ ln -s -f %{_sbindir}/service %{buildroot}%{_sbindir}/rc%{name} %{__install} -D debian/%{name}.conf %buildroot/%_sysconfdir/%{name}/%{name}.conf %{__install} -D debian/%{name}.8 %buildroot/%_mandir/man8/%{name}.8 gzip %buildroot/%_mandir/man8/%{name}.8 -%{__install} -D -m644 %{SOURCE2} %{buildroot}%{_fillupdir}/sysconfig.%{name} +%{__install} -D -m644 SuSE/%{name}.sysconfig %{buildroot}%{_fillupdir}/sysconfig.%{name} %{__install} -d -m 0755 %{buildroot}%{_tmpfilesdir} echo "d /var/run/%name 755 %name %name" >%{buildroot}%{_tmpfilesdir}/%{name}.conf diff --git a/SuSE/redsocks.sysconfig b/SuSE/redsocks.sysconfig new file mode 100644 index 00000000..efbadf70 --- /dev/null +++ b/SuSE/redsocks.sysconfig @@ -0,0 +1,9 @@ +## Path: Network/Others +## Description: socks redirector + +## Type: string +## Default: "/etc/redsocks/redsocks.conf" +# +# The config file. +# +REDSOCKS_CONF="/etc/redsocks/redsocks.conf" From 63802b4680358ecfa46f447c288b4cbd033ef8b5 Mon Sep 17 00:00:00 2001 From: Norbert Kipp Date: Fri, 5 Jun 2020 15:39:44 +0200 Subject: [PATCH 06/11] 2nd step to build direct from GIT --- RPM/redsocks.spec | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/RPM/redsocks.spec b/RPM/redsocks.spec index 7dbb92a4..039f7c94 100644 --- a/RPM/redsocks.spec +++ b/RPM/redsocks.spec @@ -27,7 +27,8 @@ License: Apache-2.0 Summary: Redirect any TCP connection to a SOCKS or HTTPS proxy server Url: http://darkk.net.ru/redsocks/ Group: Productivity/Networking/Other -Source: %{name}-%{version}.tar.gz +#Source: %{name}-%{version}.tar.gz +Source: _service BuildRequires: libevent-devel PreReq: %fillup_prereq PreReq: /usr/bin/getent @@ -50,7 +51,7 @@ Also included is a small DNS server returning answers with the "truncated" flag set for any UDP query, forcing the resolver to use TCP. %prep -%setup +%setup -n %_sourcedir/%name-%version -T -D %build CFLAGS="$RPM_OPT_FLAGS" make %{?_smp_mflags} From 0ce27de7fde41047d08747109417a120ade698b4 Mon Sep 17 00:00:00 2001 From: Norbert Kipp Date: Fri, 5 Jun 2020 16:03:40 +0200 Subject: [PATCH 07/11] Revert "2nd step to build direct from GIT" This reverts commit 63802b4680358ecfa46f447c288b4cbd033ef8b5. --- RPM/redsocks.spec | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/RPM/redsocks.spec b/RPM/redsocks.spec index 039f7c94..7dbb92a4 100644 --- a/RPM/redsocks.spec +++ b/RPM/redsocks.spec @@ -27,8 +27,7 @@ License: Apache-2.0 Summary: Redirect any TCP connection to a SOCKS or HTTPS proxy server Url: http://darkk.net.ru/redsocks/ Group: Productivity/Networking/Other -#Source: %{name}-%{version}.tar.gz -Source: _service +Source: %{name}-%{version}.tar.gz BuildRequires: libevent-devel PreReq: %fillup_prereq PreReq: /usr/bin/getent @@ -51,7 +50,7 @@ Also included is a small DNS server returning answers with the "truncated" flag set for any UDP query, forcing the resolver to use TCP. %prep -%setup -n %_sourcedir/%name-%version -T -D +%setup %build CFLAGS="$RPM_OPT_FLAGS" make %{?_smp_mflags} From bb9ae15a56a39e982308c008076c4b5a11d0d887 Mon Sep 17 00:00:00 2001 From: Norbert Kipp Date: Fri, 5 Jun 2020 20:01:45 +0200 Subject: [PATCH 08/11] added OSB _service file --- RPM/_service | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 RPM/_service diff --git a/RPM/_service b/RPM/_service new file mode 100644 index 00000000..70625519 --- /dev/null +++ b/RPM/_service @@ -0,0 +1,21 @@ + + + https://github.com/snorre-k/redsocks.git + git + RPM/redsocks.spec + @PARENT_TAG@+git@TAG_OFFSET@+%cd.%h + + + + + + + *.tar + gz + + + + From be346240df2084c89a948c976e66ec1a677917d9 Mon Sep 17 00:00:00 2001 From: snorre-k Date: Fri, 5 Jun 2020 20:32:27 +0200 Subject: [PATCH 09/11] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 3b544e3b..e66aa32d 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Adapted by Snorre to have some bugfixes * Works with proxies sending multiple authentication requests * Added RPM spec file +* Added _service for building on OSB This tool allows you to redirect any TCP connection to SOCKS or HTTPS proxy using your firewall, so redirection may be system-wide or network-wide. @@ -256,3 +257,4 @@ Mailing list also has [archives](http://librelist.com/browser/redsocks/). ## Author This program was written by Leonid Evdokimov +Changed by Snorre From 2c1ccf0f037479053835d6270d34b06fa0fcca46 Mon Sep 17 00:00:00 2001 From: Norbert Kipp Date: Fri, 5 Jun 2020 21:32:50 +0200 Subject: [PATCH 10/11] just for Testing webhook --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e66aa32d..4b0e4e3d 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # redsocks – transparent TCP-to-proxy redirector -Adapted by Snorre to have some bugfixes +Adapted by Snorre to have some bugfixes: * Works with proxies sending multiple authentication requests * Added RPM spec file From df8452fee370e92b18c9ea4b829e141a2844673b Mon Sep 17 00:00:00 2001 From: snorre-k Date: Sat, 6 Jun 2020 09:55:06 +0200 Subject: [PATCH 11/11] version is defined by latest TAG in git --- RPM/redsocks.spec | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RPM/redsocks.spec b/RPM/redsocks.spec index 7dbb92a4..ccac0ace 100644 --- a/RPM/redsocks.spec +++ b/RPM/redsocks.spec @@ -21,7 +21,7 @@ %endif Name: redsocks -Version: 0.5.1 +Version: _service Release: 0 License: Apache-2.0 Summary: Redirect any TCP connection to a SOCKS or HTTPS proxy server