Last active
January 25, 2024 04:37
-
-
Save nuxlli/7553996 to your computer and use it in GitHub Desktop.
Examples of http request in unix domain socket with shell, using socat, netcat or curl
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# References | |
# http://www.computerhope.com/unix/nc.htm#03 | |
# https://github.com/daniloegea/netcat | |
# http://unix.stackexchange.com/questions/26715/how-can-i-communicate-with-a-unix-domain-socket-via-the-shell-on-debian-squeeze | |
# http://unix.stackexchange.com/questions/33924/write-inside-a-socket-open-by-another-process-in-linux/33982#33982 | |
# http://www.linuxjournal.com/content/more-using-bashs-built-devtcp-file-tcpip | |
# http://www.dest-unreach.org/socat/ | |
# http://stuff.mit.edu/afs/sipb/machine/penguin-lust/src/socat-1.7.1.2/EXAMPLES | |
# http://ubuntuforums.org/showthread.php?t=828870 | |
# Socat (tested: Linux and macOS) | |
echo -e "GET /v1.18/containers/json HTTP/1.1\r\nhost: localhost\r\n\r\n" | socat unix-connect:/var/run/docker.sock STDIO | |
# netcat (Linux) (netcat-freebsd or netcat-openbsd for Debian) | |
echo -e "GET /v1.18/containers/json HTTP/1.1\r\nhost: localhost\r\n\r\n" | nc -U /var/run/docker.sock | |
# netcat (macOS) (gnu netcat from homebrew is not supported) | |
echo -e "GET /v1.18/containers/json HTTP/1.1\r\nhost: localhost\r\n\r\n" | /usr/bin/nc -U /var/run/docker.sock | |
# curl version | |
curl --silent --unix-socket /var/run/docker.sock http://v1.18/containers/json | |
# bonus round: relay socket (unix sock -> tcp) | |
socat -d -d TCP-L:8080,fork UNIX:/var/run/docker.sock | |
# (tcp -> unix sock) | |
socat -d -d UNIX-L:/var/run/httpbin.sock,fork TCP:httpbin.org:80 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI: you can also use curl like:
curl --silent --unix-socket /var/run/docker.sock http://v1.41/containers/json
.If you have a payload you can read it first from stdin:
But on the OpenWrt prior to Mar 27 2023 the curl is compiled without UNIX sockets. To check it use
curl -V
.On Ubuntu it will have
Features: UnixSockets
but on the OpenWrt you won't see it.