Module: Msf::DBManager::WMAP

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

Overview

Note:

Wmap is a plugin and so these methods, that are only meant for that plugin, should not be part of the core library.

Instance Method Summary collapse

Instance Method Details

#create_request(host, port, ssl, meth, path, headers, query, body, respcode, resphead, response) ⇒ Object

Create a request (by hand)


5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/msf/core/db_manager/wmap.rb', line 5

def create_request(host,port,ssl,meth,path,headers,query,body,respcode,resphead,response)
::ApplicationRecord.connection_pool.with_connection {
  req = ::Mdm::WmapRequest.create(
      :host => host,
      :address => host,
      :port => port,
      :ssl => ssl,
      :meth => meth,
      :path => path,
      :headers => headers,
      :query => query,
      :body => body,
      :respcode => respcode,
      :resphead => resphead,
      :response => response
    )
  #framework.events.on_db_request(rec)
}
end

#create_target(host, port, ssl, sel) ⇒ Object

Create a target


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/msf/core/db_manager/wmap.rb', line 26

def create_target(host,port,ssl,sel)
::ApplicationRecord.connection_pool.with_connection {
  tar = ::Mdm::WmapTarget.create(
      :host => host,
      :address => host,
      :port => port,
      :ssl => ssl,
      :selected => sel
    )
  #framework.events.on_db_target(rec)
}
end

#delete_all_targetsObject

This methods deletes all targets from targets table in the database


40
41
42
43
44
# File 'lib/msf/core/db_manager/wmap.rb', line 40

def delete_all_targets
::ApplicationRecord.connection_pool.with_connection {
  ::Mdm::WmapTarget.delete_all
}
end

#each_distinct_target(&block) ⇒ Object

This method iterates the requests table identifying possible targets This method will be removed on second phase of db merging.


48
49
50
51
52
# File 'lib/msf/core/db_manager/wmap.rb', line 48

def each_distinct_target(&block)
  request_distinct_targets.each do |target|
    block.call(target)
  end
end

#each_request(&block) ⇒ Object

This method iterates the requests table calling the supplied block with the request instance of each entry.


56
57
58
59
60
# File 'lib/msf/core/db_manager/wmap.rb', line 56

def each_request(&block)
  requests.each do |request|
    block.call(request)
  end
end

#each_request_target(&block) ⇒ Object

This method iterates the requests table returning a list of all requests of a specific target


63
64
65
66
67
# File 'lib/msf/core/db_manager/wmap.rb', line 63

def each_request_target(&block)
  target_requests('').each do |req|
    block.call(req)
  end
end

#each_request_target_with_body(&block) ⇒ Object

This method iterates the requests table returning a list of all requests of a specific target


70
71
72
73
74
# File 'lib/msf/core/db_manager/wmap.rb', line 70

def each_request_target_with_body(&block)
  target_requests('AND wmap_requests.body IS NOT NULL').each do |req|
    block.call(req)
  end
end

#each_request_target_with_headers(&block) ⇒ Object

This method iterates the requests table returning a list of all requests of a specific target


77
78
79
80
81
# File 'lib/msf/core/db_manager/wmap.rb', line 77

def each_request_target_with_headers(&block)
  target_requests('AND wmap_requests.headers IS NOT NULL').each do |req|
    block.call(req)
  end
end

#each_request_target_with_path(&block) ⇒ Object

This method iterates the requests table returning a list of all requests of a specific target


84
85
86
87
88
# File 'lib/msf/core/db_manager/wmap.rb', line 84

def each_request_target_with_path(&block)
  target_requests('AND wmap_requests.path IS NOT NULL').each do |req|
    block.call(req)
  end
end

#each_request_target_with_query(&block) ⇒ Object

This method iterates the requests table returning a list of all requests of a specific target


91
92
93
94
95
# File 'lib/msf/core/db_manager/wmap.rb', line 91

def each_request_target_with_query(&block)
  target_requests('AND wmap_requests.query IS NOT NULL').each do |req|
    block.call(req)
  end
end

#each_target(&block) ⇒ Object

This method iterates the targets table calling the supplied block with the target instance of each entry.


99
100
101
102
103
# File 'lib/msf/core/db_manager/wmap.rb', line 99

def each_target(&block)
  targets.each do |target|
    block.call(target)
  end
end

#get_target(id) ⇒ Object

Find a target matching this id


106
107
108
109
110
111
# File 'lib/msf/core/db_manager/wmap.rb', line 106

def get_target(id)
::ApplicationRecord.connection_pool.with_connection {
  target = ::Mdm::WmapTarget.where("id = ?", id).first()
  return target
}
end

#request_distinct_targetsObject

This method returns a list of all possible targets available in requests This method will be removed on second phase of db merging.


115
116
117
118
119
# File 'lib/msf/core/db_manager/wmap.rb', line 115

def request_distinct_targets
::ApplicationRecord.connection_pool.with_connection {
  ::Mdm::WmapRequest.select('DISTINCT host,address,port,ssl')
}
end

#request_sql(host, port, extra_condition) ⇒ Object

This method allows to query directly the requests table. To be used mainly by modules


122
123
124
125
126
# File 'lib/msf/core/db_manager/wmap.rb', line 122

def request_sql(host,port,extra_condition)
::ApplicationRecord.connection_pool.with_connection {
  ::Mdm::WmapRequest.where("wmap_requests.host = ? AND wmap_requests.port = ? #{extra_condition}", host , port)
}
end

#requestsObject

This methods returns a list of all targets in the database


129
130
131
132
133
# File 'lib/msf/core/db_manager/wmap.rb', line 129

def requests
::ApplicationRecord.connection_pool.with_connection {
  ::Mdm::WmapRequest.all
}
end

#selected_hostObject

Selected host


136
137
138
139
140
141
142
143
144
145
# File 'lib/msf/core/db_manager/wmap.rb', line 136

def selected_host
::ApplicationRecord.connection_pool.with_connection {
  selhost = ::Mdm::WmapTarget.where("selected != 0").first()
  if selhost
    return selhost.host
  else
    return
  end
}
end

#selected_idObject

Selected id


148
149
150
# File 'lib/msf/core/db_manager/wmap.rb', line 148

def selected_id
  selected_wmap_target.object_id
end

#selected_portObject

Selected port


153
154
155
# File 'lib/msf/core/db_manager/wmap.rb', line 153

def selected_port
  selected_wmap_target.port
end

#selected_sslObject

Selected ssl


158
159
160
# File 'lib/msf/core/db_manager/wmap.rb', line 158

def selected_ssl
  selected_wmap_target.ssl
end

#selected_wmap_targetObject

Selected target


163
164
165
166
167
# File 'lib/msf/core/db_manager/wmap.rb', line 163

def selected_wmap_target
::ApplicationRecord.connection_pool.with_connection {
  ::Mdm::WmapTarget.find.where("selected != 0")
}
end

#sql_query(sqlquery) ⇒ Object

Quick way to query the database (used by wmap_sql)


170
171
172
173
174
# File 'lib/msf/core/db_manager/wmap.rb', line 170

def sql_query(sqlquery)
::ApplicationRecord.connection_pool.with_connection {
  ApplicationRecord.connection.select_all(sqlquery)
}
end

#target_requests(extra_condition) ⇒ Object

This method returns a list of all requests from target


177
178
179
180
181
# File 'lib/msf/core/db_manager/wmap.rb', line 177

def target_requests(extra_condition)
::ApplicationRecord.connection_pool.with_connection {
  ::Mdm::WmapRequest.where("wmap_requests.host = ? AND wmap_requests.port = ? #{extra_condition}",selected_host,selected_port)
}
end

#targetsObject

This methods returns a list of all targets in the database


184
185
186
187
188
# File 'lib/msf/core/db_manager/wmap.rb', line 184

def targets
::ApplicationRecord.connection_pool.with_connection {
  ::Mdm::WmapTarget.all
}
end