-
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathknoxsser.sh
executable file
·425 lines (385 loc) · 16.5 KB
/
knoxsser.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
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
#!/usr/bin/env bash
# Color codes for output
CYAN='\033[0;36m'
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[0;33m'
BOLD='\033[1m'
NC='\033[0m' # No Color
# Script version and URLs
VERSION="v2.0"
REPO_URL="https://raw.githubusercontent.com/0xPugal/knoxsser/master/VERSION"
SCRIPT_URL="https://raw.githubusercontent.com/0xPugal/knoxsser/master/knoxsser.sh"
SCRIPT_PATH="/usr/bin/knoxsser"
# Function to print the banner
print_banner() {
echo ""
echo -e "${CYAN}██╗ ██╗███╗ ██╗ ██████╗ ██╗ ██╗███████╗███████╗███████╗██████╗ ${NC}"
echo -e "${CYAN}██║ ██╔╝████╗ ██║██╔═══██╗╚██╗██╔╝██╔════╝██╔════╝██╔════╝██╔══██╗ ${NC}"
echo -e "${CYAN}█████╔╝ ██╔██╗ ██║██║ ██║ ╚███╔╝ ███████╗███████╗█████╗ ██████╔╝ ${NC}"
echo -e "${CYAN}██╔═██╗ ██║╚██╗██║██║ ██║ ██╔██╗ ╚════██║╚════██║██╔══╝ ██╔══██╗ ${NC}"
echo -e "${CYAN}██║ ██╗██║ ╚████║╚██████╔╝██╔╝ ██╗███████║███████║███████╗██║ ██║ ${NC}"
echo -e "${CYAN}╚═╝ ╚═╝╚═╝ ╚═══╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚══════╝╚═╝ ╚═╝$VERSION ${NC}"
echo -e " Made with ${RED}${BOLD}<3${NC} by${BOLD} @0xPugal ${NC}"
echo ""
}
# Function to check for script updates
check_version() {
latest_version=$(curl -s "$REPO_URL")
if [[ "$VERSION" != "$latest_version" ]]; then
echo -e "${YELLOW}Your script is outdated. Latest version is ${latest_version}.${NC}"
read -p "${BOLD}Do you want to update to the latest version? (Y/N):${NC} " update_choice
if [[ "$update_choice" =~ ^[Yy]$ ]]; then
echo -e "${YELLOW}Updating KNOXSSer...${NC}"
# Remove existing knoxsser script if it exists
if command -v knoxsser &>/dev/null; then
echo -e "${YELLOW}Removing existing knoxsser script...${NC}"
sudo rm -f "$(which knoxsser)"
fi
# Download and update to the latest version
curl -sSL "$SCRIPT_URL" -o knoxsser.sh && chmod +x knoxsser.sh && sudo mv knoxsser.sh "$SCRIPT_PATH"
echo -e "${GREEN}${BOLD}KNOXSSer updated!!!${NC}"
echo -e "${YELLOW}Reminder: Make sure to set the API key in the knoxsser file (updating overwrites the knoxsser file), or pass it with the -A argument.${NC}"
exit 0
fi
else
echo -e "${GREEN}Your script is up-to-date.${NC}"
fi
}
# Function to display the number of targets
target_count() {
if ! $silent_mode; then
echo -e "${BOLD}Scanning $(wc -l < "$urls_file") URLs for XSS...${NC}\n"
fi
}
# Exit if no arguments are provided
if [[ $# -eq 0 ]]; then
print_banner
exit 0
fi
# Default values
input_type="file"
input_file=""
api_key="KNOXSS_API_KEY"
output_file="xss.txt"
silent_mode=false
use_notify=false
parallel_processes=3
verbose_mode=false
retry_count=2
retry_interval=15
unknown_error_log="error.log"
cookies=""
post_data=""
# Function to display usage
usage() {
print_banner
echo "Options:"
echo " -i, --input Input file containing URLs or single URL to scan"
echo " -o, --output Output file to save XSS results (default: xss.txt)"
echo " -A, --api API key for Knoxss"
echo " -s, --silent Print only results without displaying the banner and target count"
echo " -n, --notify Send notifications on successful XSSes via notify"
echo " -p, --process Number of URLs to scan in parallel (1-5) (default: 3)"
echo " -r, --retry Number of times to retry on target connection issues & can't finish scans (default: 1)"
echo " -ri, --retry-interval Seconds to wait before retrying when having issues connecting to the KNOXSS API (default: 15)"
echo " -v, --version Display the version and exit"
echo " -V, --verbose Enable verbose output"
echo " -h, --help Display this help message and exit"
echo " -c, --cookies Cookies for authenticated GET requests"
echo " -pd, --postdata POST data for POST requests"
exit 1
}
# Parse command-line arguments
while [[ $# -gt 0 ]]; do
key="$1"
case $key in
-i|--input)
input="$2"
if [[ -f "$input" ]]; then
input_type="file"
input_file="$input"
else
input_type="url"
single_url="$input"
single_url=$(echo "$single_url" | sed 's/&/%26/g')
single_url=$(echo "$single_url" | sed 's/+/%2B/g')
fi
shift
shift
;;
-o|--output)
output_file="$2"
shift
shift
;;
-A|--api)
api_key="$2"
shift
shift
;;
-s|--silent)
silent_mode=true
shift
;;
-n|--notify)
use_notify=true
shift
;;
-p|--process)
parallel_processes="$2"
shift
shift
;;
-r|--retry)
retry_count="$2"
shift
shift
;;
-ri|--retry-interval)
retry_interval="$2"
shift
shift
;;
-v|--version)
echo "Version: ${VERSION}"
exit 0
;;
-V|--verbose)
verbose_mode=true
shift
;;
-c|--cookies)
cookies="$2"
shift
shift
;;
-pd|--postdata)
post_data="$2"
shift
shift
;;
-h|--help)
usage
;;
*)
echo "Error: Unknown option: $1"
usage
;;
esac
done
# Validate required arguments
if [[ "$input_type" == "file" && -z "$input_file" ]]; then
echo "Error: Input file not specified"
usage
elif [[ "$input_type" == "url" && -z "$single_url" ]]; then
echo "Error: Single URL not specified"
usage
fi
# Set up URLs for scanning based on input type
if [[ "$input_type" == "file" ]]; then
sed -i 's/&/%26/g' "$input_file"
sed -i 's/+/%2B/g' "$input_file"
urls_file="$input_file"
else
urls_file=$(mktemp)
echo "$single_url" > "$urls_file"
fi
# Function to handle Ctrl-C interruptions
handle_ctrl_c() {
echo -e "\n${BOLD}Ctrl-C detected. Remaining unscanned URLs are saved into $todo_file${NC}"
grep -vFf "$processed_file" "$urls_file" > "$todo_file"
rm -f "$processed_file"
exit 1
}
# Set up Ctrl-C handler
trap handle_ctrl_c INT
lineno=1
api_calls=0
todo_file="${urls_file}-$(date +'%Y%m%d%H%M%S').todo"
processed_file="${urls_file}-$(date +'%Y%m%d%H%M%S').processed"
# Display banner and target count
if ! $silent_mode; then
print_banner
check_version
target_count
fi
# Function to process URLs
process_url() {
local line="$1"
local lineno="$2"
local retries=0
while [[ $retries -lt $retry_count ]]; do
if [[ -n "$cookies" ]]; then
response=$(curl "https://api.knoxss.pro" -d "target=$line&auth=Cookie:$cookies" -H "X-API-KEY: $api_key" -s)
elif [[ -n "$post_data" ]]; then
response=$(curl "https://api.knoxss.pro" -d "target=$line&post=$post_data" -H "X-API-KEY: $api_key" -s)
else
response=$(curl "https://api.knoxss.pro" -d "target=$line" -H "X-API-KEY: $api_key" -s)
fi
if [[ "$response" == *"Invalid or expired API key."* ]]; then
echo -e "${RED}Invalid or expired API key. Exiting.${NC}"
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response"
fi
# Save remaining URLs to .todo file
grep -vFf "$processed_file" "$urls_file" >> "$todo_file"
exit 1
elif [[ "$response" == *"API rate limit exceeded."* ]]; then
echo -e "${RED}API rate limit exceeded. Exiting.${NC}"
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response"
fi
# Save remaining URLs to .todo file
grep -vFf "$processed_file" "$urls_file" >> "$todo_file"
exit 1
elif [[ "$response" == *"service unavailable"* ]]; then
echo -e "${RED}Service unavailable. Exiting.${NC}"
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response"
fi
# Save remaining URLs to .todo file
grep -vFf "$processed_file" "$urls_file" >> "$todo_file"
exit 1
elif [[ "$response" == *"<p"* ]]; then
echo -e "${YELLOW}[ NOPE/ ] - $line - [XSS is not possible in this content-type]${NC} [0]"
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response"
fi
break
else
xss=$(jq -r '.XSS' <<< "$response")
poc=$(jq -r '.PoC' <<< "$response")
error=$(jq -r '.Error' <<< "$response")
api_call=$(jq -r '.["API Call"]' <<< "$response")
time_elapsed=$(jq -r '.["Time Elapsed"]' <<< "$response")
timestamp=$(jq -r '.Timestamp' <<< "$response")
version=$(jq -r '.Version' <<< "$response")
# Handle XSS detection
if [[ "$xss" == "true" ]]; then
echo -e "${GREEN}${BOLD}[ XSS!! ] - $poc ${NC} [$api_call]"
echo "$response" >> "$output_file"
if [[ "$use_notify" == true ]]; then
echo "$poc" | notify -silent > /dev/null 2>&1
if [[ "$api_call" != "0" ]]; then
api_calls=$((api_calls + 1))
fi
fi
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response" | jq .
fi
break
elif [[ "$xss" == "false" ]]; then
echo -e "${YELLOW}[ noXSS ] - $line ${NC} [$api_call]"
if [[ "$api_call" != "0" ]]; then
api_calls=$((api_calls + 1))
fi
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response" | jq .
fi
break
elif [[ "$error" == "KNOXSS can't test it (forbidden)" ]]; then
echo -e "${RED}[ 403:( ] - $line - [$error]${NC} [$api_call]"
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response" | jq .
fi
break
elif [[ "$error" == "target connection issues (timeout)" ]]; then
retries=$((retries + 1))
if [[ $retries -lt $retry_count ]]; then
echo -e "${RED}[ ERROR ] - $line - [Target connection issues (timeout)] Retrying in ${retry_interval} seconds... (${retries}/${retry_count})${NC}"
sleep "$retry_interval"
else
echo -e "${RED}[ ERROR ] - $line - [Target connection issues (timeout)]${NC} [$api_call]"
echo "$line" >> "$todo_file"
fi
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response" | jq .
fi
elif [[ "$error" == "KNOXSS can't finish scan gracefully (reason unknown)" ]]; then
retries=$((retries + 1))
if [[ $retries -lt $retry_count ]]; then
echo -e "${RED}[ ERROR ] - $line - [KNOXSS can't finish scan gracefully (reason unknown)] Retrying in ${retry_interval} seconds... (${retries}/${retry_count})${NC}"
sleep "$retry_interval"
else
echo -e "${RED}[ ERROR ] - $line - [KNOXSS can't finish scan gracefully (reason unknown)]${NC} [$api_call]"
echo "$line" >> "$todo_file"
fi
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response" | jq .
fi
elif [[ "$error" == "KNOXSS engine failed at some point, please retry" ]]; then
retries=$((retries + 1))
if [[ $retries -lt $retry_count ]]; then
echo -e "${RED}[ ERROR ] - $line - [KNOXSS engine failed at some point, please retry] Retrying in ${retry_interval} seconds... (${retries}/${retry_count})${NC}"
sleep "$retry_interval"
else
echo -e "${RED}[ ERROR ] - $line - [KNOXSS engine failed at some point, please retry]${NC} [$api_call]"
echo "$line" >> "$todo_file"
fi
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response" | jq .
fi
elif [[ "$error" == "KNOXSS PoC attempt got no response from target, please retry" ]]; then
retries=$((retries + 1))
if [[ $retries -lt $retry_count ]]; then
echo -e "${RED}[ ERROR ] - $line - [KNOXSS PoC attempt got no response from target, please retry] Retrying in ${retry_interval} seconds... (${retries}/${retry_count})${NC}"
sleep "$retry_interval"
else
echo -e "${RED}[ ERROR ] - $line - [KNOXSS PoC attempt got no response from target, please retry]${NC} [$api_call]"
echo "$line" >> "$todo_file"
fi
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response" | jq .
fi
elif [[ "$error" == "Expiration time reset, please try again." ]]; then
retries=$((retries + 1))
if [[ $retries -lt $retry_count ]]; then
echo -e "${RED}[ ERROR ] - $line - [Expiration time reset, please try again.] Retrying in ${retry_interval} seconds... (${retries}/${retry_count})${NC}"
sleep "$retry_interval"
else
echo -e "${RED}[ ERROR ] - $line - [Expiration time reset, please try again.]${NC} [$api_call]"
echo "$line" >> "$todo_file"
fi
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response" | jq .
fi
else
echo -e "${RED}[ ERROR ] - $line - [Unknown Error]${NC} [$api_call]"
echo "$line" >> "$todo_file"
echo "$response" >> "$unknown_error_log"
if $verbose_mode; then
echo -e "${BOLD}Verbose response from KNOXSS API:${NC}"
echo "$response" | jq .
fi
break
fi
fi
done
echo "$line" >> "$processed_file"
}
# Setup for parallel processing
export -f process_url
export api_key output_file use_notify todo_file processed_file unknown_error_log verbose_mode CYAN GREEN RED YELLOW BOLD NC retry_count retry_interval cookies post_data
# Start processing URLs in parallel
parallel -j "$parallel_processes" process_url :::: "$urls_file"
# Final summary
if [[ -s "$todo_file" ]]; then
echo -e "\n${BOLD}Some URLs encountered errors and are saved into $todo_file${NC}"
fi
if [[ -s "$unknown_error_log" ]]; then
echo -e "\n${BOLD}Some URLs encountered unknown errors and their responses are saved into $unknown_error_log${NC}"
fi
rm -f "$processed_file"