
Eu configurei o seguinte pipeline. Isso me permite ver as solicitações e respostas HTTP brutas que passam pelo pipeline.
Observação:Eu uso o BSD nc
abaixo (é o que vem com o macOS e o AmazonLinux), mas também tentei o do nmap ncat
, que pode receber os mesmos argumentos, e socat
1.7.3.2 O comportamento é o mesmo.
socat
aceita argumentos diferentes, mas o pipeline é o mesmo. Acrescentarei socat
apenas uma linha, pois a explicação seria a mesma.
Uma linha:
mkfifo res; nc -kl 8888 < res | tee /dev/stderr | nc google.com 80 | tee res
OU
mkfifo res; socat tcp-listen:8888,reuseaddr,fork - < res | tee /dev/stderr | socat - tcp:google.com:80 | tee res
Explicação:
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.
Eu executo esse pipeline em um terminal (oterminal pipline), e use curl
para fazer a requisição em outro terminal (oterminal de ondulação):
curl --resolve google.com:8888:127.0.0.1 http://google.com:8888
No macOS e no Linux:
Oterminal de ondulaçãorecebe e exibe corretamente a resposta. Oterminal de gasodutoexibe a solicitação E a resposta.
No macOS (macOS Mojave 10.14.3):
O pipeline continua em execução. Posso enviar outra solicitação com curl
e posso ver a solicitação noterminal de gasodutoe a resposta emambosterminais.
No Linux (AmazonLinux 4.1.13):
O pipeline continua em execução. curl
trava se eu enviar outra solicitação e não consigo ver a solicitação ou resposta em lugar nenhum.
Versões:
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 )
Não tenho certeza, nc
pois não tem sinalizador --version
, mas veio com o sistema operacional. Há esta string no binário:
$ 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