forked from cardigliano/wireshark-fritzbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fritzcap.sh
executable file
·103 lines (92 loc) · 2.86 KB
/
fritzcap.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
#!/bin/bash
EXTCAP_VERSION="0.0.2"
DEFAULT_FRITZ_IFACE="1-lan"
WGET=/usr/bin/wget
SID_FILE="/tmp/fritz.sid"
while [ "$1" != "" ]; do
case $1 in
--extcap-interfaces)
echo "extcap {version=$EXTCAP_VERSION}"
echo "interface {value=remote-fritzbox}{display=Remote FRITZ!Box Capture}"
shift
;;
--extcap-config)
echo "arg {number=0}{call=--ifname}{display=Interface Name}{type=string}{tooltip=FRITZ!Box capture interface }{default=$DEFAULT_FRITZ_IFACE}"
#echo "arg {number=0}{call=--ifname}{display=Capture Interface}{type=selector}"
#echo "value {arg=0}{call=1-lan}{display=LAN}"
#echo "value {arg=0}{call=2-1}{display=WAN}"
echo "arg {number=1}{call=--host}{display=FRITZ!Box IP address}{type=string}{tooltip=The FRITZ!Box IP address or hostname}{required=true}"
echo "arg {number=2}{call=--username}{display=FRITZ!Box user}{type=string}{tooltip=The FRITZ!Box username (usually not required)}"
echo "arg {number=3}{call=--password}{display=FRITZ!Box password}{type=password}{tooltip=The FRITZ!Box password}{required=true}"
;;
--extcap-interface)
# Nothing to do as we support only 1 interface
shift
;;
--capture)
CAPTURE=1
;;
--fifo)
FIFO=$2
shift
;;
--ifname)
FRITZ_IFACE=$2
shift
;;
--host)
FRITZ_IP=$2
shift
;;
--username)
FRITZ_USER=$2
shift
;;
--password)
FRITZ_PWD=$2
shift
;;
--)
shift
break
;;
--extcap-dlts)
shift
;;
remote-fritzbox)
shift
;;
*)
echo "Unknown option $1" 1>&2
;;
esac
shift
done
if [ -z "$CAPTURE" ]; then
exit
fi
if [ -z "$FRITZ_IFACE" ]; then
FRITZ_IFACE="$DEFAULT_FRITZ_IFACE"
fi
if [ ! -f $SID_FILE ]; then
touch $SID_FILE
fi
SID=$(cat $SID_FILE)
NOTCONNECTED=$(curl -k -s "https://$FRITZ_IP/login_sid.lua?sid=$SID" | grep -c "0000000000000000")
if [ $NOTCONNECTED -gt 0 ]; then
CHALLENGE=$(curl -k -s https://$FRITZ_IP/login_sid.lua | grep -o "<Challenge>[a-z0-9]\{8\}" | cut -d'>' -f 2)
HASH=$(perl -MPOSIX -e '
use Digest::MD5 "md5_hex";
my $ch_pw = "$ARGV[0]-$ARGV[1]";
$ch_pw =~ s/(.)/$1 . chr(0)/eg;
my $md5 = lc(md5_hex($ch_pw));
print $md5;
' -- "$CHALLENGE" "$FRITZ_PWD")
curl -k -s "https://$FRITZ_IP/login_sid.lua" -d "response=$CHALLENGE-$HASH" -d 'username='${FRITZ_USER} | grep -o "<SID>[a-z0-9]\{16\}" | cut -d'>' -f 2 > $SID_FILE
fi
SID=$(cat $SID_FILE)
if [ "$SID" == "0000000000000000" ]; then
echo "Authentication error" 1>&2
exit 1
fi
$WGET --no-check-certificate -qO- https://$FRITZ_IP/cgi-bin/capture_notimeout?ifaceorminor=$FRITZ_IFACE\&snaplen=\&capture=Start\&sid=$SID > $FIFO