H
H
hellfleet2020-07-06 22:53:36
linux
hellfleet, 2020-07-06 22:53:36

How to make php work through system proxy?

the task is to log all the data sent by the PHP code to the outside.
running mitmproxy localhost:9901

cat /etc/profile.d/http_proxy.sh
export http_proxy=http://localhost:9001
export https_proxy=https://localhost:9001
export no_proxy=localhost,::1


php-fpm running as user www-data
tried
iptables -t nat -A OUTPUT -p tcp -m multiport --dport 80,443 -m owner --uid-owner 33 -j DNAT --to-destination 127.0.0.1:9001

mitmproxy error is thrown
Invalid HTTP request form (expected: authority or absolute, got: relative)
- on HTTP request

ProtocolException('Cannot connect to server, no server address given.')
- for HTTPS request

profile.d for www-data only works in the console.

How to use a global proxy for all php in the system?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Victor Taran, 2020-07-07
@shambler81

uh php perfectly knows how to proxy, what's the point of inventing a bicycle?
https://gist.github.com/codedokode/ea0503ecb0efbc3...

V
Vladimir Dubrovin, 2020-07-07
@z3apa3a

You need a local proxy that supports transparent proxying. For example
https://3proxy.ru/plugins/TransparentPlugin/

plugin /path/to/TransparentPlugin.ld.so transparent_plugin
log /path/to/log
auth iponly
allow * * * 80
parent 1000 http 0.0.0.0 0
allow *
parent 1000 socks5 SOCKS5_IP SOCKS5_PORT USER PASSWORD
transparent
tcppm -i127.0.0.1  12345 127.0.0.1 11111

in the parent command, you can already specify any proxy, incl. external, wrap traffic at 127.0.0.1:12345

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question