CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/mms/client.rb
Views: 11704
1
# -*- coding: binary -*-
2
3
module Rex
4
module Proto
5
module Mms
6
class Client
7
8
# @!attribute carrier
9
# @return [Symbol] The service provider for the phone numbers.
10
attr_accessor :carrier
11
12
# @!attribute smtp_server
13
# @return [Rex::Proto::Mms::Model::Smtp] The Smtp object with the Smtp settings.
14
attr_accessor :smtp_server
15
16
17
# Initializes the Client object.
18
#
19
# @param [Hash] opts
20
# @option opts [Symbol] Service provider name (see Rex::Proto::Mms::Model::GATEWAYS)
21
# @option opts [Rex::Proto::mms::Model::Smtp] SMTP object
22
#
23
# @return [Rex::Proto::Mms::Client]
24
def initialize(opts={})
25
self.carrier = opts[:carrier]
26
self.smtp_server = opts[:smtp_server]
27
28
validate_carrier!
29
end
30
31
32
# Sends a media text to multiple recipients.
33
#
34
# @param phone_numbers [<String>Array] An array of phone numbers.
35
# @param subject [String] MMS subject
36
# @param message [String] The message to send.
37
# @param attachment_path [String] (Optional) The attachment to include
38
# @param ctype [String] (Optional) The content type to use for the attachment
39
#
40
# @return [void]
41
def send_mms_to_phones(phone_numbers, subject, message, attachment_path=nil, ctype=nil)
42
carrier = Rex::Proto::Mms::Model::GATEWAYS[self.carrier]
43
recipients = phone_numbers.collect { |p| "#{p}@#{carrier}" }
44
address = self.smtp_server.address
45
port = self.smtp_server.port
46
username = self.smtp_server.username
47
password = self.smtp_server.password
48
helo_domain = self.smtp_server.helo_domain
49
login_type = self.smtp_server.login_type
50
from = self.smtp_server.from
51
52
smtp = Net::SMTP.new(address, port)
53
54
begin
55
smtp.enable_starttls_auto
56
smtp.start(helo_domain, username, password, login_type) do
57
recipients.each do |r|
58
mms_message = Rex::Proto::Mms::Model::Message.new(
59
message: message,
60
content_type: ctype,
61
attachment_path: attachment_path,
62
from: from,
63
to: r,
64
subject: subject
65
)
66
smtp.send_message(mms_message.to_s, from, r)
67
end
68
end
69
rescue Net::SMTPAuthenticationError => e
70
raise Rex::Proto::Mms::Exception, e.message
71
ensure
72
smtp.finish if smtp && smtp.started?
73
end
74
end
75
76
77
# Validates the carrier parameter.
78
#
79
# @raise [Rex::Proto::Mms::Exception] If an invalid service provider is used.
80
def validate_carrier!
81
unless Rex::Proto::Mms::Model::GATEWAYS.include?(self.carrier)
82
raise Rex::Proto::Mms::Exception, 'Invalid carrier.'
83
end
84
end
85
86
end
87
end
88
end
89
end
90
91