Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

curl HTTPS via an SSH proxy

Tags:

curl

ssh

proxy

I want the below curl command to run from my machine, but via a remote proxy server.

curl "https://site.fake/ping"

However, I want this to always work via a remote proxy server.

I was tring to set this up with an ssh tunnel:

sudo ssh -i ~/.ssh/private_key_file -L 443:site.com:443 [email protected]

But this did not do the trick, running under osx.

Any suggestions?

like image 261
JAR.JAR.beans Avatar asked Jul 29 '18 09:07

JAR.JAR.beans


People also ask

How do I use curl with a proxy?

To use a proxy with Curl, you must pass the required proxy address using the -x (or --proxy) command-line option and proxy credentials using the -U (or --proxy-user) command-line switch. Proxy credentials may also be passed in the proxy string and will be URL decoded by Curl.

Can you SSH through a proxy?

You need an SSH client that can issue CONNECT requests through the company HTTP proxy. If you're on Windows, using Putty is fine as it has built-in support for tunneling through a HTTP proxy. If you're on unix/linux (or cywgin) you can use openssh with corkscrew to go through the proxy to your home computer's port 443.

Does Curl use SSH?

curl supports SSH version 2 scp transfers. curl supports SFTP (draft 5) done over SSH version 2. curl supports SMB version 1 for upload and download. Uploading contents to an SMTP server means sending an email.


1 Answers

Try using a socks5 proxy for example:

$ ssh -D 8080 -f -C -q -N [email protected]
  • -D 8080 tells ssh to launch a SOCKS server on port 8080 locally.
  • -f Forks the process to the background.
  • -C Compresses the data before sending it.
  • -q Uses quiet mode.
  • -N Tells SSH that no command will be sent once the tunnel is up.

Then you could use curl like this:

curl -x socks5h://0:8080 https://example.com
like image 115
nbari Avatar answered Sep 30 '22 04:09

nbari