Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why can't proxychains4 work in this case? #483

Open
aitsc opened this issue Oct 29, 2022 · 5 comments
Open

Why can't proxychains4 work in this case? #483

aitsc opened this issue Oct 29, 2022 · 5 comments

Comments

@aitsc
Copy link

aitsc commented Oct 29, 2022

I configured proxychains4, but these lines of code doesn't work:

proxychains4 python -c "import os;os.system('curl baidu.com')"
proxychains4 apt update
proxychains4 pip install faker

However, the results of running the first 6 commands prove that the configuration of proxychains4 should be fine:

(base) root@test:~# curl baidu.com
curl: (6) Could not resolve host: baidu.com

(base) root@test:~# proxychains4 curl baidu.com
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain  ...  127.0.0.1:34567  ...  baidu.com:80  ...  OK
<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>

(base) root@test:~# python -c "import os;os.system('proxychains4 curl baidu.com')"
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain  ...  127.0.0.1:34567  ...  baidu.com:80  ...  OK
<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>

(base) root@test:~# proxychains4 python -c "import os;os.system('proxychains4 curl baidu.com')"
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain  ...  127.0.0.1:34567  ...  baidu.com:80  ...  OK
<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>

(base) root@test:~# git clone https://github.com/rofl0r/proxychains-ng.git
Cloning into 'proxychains-ng'...
fatal: unable to access 'https://github.com/rofl0r/proxychains-ng.git/': Could not resolve host: github.com

(base) root@test:~# proxychains4 git clone https://github.com/rofl0r/proxychains-ng.git
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
Cloning into 'proxychains-ng'...
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain  ...  127.0.0.1:34567  ...  github.com:443  ...  OK
[proxychains] DLL init: proxychains-ng 4.14
remote: Enumerating objects: 1557, done.
remote: Counting objects: 100% (137/137), done.
remote: Compressing objects: 100% (66/66), done.
[proxychains] DLL init: proxychains-ng 4.14
remote: Total 1557 (delta 83), reused 81 (delta 67), pack-reused 1420
Receiving objects: 100% (1557/1557), 724.93 KiB | 1.66 MiB/s, done.
Resolving deltas: 100% (1025/1025), done.

(base) root@test:~# proxychains4 python -c "import os;os.system('curl baidu.com')"
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
curl: (6) Could not resolve host: baidu.com

(base) root@test:~# proxychains4 apt update
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] DLL init: proxychains-ng 4.14
0% [Working][proxychains] Strict chain  ...  127.0.0.1:34567 [proxychains] Strict chain  ...  127.0.0.1:34567 [proxychains] Strict chain  ...  127.0.0.1:34567  ...  security.ubuntu.com:0  ...  archive.ubuntu.com:0  ...  developer.download.nvidia.com:0  ...  OK
 ...  OK
[proxychains] Strict chain  ...  127.0.0.1:34567  ...  archive.ubuntu.com:0 [proxychains] Strict chain  ...  127.0.0.1:34567  ...  security.ubuntu.com:0  ...  OK
Ign:1 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64  InRelease
0% [Connecting to archive.ubuntu.com (224.0.0.1)] [Connecting to security.ubuntu.com (224.0.0.1)][proxychains] Strict chain  ...  127.0.0.1:34567  ...  developer.download.nvidia.com:0  ...  OK
Err:2 http://archive.ubuntu.com/ubuntu focal InRelease
  Connection failed [IP: 224.0.0.1 0]
0% [Connecting to security.ubuntu.com (224.0.0.1)] [Connecting to developer.download.nvidia.com (224.0.0.1)] ...  archive.ubuntu.com:0  ...  OK
 ...  OK
Err:3 http://security.ubuntu.com/ubuntu focal-security InRelease
  Connection failed [IP: 224.0.0.1 0]
Err:4 https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64  Release
  Could not handshake: The TLS connection was non-properly terminated. [IP: 224.0.0.1 0]
0% [Connecting to archive.ubuntu.com (224.0.0.1)] ...  OK
[proxychains] Strict chain  ...  127.0.0.1:34567  ...  archive.ubuntu.com:0  ...  OK
Err:5 http://archive.ubuntu.com/ubuntu focal-updates InRelease
  Connection failed [IP: 224.0.0.1 0]
0% [Working] ...  archive.ubuntu.com:0  ...  OK
[proxychains] Strict chain  ...  127.0.0.1:34567  ...  archive.ubuntu.com:0  ...  OK
Err:6 http://archive.ubuntu.com/ubuntu focal-backports InRelease
  Connection failed [IP: 224.0.0.1 0]
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] DLL init: proxychains-ng 4.14
Reading package lists... Done
E: The repository 'https://developer.download.nvidia.com/compute/cuda/repos/ubuntu2004/x86_64  Release' no longer has a Release file.
N: Updating from such a repository can't be done securely, and is therefore disabled by default.
N: See apt-secure(8) manpage for repository creation and user configuration details.

(base) root@test:~# proxychains4 pip install faker
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fe259eab970>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/faker/
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fe259eabc70>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/faker/
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fe259eabf10>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/faker/
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fe259e561f0>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/faker/
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'NewConnectionError('<pip._vendor.urllib3.connection.HTTPSConnection object at 0x7fe259e56280>: Failed to establish a new connection: [Errno -3] Temporary failure in name resolution')': /simple/faker/
ERROR: Could not find a version that satisfies the requirement faker (from versions: none)
ERROR: No matching distribution found for faker

vim /etc/proxychains4.conf

strict_chain
proxy_dns
remote_dns_subnet 224
tcp_read_time_out 15000
tcp_connect_time_out 8000

[ProxyList]
http 127.0.0.1 34567

I don't have this problem on other ubuntu. How should I look for the cause of this problem?

@aitsc aitsc changed the title Why can't proxychains4 work under subshell? Why can't proxychains4 work in this case? Oct 29, 2022
@rofl0r
Copy link
Owner

rofl0r commented Oct 30, 2022

the problem seems to be pip and apt, which both require root permissions. some security feature might intervene. you can try whether proxydns_daemon mode fixes it.

@aitsc
Copy link
Author

aitsc commented Oct 30, 2022

@rofl0r I used proxychains4-daemon, but apt and pip still have the same output. The problem doesn't seem to be a dns proxy issue, as direct access to the ip doesn't work either.

(base) root@test# proxychains4 python -c "import os;os.system('curl 1.1.1.1')"
[proxychains] config file found: /usr/local/etc/proxychains.conf
[proxychains] preloading /usr/local/lib/libproxychains4.so
curl: (28) Failed to connect to 1.1.1.1 port 80: Connection timed out

(base) root@test# python -c "import os;os.system('proxychains4 curl 1.1.1.1')"
[proxychains] config file found: /usr/local/etc/proxychains.conf
[proxychains] preloading /usr/local/lib/libproxychains4.so
[proxychains] DLL init: proxychains-ng 4.16-git-9-g060801d
[proxychains] Strict chain  ...  127.0.0.1:34567  ...  1.1.1.1:80  ...  OK
<html>
<head><title>301 Moved Permanently</title></head>
<body>
<center><h1>301 Moved Permanently</h1></center>
<hr><center>cloudflare</center>
</body>
</html>

@rofl0r
Copy link
Owner

rofl0r commented Oct 30, 2022

the output of the second command seems to suggest that python's system deletes environment variables, such as the LD_PRELOAD one set by proxychains4 binary. so i'd just use the second method, namely running system("proxychains4 ...").

@aitsc
Copy link
Author

aitsc commented Oct 31, 2022

@rofl0r It is true that environment variables are deleted. But what is confusing is that this phenomenon only happens with the LD_PRELOAD variable, which is strange.

The first command proves that adding LD_PRELOAD manually in the subshell is valid. The second command proves that manually adding LD_PRELOAD outside is not valid. The third command proves that manually adding LD_PRELOAD1 outside is valid.

(base) root@test# proxychains4 bash -c "python -c 'import os;os.system(\"export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libproxychains.so.4 && export && curl baidu.com\")'"
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
......
export LD_PRELOAD='/usr/lib/x86_64-linux-gnu/libproxychains.so.4'
......
[proxychains] DLL init: proxychains-ng 4.14
[proxychains] Strict chain  ...  127.0.0.1:34567  ...  baidu.com:80  ...  OK
<html>
<meta http-equiv="refresh" content="0;url=http://www.baidu.com/">
</html>

(base) root@test# proxychains4 bash -c "export LD_PRELOAD=/usr/lib/x86_64-linux-gnu/libproxychains.so.4 && python -c 'import os;os.system(\"export && curl baidu.com\")'"
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
......
curl: (6) Could not resolve host: baidu.com

(base) root@test# proxychains4 bash -c "export LD_PRELOAD1=/usr/lib/x86_64-linux-gnu/libproxychains.so.4 && python -c 'import os;os.system(\"export && curl baidu.com\")'"
[proxychains] config file found: /etc/proxychains4.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.14
......
export LD_PRELOAD1='/usr/lib/x86_64-linux-gnu/libproxychains.so.4'
......
curl: (6) Could not resolve host: baidu.com

@rofl0r
Copy link
Owner

rofl0r commented Oct 31, 2022

might be a security "feature" of python. maybe you can grep the sources of your python version for "LD_PRELOAD" and find out why.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants