I want to use OpenSSL or any native Linux command to grab the certificate of a SQL Server. I tried the same way as I do with an HTTP server but it doesn't work.
openssl s_client -showcerts -connect MY.MSSQL.SERVER:1433
CONNECTED(00000003)
write:errno=104
---
no peer certificate available
---
No client certificate CA names sent
---
SSL handshake has read 0 bytes and written 249 bytes
---
New, (NONE), Cipher is (NONE)
Secure Renegotiation IS NOT supported
Compression: NONE
Expansion: NONE
---
3条答案
按热度按时间wwtsj6pe1#
This gist by github user lnattrass gives a python script that is "A terrible way to connect to MS SQL Server and dump the certificate as a PEM" (his wording) in python. Yes, that's not what you asked about, you asked about OpenSSL. But one of the comments says in part
I was able to get the same results using openssl like this:
openssl s_client -showcerts -connect <hostname>:<port> </dev/null 2>/dev/null|openssl x509 -outform PEM >dbcertfile.pem
as suggested somewhere.(no clue where "somewhere" would have been.)
I've tried the openssl method but it failed for me:
Perhaps this was because the self-signed cert (see below) was not trusted? I'm really not sure.
After fixing one indentation bug, the python method worked for me:
I haven't bothered to redact the certificate because it is the SQL Server self-signed fallback , as displayed by SSLShopper Certificate Decoder
kse8i1jr2#
Inspired by the https://gist.github.com/lnattrass/a4a91dbf439fc1719d69f7865c1b1791 with help from https://learn.microsoft.com/en-us/openspecs/windows_protocols/ms-tds/1ef08b76-1594-40cf-8ce0-d2407133dd3d
Similar implementation in groovy (java 11) which returns certificate chain from sql server:
luaexgnf3#
After looking for openssl solutions without sucesss and fighting with the python script without success too (both the initial and the fixed versions throwed an error) i resorted to use nmap, in this case it was quite easy:
In the output there should be a certificate such as this (selfsigned cert), you should be able to clean the formatting and use it where you need.