Изза "нового" оборудования пришлось отменять опцию "hide ssid" и снижать некоторые запросы по шифрованию, естественно безопасность упала. Чтобы отбиваться от возможных атак сделал ряд скриптов.
Первый - REBUILD_RULES (выстраивает новые правила firewall, лежит в /opt/etc/init.d) Воспользоваться им смогут те, кто умеет руками писать правила iptables.
Code:
echo "
# Setting defaults
iptables -F
iptables -P INPUT DROP
iptables -P FORWARD DROP
iptables -P OUTPUT ACCEPT
...{Ваше любое множество правил | Your rules}...
" > /opt/etc/init.d/S11network
cat /etc/ethers | awk {'print "iptables -t filter -I FORWARD 1 -s "$2" -m mac --mac-source "$1" -j ACCEPT"'} >> ./S11network
cat /etc/ethers | awk {'print "iptables -t filter -I INPUT 1 -s "$2" -m mac --mac-source "$1" -j ACCEPT"'} >> ./S11network
Последние две строки добавляют разрешающие правила (используя mac и IP адрес с файла /etc/ethers). Советую просто держать этот файл всегда актуальным. Как только нужно добавить новое устройство в сеть, идем в /etc/ethers и заполняем ip и мас адреса. Не забудьте сделать S11network исполняемым. Формат файла ethers такой:
Code:
00:0c:73:8e:3f:ba 192.168.1.2
00:13:02:26:53:1f 192.168.1.4
00:17:31:1f:73:59 192.168.1.3
00:0b:6c:4e:63:1b 192.168.1.5
Даже если кто-либо пройдет в wifi сеть - дальше делать будет нечего, только сканировать сеть на предмет telnet`ов к маршрутизатору (Настоятельно рекомендую ssh)
Второй скрипт (точнее группа скриптов) - maccontrol. Скрипт вешается в cron и при появлении новых mac адресов сообщает - Notify если mac адрес известен и ALARM если mac неизвестен.
Что должно быть установлено - cron, diffutils, php
1) mkdir /opt/etc/maccontrol/
2) touch /opt/etc/maccontrol/dev_old
3) Файл /opt/etc/maccontrol/scanner:
Code:
#!/bin/sh
/usr/sbin/brctl showmacs br0 | grep -v "is local?" | grep "no" | awk '{print $1" "$2}' > /opt/etc/maccontrol/dev_new
/opt/bin/diff /opt/etc/maccontrol/dev_old /opt/etc/maccontrol/dev_new | grep ">" | awk '{print $2" "$3}' > /opt/etc/maccontrol/delta
HOST="Unknown"
S=1
for j in `cat /opt/etc/maccontrol/delta` ; do
IP=""
for i in `cat /etc/ethers` ; do
if [ "$N" = "get" ]; then
IP="$i"
N=""
fi
if [ "$i" = "$j" ]; then
N="get"
fi
done
if [ $S == "2" ]; then
S=0
if [ "$IP" != "" ]; then
HOST=`cat /etc/hosts | grep $IP | awk '{print $2}'`
echo "Notify: $HOST on BR-$BR with $IP"
else
echo "!!!_ALARM_!!! $j on BR-$BR"
fi
BR=""
HOST=""
fi
if [ $S == "1" ]; then
BR="$j"
fi
S=$(($S + 1))
done
rm -f /opt/etc/maccontrol/dev_old
mv /opt/etc/maccontrol/dev_new /opt/etc/maccontrol/dev_old
rm -f /opt/etc/maccontrol/delta
4) файл /opt/etc/maccontrol/sendmail.php:
Code:
<?php
//new function
$to = "7914xxxxxxxxxx@sms.primtel.ru";
$nameto = "nameto";
$from = "xxxxxxxxxx@mail.ru";
$namefrom = "namefrom";
$subject = "wi-info";
$message = file_get_contents("/opt/etc/maccontrol/out.txt");
if (strlen($message)>10){
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
}
?>
<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */
//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection,
function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "smtp.mail.ru";
$port = "25";
$timeout = "30";
$username = "xxxxxxxxxx";
$password = "xxxxxxxxxx";
$localhost = "localhost";
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */
//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}
//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";
//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";
//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";
//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";
//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";
//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";
//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";
//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;
fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";
// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
#print_r($logArray);
}
?>
Замените xxxxxxxxxx на нужное Вам.
5) Файл /opt/etc/maccontrol/starter:
Code:
#!/bin/sh
/opt/etc/maccontrol/scanner > /opt/etc/maccontrol/out.txt
/opt/bin/php /opt/etc/maccontrol/sendmail.php
6) Делаем cd /opt/etc/maccontrol ; chmod 755 starter, scanner
7) В cron lобавляем правило "*/3 * * * * admin /opt/etc/maccontrol/starter"
Через 3 минуты (или раньше) после коннекта получаем смс сообщение - "Notify: Unknown on BR-2 with 192.168.1.4", где BR-2 wifi, BR-1 - Ethernet. Чтобы вместо Unknown было нормальное имя хоста - прописываем в /etc/hosts