From 792b0d78d4feae7c2e59f4990cf98d37c1df4451 Mon Sep 17 00:00:00 2001 From: Joey Riches Date: Thu, 29 Feb 2024 17:45:03 +0000 Subject: [PATCH] common/Scripts: Allow no args usage of cpesearch() **Summary** - When no args are passed to cpesearch() it'll use the current directory name. Useful in combination with gotopkg(). --- common/Scripts/helpers.sh | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/common/Scripts/helpers.sh b/common/Scripts/helpers.sh index f8b40149568..baa109ace8f 100755 --- a/common/Scripts/helpers.sh +++ b/common/Scripts/helpers.sh @@ -2,13 +2,20 @@ # Primitive CPE search tool function cpesearch() { - if [[ -z "$1" || "$1" == "--help" || "$1" == "-h" ]]; then - echo "usage: cpesearch " - else + function search() { curl -s -X POST https://cpe-guesser.cve-search.org/search -d "{\"query\": [\"$1\"]}" | jq . - + echo "Verify successful hits by visiting https://cve.circl.lu/search/\$VENDOR/\$PRODUCT" echo "- CPE entries for software applications have the form 'cpe:2.3:a:\$VENDOR:\$PRODUCT'" + } + + if [[ "$1" == "--help" || "$1" == "-h" ]]; then + echo "usage: cpesearch " + elif [[ $# -eq 0 ]]; then + echo "Warning: No paramaters passed, using current directory name. Pass --help to see usage" + search "$(basename "$(pwd)")" + else + search "$1" fi }