Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do you pipe "echo" into "openssl"?

Tags:

openssl

I am simply trying to submit the "OPTIONS / HTTP/1.0" request to SSL-enabled web servers; however, when running this, I am just simply getting "DONE" At the end of the connection.

Here's the exact command that I'm using:

echo -e "OPTIONS / HTTP/1.0\r\n\r\n" | openssl s_client -connect site.com:443

Any suggestions? I'm sure I'm missing something very simple.

like image 214
LewlSauce Avatar asked Oct 02 '13 21:10

LewlSauce


3 Answers

There's an -ign_eof option which does exactly what you want without any hacks. It's been in the codebase since 2000 (0.9.5a), apparently.

The option suppresses the special interpretation of Q and R, and ignores an EOF on stdin. Instead, it waits for a connection close.

like image 163
Michael Lowman Avatar answered Nov 14 '22 18:11

Michael Lowman


the problem is discussed in this thread (the linked email has the only simple answer, which i'll repeat below): http://www.mail-archive.com/[email protected]/msg02937.html

(echo "GET /"; sleep 10) | openssl s_client -connect news.ycombinator.com:443

the problem being that s_client shuts down as soon as stdin closes. so your code works fine, but s_client is exiting after receiving the OPTIONS and before receiving the server response.

like image 32
andrew cooke Avatar answered Nov 14 '22 17:11

andrew cooke


Late answer...

seems if you add a 'cat' to your subshell it works.

(echo -ne "GET / HTTP/1.1\r\nHost: google.com\r\n\r\n" ; cat ) | openssl s_client -connect google.com:443

That 'cat' hangs around, and you can actually then continue interacting with s_client manually. I have only done a single test here, but I need this same ability to pipe in http headesr/bodies from command line to an ssl server.

like image 18
user3524425 Avatar answered Nov 14 '22 18:11

user3524425