The following command works on the command line:
wget --secure-protocol=PFS -O dcm4chee-arc-5.15.1-mysql.zip https://sourceforge.net/projects/dcm4che/files/dcm4chee-arc-light5/5.15.1/dcm4chee-arc-5.15.1-mysql.zip/download
However, when I put the exact same line into a bash script (it's inside a function), it results in this error:
Resolving sourceforge.net (sourceforge.net)... 216.105.38.13
Connecting to sourceforge.net (sourceforge.net)|216.105.38.13|:443... connected.
Unable to establish SSL connection.
I've even pulled it out of the function to see if that makes any difference, but it doesn't.
Any thoughts?
Kicking myself ... my IDE had #!/usr/bin/env bash at the top of the file, whereas changing it to simply #!/bin/bash made everything work as expected. I thank you all for the responses, crediting #Mihai with direct assistance due to the comment about "environment"
Trying to create a function to check if there are issues with the SSL on a webpage.In the specific scenario we've setup the expected output for curl https://domain includes:
curl: (60) SSL certificate problem: self signed certificate
...we are using grep, as per the line below to to set the SSL_STATUS variable to that line which we will then pump through an if statement. Problem is that it sets the variable and then drops out of the script for no apparent reason:
+ https_status
++ curl https://steelrain.eu
++ grep 'SSL certificate problem'
+ SSL_STATUS='curl: (60) SSL certificate problem: self signed certificate'
Having tested this is not the result of the grep but curl, and I do not know why (it still occurred when using SSL_STATUS=$( curl https://${DOMAIN} ) which is the basis).
I might just not be understanding how something works here because I'm thick but any assistance would be appreciated.
SSL_STATUS=$( curl https://${DOMAIN} 2>&1 | grep "SSL certificate problem" )
probably should have mentioned before but setting the function to just run the curl command drops it out of the script too so it's not setting the output to a variable that's causing trouble.
set -e was in the main script for debugging:
set -euox pipefail
Commented out and now it's sorted. Cheers!
I've been trying to use socat to respond on each connection to a socket it's listening to with a fake HTTP reply. I cannot get it working. It might be because I'm using the cygwin version of socat? I don't know.
Part of the problem is I want the second argument <some_file_response> not to be written to. In other words because it's bidirectional it will read what's in response.txt and then write to that same file, and I don't want that. Even if I do open:response.txt,rdonly it doesn't work repeatedly. system: doesn't seem to do anything. exec seems like it works, for example I can do exec:'cat response.txt' but that never gets sent to the client connecting to port 1234.
socat -vv tcp-listen:1234,reuseaddr,fork <some_file_response>
I want it to read a file to the client that's connected and then close the connection, and do that over and over again (that's why I used fork).
I am putting a bounty on this question. Please only give me solutions that work with the cygwin version from the windows command prompt.
Tested with cygwin:
socat -vv TCP-LISTEN:1234,crlf,reuseaddr,fork SYSTEM:"echo HTTP/1.0 200; echo Content-Type\: text/plain; echo; cat <some_file_response>"
If you do not want a complete HTTP response, leave out the echos:
socat -vv TCP-LISTEN:1234,crlf,reuseaddr,fork SYSTEM:"cat <some_file_response>"
Taken from socat examples
socat -vv TCP-LISTEN:8000,crlf,reuseaddr,fork SYSTEM:"echo HTTP/1.0 200; echo Content-Type\: text/plain; echo; cat"
This one works:
socat -v -v -d -d TCP-LISTEN:8080,reuseaddr,fork exec:"cat http.response",pipes
Two things need to be aware,
should you add crlf, as in other answers. I recommend not.
crlf caused problem sending image
just use \r\n explicitly in http response headers.
without pipes, seems no data sent to client. browser complains:
127.0.0.1 didn’t send any data.
ERR_EMPTY_RESPONSE
tested in cygwin.
== EDIT ==
If you want use inside cmd.exe, make sure PATH is correctly set, so that socat and cat can be found.
Say both socat.exe and cat.exe located under E:\cygwin64\bin
set PATH=%PATH%;E:\cygwin64\bin
Works in cmd.exe, with socat & cat from cygwin.
openssl takes over the input into its own interactive environment from what I can tell.
I want to try something like this:
openssl s_client -starttls smtp -connect smtp.gmail.com:587 -crlf -ign_eof
As the first line in my Bash script, then after that send some SMTP commands like HELO localhost. But if I put it right after that line in my script.sh file, and run it with sh, the second line never gets sent.
How do I accomplish something like this in a Bash script?
I'm trying to demonstrate to our QA department that we have (or have not) fixed a vulnerability shown in a recent scan. I would like to write a simple script that can demonstrate the vulnerability and show that the remediation actually fixes it. However since the vulnerability involves a invalid (possibly intentionally) HTTPS request I can't use a standard client to easily replicate it. Because there are several servers to test and several different vulnerabilities I would like to automate the testing a bit.
The following command line replicates the test but requires human intervention:
>openssl s_client -connect {server:ip} | grep Location
GET /images HTTP/1.0 <---- (user types this plus two Enter keys)
Location:{text here proves success/failure}
How can I automate the test above?
I'm using openssl because it's convenient. I'm willing to get another tool if it can accept arbitrary HTTPS request headers.
In bash you can just pipe your text into the OpenSSL command-line utility:
printf 'GET /images HTTP/1.0\r\n\r\n' | openssl s_client -connect {server:ip} | grep Location