如何阻止 Asterisk 上的注册尝试

如何阻止 Asterisk 上的注册尝试

主要问题:

我的 Asterisk 日志中充斥着如下消息:

[2012-05-29 15:53:49] NOTICE[5578] chan_sip.c: Registration from '<sip:[email protected]>' failed for '37.75.210.177' - No matching peer found
[2012-05-29 15:53:50] NOTICE[5578] chan_sip.c: Registration from '<sip:[email protected]>' failed for '37.75.210.177' - No matching peer found
[2012-05-29 15:53:55] NOTICE[5578] chan_sip.c: Registration from '<sip:[email protected]>' failed for '37.75.210.177' - No matching peer found
[2012-05-29 15:53:55] NOTICE[5578] chan_sip.c: Registration from '<sip:[email protected]>' failed for '37.75.210.177' - No matching peer found
[2012-05-29 15:53:57] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device <sip:[email protected]>;tag=cb23fe53
[2012-05-29 15:53:57] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device <sip:[email protected]>;tag=cb23fe53
[2012-05-29 15:54:02] NOTICE[5578] chan_sip.c: Registration from '<sip:[email protected]>' failed for '37.75.210.177' - No matching peer found
[2012-05-29 15:54:03] NOTICE[5578] chan_sip.c: Registration from '<sip:[email protected]>' failed for '37.75.210.177' - No matching peer found
[2012-05-29 21:20:36] NOTICE[5578] chan_sip.c: Registration from '"55435217"<sip:[email protected]>' failed for '65.218.221.180' - No matching peer found
[2012-05-29 21:20:36] NOTICE[5578] chan_sip.c: Registration from '"1731687005"<sip:[email protected]>' failed for '65.218.221.180' - No matching peer found
[2012-05-30 01:18:58] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device "unknown" <sip:[email protected]>;tag=dEBcOzUysX
[2012-05-30 01:18:58] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device "unknown" <sip:[email protected]>;tag=9zUari4Mve
[2012-05-30 01:19:00] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device "unknown" <sip:[email protected]>;tag=sOYgI1ItQn
[2012-05-30 01:19:02] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device "unknown" <sip:[email protected]>;tag=2EGLTzZSEi
[2012-05-30 01:19:04] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device "unknown" <sip:[email protected]>;tag=j0JfZoPcur
[2012-05-30 01:19:06] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device "unknown" <sip:[email protected]>;tag=Ra0DFDKggt
[2012-05-30 01:19:08] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device "unknown" <sip:[email protected]>;tag=rR7q7aTHEz
[2012-05-30 01:19:10] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device "unknown" <sip:[email protected]>;tag=VHUMtOpIvU
[2012-05-30 01:19:12] NOTICE[5578] chan_sip.c: Sending fake auth rejection for device "unknown" <sip:[email protected]>;tag=JxZUzBnPMW

我使用 Asterisk 来建立自动电话系统。它的唯一作用是接收来电并执行 Perl 脚本。不接听外拨电话,不接听实际电话的来电,也不在 Asterisk 上注册任何电话。

似乎应该有一种简单的方法来阻止所有未经授权的注册尝试,但我为此苦苦挣扎了很长时间。似乎应该有一种更有效的方法来阻止这些尝试甚至到达我的 Asterisk 日志。我可以打开/关闭某些设置,完全不允许注册尝试或类似的东西。有什么办法吗?

另外,我是否正确地假设“注册自 ...”消息可能是有人试图访问我的 Asterisk 服务器(可能用我的帐户拨打电话)?这些消息与“发送虚假身份验证拒绝 ...”消息之间有什么区别?

更多细节:

我知道“Registering from ...”行表示入侵者试图访问我的 Asterisk 服务器。设置 Fail2Ban 后,这些 IP 会在尝试 5 次后被禁止(出于某种原因,其中一个尝试了 6 次,但不管怎样)。

但我不知道“发送虚假身份验证拒绝...”消息是什么意思,也不知道如何阻止这些潜在的入侵企图。据我所知,他们从未得逞过(我从未在账单上看到任何奇怪的费用或其他东西)。

以下是我所做的:

  1. 如下所示设置硬件防火墙规则。其中,xx.xx.xx.xx是服务器的 IP 地址,yy.yy.yy.yy是我们设施的 IP 地址,并且aa.aa.aa.aabb.bb.bb.bbcc.cc.cc.cc是我们 VoIP 提供商使用的 IP 地址。理论上,端口 10000-20000 应该只能由这三个 IP 访问。
    +-------+-----------------------------+----------+-----------+--------+-----------------------------+------------------+
    | Order |         Source Ip           | Protocol | Direction | Action |        Destination Ip       | Destination Port |
    +-------+-----------------------------+----------+-----------+--------+-----------------------------+------------------+
    |   1   | cc.cc.cc.cc/255.255.255.255 |    udp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |    10000-20000   |
    |   2   |            any              |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |        80        |
    |   3   |            any              |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |       2749       |
    |   4   |            any              |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |        443       |
    |   5   |            any              |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |        53        |
    |   6   |            any              |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |       1981       |
    |   7   |            any              |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |       1991       |
    |   8   |            any              |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |       2001       |
    |   9   | yy.yy.yy.yy/255.255.255.255 |    udp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |      137-138     |
    |   10  | yy.yy.yy.yy/255.255.255.255 |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |        139       |
    |   11  | yy.yy.yy.yy/255.255.255.255 |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |        445       |
    |   14  | aa.aa.aa.aa/255.255.255.255 |    udp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |    10000-20000   |
    |   17  | bb.bb.bb.bb/255.255.255.255 |    udp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |    10000-20000   |
    |   18  |            any              |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |       1971       |
    |   19  |            any              |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |       2739       |
    |   20  |            any              |    tcp   |  inbound  | permit | xx.xx.xx.xx/255.255.255.255 |     1023-1050    |
    |   21  |            any              |    all   |  inbound  |  deny  |        any on server        |      1-65535     |
    +-------+-----------------------------+----------+-----------+--------+-----------------------------+------------------+
  2. 设置 Fail2Ban。这有点用,但它是被动的,而不是主动的,而且似乎不能阻止一切(比如“发送虚假身份验证拒绝...”消息)。
  3. 在 sip.conf 中设置规则以拒绝除我的 VoIP 提供商之外的所有提供商。这是我的 sip.conf,删除了几乎所有注释行(以节省空间)。请注意,底部是我尝试拒绝除我的 VoIP 提供商之外的所有提供商:
    [general]
    context=default
    allowguest=no
    allowoverlap=no
    bindport=5060
    bindaddr=0.0.0.0
    srvlookup=yes
    disallow=all allow=g726 allow=ulaw allow=alaw allow=g726aal2 allow=adpcm allow=slin allow=lpc10 allow=speex allow=g726
    insecure=invite
    alwaysauthreject=yes
    ;registertimeout=20 registerattempts=0 register => user:pass:[email protected]:5060/700
    [mysipprovider] type=peer username=user fromuser=user secret=pass host=sip.mysipprovider.com fromdomain=sip.mysipprovider.com nat=no ;canreinvite=yes qualify=yes context=inbound-mysipprovider disallow=all allow=ulaw allow=alaw allow=gsm insecure=port,invite
    deny=0.0.0.0/0.0.0.0 permit=aa.aa.aa.aa/255.255.255.255 permit=bb.bb.bb.bb/255.255.255.255 permit=cc.cc.cc.cc/255.255.255.255

答案1

这些防火墙规则已经实施多久了?如果您刚刚配置了它们,并且根据您配置它们的方式,这些规则可能仅适用于新的连接尝试,但仍将允许任何已建立的连接。因此,仍将允许通过已建立的连接进行的注册尝试。

你没有提供足够的信息说明你使用的防火墙类型,但请查看是否可以找到以下列表已建立连接在端口 5060 上,然后手动删除它们。现在应该会根据防火墙规则阻止后续的新连接尝试。

我还看到您在 Asterisk 配置文件中进行了设置bindaddr=0.0.0.0,这会导致 Asterisk 监听所有可用接口。此服务器有多少个 IP 地址?如果它有多个 IP 地址,则需要在防火墙规则中指定所有 IP 地址,因为目前您仅将其列为xx.xx.xx.xx目标 IP 以阻止端口 5060 上的传入流量。

答案2

简而言之,您阻止了错误的端口。SIP 注册发生在端口 5060(TCP 或 UDP)上。10000 多个端口将用于实际的 RTP 承载流量,而不是呼叫设置。调整防火墙以阻止 5060 和 5061 入站,您应该不会再看到这些消息。在此过程中,您可能还会考虑是否希望或需要您的系统在所有接口上侦听 SIP 注册。请记住 - 您可能连接到您的提供商,而不是相反。

答案3

在这种情况下,我会将特定的拒绝规则设置为防火墙上的第一条规则 - 阻止端口 5060 到 Asterisk 盒的流量。如果仍然允许注册 - 那么你将不得不仔细查看防火墙配置并确定它不起作用的原因。

当然 - 它应该被您当前实施的全面拒绝规则所阻止,但这显然无法捕获它。

希望这可以帮助。

答案4

注册显然可以通过端口 5060/5061 进入。即使您指定

端口=5061

或者

绑定端口=5061

或者

绑定地址=0.0.0.0:5061

asterisk 似乎仍然在端口 5060 上接受注册,并且一切仍然正常。

相关内容