Skip to content

Commit 92c0748

Browse files
committed
Land rapid7#8102, Add a plugin to notify new sessions via SMS
2 parents e04f01e + 3c18b19 commit 92c0748

File tree

9 files changed

+388
-8
lines changed

9 files changed

+388
-8
lines changed

documentation/modules/auxiliary/client/sms/send_text.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ Remember that these phone numbers must be the same carrier.
2323
The carrier that the targeted numbers use. See **Supported Carrier Gateways** to learn more about
2424
supported carriers.
2525

26+
**SMSSUBJECT**
27+
28+
The text subject.
29+
2630
**SMSMESSAGE**
2731

2832
The text message you want to send. For example, this will send a text with a link to google:

lib/msf/core/auxiliary/sms.rb

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ def initialize(info={})
2222
OptString.new('SMTPPASSWORD', [true, 'The SMTP password to use to send the text messages']),
2323
OptEnum.new('SMSCARRIER', [true, 'The targeted SMS service provider', nil,Rex::Proto::Sms::Model::GATEWAYS.keys.collect { |k| k.to_s }]),
2424
OptString.new('CELLNUMBERS', [true, 'The phone numbers to send to']),
25-
OptString.new('SMSMESSAGE', [true, 'The text message to send'])
25+
OptString.new('SMSMESSAGE', [true, 'The text message to send']),
26+
OptString.new('SMSSUBJECT', [false, 'The text subject', ''])
2627
], Auxiliary::Sms)
2728

2829
register_advanced_options(
@@ -42,10 +43,11 @@ def initialize(info={})
4243
# sms.send_text_to_phones(numbers, 'Hello from Gmail')
4344
#
4445
# @param phone_numbers [<String>Array] An array of numbers of try (of the same carrier)
46+
# @param subject [String] The text subject
4547
# @param message [String] The text to send.
4648
#
4749
# @return [void]
48-
def send_text(phone_numbers, message)
50+
def send_text(phone_numbers, subject, message)
4951
smtp = Rex::Proto::Sms::Model::Smtp.new(
5052
address: datastore['SMTPADDRESS'],
5153
port: datastore['SMTPPORT'],
@@ -57,7 +59,7 @@ def send_text(phone_numbers, message)
5759

5860
carrier = datastore['SMSCARRIER'].to_sym
5961
sms = Rex::Proto::Sms::Client.new(carrier: carrier, smtp_server: smtp)
60-
sms.send_text_to_phones(phone_numbers, message)
62+
sms.send_text_to_phones(phone_numbers, subject, message)
6163
end
6264

6365
end

lib/rex/proto/sms/client.rb

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,11 @@ def initialize(opts={})
3232
# Sends a text to multiple recipients.
3333
#
3434
# @param phone_numbers [<String>Array] An array of phone numbers.
35+
# @param subject [String] Subject of the message
3536
# @param message [String] The text message to send.
3637
#
3738
# @return [void]
38-
def send_text_to_phones(phone_numbers, message)
39+
def send_text_to_phones(phone_numbers, subject, message)
3940
carrier = Rex::Proto::Sms::Model::GATEWAYS[self.carrier]
4041
recipients = phone_numbers.collect { |p| "#{p}@#{carrier}" }
4142
address = self.smtp_server.address
@@ -52,7 +53,13 @@ def send_text_to_phones(phone_numbers, message)
5253
smtp.enable_starttls_auto
5354
smtp.start(helo_domain, username, password, login_type) do
5455
recipients.each do |r|
55-
smtp.send_message(message, from, r)
56+
sms_message = Rex::Proto::Sms::Model::Message.new(
57+
from: from,
58+
to: r,
59+
subject: subject,
60+
message: message
61+
)
62+
smtp.send_message(sms_message.to_s, from, r)
5663
end
5764
end
5865
rescue Net::SMTPAuthenticationError => e

lib/rex/proto/sms/model.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,4 +28,5 @@ module Model
2828

2929
require 'net/smtp'
3030
require 'rex/proto/sms/model/smtp'
31+
require 'rex/proto/sms/model/message'
3132
require 'rex/proto/sms/client'

lib/rex/proto/sms/model/message.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# -*- coding: binary -*-
2+
3+
module Rex
4+
module Proto
5+
module Sms
6+
module Model
7+
class Message
8+
9+
# @!attribute message
10+
# @return [String] The text message
11+
attr_accessor :message
12+
13+
14+
# @!attribute from
15+
# @return [String] The from field in the email
16+
attr_accessor :from
17+
18+
# @!attribute to
19+
# @return [String] The to field in the email
20+
attr_accessor :to
21+
22+
# @!attribute subject
23+
# @return [String] The subject of the email
24+
attr_accessor :subject
25+
26+
27+
# Initializes the SMTP object.
28+
#
29+
# @param [Hash] opts
30+
# @option opts [String] :from
31+
# @option opts [String] :to
32+
# @option opts [String] :message
33+
#
34+
# @return [Rex::Proto::Sms::Model::Message]
35+
def initialize(opts={})
36+
self.from = opts[:from]
37+
self.to = opts[:to]
38+
self.message = opts[:message]
39+
self.subject = opts[:subject]
40+
end
41+
42+
43+
# Returns the raw SMS message
44+
#
45+
# @return [String]
46+
def to_s
47+
body = Rex::MIME::Message.new
48+
body.add_part(self.message, 'text/plain; charset=UTF-8', nil)
49+
50+
sms = "MIME-Version: 1.0\n"
51+
sms << "From: #{self.from}\n"
52+
sms << "To: #{self.to}\n"
53+
sms << "Subject: #{self.subject}\n"
54+
sms << "Content-Type: multipart/alternative; boundary=#{body.bound}\n"
55+
sms << "\n"
56+
sms << body.to_s
57+
58+
sms
59+
end
60+
61+
end
62+
end
63+
end
64+
end
65+
end

modules/auxiliary/client/sms/send_text.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def run
2828
phone_numbers = datastore['CELLNUMBERS'].split
2929
print_status("Sending text (#{datastore['SMSMESSAGE'].length} bytes) to #{phone_numbers.length} number(s)...")
3030
begin
31-
res = send_text(phone_numbers, datastore['SMSMESSAGE'])
31+
res = send_text(phone_numbers, datastore['SMSSUBJECT'], datastore['SMSMESSAGE'])
3232
print_status("Done.")
3333
rescue Rex::Proto::Sms::Exception => e
3434
print_error(e.message)

0 commit comments

Comments
 (0)