Sslscan is a tool used to enumerate the ciphers supported by HTTPS sites. Knowing the ciphers that are supported by a site is useful in web application testing. This is even more useful in a penetration test if some of the supported ciphers are weak.
This recipe will run Sslscan on a specified IP address and output the results into a CSV format:
import subprocess
import sys
ipfile = sys.argv[1]
IPs = open(ipfile, “r”)
output = open(“sslscan.csv”, “w+”)
for IP in IPs:
try:
command = “sslscan “+IP
ciphers = subprocess.check_output(command.split())
for line in ciphers.splitlines():
if “Accepted” in line:
output.write(IP+”,”+line.split()[1]+”,”+ line.split()[4]+”,”+line.split()[2]+”\r”)
except:
passWe first import the necessary modules and assign the filename supplied in the argument to a variable:
import subprocess import sys ipfile = sys.argv[1]
The filename supplied should point to a file containing a list of IP addresses. We open this file as read-only:
IPs = open(ipfile, “r”)
We then open up a file for reading and writing output by using w+ instead of r:
output = open(“sslscan.csv”, “w+”)
Now that we have our input and somewhere to write our output, we’re ready to rock and roll. We start by iterating through the IP addresses:
for IP in IPs:
For each IP, we run Sslscan:
try:
command = “sslscan “+IPWe then split up the output from the command into chunks:
ciphers = subprocess.check_output(command.split())
We then go through the output, line by line. If the line contains the word Accepted, then we arrange the elements of the line for CSV output:
for line in ciphers.splitlines():
if “Accepted” in line:
output.write(IP+”,”+line.split()[1]+”,”+ line.split()[4]+”,”+line.split()[2]+”\r”)Finally, if for any reason the attempt to run the SSL scan on the IP fails, we simply move on to the next IP address:
except: pass