-
Notifications
You must be signed in to change notification settings - Fork 1
/
mapover.sh
199 lines (180 loc) · 5.57 KB
/
mapover.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
#!/bin/bash
# Not the best bash of the world ... but it works ;)
get_lib_from_maps () {
echo "[+] Retreive libs from maps files"
for map in `cat $MAP_FILE`
do
#echo "----> $map <----"
name=$(echo "$map" | base64 -w 0 | tr -d "=")
curl "$map" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko" 2>/dev/null > ${ROOT_DIR}/maps/$name.map
# Get modules like @aaaa/bbbb
cat ${ROOT_DIR}/maps/$name.map | jq ".sources[]" -r | grep -Po 'node_modules\/\K(@[a-zA-Z0-9\-]+\/[a-zA-Z0-9\-]+)' | sort | uniq > "${ROOT_DIR}/maps/$name.dep"
# Get modules like aaaa
cat ${ROOT_DIR}/maps/$name.map | jq ".sources[]" -r | grep -Po 'node_modules\/\K([a-zA-Z0-9\-]+)' | sort | uniq >> "${ROOT_DIR}/maps/$name.dep"
done
cat ${ROOT_DIR}/maps/*.dep | sort | uniq > ${ROOT_DIR}/all_root_deps.txt
# Little hack to link with next function in case of recurse=0
cp ${ROOT_DIR}/all_root_deps.txt ${ROOT_DIR}/dep-of-dep-list.txt
}
get_deps_of_deps () {
i=$1
srcfile=$2
if [ $i -eq 0 ]
then
cat ${ROOT_DIR}/dep-of-dep-list* | sort | uniq > "${ROOT_DIR}/all_deps.txt"
return
else
i=$((i-1))
echo " --> Get dependencies of dependencies ${i}..."
echo "" > "${ROOT_DIR}/dep-of-dep-list-${i}.txt"
echo "" > "${ROOT_DIR}/dep-of-dep-${i}-with-parent.txt"
for dep in `cat ${ROOT_DIR}/${srcfile}`
do
ver=$(curl "https://registry.npmjs.org/$dep" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko" 2>/dev/null | jq '."dist-tags".latest')
curl "https://registry.npmjs.org/$dep" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko" 2>/dev/null | jq -r ".versions.$ver.dependencies | keys[] // empty" 2>/dev/null | while read d;
do
echo "$dep:$d" >> "${ROOT_DIR}/dep-of-dep-${i}-with-parent.txt"
echo "$d" >> "${ROOT_DIR}/dep-of-dep-list-${i}.txt"
done
sleep 1
done
sort --unique ${ROOT_DIR}/dep-of-dep-list-${i}.txt -o ${ROOT_DIR}/dep-of-dep-list-${i}.txt
sort --unique ${ROOT_DIR}/dep-of-dep-${i}-with-parent.txt -o ${ROOT_DIR}/dep-of-dep-${i}-with-parent.txt
get_deps_of_deps $i dep-of-dep-list-${i}.txt
fi
}
get_email_from_libs () {
echo "[+] Retreive all lib emails"
echo "" > ${ROOT_DIR}/dep-email.txt
for dep in `cat ${ROOT_DIR}/all_deps.txt`
do
curl "https://registry.npmjs.org/$dep" -H "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; Trident/7.0; AS; rv:11.0) like Gecko" 2>/dev/null | jq -r '.versions[].maintainers[].email' | while read i;
do
echo "$dep:$i"
done >> ${ROOT_DIR}/dep-email.txt
sleep 1
done
sort --unique ${ROOT_DIR}/dep-email.txt -o ${ROOT_DIR}/dep-email.txt
}
get_domain_from_emails () {
echo "[+] Get domains from emails"
cat ${ROOT_DIR}/dep-email.txt | cut -d ":" -f2 | cut -d '@' -f2 | sort | uniq > ${ROOT_DIR}/domain_list.txt
}
get_domain_without_a () {
echo "[+] Get domains without A record"
domains=$(cat ${ROOT_DIR}/domain_list.txt)
for domain in $domains
do
nbip=$(dig in A $domain +short | wc -l)
if [ $nbip -eq 0 ]
then
echo "$domain"
fi
done > ${ROOT_DIR}/domain_no_A.txt
}
get_domain_without_ns () {
echo "[+] Get domains without NS record"
domains=$(cat ${ROOT_DIR}/domain_list.txt)
for domain in $domains
do
nbip=$(dig in NS $domain +short | wc -l)
if [ $nbip -eq 0 ]
then
echo "$domain"
fi
done > ${ROOT_DIR}/domain_no_NS.txt
}
check_gmails_accounts () {
echo -n "[+] Check GHunt configuration --> "
$GHUNT_PYTHON $GHUNT_MAIN email "[email protected]" 2>&1 | grep "Creds aren't loaded. Are you logged in" >/dev/null
if [ $? -eq 0 ]
then
echo "FAIL"
echo "[-] GHunt is not configured, try by yoursef << $GHUNT_PYTHON $GHUNT_MAIN email \"[email protected]\" >>"
exit 0
else
echo "OK"
fi
echo "[+] Check gmail accounts"
gmails=$(cat ${ROOT_DIR}/dep-email.txt | cut -d ":" -f2 | grep 'gmail.com' | sort | uniq | tr -d "\"" )
for gmail in $gmails
do
$GHUNT_PYTHON $GHUNT_MAIN email $gmail >/dev/null
if [ $? -eq 1 ]
then
echo $gmail
fi
done > ${ROOT_DIR}/non_existing_gmails.txt
}
##############
#### MAIN ####
##############
recursive=1
while getopts o:m:g:p:r:h flag
do
case "${flag}" in
o) output=${OPTARG};;
m) mapsfile=${OPTARG};;
g) ghunt=${OPTARG};;
p) pythonghunt=${OPTARG};;
r) recursive=${OPTARG};;
h)
echo "Usage of $0"
echo " -o output_dir : will be created if not exists"
echo " -m maps_file : A file that contains all the map files to download"
echo " -r <0-oo> : to retreive N level en dependencies"
echo " -g ghunt-path : path to the GHunt main.py file"
echo " -p python-ghunt-folder : python path for ghunt if you are using a venv for exemple"
echo ""
echo "Example: $0 -o out -m maps.txt [-r 3] [[-g venv/bin/python] -g GHUNT/main.py]"
exit 0
;;
esac
done
ROOT_DIR=$output
MAP_FILE=$mapsfile
USE_GHUNT=0
GHUNT_PYTHON=$pythonghunt
GHUNT_MAIN=$ghunt
if [ ${#ROOT_DIR} -eq 0 ]
then
echo "output folder is mandatory"
exit 1
fi
if [ ${#MAP_FILE} -eq 0 ]
then
echo "maps file is mandatory"
exit 1
fi
if [ -n "${recursive//[0-9]}" ]
then
echo "[-] -r should be a number"
exit 0
fi
if [ $recursive -lt 0 ]
then
echo "[-] Recursive should be greater or equal than 0"
exit 0
fi
if [ ${#GHUNT_MAIN} -ne 0 ]
then
USE_GHUNT=1
if [ ${#GHUNT_PYTHON} -eq 0 ]
then
# use default python
GHUNT_PYTHON="python3"
fi
fi
mkdir -p "${ROOT_DIR}/maps"
get_lib_from_maps
echo "[+] Retreive $recursive level of dependencies"
get_deps_of_deps $recursive "all_root_deps.txt"
get_email_from_libs
get_domain_from_emails
get_domain_without_ns
get_domain_without_a
if [ $USE_GHUNT -eq 1 ]
then
check_gmails_accounts
fi
echo "[+] Finished"