Easy Tutorial
❮ C Get Keycode Verilog2 Udp Logic ❯

OpenSSL Vulnerability Scanner (Python)

Category Programming Technology

Linux servers use the OpenSSL protocol, but some older versions of OpenSSL have vulnerabilities, such as the famous "Bar Mitzvah" or "Freak" vulnerabilities. Here, a GUI mini-program under Windows is written using the Python paramiko library to batch-check if Linux servers have these two vulnerabilities.

Scanner2.py File Code (Python2.x):

# -*- coding:UTF-8 -*-

'''
OpenSSL Bar Mitzvah and Freak Vulnerability Detection Script

DesignBy: XB
2016.07
'''

import paramiko
import os
from Tkinter import *

server = []
sjl_sign = "Server certificate\n"
freak_sign = "Server certificate\n"

ip = raw_input("Please Input Plart IP:")
username = raw_input("Username:")
pwd = raw_input("Password:")

def ReadServerlist():
    print "The Plart:%s(Confirm Platform Always Online)" % ip
    if os.path.exists("serverlist.txt"):
        print "Find The Existing Serverlist."
    else:
        print "Didn't Find The Existing Serverlist, We Will Create It."
        create = open("serverlist.txt", 'w')
        create.close()
ReadServerlist()

def scan():
    read = file("serverlist.txt", "r")
    for line in read.readlines():
        server.append(line)
    for i in server:
        i = i.strip("\n")  # Remove line break at the end of the line
        cmd_sjl = "openssl s_client -connect" + " " + i + ":443 -cipher RC4"
        cmd_freak = "openssl s_client -connect" + " " + i + ":443 -cipher EXPORT"
        print "\nScanning %s..." % i
        scanbody(ip, username, pwd, cmd_sjl, cmd_freak)

    print "\nAll Done"
    print "@Colasoft2016"

def scanbody(ip, username, pwd, cmd_sjl, cmd_freak):
    try:

        ssh = paramiko.SSHClient()
        ssh.set_missing_host_key_policy(paramiko.AutoAddPolicy())

        ssh.connect(ip, 22, username, pwd)

        stdin, stdout, stderr = ssh.exec_command(cmd_sjl)
        sjl = stdout.readlines()
        stdin, stdout, stderr = ssh.exec_command(cmd_freak)
        freak = stdout.readlines()
        ssh.close()

        list_sjl = []
        list_freak = []

        for k in sjl:
            list_sjl.append(k)

        for j in freak:
            list_freak.append(j)

        if sjl_sign in list_sjl:
            if freak_sign in list_freak:
                print "Danger: Server has OpenSSL Bar Mitzvah and Freak vulnerabilities"
            else:
                print "Danger: Server has OpenSSL Bar Mitzvah vulnerability"
        else:
            if freak_sign in list_freak:
                print "Danger: Server has OpenSSL Freak vulnerability"
            else:
                print "Congratulations: Server does not have OpenSSL Bar Mitzvah and Freak vulnerabilities"

    except paramiko.AuthenticationException, e:
        print 'Error'
        print 'Error Detail', e

# GUI Program
root = Tk()
root.title("OpenSSL Bar Mitzvah and Freak Vulnerability Detection Program")
root.geometry('380x380')  # Set window size, middle is x
root.resizable(width=False, height=False)  # Set whether the window can change width and height, here width and height are not changeable;

notice1 = Label(root, text="Please input the server IP that needs to be scanned (one IP per line)", fg='red')
notice1.pack(side=TOP)
# Scrollbar
scrollbar = Scrollbar(root)
scrollbar.pack(side=RIGHT, fill=Y)
scrollbar.set(1, 5)

# Get file content
content = file("serverlist.txt", "r")
readtext = content.read()
content.close()

# Write to file
server_list = Text(root, width=35, height=22, yscrollcommand=scrollbar.set)
server_list.place(x=5, y=80)
server_list.insert(END, readtext)
scrollbar.config(command=server_list.yview)

# Save function
def save():
    save = server_list.get('0.0', END).strip()
    print "Save:"
    print save
    file_object = open("serverlist.txt", "w")
    file_object.writelines(save)
    file_object.close()
# Save and scan buttons
save_button = Button(root, text="Save", width=9, height=2, command=save).place(x=260, y=80)
scan_button = Button(root, text="Scan", width=9, height=2, command=scan).place(x=260, y=150)

root.mainloop()

Contributor: Song Xiaobing

Nickname: Xiaobing

Email: [email protected]

❮ C Get Keycode Verilog2 Udp Logic ❯