Skip to content

Commit 22fd0f0

Browse files
committed
follow-cvelist.py optional ansi colors
1 parent 4e4db31 commit 22fd0f0

File tree

2 files changed

+71
-6
lines changed

2 files changed

+71
-6
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Miscellaneous scripts for different purposes. Mostly unrelated to each other.
1212
| Email | [`mail-prepender.sh`](bin/mail-prepender.sh)<br>Shell (bash) | Prepends (to stdin/stdout) email header strings given in as flags `i`, `I`, `a`, or `A`; after possible mbox `From` & `Return-Path` header lines. Intended as a limited `formail` replacement that ignores the nyanses of the flags and simply prepends the valid (RFC 5322, 2.2) non-empty headers keeping the other headers as is. Flags `x` & `X` are implemented. Any other flags are ignored. |
1313
| Git | [`git-find-commits-by-file-hash.sh`](bin/git-find-commits-by-file-hash.sh)<br>Shell (bash) | Search Git repository history for commits with SHA-256 checksum of a file. Answers the question "Has this version of this file ever been committed as the file on this path of this Git repository?" and shows a summary (`git show --stat`) of the matching commit(s). The `path` should be relative to the repository root.<br>`git-find-commits-by-file-hash.sh sha256sum path`|
1414
| Infosec | [`netcat-proxy.sh`](bin/netcat-proxy.sh)<br>Shell (sh) | Creates a simple persistent TCP proxy with netcat & named pipes.<br>`netcat-proxy.sh listenport targethost targetport` |
15-
| Infosec | [`follow-cvelist.py`](bin/follow-cvelist.py)<br>Python 3 | Follow changes (commits) in CVEProject / [cvelistV5](https://github.com/CVEProject/cvelistV5). Requires git. Working directory must be the root of the cvelistV5 repository.<br>`follow-cvelist.py [-h] [--interval s] [--commits N]`|
15+
| Infosec | [`follow-cvelist.py`](bin/follow-cvelist.py)<br>Python 3 | Follow changes (commits) in CVEProject / [cvelistV5](https://github.com/CVEProject/cvelistV5). Requires git. Working directory must be the root of the cvelistV5 repository.<br>`follow-cvelist.py [-h] [-i s] [-c N] [-a]`|
1616
| Infosec | [`partialpassword.sh`](bin/partialpassword.sh)<br>Shell (bash) | Creates a new wordlist from a wordlist by replacing all ambiguous characters with all their possible combinations.<br>`partialpassword.sh input.txt output.txt O0 [Il1 ...]` |
1717
| Infosec | [`duplicate-ssh-hostkeys.sh`](bin/duplicate-ssh-hostkeys.sh)<br>Shell (bash) | Find duplicate SSH host keys in a CIDR range. Examine your network for shared host keys that could potentially be dangerous.<br>`duplicate-ssh-hostkeys.sh CIDR [HostKeyAlgorithm ...]` |
1818
| Infosec<br>Automation | [`make-mac-prefixes.py`](bin/make-mac-prefixes.py)<br>Python 3 | Processes registered MAC address prefixes from [IEEE MA-L Assignments (CSV)](https://standards.ieee.org/products-programs/regauth/) (stdin) to Nmap's [`nmap-mac-prefixes`](https://github.com/nmap/nmap/blob/master/nmap-mac-prefixes) (stdout) with a few additional unregistered OUIs.<br>`curl https://standards-oui.ieee.org/oui/oui.csv \| make-mac-prefixes.py > nmap-mac-prefixes` |

bin/follow-cvelist.py

Lines changed: 70 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,12 @@
33
# ------------------------------------------------------------------------------
44
# Follow changes (commits) in CVEProject / cvelistV5
55
#
6-
# Usage: follow-cvelist.py [-h] [-i s] [-c N]
6+
# Usage: follow-cvelist.py [-h] [-i s] [-c N] [-a]
77
#
88
# -h, --help show this help message and exit
99
# -i s, --interval s pull interval in seconds
1010
# -c N, --commits N amount of commits to include in the initial print
11+
# -a, --ansi add ansi colors to the output (default: False)
1112
#
1213
# Requires git. Working directory must be the root of the cvelistV5 repository.
1314
#
@@ -50,7 +51,7 @@ def main(args):
5051
)
5152
print(f"{''.ljust(os.get_terminal_size()[0], '-')}", file=sys.stderr)
5253

53-
monitor(get_cursor(args.commits), args.interval)
54+
monitor(args)
5455

5556

5657
def interrupt_handler(signum, frame):
@@ -69,18 +70,23 @@ def check_interrupt():
6970
sys.exit(0)
7071

7172

72-
def monitor(cursor: str, interval: int):
73+
def monitor(agrs):
7374
"""Monitors cvelistV5 commits and prints changed CVEs"""
75+
cursor = get_cursor(args.commits)
76+
7477
while True:
7578
pull()
7679
new_cursor = get_cursor()
7780

7881
if new_cursor != cursor:
79-
print_changes(new_cursor, cursor)
82+
if args.ansi:
83+
print_changes_color(new_cursor, cursor)
84+
else:
85+
print_changes(new_cursor, cursor)
8086

8187
cursor = new_cursor
8288

83-
for x in range(interval):
89+
for x in range(args.interval):
8490
check_interrupt()
8591
time.sleep(1)
8692

@@ -103,6 +109,58 @@ def get_cursor(offset: int = 0) -> str:
103109
def print_changes(current_commit: str, past_commit: str):
104110
"""Print summary of changed CVE"""
105111
lines = []
112+
width = os.get_terminal_size()[0]
113+
114+
for file in changed_files(current_commit, past_commit):
115+
type = re.split(r"\t+", file.decode("utf-8").strip())[0]
116+
path = re.split(r"\t+", file.decode("utf-8").strip())[1]
117+
118+
# Skip delta files
119+
if "delta" in path:
120+
continue
121+
122+
if type == "D":
123+
print(f"Deleted: {Path(path).stem}", file=sys.stderr)
124+
else:
125+
current = json_at_commit(path, current_commit)
126+
modified = current["cveMetadata"]["dateUpdated"]
127+
modified = re.sub(r"\..*", "", modified)
128+
modified = re.sub(r"T", " ", modified)
129+
cve = current["cveMetadata"]["cveId"]
130+
131+
if type == "M":
132+
past = json_at_commit(path, past_commit)
133+
past_cvss = cvss31score(past)
134+
else:
135+
past_cvss = " "
136+
137+
current_cvss = cvss31score(current)
138+
139+
if current_cvss == 0.0:
140+
current_cvss = " "
141+
if past_cvss == 0.0:
142+
past_cvss = " "
143+
144+
if current_cvss != past_cvss:
145+
cvss = f"{past_cvss}{current_cvss}"
146+
else:
147+
cvss = f"{current_cvss}"
148+
149+
summary = re.sub(r"\n", " ", generate_summary(current))
150+
151+
lines.append(
152+
f"{modified.ljust(20)} {cve.ljust(15)} {cvss.ljust(10)} {summary}"
153+
)
154+
155+
lines.sort()
156+
157+
for line in lines:
158+
print(line[:width])
159+
160+
161+
def print_changes_color(current_commit: str, past_commit: str):
162+
"""Print summary of changed CVE with ANSI colors"""
163+
lines = []
106164

107165
# adjust screen width to the ansi colors in CVSS
108166
width = os.get_terminal_size()[0] + 21
@@ -330,5 +388,12 @@ def check_positive(value: int):
330388
help="amount of commits to include in the initial print",
331389
default=30,
332390
)
391+
argParser.add_argument(
392+
"-a",
393+
"--ansi",
394+
action="store_true",
395+
help="add ansi colors to the output",
396+
default=False,
397+
)
333398
args = argParser.parse_args()
334399
main(args)

0 commit comments

Comments
 (0)