git
's own git --config 'http.proxy=socks5://127.0.0.1:4444'
or ssh_config
's proxycommand
using socat
and nc
techniques successfully reroute git
commands over the SOCKS proxy.
The problem could be, however, that the DNS lookup fails due to the lookup being done locally rather than remotely over over the SOCKS proxy. For example, in the case of an intranet, the servers may not have domain names on the internet (only known to intranet DNS).
There are two ways to solve this. The first one I've seen recommended several times, but it makes the ambitious assumption that you control the remote server.
Reroute local 53 traffic (DNS) to port X, forward that to the server at port Y, forward port Y to 53 on the server. Usually X=Y for simplicity.
Intercept local system calls that retrieve ip addresses for names.
I would argue that 2. is better, because it catches the problem at the source and only assumes that you control your local machine, which is a more likely case than controlling the remote server.
proxychains-ng
intecepts the getaddrinfo system call before it accesses your local nss.
Steps
Open a SOCKS5 port
ssh -v -NT -D 127.0.0.1:4444 intranethost
Setup proxychains
to use that port.
~/.proxychains/proxychains.conf
strict_chain
proxy_dns
tcp_read_time_out 150000
tcp_connect_time_out 80000
[ProxyList]
socks5 127.0.0.1 4444
Use proxychains to encapsulate git.
alias gitproxy='proxychains git'
gitproxy clone intranethost:path/to/repo.git
The beauty of taking this route is that this is all transparent to git and its remotes.
ProxyCommand connect -S localhost:1081 %h %p
instead. – zz-m Nov 17 '22 at 08:42