Created
July 28, 2010 15:48
-
-
Save jzellman/494966 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
# save as vuln2csv and run | |
# ./vuln2csv < infile.txt > outfile.csv | |
require 'rubygems' | |
require 'fastercsv' | |
class CVERow | |
def initialize(line) | |
# not assuming " is text delimiter | |
ip_address, host_port, description = line.split("|", 3) | |
@ip_address = clean_quote(ip_address) | |
@host_port = clean_quote(host_port) | |
@vulnerabilities = extract_vulnerabilities(description) | |
end | |
def to_csv | |
@vulnerabilities.map do |v| | |
[@ip_address, @host_port, v].to_csv | |
end | |
end | |
def extract_vulnerabilities(str) | |
str.scan(/CVE-\d{4}-\d{4}/).sort | |
end | |
def clean_quote(str) | |
str.gsub('"', '') | |
end | |
end | |
STDIN.read.each do |line| | |
STDOUT.write(CVERow.new(line).to_csv) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment