Skip to content

Unified output #410

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 65 commits into from
Feb 29, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
65 commits
Select commit Hold shift + click to select a range
c50dcfa
file test added for gnutls
SinghHrmn Jan 28, 2020
fbd59da
comment out bluez test
SinghHrmn Jan 28, 2020
3e15d7b
formatted test_scanner with black
SinghHrmn Jan 28, 2020
26b5f5d
gnutls file test 2.3.11
SinghHrmn Jan 28, 2020
8fcb64d
Merge pull request #1 from intel/master
SinghHrmn Jan 29, 2020
8bcd84e
checkers printing twice #317 solved
SinghHrmn Jan 30, 2020
1478120
updated clipy
SinghHrmn Feb 1, 2020
bf5a596
Merge branch 'master' of git://github.com/intel/cve-bin-tool
SinghHrmn Feb 1, 2020
ec95f46
updated cli.py
SinghHrmn Feb 1, 2020
fdc4db5
formatted cli.py BLACK
SinghHrmn Feb 1, 2020
4b6a401
updated cli.py
SinghHrmn Feb 4, 2020
e4cbf57
cli.py updated
SinghHrmn Feb 4, 2020
e535cb9
added modifications for empty versions
SinghHrmn Feb 4, 2020
79e8cc4
black formatted cli kerberos
SinghHrmn Feb 4, 2020
dfa7b3d
regex_find now return UNKNOWN
SinghHrmn Feb 6, 2020
a2ff873
Updated cli.py -- added waring for UNKNOWN
SinghHrmn Feb 7, 2020
ff06a3b
removed bluez.py from PR
SinghHrmn Feb 8, 2020
07fda55
removed gnutls from PR
SinghHrmn Feb 8, 2020
31b67bc
black formatted bluez
SinghHrmn Feb 8, 2020
0a84fbc
updated cli.py,warning and error in if, elif,else
SinghHrmn Feb 8, 2020
32b24e6
kerberos, libjpeg returns Unknown on Failure
SinghHrmn Feb 11, 2020
7f99728
Merge branch 'master' of git://github.com/intel/cve-bin-tool
SinghHrmn Feb 11, 2020
5f40676
Also updated icu.py
SinghHrmn Feb 11, 2020
66f7600
Merged upstream
SinghHrmn Feb 21, 2020
30a3b10
Add test for skips arg (#327)
PrajwalM2212 Feb 3, 2020
9708cdc
Fix final_log to check only the skip line, switch to scanning only a …
terriko Feb 3, 2020
14127fd
Make test more robust to output changes
terriko Feb 3, 2020
4028f27
Make build status badge link to /actions page (#333)
terriko Feb 5, 2020
090696d
Mention csv2cve earlier in the readme (#335)
terriko Feb 6, 2020
442432e
Improve csv2cve tests
terriko Feb 6, 2020
284da61
Support runs option (#338)
PrajwalM2212 Feb 7, 2020
c551640
README: Point workflow status at master branch
pdxjohnny Feb 8, 2020
4a9d726
Output filename when warning about version UNKNOWN (#348)
SaurabhK122 Feb 12, 2020
50fd4ab
Reverse arguments for filename in UNKNOWN version warning (#347)
param211 Feb 13, 2020
38d1a81
Add version option (#350)
PrajwalM2212 Feb 14, 2020
dead591
Add additional version-finding advice for writing checkers (#355)
terriko Feb 14, 2020
42e2ef9
Added Python checker (#353)
SinghHrmn Feb 18, 2020
daafcdf
Add Berkeleydb checker
terriko Feb 19, 2020
8406c1e
Test for version unknown warning message
terriko Feb 19, 2020
0824540
Added unittest for package: sqlite3 and version: 3.30.1 (#356)
Niraj-Kamdar Feb 19, 2020
cb53531
Added test for openssl-1.1.1d (#358)
param211 Feb 19, 2020
ebfbb42
Enable test_sample_csv (fixes #249) (#359)
terriko Feb 19, 2020
ebb21f9
Add python 3.8.2 rpm test
terriko Feb 19, 2020
561b69b
Improve help text
terriko Feb 20, 2020
d236711
Make quiet mode actually quiet
terriko Feb 20, 2020
00fd049
Test on windows in github actions (#365)
terriko Feb 20, 2020
a74986f
Remove separate run of helper file test_definitions.py (#371)
terriko Feb 21, 2020
f7dd510
test: Rename test_definitions to utils (#373)
Feb 21, 2020
8e6b042
cli.py updated
SinghHrmn Feb 4, 2020
3f98ff5
kerberos, libjpeg returns Unknown on Failure
SinghHrmn Feb 11, 2020
e5c65bf
Test for update flag (#328)
PrajwalM2212 Feb 6, 2020
95d6dec
Test some overly long version strings
terriko Feb 6, 2020
9765481
Mark the json schema test as a long test (because it really is) (#341)
terriko Feb 10, 2020
6adf998
Fix deprecation warning in test_csv2cve (#343)
shreyamalviya Feb 11, 2020
8c0ca28
Systemd checker improvements
terriko Feb 12, 2020
0509abb
Merge branch 'master' of https://github.com/SinghHrmn/cve-bin-tool
SinghHrmn Feb 21, 2020
905362f
unified string formatting
SinghHrmn Feb 21, 2020
e0b8b73
Merge branch 'master' of https://github.com/intel/cve-bin-tool
SinghHrmn Feb 22, 2020
87590be
updated python checker
SinghHrmn Feb 22, 2020
75c8a7d
updated python checker
SinghHrmn Feb 25, 2020
f93693a
Revert "updated python checker"
SinghHrmn Feb 26, 2020
29ce47b
Unified OutputTypes
SinghHrmn Feb 26, 2020
6f32f92
Merge branch 'master' of https://github.com/intel/cve-bin-tool
SinghHrmn Feb 26, 2020
f1d3f24
Updated cli and OutputEngine
SinghHrmn Feb 28, 2020
c87347f
Output Folder removed
SinghHrmn Feb 28, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions cve_bin_tool/OutputEngine.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import csv
import os

from datetime import datetime
from .log import LOGGER


class OutputEngine(object):
def __init__(self, filename=None, modules=None, logger=None):
if logger is None:
logger = LOGGER.getChild(self.__class__.__name__)
self.filename = filename
self.modules = modules
self.logger = logger

def generate_filename(self, extention=None):
""" Generates a random filename"""
if not extention == None:
now = datetime.now().strftime("%Y-%m-%d.%H:%m:%S")
self.filename = f"output.cve-bin-tool.{now}.{extention}"

def output_cves(self, outfile, output=None):

""" Output a list of CVEs
format is modules[checker_name][version] = dict{id: severity}
"""
# if the output is csv we must open a file
if output == "csv":
outfile = open(f"{outfile}", "w")

writer = csv.writer(outfile)
writer.writerow(["Module Name", "Version", "CVE Number", "Severity"])

writer = csv.writer(outfile)
for modulename, versions in self.modules.items():
for version, cve_list in versions.items():
for cve_number, cve_severity in cve_list.items():
row = [modulename, version, cve_number, cve_severity]
writer.writerow(row)

# We must also close the file
if output == "csv":
outfile.close()

def output_csv(self):

""" Generate a CSV file for list of CVE """

# Check if we need to generate a filename
if self.filename == None:
self.generate_filename("csv")
else:
self.filename = f"{self.filename}.csv"
# check if the filename already exists
file_list = os.listdir(os.getcwd())
if self.filename in file_list:
self.logger.warning(
f"Failed to write at '{self.filename}'. File already exists"
)
self.logger.info(
"Generating a new filename with Default Naming Convention"
)
self.generate_filename("csv")

# try opening that file
try:
with open(self.filename, "w") as f:
f.write("testing")
os.remove(self.filename)
except Exception as E:
self.logger.warning(E)
self.logger.info("Switching Back to Default Naming Convention")
self.generate_filename("csv")

# Log the filename generated
self.logger.info(f"CSV output stored at {os.getcwd()}/{self.filename}")

# call to output_cves
self.output_cves(self.filename, "csv")
43 changes: 29 additions & 14 deletions cve_bin_tool/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from .extractor import Extractor
from .strings import Strings
from .file import is_binary
from .OutputEngine import OutputEngine

from .cvedb import CVEDB
from .log import LOGGER
Expand Down Expand Up @@ -291,18 +292,6 @@ def scan_files_unpack(unpacked):
return scan_files(*unpacked)


def output_cves(outfile, modules):
""" Output a list of CVEs
format is modules[checker_name][version] = dict{id: severity}
"""
writer = csv.writer(outfile)
for modulename, versions in modules.items():
for version, cve_list in versions.items():
for cve_number, cve_severity in cve_list.items():
row = [modulename, version, cve_number, cve_severity]
writer.writerow(row)


def main(argv=None, outfile=sys.stdout):
""" Scan a binary file for certain open source libraries that may have CVEs """
if argv is None:
Expand Down Expand Up @@ -338,6 +327,21 @@ def main(argv=None, outfile=sys.stdout):
action=LogAction,
choices=["debug", "info", "warning", "error", "critical"],
)
output_group.add_argument(
"-o",
"--output",
action="store",
choices=["csv", "json", "console"],
default="console",
help="update output format (default: console)",
)
output_group.add_argument(
"-f",
"--filename",
action="store",
default=None,
help="provide output file name",
)
parser.add_argument(
"-v", "--version", action="version", version=f"{get_version_string()}",
)
Expand Down Expand Up @@ -478,8 +482,19 @@ def main(argv=None, outfile=sys.stdout):
)
)
LOGGER.info(f"Known CVEs in {affected_string}:")
if LOGGER.getEffectiveLevel() != logging.CRITICAL:
output_cves(outfile, scanner.all_cves)

# Creates a Object for OutputEngine
output = OutputEngine(modules=scanner.all_cves, filename=args.filename)

if (
LOGGER.getEffectiveLevel() != logging.CRITICAL
and args.output == "console"
):
output.output_cves(outfile)

# If the args are passed for csv we will generate a CSV output
if args.output == "csv":
output.output_csv()

# Use the number of files with known cves as error code
# as requested by folk planning to automate use of this script.
Expand Down