
Configuré la siguiente canalización. Esto me permite ver las solicitudes y respuestas HTTP sin procesar que pasan por la canalización.
Nota:Utilizo BSD nc
a continuación (esto es lo que viene con macOS y AmazonLinux), pero también probé nmap's ncat
, que puede tomar los mismos argumentos, y socat
1.7.3.2. El comportamiento es el mismo.
socat
Toma argumentos diferentes, pero el proceso es el mismo. Agregaré socat
solo la frase breve, ya que la explicación sería la misma.
Un trazador de líneas:
mkfifo res; nc -kl 8888 < res | tee /dev/stderr | nc google.com 80 | tee res
O
mkfifo res; socat tcp-listen:8888,reuseaddr,fork - < res | tee /dev/stderr | socat - tcp:google.com:80 | tee res
Explicación:
mkfifo res; \ <-- Make a named pipe file with the name 'res'.
nc -kl 8888 < res \ <-- Open a socket listening on all interfaces at TCP port 8888. Use the 'res' pipe as input.
| tee /dev/stderr \ <-- Copy the request to stderr, so it's emitted by the terminal. stdout will be used as input for the next netcat.
| nc google.com 80 \ <-- Resolve google.com, connect to it on TCP port 80, and send what was received on stdin. The response goes to stdout.
| tee res <-- Copy the response to the 'res' pipe.
Ejecuto esta canalización en una terminal (laterminal de tubería), y utilizar curl
para realizar la solicitud en otro terminal (elterminal de rizo):
curl --resolve google.com:8888:127.0.0.1 http://google.com:8888
Tanto en macOS como en Linux:
Elterminal de rizorecibe y muestra correctamente la respuesta. Elterminal de oleoductomuestra la solicitud Y la respuesta.
En macOS (macOS Mojave 10.14.3):
El oleoducto continúa funcionando. Puedo enviar otra solicitud con curl
y puedo ver la solicitud en elterminal de oleoductoy la respuesta enambosterminales.
En Linux (AmazonLinux 4.1.13):
El oleoducto continúa funcionando. curl
Se cuelga si envío otra solicitud y no puedo ver la solicitud o la respuesta en ninguna parte.
Versiones:
Mac OS
$ uname -a
Darwin ch007837.na.webmd.net 18.2.0 Darwin Kernel Version 18.2.0: Thu Dec 20 20:46:53 PST 2018; root:xnu-4903.241.1~1/RELEASE_X86_64 x86_64 i386 MacBookPro15,1 Darwin
$ curl --version
curl 7.64.1 (x86_64-apple-darwin18.2.0) libcurl/7.64.1 SecureTransport zlib/1.2.11
Release-Date: 2019-03-27
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IPv6 Largefile libz NTLM NTLM_WB SSL UnixSockets
$ bash --version | head -1
GNU bash, version 5.0.3(1)-release (x86_64-apple-darwin18.2.0)
$ ncat --version
Ncat: Version 7.70 ( https://nmap.org/ncat )
No estoy seguro nc
porque no tiene --version
bandera, pero vino con el sistema operativo. Sin embargo, existe esta cadena en el binario:
$ strings "$(which nc)" | tail -1
@(#)PROGRAM:nc PROJECT:netcat-42.200.1
linux
$ uname -a
Linux ip-10-200-38-72 4.1.13-19.31.amzn1.x86_64 #1 SMP Wed Jan 20 00:25:47 UTC 2016 x86_64 x86_64 x86_64 GNU/Linux
$ curl --version
curl 7.40.0 (x86_64-redhat-linux-gnu) libcurl/7.40.0 NSS/3.19.1 Basic ECC zlib/1.2.8 libidn/1.18 libssh2/1.4.2
Protocols: dict file ftp ftps gopher http https imap imaps ldap ldaps pop3 pop3s rtsp scp sftp smb smbs smtp smtps telnet tftp
Features: AsynchDNS IDN IPv6 Largefile GSS-API Kerberos SPNEGO NTLM NTLM_WB SSL libz UnixSockets
$ bash --version | head -1
GNU bash, version 4.2.46(1)-release (x86_64-redhat-linux-gnu)
$ ncat --version
Ncat: Version 5.51 ( http://nmap.org/ncat )
$ yum list nc | tail -1 | sed 's/ \+/ /g'
nc.x86_64 1.84-24.8.amzn1 @amzn-main