Module: Msf::DBManager::Payload

Included in:
Msf::DBManager
Defined in:
lib/msf/core/db_manager/payload.rb

Instance Method Summary collapse

Instance Method Details

#create_payload(opts) ⇒ Object


3
4
5
6
7
8
9
10
11
12
13
# File 'lib/msf/core/db_manager/payload.rb', line 3

def create_payload(opts)
  ::ApplicationRecord.connection_pool.with_connection do
    if opts[:uuid] && !opts[:uuid].to_s.empty?
      if Mdm::Payload.find_by(uuid: opts[:uuid])
        raise ArgumentError.new("A payload with this uuid already exists.")
      end
    end

    Mdm::Payload.create!(opts)
  end
end

#delete_payload(opts) ⇒ Object

Raises:

  • (ArgumentError)

37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/msf/core/db_manager/payload.rb', line 37

def delete_payload(opts)
  raise ArgumentError.new("The following options are required: :ids") if opts[:ids].nil?

  ::ApplicationRecord.connection_pool.with_connection do
    deleted = []
    opts[:ids].each do |payload_id|
      payload = Mdm::Payload.find(payload_id)
      begin
        deleted << payload.destroy
      rescue
        elog("Forcibly deleting #{payload}")
        deleted << payload.delete
      end
    end

    return deleted
  end
end

#get_payload(opts) ⇒ Object

Raises:

  • (ArgumentError)

56
57
58
59
60
61
62
63
# File 'lib/msf/core/db_manager/payload.rb', line 56

def get_payload(opts)
  raise ArgumentError.new("The following options are required: :uuid") if opts[:uuid].nil?

  ::ApplicationRecord.connection_pool.with_connection do
    return Mdm::Payload.find_by(uuid: opts[:uuid])
  end

end

#payloads(opts) ⇒ Object


15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/msf/core/db_manager/payload.rb', line 15

def payloads(opts)
  ::ApplicationRecord.connection_pool.with_connection do
    if opts[:id] && !opts[:id].to_s.empty?
      return Array.wrap(Mdm::Payload.find(opts[:id]))
    else
      # Check the database for a matching UUID, returning an empty array if no results are found
      begin
        return Array.wrap(Mdm::Payload.where(uuid: opts[:uuid]))
      rescue ActiveRecord::RecordNotFound
        return []
      end
    end
  end
end

#update_payload(opts) ⇒ Object


30
31
32
33
34
35
# File 'lib/msf/core/db_manager/payload.rb', line 30

def update_payload(opts)
  ::ApplicationRecord.connection_pool.with_connection do
    id = opts.delete(:id)
    Mdm::Payload.update(id, opts)
  end
end