Skip to content

Instantly share code, notes, and snippets.

@jzellman
Created July 28, 2010 15:48
Show Gist options
  • Save jzellman/494966 to your computer and use it in GitHub Desktop.
Save jzellman/494966 to your computer and use it in GitHub Desktop.
#!/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