Run Java Through Socks Proxy with proxychains
Steps to Get the cap-credentials-provider
Java Application to Work with ProxyChainsβ
This guide details all the required steps to configure ProxyChains to route Java application (cap-credentials-provider
) traffic through a SOCKS5 proxy.
A SOCKS proxy can be used to provide a different exit point for traffic that is originating from the application, almost like a lightweight VPN tunnel. When the application is run with proxychains all of its traffic is captured and redirected through the SSH based SOCKS proxy (established later in this example). The traffic then exits out of the end of the SSH tunnel and all replies are routed back through the SSH tunnel to the originating application.
This guide currently works ONLY with Linux based operating systems.β
At this time it appears that Mac OS does not allow network traffic to be redirected from Java through proxychains / SOCKS and the issue will need to be resolved in order to utilize the functionality. The primary suspect is SIP (System Integrity Protection)
Should this problem be resolved it will allow for local development and debugging of Java applications while they are effectively executed within the VPC.
1. Install Proxychainsβ
Ensure the following are installed on your system:
sudo apt install proxychains4
2. Configure ProxyChainsβ
Modify the configuration file /etc/proxychains.conf
:
sudo nano /etc/proxychains.conf
Required Changes:β
Many of these options are already present within the configuration file. Ensure that they are not commented out.
- Set the proxy mode to strict:
strict_chain
- Enable DNS resolution via proxy:
proxy_dns
- Add your SOCKS5 proxy at the end of the file:
(Replace
[ProxyList]
socks5 127.0.0.1 9050127.0.0.1 9050
with the actual proxy settings if different.)
Save and exit (Ctrl + X
, then Y
, then Enter
).
3. Ensure the Proxy is Runningβ
If using an SSH-based SOCKS5 proxy, start it with:
ssh -D 9050 -i /path/to/key.pem -N -f user@proxy-server-ip
Confirm itβs running:
ss -pantu | grep 1080
5. Run Java Application with ProxyChainsβ
Run the built Java application using proxychains
:
proxychains4 java -jar target/cap-credentials-provider.jar
(Ensure the correct JAR file name is used.)
Successful execution should yield output similar to the following:
[proxychains] config file found: /etc/proxychains.conf
[proxychains] preloading /usr/lib/x86_64-linux-gnu/libproxychains.so.4
[proxychains] DLL init: proxychains-ng 4.16
...
[proxychains] Strict chain ... 127.0.0.1:9050 ... website.target.something.mil:443 ... OK
6. Debugging & Testingβ
-
Check network traffic via proxy:
proxychains4 curl ifconfig.me
If it returns the proxyβs IP, ProxyChains is working.
-
Run Java with debugging logs:
proxychains4 java -Djava.net.debug=all -jar target/cap-credentials-provider.jar [arguments]
This provides detailed networking logs.
7. Verify DNS Resolution Over Proxyβ
Since Java applications may directly resolve DNS, test if proxychains
is handling DNS correctly:
proxychains4 dig +tcp website.target.something.mil
Final Checklistβ
β
Install proxychains4 (sudo apt install proxychains4
)
β
Configure ProxyChains (/etc/proxychains.conf
).
β
Ensure the SOCKS5 proxy is running (ssh -D 9050
).
β
Run Java through ProxyChains (proxychains4 java -jar ...
).
β
Verify traffic & DNS resolution (proxychains4 dig +tcp ...
).
This setup will ensure all network requests from the Java application are routed through the SOCKS5 proxy via ProxyChains.