Skip to content

Commit

Permalink
follow-cvelist.py configurable terminal width
Browse files Browse the repository at this point in the history
Allow overwriting autodetected terminal width
  • Loading branch information
oh2fih committed Aug 11, 2024
1 parent 746c860 commit 8e793a1
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Miscellaneous scripts for different purposes. Mostly unrelated to each other.
| 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. |
| 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`|
| 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` |
| 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 [-haou4] [-vvvv] [-i s] [-c N]`|
| 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 [-haou4] [-vvvv] [-i s] [-c N] [-w c]`|
| 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 ...]` |
| 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 ...]` |
| 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` |
Expand Down
34 changes: 25 additions & 9 deletions bin/follow-cvelist.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# ------------------------------------------------------------------------------
# Follow changes (commits) in CVEProject / cvelistV5
#
# Usage: follow-cvelist.py [-haou4] [-vvvv] [-i s] [-c N]
# Usage: follow-cvelist.py [-haou4] [-vvvv] [-i s] [-c N] [-w c]
#
# -h, --help show this help message and exit
# -a, --ansi add ansi colors to the output (default: False)
Expand All @@ -13,6 +13,7 @@
# -v, --verbose each -v increases verbosity (commits, git pull, raw data)
# -i s, --interval s pull interval in seconds (default: 150)
# -c N, --commits N number of commits to print initially (default: 30)
# -w c, --width c overwrite autodetected terminal width (<50 => multiline)
#
# Requires git. Working directory must be the root of the cvelistV5 repository.
#
Expand Down Expand Up @@ -89,6 +90,16 @@ def check_interrupt(self) -> None:
)
sys.exit(0)

def width(self) -> int:
"""Configured or detected terminal width for line lenght limits"""
if args.width:
return int(args.width)
else:
try:
return os.get_terminal_size()[0]
except OSError:
return 1

def header(self) -> None:
"""Print header"""
if self.args.cvss4:
Expand All @@ -106,10 +117,7 @@ def header(self) -> None:
f"{cvss_title.ljust(10)} SUMMARY [vendor: product]",
file=sys.stderr,
)
try:
print(f"{''.ljust(os.get_terminal_size()[0], '-')}", file=sys.stderr)
except OSError:
print(f"{''.ljust(80, '-')}", file=sys.stderr)
print(f"{''.ljust(self.width(), '-')}", file=sys.stderr)

def history(self) -> None:
"""Prints CVE changes from the commit history, one commit at a time"""
Expand Down Expand Up @@ -174,14 +182,15 @@ def get_cursor(self, offset: int = 0) -> str:
def print_changes(self, current_commit: str, past_commit: str) -> None:
"""Print summary of changed CVE"""
lines = []
try:
# multiline mode if terminal width is too small to fit summary on the same line
if self.width() >= 50:
if self.args.ansi:
# add extra width for invisible characters (ANSI codes)
width = os.get_terminal_size()[0] + 21
width = self.width() + 21
else:
# substract one character to fit occasional wide characters like emojis
width = os.get_terminal_size()[0] - 1
except OSError:
width = self.width() - 1
else:
width = False

for change in self.get_changes(current_commit, past_commit):
Expand Down Expand Up @@ -584,6 +593,13 @@ def check_positive(value: str) -> int:
help="number of commits to print initially",
default=30,
)
argParser.add_argument(
"-w",
"--width",
type=check_positive,
metavar="c",
help="overwrite autodetected terminal width (<50 => multiline)",
)
args = argParser.parse_args()
if args.verbose > 4:
args.verbose = 4
Expand Down

0 comments on commit 8e793a1

Please sign in to comment.