
Ich habe die folgende Pipeline eingerichtet. Dadurch kann ich die unverarbeiteten HTTP-Anfragen und -Antworten sehen, die durch die Pipeline laufen.
Notiz:Ich verwende unten BSD nc
(das ist das, was mit macOS und AmazonLinux geliefert wird), aber ich habe auch nmap ausprobiert ncat
, das dieselben Argumente annehmen kann, und socat
1.7.3.2. Das Verhalten ist dasselbe. nimmt unterschiedliche Argumente an, aber die Pipeline ist dieselbe. Ich werde nur den Einzeiler
socat
hinzufügen , da die Erklärung dieselbe wäre.socat
Einzeiler:
mkfifo res; nc -kl 8888 < res | tee /dev/stderr | nc google.com 80 | tee res
ODER
mkfifo res; socat tcp-listen:8888,reuseaddr,fork - < res | tee /dev/stderr | socat - tcp:google.com:80 | tee res
Erläuterung:
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.
Ich führe diese Pipeline in einem Terminal aus (demRohrleitungsterminal) und verwenden Sie , curl
um die Anfrage in einem anderen Terminal zu stellen (demCurl-Terminal):
curl --resolve google.com:8888:127.0.0.1 http://google.com:8888
Sowohl unter macOS als auch unter Linux:
DerCurl-Terminalempfängt und zeigt die Antwort korrekt an.Pipeline-Terminalzeigt die Anfrage UND die Antwort an.
Unter macOS (macOS Mojave 10.14.3):
Die Pipeline läuft weiter. Ich kann eine weitere Anfrage mit senden curl
und sehe die Anfrage imPipeline-Terminalund die Antwort inbeideKlemmen.
Unter Linux (AmazonLinux 4.1.13):
Die Pipeline wird weiter ausgeführt. curl
Sie bleibt hängen, wenn ich eine weitere Anfrage sende, und ich kann die Anfrage oder die Antwort nirgendwo sehen.
Versionen:
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 )
Ich bin mir nicht sicher, nc
da es kein Flag hat --version
, aber es war im Betriebssystem enthalten. In der Binärdatei gibt es jedoch diese Zeichenfolge:
$ 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