2009-01-11 06:09:02 +00:00
|
|
|
module Msf
|
|
|
|
|
|
|
|
module Exploit::Remote::Dialup
|
|
|
|
|
|
|
|
def initialize(info = {})
|
|
|
|
super
|
|
|
|
|
|
|
|
register_options(
|
|
|
|
[
|
2009-01-11 17:30:26 +00:00
|
|
|
OptInt.new( 'BAUDRATE', [true, 'Baud Rate', 19200]),
|
|
|
|
OptEnum.new( 'DATABITS', [true, 'Data Bits (4 is Windows Only)', '8', ['4', '5', '6', '7', '8'], '8']),
|
|
|
|
OptString.new('DIALPREFIX', [true, 'Dial Prefix', 'ATDT *67, *70,']),
|
|
|
|
OptString.new('DIALSUFFIX', [false, 'Dial Suffix', nil]),
|
|
|
|
OptInt.new( 'DIALTIMEOUT', [true, 'Dial Timeout in seconds', 60]),
|
|
|
|
OptBool.new( 'DISPLAYMODEM', [true, 'Displays modem commands and responses on the console', false]),
|
|
|
|
OptEnum.new( 'FLOWCONTROL', [true, 'Flow Control', 'None', ['None', 'Hardware', 'Software', 'Both'], 'None']),
|
|
|
|
OptString.new('INITSTRING', [true, 'Initialization String', 'AT X6 S11=80']),
|
|
|
|
OptString.new('NUMBER', [true, 'Number to Dial (e.g. 1.800.950.9955, (202) 358-1234, 358.1234 etc.)', nil]),
|
|
|
|
OptEnum.new( 'PARITY', [true, 'Parity (Mark & Space are Windows Only)', 'None', ['None', 'Even', 'Odd', 'Mark', 'Space'], 'None']),
|
|
|
|
OptString.new('SERIALPORT', [true, 'Serial Port (e.g. 0 (COM1), 1 (COM2), /dev/ttyS0, etc.)', '/dev/ttyS0']),
|
|
|
|
OptEnum.new( 'STOPBITS', [true, 'Stop Bits', '1', ['1', '2'], '1']),
|
2009-01-11 06:09:02 +00:00
|
|
|
], self.class)
|
|
|
|
|
|
|
|
deregister_options('RHOST')
|
2009-01-11 17:30:26 +00:00
|
|
|
|
|
|
|
begin
|
|
|
|
require 'telephony'
|
|
|
|
@telephony_loaded = true
|
|
|
|
rescue ::Exception => e
|
|
|
|
@telephony_loaded = false
|
|
|
|
@telephony_error = e
|
|
|
|
end
|
2009-01-11 06:09:02 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Opens the modem connection
|
|
|
|
def connect_dialup(global = true, opts={})
|
2009-01-11 17:30:26 +00:00
|
|
|
|
|
|
|
if (not @telephony_loaded)
|
|
|
|
print_status("The serialport module is not available: #{telephony_error}")
|
|
|
|
raise RuntimeError, "Telephony not available"
|
|
|
|
end
|
|
|
|
|
2009-01-11 06:09:02 +00:00
|
|
|
serialport = datastore['SERIALPORT']
|
|
|
|
baud = datastore['BAUDRATE'].to_i
|
|
|
|
data_bits = datastore['DATABITS'].to_i
|
|
|
|
stop_bits = datastore['STOPBITS'].to_i
|
|
|
|
parity = case datastore['PARITY']
|
2009-03-07 18:18:38 +00:00
|
|
|
when 'Even' ; Telephony::Modem::EVEN
|
|
|
|
when 'Odd' ; Telephony::Modem::ODD
|
|
|
|
when 'Mark' ; Telephony::Modem::MARK
|
|
|
|
when 'Space'; Telephony::Modem::SPACE
|
2009-01-11 07:45:08 +00:00
|
|
|
else Telephony::Modem::NONE
|
2009-01-11 07:23:43 +00:00
|
|
|
end
|
|
|
|
flowcontrol = case datastore['FLOWCONTROL']
|
2009-03-07 18:18:38 +00:00
|
|
|
when 'Hardware' ; Telephony::Modem::HARD
|
|
|
|
when 'Software' ; Telephony::Modem::SOFT
|
|
|
|
when 'Both' ; Telephony::Modem::HARD | Telephony::Modem::SOFT
|
2009-01-11 07:45:08 +00:00
|
|
|
else Telephony::Modem::NONE
|
2009-01-11 06:09:02 +00:00
|
|
|
end
|
2009-01-13 07:08:40 +00:00
|
|
|
|
2009-01-11 06:09:02 +00:00
|
|
|
initstring = datastore['INITSTRING']
|
|
|
|
dialprefix = datastore['DIALPREFIX']
|
|
|
|
dialsuffix = datastore['DIALSUFFIX']
|
|
|
|
dialtimeout = datastore['DIALTIMEOUT'].to_i
|
2009-01-11 17:30:26 +00:00
|
|
|
number = datastore['NUMBER'].tr(' ', '')
|
2009-01-11 06:09:02 +00:00
|
|
|
|
|
|
|
modem = Telephony::Modem.new(serialport)
|
|
|
|
modem.params = {
|
|
|
|
'baud' => baud,
|
|
|
|
'data_bits' => data_bits,
|
|
|
|
'parity' => parity,
|
|
|
|
'stop_bits' => stop_bits
|
|
|
|
}
|
2009-01-11 07:23:43 +00:00
|
|
|
modem.flow_control = flowcontrol
|
2009-01-11 06:09:02 +00:00
|
|
|
modem.display = datastore['DISPLAYMODEM']
|
|
|
|
|
|
|
|
print_status("Initializing Modem")
|
|
|
|
result = modem.put_command('ATZ', 3)
|
|
|
|
if result != 'OK'
|
|
|
|
print_error("Error resetting modem")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
result = modem.put_command(initstring, 3)
|
|
|
|
if result != 'OK'
|
|
|
|
print_error("Error initializing modem")
|
|
|
|
return
|
|
|
|
end
|
|
|
|
|
|
|
|
print_status("Dialing: #{number} (#{dialtimeout} sec. timeout)")
|
|
|
|
dialstring = dialprefix + ' ' + number
|
|
|
|
dialstring += (' ' + dialsuffix) if dialsuffix
|
|
|
|
|
|
|
|
time = Time.now
|
|
|
|
result = modem.put_command(dialstring, dialtimeout)
|
|
|
|
while result =~ /RINGING/i
|
|
|
|
result = modem.get_response(dialtimeout-(Time.now-time))
|
|
|
|
end
|
|
|
|
|
|
|
|
case result
|
2009-03-07 18:18:38 +00:00
|
|
|
when /CONNECT/i
|
2009-01-11 06:09:02 +00:00
|
|
|
print_status("Carrier: #{result}" )
|
2009-01-13 07:08:40 +00:00
|
|
|
self.modem = modem if global
|
2009-01-11 06:09:02 +00:00
|
|
|
return modem
|
|
|
|
else
|
|
|
|
#print_error("No Carrier")
|
|
|
|
disconnect_dialup(modem)
|
|
|
|
return nil
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# Closes the modem connection
|
2009-01-13 07:08:40 +00:00
|
|
|
def disconnect_dialup(nmodem = self.modem)
|
|
|
|
if(nmodem)
|
|
|
|
nmodem.hangup
|
|
|
|
nmodem.close
|
|
|
|
end
|
2009-01-11 06:09:02 +00:00
|
|
|
end
|
|
|
|
|
2009-01-28 06:13:47 +00:00
|
|
|
def dialup_expect(regexp, timeout)
|
|
|
|
return false if ! self.modem
|
|
|
|
buff = ''
|
|
|
|
|
|
|
|
time = Time.now
|
|
|
|
while Time.now < time + timeout
|
|
|
|
c = self.modem.getc
|
|
|
|
buff =+ c.chr if c
|
|
|
|
return true if buff.match(regexp) != nil
|
|
|
|
end
|
|
|
|
|
|
|
|
return false
|
|
|
|
end
|
|
|
|
|
|
|
|
def dialup_send(string)
|
|
|
|
return false if ! self.modem
|
|
|
|
self.modem.puts string
|
|
|
|
return true
|
|
|
|
end
|
|
|
|
|
2009-01-13 07:08:40 +00:00
|
|
|
def handler(nmodem = self.modem)
|
|
|
|
# If the handler claims the modem, then we don't want it to get closed
|
|
|
|
# during cleanup
|
|
|
|
if ((rv = super) == Handler::Claimed)
|
|
|
|
if (nmodem == self.modem)
|
|
|
|
self.modem = nil
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return rv
|
|
|
|
end
|
|
|
|
|
|
|
|
attr_accessor :modem
|
|
|
|
|
2009-01-11 06:09:02 +00:00
|
|
|
end
|
|
|
|
end
|