-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtests.sh
executable file
·69 lines (53 loc) · 1.55 KB
/
tests.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
#!/bin/bash
function run_challenge() {
make docker-$1 FLAG="$2" > /dev/null 2>&1
make stop-$1 > /dev/null 2>&1
make run-$1 | tail -n1 | cut -d':' -f2
}
function run_solution() {
local script="$1"
local expectedOutput="$2"
local ip="$3"
local attempt="${4-1}"
if [ $attempt -gt 5 ]; then
echo " ❌ $script"
return 1
fi
echo -n "."
local result=$(timeout 5s $script $ip 2> /dev/null)
if [ "$result" != "$expectedOutput" ]; then
let attempt++
sleep 1s
run_solution "$script" "$expectedOutput" "$ip" "$attempt"
return
fi
echo " ✅ $script"
return 0
}
function main() {
local filter="${1-.}"
local failCount=0
local successCount=0
for solutionScript in $(find solutions/ -maxdepth 3 -name "solution.*" | grep "$filter"); do
solutionNumber=$(sed -E 's:solutions/exploitme([0-9]+)/.*:\1:' <<< "$solutionScript")
flag="EME{$RANDOM-$RANDOM-$RANDOM}"
challengeIp=$(run_challenge "$solutionNumber" "$flag")
run_solution "./$solutionScript" "$flag" "$challengeIp"
if [ ! $? -eq 0 ]; then
let failCount++
else
let successCount++
fi
docker kill "exploitme$solutionNumber" > /dev/null 2> /dev/null
done
echo "----------------------"
echo "Success: $successCount"
echo "Fail: $failCount"
return $failCount
}
startTime=$(date +%s)
main "$@"
result=$?
endTime=$(date +%s)
echo "Time: $(date -d @$((endTime - startTime)) -u +%H:%M:%S)"
exit $result