|
|
@ -27,7 +27,6 @@ flags |
|
|
#!define FLB_NATB 1 |
|
|
#!define FLB_NATB 1 |
|
|
#!define FLB_NATSIPPING 2 |
|
|
#!define FLB_NATSIPPING 2 |
|
|
#!define FLB_UAC_REDIRECT 3 |
|
|
#!define FLB_UAC_REDIRECT 3 |
|
|
|
|
|
|
|
|
#!define TRUSTED_ADR_GROUP 1 |
|
|
#!define TRUSTED_ADR_GROUP 1 |
|
|
|
|
|
|
|
|
####### Global Parameters ######### |
|
|
####### Global Parameters ######### |
|
|
@ -188,12 +187,14 @@ include_file "nat-traversal-role.cfg" |
|
|
loadmodule "db_kazoo.so" |
|
|
loadmodule "db_kazoo.so" |
|
|
#!endif |
|
|
#!endif |
|
|
|
|
|
|
|
|
|
|
|
####### DB Text module ########## |
|
|
loadmodule "db_text.so" |
|
|
loadmodule "db_text.so" |
|
|
loadmodule "permissions.so" |
|
|
|
|
|
modparam("db_text", "db_mode", 1) |
|
|
modparam("db_text", "db_mode", 1) |
|
|
modparam("permissions", "db_url", "text:///etc/kamailio/dbtext") |
|
|
|
|
|
modparam("permissions", "db_mode", 1) |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
####### Permissions module ########## |
|
|
|
|
|
loadmodule "permissions.so" |
|
|
|
|
|
modparam("permissions", "db_url", "text:///etc/kazoo/kamailio/dbtext") |
|
|
|
|
|
modparam("permissions", "db_mode", 1) |
|
|
|
|
|
|
|
|
####### Routing Logic ######## |
|
|
####### Routing Logic ######## |
|
|
route |
|
|
route |
|
|
@ -244,12 +245,13 @@ route |
|
|
route[SANITY_CHECK] |
|
|
route[SANITY_CHECK] |
|
|
{ |
|
|
{ |
|
|
if (!mf_process_maxfwd_header("10")) { |
|
|
if (!mf_process_maxfwd_header("10")) { |
|
|
xlog("L_WARN", "$ci|end|Too much hops, not enough barley"); |
|
|
|
|
|
|
|
|
xlog("L_WARN", "$ci|end|too much hops, not enough barley"); |
|
|
send_reply("483", "Too Many Hops"); |
|
|
send_reply("483", "Too Many Hops"); |
|
|
exit; |
|
|
exit; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ( msg:len > 6144 ) { |
|
|
if ( msg:len > 6144 ) { |
|
|
|
|
|
xlog("L_WARN", "$ci|end|message too large"); |
|
|
send_reply("513", "Message too large"); |
|
|
send_reply("513", "Message too large"); |
|
|
exit; |
|
|
exit; |
|
|
} |
|
|
} |
|
|
@ -258,6 +260,13 @@ route[SANITY_CHECK] |
|
|
xlog("L_WARN", "$ci|end|message is insane"); |
|
|
xlog("L_WARN", "$ci|end|message is insane"); |
|
|
exit; |
|
|
exit; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($ua == "friendly-scanner" || |
|
|
|
|
|
$ua == "sundayddr" || |
|
|
|
|
|
$ua =~ "sipcli" ) { |
|
|
|
|
|
xlog("L_WARN", "$ci|end|dropping message with user-agent $ua"); |
|
|
|
|
|
exit; |
|
|
|
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
route[HANDLE_OPTIONS] |
|
|
route[HANDLE_OPTIONS] |
|
|
@ -265,10 +274,8 @@ route[HANDLE_OPTIONS] |
|
|
if (is_method("OPTIONS")) { |
|
|
if (is_method("OPTIONS")) { |
|
|
if (isflagset(FLAG_INTERNALLY_SOURCED)) { |
|
|
if (isflagset(FLAG_INTERNALLY_SOURCED)) { |
|
|
route(INTERNAL_TO_EXTERNAL_RELAY); |
|
|
route(INTERNAL_TO_EXTERNAL_RELAY); |
|
|
} |
|
|
|
|
|
else |
|
|
|
|
|
if ($rd=~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") { |
|
|
|
|
|
xlog("L_ERR", "Possible attack- Options: to $ru from $fu, UA $ua, IP $si\n"); |
|
|
|
|
|
|
|
|
} else if ($rd =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}") { |
|
|
|
|
|
xlog("L_WARN", "$ci|end|dropping OPTIONS request with IP domain"); |
|
|
} else { |
|
|
} else { |
|
|
sl_send_reply("200", "Rawr!!"); |
|
|
sl_send_reply("200", "Rawr!!"); |
|
|
} |
|
|
} |
|
|
@ -285,13 +292,13 @@ route[HANDLE_MOVE_REQUEST] |
|
|
if ($sht(associations=>$var(contact_uri)) != $null) { |
|
|
if ($sht(associations=>$var(contact_uri)) != $null) { |
|
|
$sht(associations=>$var(contact_uri)) = $null; |
|
|
$sht(associations=>$var(contact_uri)) = $null; |
|
|
xlog("L_INFO", "$ci|log|removed contact association for $var(contact_uri) |
|
|
xlog("L_INFO", "$ci|log|removed contact association for $var(contact_uri) |
|
|
with media server $sht(associations=>$var(contact_uri))\n"); |
|
|
|
|
|
|
|
|
with media server $sht(associations=>$var(contact_uri))"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if ($sht(associations=>$var(from_uri)) != $null) { |
|
|
if ($sht(associations=>$var(from_uri)) != $null) { |
|
|
$sht(associations=>$var(from_uri)) = $null; |
|
|
$sht(associations=>$var(from_uri)) = $null; |
|
|
xlog("L_INFO", "$ci|log|removed from association for $var(from_uri) |
|
|
xlog("L_INFO", "$ci|log|removed from association for $var(from_uri) |
|
|
with media server $sht(associations=>$var(from_uri))\n"); |
|
|
|
|
|
|
|
|
with media server $sht(associations=>$var(from_uri))"); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
send_reply("503", "Removed association"); |
|
|
send_reply("503", "Removed association"); |
|
|
@ -346,6 +353,7 @@ route[PREPARE_INITIAL_REQUESTS] |
|
|
t_check_trans(); |
|
|
t_check_trans(); |
|
|
|
|
|
|
|
|
if (loose_route()) { |
|
|
if (loose_route()) { |
|
|
|
|
|
xlog("L_WARN", "$ci|end|denying initial request with route-set"); |
|
|
sl_send_reply("403", "No pre-loaded routes"); |
|
|
sl_send_reply("403", "No pre-loaded routes"); |
|
|
exit(); |
|
|
exit(); |
|
|
} |
|
|
} |
|
|
@ -400,28 +408,29 @@ route[DOS_PREVENTION] |
|
|
{ |
|
|
{ |
|
|
# allow request from internal network or from whitelist |
|
|
# allow request from internal network or from whitelist |
|
|
if (isflagset(FLAG_INTERNALLY_SOURCED) || allow_source_address(TRUSTED_ADR_GROUP)) { |
|
|
if (isflagset(FLAG_INTERNALLY_SOURCED) || allow_source_address(TRUSTED_ADR_GROUP)) { |
|
|
xlog("L_DBG", "Request from trusted IP $rm $si\n"); |
|
|
|
|
|
|
|
|
xlog("L_DBG", "$ci|log|request from trusted IP"); |
|
|
return; |
|
|
return; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
# drop requests with no To domain or IP To domain (friendly-scanner) |
|
|
# drop requests with no To domain or IP To domain (friendly-scanner) |
|
|
if (is_method("REGISTER|SUBSCRIBE|OPTIONS") && |
|
|
if (is_method("REGISTER|SUBSCRIBE|OPTIONS") && |
|
|
($td == $null || $td=~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}")) { |
|
|
($td == $null || $td=~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}")) { |
|
|
xlog("L_ERR", "Possible attack- wrong td: $rm to $ru from $fu, UA $ua, IP $si\n"); |
|
|
|
|
|
|
|
|
xlog("L_WARN", "$ci|log|dropping request with IP domain in To header"); |
|
|
exit; |
|
|
exit; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
# drop Invite with IP auth realm |
|
|
# drop Invite with IP auth realm |
|
|
if (is_method("INVITE") && is_present_hf("Proxy-Authorization") && |
|
|
if (is_method("INVITE") && is_present_hf("Proxy-Authorization") && |
|
|
$ar =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}" ) { |
|
|
$ar =~ "[0-9]{1,3}\.[0-9]{1,3}.[0-9]{1,3}\.[0-9]{1,3}" ) { |
|
|
xlog("L_ERR", "Possible attack- Invite realm $ar: to $ru from $fu, UA $ua, IP $si\n"); |
|
|
|
|
|
|
|
|
xlog("L_WARN", "$ci|log|dropping request with IP domain in Proxy-Authorization header"); |
|
|
exit; |
|
|
exit; |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
# use pike check for the others |
|
|
# use pike check for the others |
|
|
if (!pike_check_req()) { |
|
|
if (!pike_check_req()) { |
|
|
if( $rc == -2) { |
|
|
|
|
|
xlog("L_ERR", "DOS attack: $rm to $ru from $fu, UA $ua, IP $si\n"); |
|
|
|
|
|
|
|
|
# If it is a new flood, emit a log |
|
|
|
|
|
if($rc == -2) { |
|
|
|
|
|
xlog("L_WARN", "$ci|log|dropping due to rate of requests from IP"); |
|
|
} |
|
|
} |
|
|
exit; |
|
|
exit; |
|
|
} |
|
|
} |
|
|
|