test me

Site Search:

How to verify a website with nslookup and openssl

Back>

When a website asking for sensitive information. We have two questions:

  1. should we trust this organization?
  2. are we dealing with the organization's website it is claim to be?
There are tools help us to find out, nslookup can translate the url to ip address of the host's IP.
openssl s_client can connect to the port our browser uses and verify the host's certificate is valid



demoAdmin@deomPC ~
$ nslookup www.bankofamerica.com
Non-authoritative answer:
Server:  Wireless_Broadband_Router.home
Address:  192.168.2.1

Name:    wwwui.ecglb.bac.com
Address:  171.161.207.100
Aliases:  www.bankofamerica.com


demoAdmin@deomPC ~
$ nslookup -type=ns www.bankofamerica.com
Non-authoritative answer:
Server:  Wireless_Broadband_Router.home
Address:  192.168.2.1

www.bankofamerica.com   canonical name = wwwui.ecglb.bac.com

ecglb.bac.com
        primary name server = ns1.ecglb.bac.com
        responsible mail addr = hostmaster.bankofamerica.com
        serial  = 337
        refresh = 3600 (1 hour)
        retry   = 7200 (2 hours)
        expire  = 1209600 (14 days)
        default TTL = 30 (30 secs)

demoAdmin@deomPC ~
$ nslookup wwwui.ecglb.bac.com ns1.ecglb.bac.com
Server:  UnKnown
Address:  171.162.17.30

Name:    wwwui.ecglb.bac.com
Address:  171.161.207.100


demoAdmin@deomPC ~
$ openssl s_client -connect 171.161.207.100:443 -showcerts -verify 5
verify depth is 5
CONNECTED(00000003)
depth=2 C = US, O = "VeriSign, Inc.", OU = VeriSign Trust Network, OU = "(c) 2006 VeriSign, Inc. - For authorized use only", CN = VeriSign Class 3 Public Primary Certification Authority - G5
verify return:1
depth=1 C = US, O = Symantec Corporation, OU = Symantec Trust Network, CN = Symantec Class 3 EV SSL CA - G3
verify return:1
depth=0 jurisdictionC = US, jurisdictionST = Delaware, businessCategory = Private Organization, serialNumber = 2927442, C = US, postalCode = 60603, ST = Illinois, L = Chicago, street = 135 S La Salle St, O = Bank of America Corporation, OU = eComm Network Infrastructure, CN = www.bankofamerica.com
verify return:1
---
Certificate chain
 0 s:/jurisdictionC=US/jurisdictionST=Delaware/businessCategory=Private Organization/serialNumber=2927442/C=US/postalCode=60603/ST=Illinois/L=Chicago/street=135 S La Salle St/O=Bank of America Corporation/OU=eComm Network Infrastructure/CN=www.bankofamerica.com
   i:/C=US/O=Symantec Corporation/OU=Symantec Trust Network/CN=Symantec Class 3 EV SSL CA - G3
-----BEGIN CERTIFICATE-----
MIIGzTCCBbWgAwIBAgIQZw38pkdGCfyVtu3gGj6+wDANBgkqhkiG9w0BAQsFADB3
MQswCQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAd
BgNVBAsTFlN5bWFudGVjIFRydXN0IE5ldHdvcmsxKDAmBgNVBAMTH1N5bWFudGVj
IENsYXNzIDMgRVYgU1NMIENBIC0gRzMwHhcNMTYwOTA4MDAwMDAwWhcNMTcwOTA5
MjM1OTU5WjCCASwxEzARBgsrBgEEAYI3PAIBAxMCVVMxGTAXBgsrBgEEAYI3PAIB
AgwIRGVsYXdhcmUxHTAbBgNVBA8TFFByaXZhdGUgT3JnYW5pemF0aW9uMRAwDgYD
VQQFEwcyOTI3NDQyMQswCQYDVQQGEwJVUzEOMAwGA1UEEQwFNjA2MDMxETAPBgNV
BAgMCElsbGlub2lzMRAwDgYDVQQHDAdDaGljYWdvMRowGAYDVQQJDBExMzUgUyBM
YSBTYWxsZSBTdDEkMCIGA1UECgwbQmFuayBvZiBBbWVyaWNhIENvcnBvcmF0aW9u
MSUwIwYDVQQLDBxlQ29tbSBOZXR3b3JrIEluZnJhc3RydWN0dXJlMR4wHAYDVQQD
DBV3d3cuYmFua29mYW1lcmljYS5jb20wggEiMA0GCSqGSIb3DQEBAQUAA4IBDwAw
ggEKAoIBAQC/TqlEZRi3BOSn3Tb6R9TGlgPTAOVPjRZ3hHnApUrWqxBu4if/0DMT
Fd5Z3pjLZwj7AApuSqO4UxsU8x9vnuknqOQqa8rFEUON4zVUDsoCR3l+7KC7Acj7
tPDUT/pjdPIe+X00GLEKf7GeZQPZsuR7ha7ubdlfAWNyM4KlCiS0HtDMY6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3hziMWb84m0wDQYJKoZIhvcNAQELBQADggEB
AG3/NuJP9lMxDhdMXEbYegw554x57PDcJOhxadv6mvtMIhenfCyXdv3DDwCFUsu3
zmgqkXc/LpixanSdSWK6fsiujjpspeyo8XhGpW/ABMlPkUIJATJ76nSF5uLmC5uv
kX1KYhTW7kGN8wU2zsxkQvOvM/fSc0StjtoXFp1BwtqtImR6MQyGf1WQVs+LF8TW
g9bnbOOLr2OT0uLFpG4UnuYuGlv6uJOp7edAAjUzKTFZA3tCZqU0hhves7JPcIOO
BXmCxcOhEmCii/np+tHDsWIgSaf2emIw9YapJBk8Qfwl7t4pwt/JldNk5a7wwkgd
xuq62FwAYaD+xFi3yIp1H2c=
-----END CERTIFICATE-----
 1 s:/C=US/O=Symantec Corporation/OU=Symantec Trust Network/CN=Symantec Class 3 EV SSL CA - G3
   i:/C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=(c) 2006 VeriSign, Inc. - For authorized use only/CN=VeriSign Class 3 Public Primary Certification Authority - G5
-----BEGIN CERTIFICATE-----
MIIFKzCCBBOgAwIBAgIQfuFKb2/v8tN/P61lTTratDANBgkqhkiG9w0BAQsFADCB
yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp
U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW
ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0
aG9yaXR5IC0gRzUwHhcNMTMxMDMxMDAwMDAwWhcNMjMxMDMwMjM1OTU5WjB3MQsw
CQYDVQQGEwJVUzEdMBsGA1UEChMUU3ltYW50ZWMgQ29ycG9yYXRpb24xHzAdBgNV
BAsTFlN5bWFudGVjIFRydXN0IE5ldHdvcmsxKDAmBgNVBAM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LRtzsMarNvSWbCAI7woeZiRFT2cAQMgHVHQzO6atuyOfZu2iRHA0+w7qAf3P
eHTfp61Vt19N9tY/4IbOJMdCqRMURDVLtt/JYKwMf9mTIUvunORJApjTYHtcvNUw
LwfORELEC5n+5p/8sHiGUW3RLJ3GlvuFgrsEL/digO9i2n/2DqyQuFa9eT/ygG6j
2bkPXToHHZGThkspTOHcteHgM52zyzaRS/6htO7w+Q==
-----END CERTIFICATE-----
 2 s:/C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=(c) 2006 VeriSign, Inc. - For authorized use only/CN=VeriSign Class 3 Public Primary Certification Authority - G5
   i:/C=US/O=VeriSign, Inc./OU=VeriSign Trust Network/OU=(c) 2006 VeriSign, Inc. - For authorized use only/CN=VeriSign Class 3 Public Primary Certification Authority - G5
-----BEGIN CERTIFICATE-----
MIIE0zCCA7ugAwIBAgIQGNrRniZ96LtKIVjNzGs7SjANBgkqhkiG9w0BAQUFADCB
yjELMAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQL
ExZWZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJp
U2lnbiwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxW
ZXJpU2lnbiBDbGFzcyAzIFB1YmxpYyBQcmltYXJ5IENlcnRpZmljYXRpb24gQXV0
aG9yaXR5IC0gRzUwHhcNMDYxMTA4MDAwMDAwWhcNMzYwNzE2MjM1OTU5WjCByjEL
MAkGA1UEBhMCVVMxFzAVBgNVBAoTDlZlcmlTaWduLCBJbmMuMR8wHQYDVQQLExZW
ZXJpU2lnbiBUcnVzdCBOZXR3b3JrMTowOAYDVQQLEzEoYykgMjAwNiBWZXJpU2ln
biwgSW5jLiAtIEZvciBhdXRob3JpemVkIHVzZSBvbmx5MUUwQwYDVQQDEzxWZXJp
U2lnbiBDbGFzcyAzIFB1YmxpYy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Nq
-----END CERTIFICATE-----
---
Server certificate
subject=/jurisdictionC=US/jurisdictionST=Delaware/businessCategory=Private Organization/serialNumber=2927442/C=US/postalCode=60603/ST=Illinois/L=Chicago/street=135 S La Salle St/O=Bank of America Corporation/OU=eComm Network Infrastructure/CN=www.bankofamerica.com
issuer=/C=US/O=Symantec Corporation/OU=Symantec Trust Network/CN=Symantec Class 3 EV SSL CA - G3
---
No client certificate CA names sent
---
SSL handshake has read 4478 bytes and written 626 bytes
---
New, TLSv1/SSLv3, Cipher is AES256-GCM-SHA384
Server public key is 2048 bit
Secure Renegotiation IS supported
Compression: NONE
Expansion: NONE
No ALPN negotiated
SSL-Session:
    Protocol  : TLSv1.2
    Cipher    : AES256-GCM-SHA384
    Session-ID: A5BF1DE3E585A246ADAD5642033F097B7A37E7051F7A3A64950ED846055B5EDF
    Session-ID-ctx:
    Master-Key: 70634E09C0BB6679F8289119C7D88A31AB739F97747994ED8E1971DBDCD34A75945A2C4F0F83AA76CDF806805B2031EF
    Key-Arg   : None
    PSK identity: None
    PSK identity hint: None
    SRP username: None
    Start Time: 1502575042
    Timeout   : 300 (sec)
    Verify return code: 0 (ok)
---
Q
DONE

demoAdmin@deomPC ~
$



Notice openssl s_client -connect host:port -showcerts -verify depthNum and openssl verify -CAfile ca.crt certfile.crt do the same thing but with subtle differences. Let's say you put bankofamerica's cert (text between first -----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----) into
bac.crt, put Symantec's cert (text between second-----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----) into ca.crt, and put the Verisign's cert (text between third-----BEGIN CERTIFICATE----- and -----END CERTIFICATE-----) into root.crt.

The verification commands with openssl verify output will looks like the following. openssl verify -CAfile ca.crt bac.crt fails because openssl verify consider the Symantec as a root CA, and expect the root CA to be self-signed. In another words you can only have one true root CA cert, which is the self-signed Verisign cert, all the intermediate certificates should be marked as untrusted in order to have the verify to pass.

demoAdmin@deomPC ~
$ ls
bac.crt  bk  ca.crt  root.crt

demoAdmin@deomPC ~
$ openssl verify -CAfile root.crt ca.crt
ca.crt: OK

demoAdmin@deomPC ~
$ openssl verify -CAfile ca.crt bac.crt
bac.crt: C = US, O = Symantec Corporation, OU = Symantec Trust Network, CN = Symantec Class 3 EV SSL CA - G3
error 2 at 1 depth lookup:unable to get issuer certificate

demoAdmin@deomPC ~
$ openssl verify -CAfile root.crt -untrusted ca.crt bac.crt
bac.crt: OK



Modern browsers did the above job for you under the hood. Chrome for example, keeps a list of trusted root CA certs, Verisign is one of them.

Under Settings -> Advanced -> Manage Certificates -> Trusted Root Certification Authorities
Double click entry "VeriSign Class 3 Public Primary Certification Authority - G5"
root CA
root CA

When you type address www.bankofamerica.com in the browser's address bar, browser automatically add https:// in front of it, which indicates that the browser is connecting to the server's port 443 instead of port 80, and start ssl hand-shake. During hand-shake, the server will present the certificate together with the issuers' certificate. Your browser verify them from host's cert all way down to the intermediate CAs' cert then to the root CA's cert. Since root CA's cert matches the one stored in brower's "Trusted Root Certification Authorities" list, the website https://www.bankofamerica.com/ is marked as trusted, otherwise a warning will be given by the browser.

A rogue host can advertise itself as  www.bankofamerica.com by poison the DNS server systems (very hard but not impossible) and impose itself as bank of america's website with all the certs. However, as long as bank of america didn't lost the private key, the imposer won't be able to gain any advantage from the user. Even though the client's browser trusted the certs presented by the rogue host, and start to send traffic encrypted with bank of america's certs, the rogue host won't be able to make sense of these gibberish without bank of america's private key.  


The certificate verification is not end there yet, the host's certificate could have been revoked yesterday and openssl's -verify flag wont consider that.


No comments:

Post a Comment