-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommon.sh
65 lines (54 loc) · 1.36 KB
/
common.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
. $(dirname ${BASH_SOURCE[0]})/config
override() {
local bin func
bin="$1"
func="$2"
eval "
$bin() {
unset $bin
$func \"\$@\"
override \"$bin\" \"$func\"
}"
}
func_curl() {
for i; do
if [[ "$i" == *PHPSESSID* ]]; then
echo "CURL STOP! FOUND PHPSESSID" >&2
exit 127
fi
done
local -a args=()
if [[ -n $CURL_VERBOSE ]]; then
args+=(-v)
fi
curl "${args[@]}" -s -A "RingZer0/0.1" -H 'Cookie: PHPSESSID='$PHPSESSID "$@"
}
retrieve_challenge() {
local rc
pushd $(dirname ${BASH_SOURCE[0]})/lib/ >/dev/null
curl 'https://ringzer0team.com/challenges/'$QID -H 'Referer: https://ringzer0team.com/challenges' | node parser.js | dos2unix
rc=$?
popd >/dev/null
return $rc
}
parse_block() {
local keyword="$1"
local write_code=false
while read -r line; do
if [[ $line == "----- BEGIN "$keyword" -----" ]]; then
write_code=true
continue
elif [[ $line == "----- END "$keyword" -----" ]]; then
return
fi
if $write_code; then
echo "$line"
fi
done
}
submit_answer() {
local answer="$1"
curl https://ringzer0team.com/challenges/$QID/"$answer" | grep -A1 "challenge-wrapper"
}
override curl func_curl
QID=$(basename $(dirname $(readlink -f ${BASH_SOURCE[1]})))