-
Notifications
You must be signed in to change notification settings - Fork 0
/
deepconfusion.sh
78 lines (65 loc) · 2.37 KB
/
deepconfusion.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#!/bin/bash
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[0;33m'
BLUE='\033[0;34m'
RESET='\033[0m'
if [ $# -eq 0 ]; then
echo -e "${RED}[!]${RESET} Usage: $0 <package.json or requirements.txt>"
exit 1
fi
file_extension="${1##*.}"
if [ "$file_extension" == "json" ]; then
if [ ! -f "$1" ]; then
echo -e "${RED}[!]${RESET} Error: File '$1' not found."
exit 1
fi
package_names=($(grep -oE '"[^"]+":' "$1" | sed 's/"//g' | sed 's/:$//'))
for package_name in "${package_names[@]}"; do
echo -e "Searching public npm package for ${GREEN}$package_name${RESET}..."
npm_search_response=$(npm search "$package_name" --json)
matching_package=$(echo "$npm_search_response" | jq -r '.[] | select(.name == "'"$package_name"'")')
if [ -z "$matching_package" ]; then
echo -e "${RED}[!]${RESET} $package_name ${RED}NOT${RESET} in public registry !"
echo -e "${BLUE}[*]${RESET} Checking if package has been deprecated"
if curl -s "https://www.npmjs.com/package/$package_name" | grep -q 'has been deprecated'; then
echo -e "${YELLOW}[-]${RESET} Here but ${YELLOW}deprecated${RESET}"
else
echo $package_name >> confusion.txt
fi
else
echo -e "${GREEN}[+]${RESET} $package_name in public registry."
fi
echo "---------------------------------------------------"
done
elif [ "$file_extension" == "txt" ]; then
if [ ! -f "$1" ]; then
echo -e "${RED}[!]${RESET} Error: File '$1' not found."
exit 1
fi
cat "$1" \
| awk '{print $1;}' \
| tr -d '><~#$' \
| sort -u \
| cut -d '=' -f 1 \
| awk '{print $1;}' \
| sed -r 's/[^[:space:]]*[0-9][^[:space:]]* ?//g' \
| sort -u \
| xargs -n1 -I{} echo "https://pypi.org/project/{}/" \
| httpx -status-code -silent
elif [ "$(basename $1)" == "Gemfile" ]; then
if [ ! -f "$1" ]; then
echo -e "${RED}[!]${RESET} Error: File '$1' not found."
exit 1
fi
cat "$1" \
| awk '{print $1S;}' \
| tr -d '"' \
| tr -d ",'" \
| sort -u \
| xargs -n1 -I{} echo "https://rubygems.org/gems/{}" \
| httpx -status-code -silent
else
echo -e "${RED}[!]${RESET} Unsupported file extension. Only ${GREEN}JSON${RESET}, ${GREEN}TXT${RESET} and ${GREEN}Gemfile${RESET} files are supported."
exit 1
fi