[Asterisk] Defence of brute force attack

Asterisk Server 를 생성하고 계속해서 Brute-force Attack 이 들어왔다.
비록 뚫린 흔적은 발견하지 못했지만 계속해서 들어오는 Brute Force Attack 은 내게 계속해서 “방심하면 뚫린다”라는 긴장감을 주었다..

그래서 그 방지책으로 fail2ban 설정을 찾을 수 있었고, 아래의 내용으로 fail2ban 설정 후, 안심할 수 있었다.

Asterisk 관련 fail2ban 스크립트 설정법

jail2ban.conf

logpath 가 약간 이상하게 잡혀있는데, 이는 Freepbx 를 설치해서 기본 로그 파일 경로가 수정되었기 때문이다.

[asterisk-iptables]

enabled  = true
filter   = asterisk
action   = iptables-allports[name=ASTERISK, protocol=all]
logpath  = /var/log/asterisk/full
maxretry = 5
bantime = 259200
findtime = 8640

 

filter.d/asterisk.conf

# Fail2Ban configuration file
#
#
# $Revision: 250 $
#

[INCLUDES]

# Read common prefixes. If any customizations available -- read them from
# common.local
#before = common.conf


[Definition]

#_daemon = asterisk

# Option:  failregex
# Notes.:  regex to match the password failures messages in the logfile. The
#          host must be matched by a group named "host". The tag "<HOST>" can
#          be used for standard IP/hostname matching and is only an alias for
#          (?:::f{4,6}:)?(?P<host>S+)
# Values:  TEXT
#

# Asterisk 1.4 use the following failregex

failregex = NOTICE.* .*: Registration from '.*' failed for '<HOST>' - Wrong password
            NOTICE.* .*: Registration from '.*' failed for '<HOST>:.*' - Wrong password
            NOTICE.* .*: Registration from '.*' failed for '<HOST>:.*' - No matching peer found
            NOTICE.* .*: Registration from '.*' failed for '<HOST>' - No matching peer found
            NOTICE.* .*: Registration from '.*' failed for '<HOST>' - Username/auth name mismatch
            NOTICE.* .*: Registration from '.*' failed for '<HOST>' - Device does not match ACL
            NOTICE.* .*: Registration from '.*' failed for '<HOST>' - Peer is not supposed to register
            NOTICE.* .*: Registration from '.*' failed for '<HOST>' - ACL error (permit/deny)
            NOTICE.* .*: Registration from '.*' failed for '<HOST>' - Device does not match ACL
            NOTICE.* <HOST> failed to authenticate as '.*'$
            NOTICE.* .*: No registration for peer '.*' (from <HOST>)
            NOTICE.* .*: Host <HOST> failed MD5 authentication for '.*' (.*)
            NOTICE.* .*: Failed to authenticate user .*@<HOST>.*
            NOTICE.* .*: Sending fake auth rejection for device .*<sip:.*@<HOST>>;tag=.*
            NOTICE.* .*: Registration from '".*".*' failed for '<HOST>' - No matching peer found
            NOTICE.* .*: Registration from '".*".*' failed for '<HOST>:.*' - No matching peer found
            NOTICE.* .*: Registration from '".*".*' failed for '<HOST>' - Wrong password
            NOTICE.* .*: Registration from '".*".*' failed for '<HOST>:.*' - Wrong password

# In Asterisk 1.8 use the same as above, but after <HOST> add :.* before the single quote. This is because in Asterisk 1.8, the log file includes a port number which 1.4 did not.

# Option:  ignoreregex
# Notes.:  regex to ignore. If this regex matches, the line is ignored.
# Values:  TEXT
#
ignoreregex =

 

출처: http://www.voip-info.org/wiki/view/Fail2Ban+%28with+iptables%29+And+Asterisk

 

 

[Freeswitch] python-bridge

Freeswitch 에서 Python 으로 dialplan 작성시…

Call-Bridge 를 해야 하는 경우..

call_addr = ‘sofia/profile_name/call_to@host_ip’
session.execute(“bridge”, call_addr)

과 같이 입력하면 된다.

Freeswitch Python 모듈에서 제공하는 Transfer 의 경우, 이미 작성되어 있는 Dailplan 으로 넘겨주는 역할밖에 하지 못한다.
즉, 다른 곳으로 전화를 걸어서 그쪽으로 넘겨주는 기능이 아닌 것이다.

가장 대표적인 기능이 음성 사서함에서의 콜백 기능인데, 콜백 기능을 Freeswitch Python 으로 작성할 경우, 위와 같이 작성하면 된다.

만약, Bridge 와 동시(즉, INVITE 시)에 특정 값들을 같이 넘겨 주어야 하는 경우, Originate 와 마찬가지로 call_addr 앞부분에 입력하고자 하는 파라미터 값을 넣어주면 된다.

[Asterisk] Auto fallthrough, “channel sip/xxxxxxxxx” status is ‘UNKNOWN’

Asterisk 연동 테스트를 진행 중, 다음의 에러가 발생했다.

[2014-06-11 09:59:30.319]     -- Executing [s@SetCalledIDNum:15] Set("SIP/200-ipvstk-softphone-1-000000f7", "ChannelB=") in new stack
[2014-06-11 09:59:30.319]     -- Executing [s@SetCalledIDNum:16] Return("SIP/200-ipvstk-softphone-1-000000f7", "") in new stack
[2014-06-11 09:59:30.320]     -- Executing [s@app_dial_gosub_virtual_context:1] NoOp("SIP/200-ipvstk-softphone-1-000000f7", "") in new stack
[2014-06-11 09:59:30.320]     -- Auto fallthrough, channel 'SIP/200-ipvstk-softphone-1-000000f7' status is 'UNKNOWN'
[2014-06-11 09:59:30.322]     -- Local/200-ipvstk-softphone-1@DialLine-5336;1 answered Local/200@DialAccount-d00c;2
[2014-06-11 09:59:30.328] WARNING[11975]: res_rtp_asterisk.c:2142 ast_rtp_read: RTP Read too short
[2014-06-11 09:59:30.328]     -- Local/200@DialAccount-d00c;1 answered Local/200@DuetNumber-ee9e;2
[2014-06-11 09:59:30.330]     -- Local/200@DuetNumber-ee9e;1 answered SIP/voicemail01-000000f6
[2014-06-11 09:59:40.670]   == Spawn extension (VoiceMailMain, s, 14) exited non-zero on 'SIP/201-ipvstk-softphone-2-000000f4'

Asterisk 서버로 Make Call 을 시도하여 이미 연결되어 있는 기존의 콜과 새로 생성한 콜을 서로 Bridge 시키는 간단한 연동작업이었는데… Make call 시도시, 위의 에러가 발생한 것이다.
문제의 라인은

[2014-06-11 09:59:30.320]     -- Auto fallthrough, channel 'SIP/200-ipvstk-softphone-1-000000f7' status is 'UNKNOWN'

부분으로, Status 를 확인할 수 없다는 내용이다.
이후, 새로 생성한 콜과  기존의 콜은 Bridge 가 정상적으로 되는 것 처럼 보이나, 10 초 뒤, 갑자기 콜이 Hangup 되는 현상이 발생한다.

구글 검색 후, Auto fallthrough 는 더이상 해당 Extension 에 대한 Dailplan 이 없을 때, 자동으로 실행되는 Context 라는 것을 확인했다.

 

참조: http://forums.whirlpool.net.au/archive/885099

[Freeswitch] python-originate

Freeswitch 에서 python 으로 dialplan 작성시,.. originate 를 해야 하는 경우.

from freeswitch import *

new_session = Session(sofia/profile_name/call_to@host_ip)

만약 콜 생성을 하면서 (INVITE) 시, 특정 옵션 값들을 입력하고 싶다면..

{sip_h_TestOpt=test}sofia/internal/200@pchero21.com

과 같이 sofia 앞부분에 “{}” 를 넣어서 입력하고자 하는 값들을 입력하면 된다.

 

출처 : http://lists.freeswitch.org/pipermail/freeswitch-users/2011-March/070126.html