| 1 |
<?php |
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 |
|
|---|
| 5 |
|
|---|
| 6 |
|
|---|
| 7 |
|
|---|
| 8 |
|
|---|
| 9 |
|
|---|
| 10 |
|
|---|
| 11 |
|
|---|
| 12 |
|
|---|
| 13 |
|
|---|
| 14 |
function weakpasswords_get_config($engine) { |
|---|
| 15 |
switch($engine) { |
|---|
| 16 |
case "asterisk": |
|---|
| 17 |
|
|---|
| 18 |
$nt = notifications::create($db); |
|---|
| 19 |
$security_notifications = $nt->list_security(); |
|---|
| 20 |
foreach($security_notifications as $notification) { |
|---|
| 21 |
if($notification['module'] == "weakpasswords") { |
|---|
| 22 |
$nt->delete($notification['module'],$notification['id']); |
|---|
| 23 |
} |
|---|
| 24 |
} |
|---|
| 25 |
|
|---|
| 26 |
$weak = weakpasswords_get_users(); |
|---|
| 27 |
if(sizeof($weak) > 0) { |
|---|
| 28 |
$extended_text = _("Warning: The use of SIP/IAX passwords that are weak can allow hackers to make brute force registrations and possibly make calls through your PBX. It is strongly recommended, you choose strong secrets.")."<br>"; |
|---|
| 29 |
$count = 0; |
|---|
| 30 |
foreach($weak as $details) { |
|---|
| 31 |
$extended_text .= sprintf(_("%s %s has a weak secret of %s: %s<br>"), $details['deviceortrunk'], $details['name'], $details['secret'], $details['message']); |
|---|
| 32 |
$count++; |
|---|
| 33 |
} |
|---|
| 34 |
$nt->add_security("weakpasswords", "all", $count." "._("extensions/trunks has weak secrets"),$extended_text); |
|---|
| 35 |
|
|---|
| 36 |
|
|---|
| 37 |
} |
|---|
| 38 |
break; |
|---|
| 39 |
} |
|---|
| 40 |
} |
|---|
| 41 |
|
|---|
| 42 |
function weakpasswords_get_users() { |
|---|
| 43 |
global $db; |
|---|
| 44 |
|
|---|
| 45 |
$sql = "SELECT 'SIP' as tech,s.id as id, s2.data as device,s.data as secret FROM sip s LEFT JOIN sip s2 ON s.id=s2.id AND s2.keyword='account' WHERE s.keyword='secret'"; |
|---|
| 46 |
$sipsecrets = sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 47 |
$sql = "SELECT 'IAX' as tech,s.id as id, s2.data as device,s.data as secret FROM iax s LEFT JOIN iax s2 ON s.id=s2.id AND s2.keyword='account' WHERE s.keyword='secret'"; |
|---|
| 48 |
$iaxsecrets = sql($sql,"getAll",DB_FETCHMODE_ASSOC); |
|---|
| 49 |
$secrets = array_merge($sipsecrets,$iaxsecrets); |
|---|
| 50 |
$weak = array(); |
|---|
| 51 |
foreach($secrets as $arr) { |
|---|
| 52 |
$name = $arr['device']; |
|---|
| 53 |
$id = $arr['id']; |
|---|
| 54 |
$secret = $arr['secret']; |
|---|
| 55 |
$tech = $arr['tech']; |
|---|
| 56 |
|
|---|
| 57 |
if($id == $name) { |
|---|
| 58 |
$deviceortrunk = _("Extension"); |
|---|
| 59 |
} |
|---|
| 60 |
else { |
|---|
| 61 |
$deviceortrunk = sprintf(_("%s Trunk"), $tech); |
|---|
| 62 |
} |
|---|
| 63 |
$reversed = strrev($secret); |
|---|
| 64 |
$match = "0123456789"; |
|---|
| 65 |
if(strpos($match,$secret) || strpos($match,$reversed)) { |
|---|
| 66 |
$weak[] = array("deviceortrunk" => $deviceortrunk, "name" => $name, "message" => _("Secret has sequential digits"), "secret" => $secret); |
|---|
| 67 |
} |
|---|
| 68 |
else if($device == $secret) { |
|---|
| 69 |
$weak[] = array("deviceortrunk" => $deviceortrunk, "name" => $name, "message" => _("Secret same as device"), "secret" => $secret); |
|---|
| 70 |
} |
|---|
| 71 |
else if(preg_match("/(.)\\1{3,}/",$secret,$regs)) { |
|---|
| 72 |
$weak[] = array("deviceortrunk" => $deviceortrunk, "name" => $name, "message" => _("Secret has consecutive digit ").$regs[1], "secret" => $secret); |
|---|
| 73 |
} |
|---|
| 74 |
else if(strlen($secret) < 6) { |
|---|
| 75 |
$weak[] = array("deviceortrunk" => $deviceortrunk, "name" => $name, "message" => _("Secret less than 6 digits"), "secret" => $secret); |
|---|
| 76 |
} |
|---|
| 77 |
} |
|---|
| 78 |
return $weak; |
|---|
| 79 |
} |
|---|
| 80 |
?> |
|---|
| 81 |
|
|---|