Repository navigation
Expand file tree
/
Copy pathuse_cookies.sh
More file actions
executable file
·91 lines (75 loc) · 1.99 KB
/
Copy pathuse_cookies.sh
File metadata and controls
executable file
·91 lines (75 loc) · 1.99 KB
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
#!/bin/bash -
#use cookies from wireshark.
#format the cookies into json for chrome's Edit this cookie
#by needlewang
#2014年 04月 29日 星期二 01:23:48 CST
#pick up some unregular cookie's value with '='
#and some values are wrapped like '"..."', ugly.
#2014年 04月 28日 星期一 21:12:03 CST
#add the pipe(just add test "$1" == "-").
#2013年 10月 28日 星期一 06:14:10 CST
([ -r "$1" -o "$1" == "-" ]) || {
echo "
format the cookies into json for chrome's Edit this cookie
alternative 1:
echo 'Cookie:...' | $0 - .google.com
alternative 2:
step 1:
Run wireshark, then the filter is like:
http.cookie contains "skey"
step 2:
select a HTTP line in Packet List.
Find the Cookie line from Packet Details,
right click at the Cookie line:
copy -> Bytes -> Printable Text Only.
step 3:
put them in a void or blank file.
stop 4:
then, tell me where is the file, which is one line.
like: $0 cookie.txt .google.com
by needlewang
needlewang2011@gmail.com
"
exit 1;
}
test "$2" || {
echo "need a domain, which is from HTTP Packet. like:
$0 cookie.txt .google.com
by needlewang
needlewang2011@gmail.com
"
exit 2
}
domain="$2"
cookies=$(grep -i '^[ ]*Cookie:' "$1")
cookies=$(echo "$cookies" | sed 's/^[[:space:]]*Cookie: *//;s/; */\n/g')
#don't use wc.
max_line_number=$(echo "$cookies" | awk 'END{print NR}')
count=0
echo -n '['
IFS=$'\n'
#hope no special charactor...
#or use while in pipe.
for one in $cookies
do
echo '{'
echo ' "domain": "'"$domain"'",'
#cookie's name or value should not contains '='
#name=$(echo "$one" | awk -F'=' '{print $1}')
#value=$(echo "$one" | awk -F'=' '{print $2}')
#unfortunately, some cookies does contains '=', so:
name=$(echo "$one" | cut -d'=' -f1)
value=$(echo "$one" | cut -d'=' -f2-)
echo ' "name": "'"$name"'",'
echo ' "path": "'"/"'",'
#echo ' "value": "'"$value"'"'
echo ' "value": "'"${value//\"/\\\"}"'"'
#count can not be used in pipe..., so:
((count++))
if [ "$count" -lt "$max_line_number" ]
then
echo '},'
else
echo '}]'
fi
done