Skip to content

Commit

Permalink
Add cvehound_update_rules script
Browse files Browse the repository at this point in the history
Signed-off-by: Denis Efremov <[email protected]>
  • Loading branch information
evdenis committed Sep 30, 2021
1 parent b5cee64 commit 2403302
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
38 changes: 38 additions & 0 deletions cvehound/scripts/update_rules.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env python3

import os
import sys
import pkg_resources
from urllib.request import urlopen
from io import BytesIO
from zipfile import ZipFile

def main(args=sys.argv):
rule_dir = pkg_resources.resource_filename('cvehound', 'cve')

for rule in os.listdir(rule_dir):
rule_path = os.path.join(rule_dir, rule)
try:
os.unlink(rule_path)
pass
except Exception as e:
print('Failed to delete {}: {}'.format(rule_path, e))

with urlopen('https://github.com/evdenis/cvehound/archive/refs/heads/master.zip') as uh:
rules = []
with ZipFile(BytesIO(uh.read())) as zh:
rules = filter(lambda x: x.startswith('cvehound-master/cvehound/cve'), zh.namelist())
rules = list(rules)
zh.extractall(path=rule_dir, members=rules)
prefix_len = len('cvehound-master/cvehound/cve') + 1
os.chdir(rule_dir)
for rule in rules:
if not os.path.isfile(rule):
continue
os.rename(rule, rule[prefix_len:])
os.rmdir('cvehound-master/cvehound/cve')
os.rmdir('cvehound-master/cvehound')
os.rmdir('cvehound-master')

if __name__ == '__main__':
main(sys.argv)
3 changes: 2 additions & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ def find_version(source):
entry_points={
'console_scripts': [
'cvehound=cvehound.__main__:main',
'cvehound_update_metadata=cvehound.scripts.update_metadata:main'
'cvehound_update_metadata=cvehound.scripts.update_metadata:main',
'cvehound_update_rules=cvehound.scripts.update_rules:main'
]
},
include_package_data=True
Expand Down

0 comments on commit 2403302

Please sign in to comment.