forked from denouche/sfr-neufbox-change-ip
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathneufbox_change_marge_bruit.sh
102 lines (87 loc) · 3.73 KB
/
neufbox_change_marge_bruit.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
#!/bin/bash
NOISE_RATE="$1"
CREDENTIALS="/home/rapha/bin/neufbox_change_bruit/.credentials"
IP="192.168.1.1"
PHANTOM="/home/rapha/bin/neufbox_change_bruit/phantomjs-1.9.7-linux-x86_64/bin/phantomjs"
TMP="/home/rapha/bin/neufbox_change_bruit//tmp"
COOKIES_FILE="$TMP/cookies"
GET_IP_URL="http://myip.leveugle.net"
TEMPLATES_DIR="/home/rapha/bin/neufbox_change_bruit/templates"
FILE_HASH="getHash.js"
PAGE_REF="/maintenance/dsl/config"
copyAndReplaceTemplate()
{
FILE="$TMP/$1"
cp $TEMPLATES_DIR/$1.tpl $FILE
sed -i 's/%%IP%%/'$IP'/' $FILE
sed -i 's/%%challenge%%/'$ZSID'/' $FILE
sed -i 's/%%login%%/'$WEBLOGIN'/' $FILE
sed -i 's/%%password%%/'$WEBPASS'/' $FILE
}
clean()
{
rm -rf $TMP/
}
init()
{
if [ -e $CREDENTIALS ]
then
WEBLOGIN="$(cat $CREDENTIALS | cut -d: -f1)"
WEBPASS="$(cat $CREDENTIALS | cut -d: -f2)"
else
echo -e "Erreur: Le fichier $CREDENTIALS est manquant.\nIl contient les login et mot de passe utlisés pour se connecter à l'interface Web.\nSon format est:\nlogin:password"
exit 1
fi
mkdir -p $TMP
}
main()
{
# Vérifie si la 'marge de bruit' donnée en argument est comprise entre 1 et 100
echo " $(echo {1..100}) " | grep -q " $NOISE_RATE " || { echo "La 'marge de bruit' doit être un nombre compris entre 1 et 100"; exit 1; }
# marge de bruit temporaire (permettra d'éviter de rentrer un MdB égal à celle déjà en cours)
NOISE_RATE_2=$((NOISE_RATE+1))
clean
init
echo -n "Authentication..." | tee $TMP/log
wget -O /dev/null \
--keep-session-cookies --save-cookies=$COOKIES_FILE \
--referer=http://$IP/login \
--post-data='action=challenge' \
--header='Content-Type: application/x-www-form-urlencoded; charset=UTF-8' \
--header='X-Requested-With: XMLHttpRequest' \
http://$IP/login &>>$TMP/log
[[ $? ]] && echo OK | tee -a $TMP/log || echo ECHEC
ZSID=$(cat $COOKIES_FILE | grep sid | cut -f7)
# création du hash
copyAndReplaceTemplate $FILE_HASH
HASH=$($PHANTOM $TMP/$FILE_HASH)
echo -n "Connection..." | tee -a $TMP/log
POST_AUTH="method=passwd&page_ref=$PAGE_REF&zsid=$ZSID&hash=$HASH&login=&password="
wget -O /dev/null \
--load-cookies $COOKIES_FILE \
--referer=http://$IP/login \
--post-data="$POST_AUTH" \
--header='Content-Type: application/x-www-form-urlencoded' \
http://$IP/login &>>$TMP/log
[[ $? ]] && echo "OK" | tee -a $TMP/log || echo ECHEC
echo -n "Changement de la Marge de Bruit temporaire à $NOISE_RATE_2 ..." | tee -a $TMP/log
POST_AUTH="dsl_mod_p=p&dsl_mod_e=e&dsl_mod_v=v&dsl_lpair=inner&dsl_trellis=on&dsl_snr=$NOISE_RATE_2&dsl_bitswap=on&dsl_sesdrop=off&dsl_sra=off&dsl_diag=off&submit="
wget -O /dev/null \
--load-cookies $COOKIES_FILE \
--referer=http://$IP$PAGE_REF \
--post-data="$POST_AUTH" \
--header='Content-Type: application/x-www-form-urlencoded' \
http://$IP$PAGE_REF &>>$TMP/log
[[ $? ]] && echo OK | tee -a $TMP/log || echo ECHEC
sleep 3
echo -n "Changement de la Marge de Bruit à $NOISE_RATE ..." | tee -a $TMP/log
POST_AUTH="dsl_mod_p=p&dsl_mod_e=e&dsl_mod_v=v&dsl_lpair=inner&dsl_trellis=on&dsl_snr=$NOISE_RATE&dsl_bitswap=on&dsl_sesdrop=off&dsl_sra=off&dsl_diag=off&submit="
wget -O /dev/null \
--load-cookies $COOKIES_FILE \
--referer=http://$IP$PAGE_REF \
--post-data="$POST_AUTH" \
--header='Content-Type: application/x-www-form-urlencoded' \
http://$IP$PAGE_REF &>>$TMP/log
[[ $? ]] && echo -e "OK\n\t------ Internet sera à nouveau disponible d'ici une trentaine de secondes ------" | tee -a $TMP/log || echo ECHEC
}
main