GoRuCo talk: Pwning your phone with Arhearsion and Asterisk

Presented by Jay Phillips

  • Ruby is more than a language for building websites

Past & Today

  • Started playing with extending Asterisk, ended up with Adhearsion
  • Got into Rails, rewrote Adhearsion from scratch
  • Released Adhearsion last Christmas
  • Writing a section on Adhearsion for the next O’Reilly Asterisk book

Adhearsion in a nutshell

  • More of a collaboration framework than an “Asterisk development framework”
  • Asterisk is a good way to do VOIP
  • Adhearsion is a good way to do Asterisk development
  • Adhearsion is open source software
  • Adhearsion attempts not to loose any Asterisk functionality

Why VoIP Rocks

  • Being a hacker rocks… and you can hack VoIP
  • VoIP can allow you to cut business expenses
  • Now you can use Ruby!

Fun VoIP Projects

  • Unlock your apartment door with your cell phone (with voice authentication)
  • Control your hacked Xbox Media Center with a cell phone
  • Rarely have to pay for a phone call
  • Crazy phone-based reminder system
  • Control anything with voice commands
  • Phone-controlled Roomba

What is Asterisk?

  • Open source phone call manager (PBX)
  • Revolutionized the telecom world forever
  • Makes hackers really happy
  • Makes cash flow statements really happy
  • Does everything you could want with a phone

Existing Asterisk Control Grammars Suck At…

  • Conditional looping and branching
  • Variables
  • Complex data structures
  • Database/LDAP integration
  • etc.

Old Dialplan Example

  • Looks like mutated BASIC and Perl hell
  • GOTO statements FTW

Why use Adhearsion?

  • Breaks down barrier of entry to Asterisk
  • Grammar feels like assembler or Excel
  • Adds many new features to your PBX
  • Adhearsion dramatically improves Asterisk
  • Database integration with ActiveRecord
  • Integrate Rails and VoIP!

Other Aspects of Adhearsion

  • Helper system for extending Asterisk framework
  • One of the first times VoIP code can be traded
  • Integrates with on-phone micro-browsers (via subframework Micromenus)
  • Use other collaboration technologies together (AIM, email, SMS, etc.)
  • Instant messaging, Growl, weather, reverse number lookup, etc.

Getting Started with Adhearsion

Asterisk?! Isn’t that hard to install?

  • NO! Use Digium’s AsteriskNOW Linux distro
  • Available on Live CD, VMWare and Xen
  • Installed and running when booted
  • Asterisk 1.4 has a web GUI
  • Many good resources
  • Works with Adhearsion

Installing Adhearsion

  • gem install adhearsion

Writing Adhearsion Dialplans

  • Dialplans – ways to process phone calls
1
2
3
internal {
  loop { play 'hello-world' }
}
  • Including other contexts:
1
2
3
4
5
6
7
8
9
internal {
  +foo
}

foo {
  record {
    dial SIP/:out_trunk/1234
  }
}
  • Above code is Ruby – overloading operators
  • SIP is session initiating protocol – lets you make calls
  • Another example:
1
2
3
4
5
internal {
  play %w"a-connect-charge-of
          16 cents-per-minute
          will-apply"
}
  • Adhearsion unifies API for playing numbers and other sounds
1
2
3
4
5
6
7
8
9
10
11
12
13
14
internal {
  case extension
    when 10...100
      dial SIP/extension  # transfer
    when 6000...6820
      join extension      # join conf call
      
    when _"21XX"
      
      if Time.now.hour.between? 2, 10
        dial SIP/"berlin-office"/extension[2..4]
      else speak "It is not business hours now in Germany"
      end
}
  • #_() is a method that converts String to Regex

Database-Driven Dialplans

1
2
3
4
5
6
7
8
9
10
11
service {
  customer = Account.find_by_phone_number callerid
  usage = customer.usage_this_month
  
  if usage >= 100 then +beyond_limit
  else
    customer.usage_this_month += time do
      dial IAX2/"main-trunk"/extension
    end
  end
}
  • #time method times execution of a block and returns the result

How Does Adhearsion Talk to Asterisk?

  • Asterisk receives a call normally
  • Asterisk connects to Adhearsion via socket and sends all call info
  • Ashearsion evaluates dialplan, executes appropriate context

Things You Can Do From Rails

  • Invoke virtually any PBX event with Adhearsion’s sexy syntax
    • Uses DRb
    • Start calls, view live channels, record channel
  • Share Adhearsion’s ActiveRecord models
    • Manage users, groups, etc.
  • Use your imagination!

What’s a helper?

  • Code loaded when Adhearsion boots
  • Introduce a technology to the framework
  • Can do virtually everything
  • Can be written in Ruby, C, Java (JRuby)

Micromenus

  • Many modern phones have micro-browsers
  • Use custom XML schema over HTTP
  • Use a Ruby DSL to generate
  • Mini-web app framework
  • Also viewable in a web browser!
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
item "Adhearsion Server Statistics" do
  item "View Registered SIP users" do
    PBX.sip_users.each do |u|
      item "SIP user #{u.uername} on IP #{u.ip}"
    end
  end
  
  item "View System Uptime" do
    item `uptime`
  end
  
  item "Network" do
    heading "Network Interface condig" do
      ...
    end
  end
end
1
2
3
4
5
6
item "Call an Employee" do
  item "Select an employee below."
  User.find(:all).each do |user|
    ...
  end
end

...And then my laptop battery died…

Get Involved

Q & A

3 Responses to “GoRuCo talk: Pwning your phone with Arhearsion and Asterisk”

  1. # Ralph Reid Says:

    Jay’s email address is mispelled! codemecca

  2. # Jay Phillips Says:

    Hehe, it’s mispelled, but that may be a good thing. Bryan, can you please change it to be “jay at codemecca.com” (or the like) to keep the spammers away?

    Thanks for the coverage! (by the way, I recommend giving it a read over once more. There’re several other typos).

    :)

  3. # Bryan Helmkamp Says:

    Ralph—Fixed.

    Jay—Done. Thanks.