Class: Msf::RPC::RPC_Db
- Includes:
- Metasploit::Credential::Creation
- Defined in:
- lib/msf/core/rpc/v10/rpc_db.rb
Instance Attribute Summary
Attributes inherited from RPC_Base
#framework, #job_status_tracker, #service, #tokens, #users
Instance Method Summary collapse
-
#rpc_add_workspace(wspace) ⇒ Hash
Adds a new workspace.
-
#rpc_analyze_host(xopts) ⇒ Hash
Returns analysis of module suggestions for known data about a host.
-
#rpc_clients(xopts) ⇒ Hash
Returns browser clients information.
-
#rpc_connect(xopts) ⇒ Hash
Connects to the database.
-
#rpc_create_cracked_credential(xopts) ⇒ Metasploit::Credential::Core
Creates a cracked credential.
-
#rpc_create_credential(xopts) ⇒ Hash
Creates a credential.
-
#rpc_creds(xopts) ⇒ Hash
Returns login credentials from a specific workspace.
-
#rpc_current_workspace ⇒ Hash
Returns the current workspace.
-
#rpc_del_client(xopts) ⇒ Hash
Deletes browser information from a client.
-
#rpc_del_creds(xopts) ⇒ Hash
Delete credentials from a specific workspace.
-
#rpc_del_host(xopts) ⇒ Hash
Deletes hosts.
-
#rpc_del_note(xopts) ⇒ Hash
Deletes notes.
-
#rpc_del_service(xopts) ⇒ Hash
Deletes services.
-
#rpc_del_vuln(xopts) ⇒ Hash
Deletes vulnerabilities.
-
#rpc_del_workspace(wspace) ⇒ Hash
Deletes a workspace.
-
#rpc_disconnect ⇒ Hash
Disconnects the database.
-
#rpc_driver(xopts) ⇒ Hash
Sets the driver for the database or returns the current one.
-
#rpc_events(xopts) ⇒ Hash
Returns framework events.
-
#rpc_get_client(xopts) ⇒ Hash
Returns information about a client connection.
-
#rpc_get_host(xopts) ⇒ Hash
Returns information about a host.
-
#rpc_get_note(xopts) ⇒ Hash
Returns a note.
-
#rpc_get_ref(name) ⇒ String
Returns an external vulnerability reference.
-
#rpc_get_service(xopts) ⇒ Hash
Returns information about a service.
-
#rpc_get_vuln(xopts) ⇒ Hash
Returns vulnerabilities from services or from a host.
-
#rpc_get_workspace(wspace) ⇒ Hash
Returns the current workspace.
-
#rpc_hosts(xopts) ⇒ Hash
Returns information about hosts.
-
#rpc_import_data(xopts) ⇒ Hash
Imports file to the database.
-
#rpc_invalidate_login(xopts) ⇒ void
Sets the status of a login credential to a failure.
-
#rpc_loots(xopts) ⇒ Hash
Returns all the looted items.
-
#rpc_notes(xopts) ⇒ Hash
Returns notes from the database.
-
#rpc_report_client(xopts) ⇒ Hash
Reports a client connection.
-
#rpc_report_event(xopts) ⇒ Hash
Reports a framework event.
-
#rpc_report_host(xopts) ⇒ Hash
Reports a new host to the database.
-
#rpc_report_loot(xopts) ⇒ Hash
Reports a looted item.
-
#rpc_report_note(xopts) ⇒ Hash
Reports a note.
-
#rpc_report_service(xopts) ⇒ Hash
Reports a service to the database.
-
#rpc_report_vuln(xopts) ⇒ Hash
Reports a vulnerability.
-
#rpc_services(xopts) ⇒ Hash
Returns information about services.
-
#rpc_set_workspace(wspace) ⇒ Hash
Sets a workspace.
-
#rpc_status ⇒ Hash
Returns the database status.
-
#rpc_vulns(xopts) ⇒ Hash
Returns information about reported vulnerabilities.
-
#rpc_workspaces ⇒ Hash
Returns information about workspaces.
Methods inherited from RPC_Base
Constructor Details
This class inherits a constructor from Msf::RPC::RPC_Base
Instance Method Details
#rpc_add_workspace(wspace) ⇒ Hash
Adds a new workspace.
688 689 690 691 692 693 694 695 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 688 def rpc_add_workspace(wspace) ::ApplicationRecord.connection_pool.with_connection { db_check wspace = self.framework.db.add_workspace(wspace) return { 'result' => 'success' } if wspace { 'result' => 'failed' } } end |
#rpc_analyze_host(xopts) ⇒ Hash
Returns analysis of module suggestions for known data about a host.
- Array<String>
-
:payloads Modules returned will be compatible with at least one payload
774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 774 def rpc_analyze_host(xopts) ::ApplicationRecord.connection_pool.with_connection { _opts, _wspace = init_db_opts_workspace(xopts) ret = { host: {} } opts = (xopts) opts.deep_symbolize_keys! host = self.framework.db.get_host(opts) # consider expanding to support a list of hosts? return ret unless host # as a consumer options should be a filter object not a top level param = {} = opts[:analyze_options] if opts[:analyze_options] analyze_result = self.framework.analyze.host(host, **) # this should just serialize the result as hosts details why did it end up limited? module_suggestions = analyze_result[:results].sort_by { |result| result.mod.fullname } host_detail = { address: host.address, modules: module_suggestions.map do |result| mod = result.mod { mtype: mod.type, mname: mod.fullname, state: result.state, description: result.description, options: { invalid: result.invalid, missing: result.missing } } end } ret[:host] = host_detail ret } end |
#rpc_clients(xopts) ⇒ Hash
Returns browser clients information.
1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1777 def rpc_clients(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) limit = opts.delete(:limit) || 100 offset = opts.delete(:offset) || 0 conditions = {} conditions[:ua_name] = opts[:ua_name] if opts[:ua_name] conditions[:ua_ver] = opts[:ua_ver] if opts[:ua_ver] conditions["hosts.address"] = opts[:addresses] if opts[:addresses] ret = {} ret[:clients] = [] wspace.clients.includes(:host).where(conditions).offset(offset).limit(limit).each do |c| client = {} client[:host] = c.host.address.to_s if c.host client[:ua_string] = c.ua_string client[:ua_name] = c.ua_name client[:ua_ver] = c.ua_ver client[:created_at] = c.created_at.to_i client[:updated_at] = c.updated_at.to_i ret[:clients] << client end ret } end |
#rpc_connect(xopts) ⇒ Hash
Connects to the database.
This must contain :driver and driver specific options.
1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1909 def rpc_connect(xopts) opts = (xopts) if not self.framework.db.driver and not opts[:driver] return { :result => 'failed' } end if opts[:driver] if self.framework.db.drivers.include?(opts[:driver]) self.framework.db.driver = opts[:driver] else return { :result => 'failed' } end end driver = self.framework.db.driver case driver when 'postgresql' opts['adapter'] = 'postgresql' else return { :result => 'failed' } end if (not self.framework.db.connect(opts)) return { :result => 'failed' } end return { :result => 'success' } end |
#rpc_create_cracked_credential(xopts) ⇒ Metasploit::Credential::Core
Creates a cracked credential.
156 157 158 159 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 156 def rpc_create_cracked_credential(xopts) opts = (xopts) create_cracked_credential(opts) end |
#rpc_create_credential(xopts) ⇒ Hash
Creates a credential.
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 189 def rpc_create_credential(xopts) opts = (xopts) core = create_credential(opts) ret = { username: core.public.try(:username), private: core.private.try(:data), private_type: core.private.try(:type), realm_value: core.realm.try(:value), realm_key: core.realm.try(:key) } if opts[:last_attempted_at] && opts[:status] opts[:core] = core opts[:last_attempted_at] = opts[:last_attempted_at].to_datetime login = create_credential_login(opts) ret[:host] = login.service.host.address, ret[:sname] = login.service.name ret[:status] = login.status end ret end |
#rpc_creds(xopts) ⇒ Hash
Returns login credentials from a specific workspace.
257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 257 def rpc_creds(xopts) ::ApplicationRecord.connection_pool.with_connection { ret = {} ret[:creds] = [] opts, wspace = init_db_opts_workspace(xopts) limit = opts.delete(:limit) || 100 offset = opts.delete(:offset) || 0 query = Metasploit::Credential::Core.where( workspace_id: wspace ).offset(offset).limit(limit) query.each do |cred| host = '' port = 0 proto = '' sname = '' unless cred.logins.empty? login = cred.logins.first host = login.service.host.address.to_s sname = login.service.name.to_s if login.service.name.present? port = login.service.port.to_i proto = login.service.proto.to_s end updated_at = nil pass = nil type = nil unless cred.private.nil? updated_at = cred.private.updated_at.to_i pass = cred.private.data.to_s type = cred.private.type.to_s else updated_at = cred.public.updated_at.to_i end ret[:creds] << { :user => cred.public.username.to_s, :pass => pass, :updated_at => updated_at, :type => type, :host => host, :port => port, :proto => proto, :sname => sname } end ret } end |
#rpc_current_workspace ⇒ Hash
Returns the current workspace.
582 583 584 585 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 582 def rpc_current_workspace db_check { "workspace" => self.framework.db.workspace.name, "workspace_id" => self.framework.db.workspace.id } end |
#rpc_del_client(xopts) ⇒ Hash
Deletes browser information from a client.
1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1826 def rpc_del_client(xopts) ::ApplicationRecord.connection_pool.with_connection { db_check opts = (xopts) wspace = find_workspace(opts[:workspace]) hosts = [] clients = [] if opts[:host] or opts[:address] or opts[:addresses] hosts = opts_to_hosts(xopts) else hosts = wspace.hosts end hosts.each do |h| cret = nil if opts[:ua_name] or opts[:ua_ver] conditions = {} conditions[:ua_name] = opts[:ua_name] if opts[:ua_name] conditions[:ua_ver] = opts[:ua_ver] if opts[:ua_ver] cret = h.clients.where(conditions) else cret = h.clients end next if cret == nil clients << cret if cret.class == ::Mdm::Client clients |= cret if cret.class == Array end deleted = [] clients.each do |c| dent = {} dent[:address] = c.host.address.to_s dent[:ua_string] = c.ua_string deleted << dent c.destroy end { :result => 'success', :deleted => deleted } } end |
#rpc_del_creds(xopts) ⇒ Hash
Delete credentials from a specific workspace.
330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 330 def rpc_del_creds(xopts) ::ApplicationRecord.connection_pool.with_connection { deleted = [] ret = {} ret[:creds] = [] opts, wspace = init_db_opts_workspace(xopts) limit = opts.delete(:limit) || 100 offset = opts.delete(:offset) || 0 query = Metasploit::Credential::Core.where( workspace_id: wspace ).offset(offset).limit(limit) query.each do |cred| host = '' port = 0 proto = '' sname = '' unless cred.logins.empty? login = cred.logins.first host = login.service.host.address.to_s sname = login.service.name.to_s if login.service.name.present? port = login.service.port.to_i proto = login.service.proto.to_s end ret[:creds] << { :user => cred.public.username.to_s, :pass => cred.private.data.to_s, :updated_at => cred.private.updated_at.to_i, :type => cred.private.type.to_s, :host => host, :port => port, :proto => proto, :sname => sname} deleted << ret cred.destroy end return { :result => 'success', :deleted => deleted } } end |
#rpc_del_host(xopts) ⇒ Hash
Deletes hosts.
1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1413 def rpc_del_host(xopts) ::ApplicationRecord.connection_pool.with_connection { db_check opts = (xopts) wspace = find_workspace(opts[:workspace]) hosts = [] if opts[:host] or opts[:address] host = opts[:host] || opts[:address] hent = wspace.hosts.find_by_address(host) return { :result => 'failed' } if hent == nil or hent.class != ::Mdm::Host hosts << hent elsif opts[:addresses] return { :result => 'failed' } if opts[:addresses].class != Array conditions = { :address => opts[:addresses] } hent = wspace.hosts.where(conditions) return { :result => 'failed' } if hent == nil hosts |= hent if hent.class == Array hosts << hent if hent.class == ::Mdm::Host end deleted = [] hosts.each do |h| deleted << h.address.to_s h.destroy end return { :result => 'success', :deleted => deleted } } end |
#rpc_del_note(xopts) ⇒ Hash
Deletes notes.
1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1300 def rpc_del_note(xopts) notes = get_notes(xopts) deleted = [] notes.each do |n| dent = {} dent[:address] = n.host.address.to_s if n.host dent[:port] = n.service.port if n.service dent[:proto] = n.service.proto if n.service dent[:ntype] = n.ntype deleted << dent n.destroy end return { :result => 'success', :deleted => deleted } end |
#rpc_del_service(xopts) ⇒ Hash
Deletes services.
1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1340 def rpc_del_service(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) hosts = [] services = [] if opts[:host] or opts[:address] host = opts[:host] || opts[:address] hent = wspace.hosts.find_by_address(host) return { :result => 'failed' } if hent == nil or hent.class != ::Mdm::Host hosts << hent elsif opts[:addresses] return { :result => 'failed' } if opts[:addresses].class != Array conditions = { :address => opts[:addresses] } hent = wspace.hosts.where(conditions) return { :result => 'failed' } if hent == nil hosts |= hent if hent.class == Array hosts << hent if hent.class == ::Mdm::Host end if opts[:addresses] or opts[:address] or opts[:host] hosts.each do |h| sret = nil if opts[:port] or opts[:proto] conditions = {} conditions[:port] = opts[:port] if opts[:port] conditions[:proto] = opts[:proto] if opts[:proto] sret = h.services.where(conditions) next if sret == nil services << sret if sret.class == ::Mdm::Service services |= sret if sret.class == Array else services |= h.services end end elsif opts[:port] or opts[:proto] conditions = {} conditions[:port] = opts[:port] if opts[:port] conditions[:proto] = opts[:proto] if opts[:proto] sret = wspace.services.where(conditions) services << sret if sret and sret.class == ::Mdm::Service services |= sret if sret and sret.class == Array end deleted = [] services.each do |s| dent = {} dent[:address] = s.host.address.to_s dent[:port] = s.port dent[:proto] = s.proto deleted << dent s.destroy end return { :result => 'success', :deleted => deleted } } end |
#rpc_del_vuln(xopts) ⇒ Hash
Deletes vulnerabilities.
1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1206 def rpc_del_vuln(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) opts[:workspace] = opts[:workspace].name hosts = [] services = [] vulns = [] if opts[:host] or opts[:address] or opts[:addresses] hosts = opts_to_hosts(opts) end if opts[:port] or opts[:proto] if opts[:host] or opts[:address] or opts[:addresses] services = opts_to_services(hosts, opts) else services = opts_to_services([], opts) end end if opts[:port] or opts[:proto] services.each do |s| vret = nil if opts[:name] vret = s.vulns.find_by_name(opts[:name]) else vret = s.vulns.to_a() end next if vret == nil vulns << vret if vret.class == ::Mdm::Vuln vulns |= vret if vret.class == Array end elsif opts[:address] or opts[:host] or opts[:addresses] hosts.each do |h| vret = nil if opts[:name] vret = h.vulns.find_by_name(opts[:name]) else vret = h.vulns.to_a() end next if vret == nil vulns << vret if vret.class == ::Mdm::Vuln vulns |= vret if vret.class == Array end else vret = nil if opts[:name] vret = wspace.vulns.find_by_name(opts[:name]) else vret = wspace.vulns.to_a() end vulns << vret if vret.class == ::Mdm::Vuln vulns |= vret if vret.class == Array end deleted = [] vulns.each do |v| dent = {} dent[:address] = v.host.address.to_s if v.host dent[:port] = v.service.port if v.service dent[:proto] = v.service.proto if v.service dent[:name] = v.name deleted << dent v.destroy end return { :result => 'success', :deleted => deleted } } end |
#rpc_del_workspace(wspace) ⇒ Hash
Deletes a workspace.
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 656 def rpc_del_workspace(wspace) ::ApplicationRecord.connection_pool.with_connection { db_check # Delete workspace workspace = find_workspace(wspace) if workspace.nil? error(404, "Workspace not found: #{wspace}") elsif workspace.default? workspace.destroy workspace = self.framework.db.add_workspace(workspace.name) else # switch to the default workspace if we're about to delete the current one self.framework.db.workspace = self.framework.db.default_workspace if self.framework.db.workspace.name == workspace.name # now destroy the named workspace workspace.destroy end { 'result' => "success" } } end |
#rpc_disconnect ⇒ Hash
Disconnects the database.
1978 1979 1980 1981 1982 1983 1984 1985 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1978 def rpc_disconnect if (self.framework.db) self.framework.db.disconnect() return { :result => 'success' } else return { :result => 'failed' } end end |
#rpc_driver(xopts) ⇒ Hash
Sets the driver for the database or returns the current one.
1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1883 def rpc_driver(xopts) opts = (xopts) if opts[:driver] if self.framework.db.drivers.include?(opts[:driver]) self.framework.db.driver = opts[:driver] return { :result => 'success' } else return { :result => 'failed' } end else return { :driver => self.framework.db.driver.to_s } end return { :result => 'failed' } end |
#rpc_events(xopts) ⇒ Hash
Returns framework events.
1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1493 def rpc_events(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) limit = opts.delete(:limit) || 100 offset = opts.delete(:offset) || 0 ret = {} ret[:events] = [] wspace.events.offset(offset).limit(limit).each do |e| event = {} event[:host] = e.host.address if e.host event[:created_at] = e.created_at.to_i event[:updated_at] = e.updated_at.to_i event[:name] = e.name event[:critical] = e.critical if e.critical event[:username] = e.username if e.username event[:info] = e.info ret[:events] << event end ret } end |
#rpc_get_client(xopts) ⇒ Hash
Returns information about a client connection.
1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1017 def rpc_get_client(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) ret = {} ret[:client] = [] c = self.framework.db.get_client(opts) if c client = {} host = c.host client[:host] = host.address client[:created_at] = c.created_at.to_i client[:updated_at] = c.updated_at.to_i client[:ua_string] = c.ua_string.to_s client[:ua_name] = c.ua_name.to_s client[:ua_ver] = c.ua_ver.to_s ret[:client] << client end ret } end |
#rpc_get_host(xopts) ⇒ Hash
Returns information about a host.
725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 725 def rpc_get_host(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) ret = {} ret[:host] = [] opts = (xopts) h = self.framework.db.get_host(opts) if h host = {} host[:created_at] = h.created_at.to_i host[:address] = h.address.to_s host[:mac] = h.mac.to_s host[:name] = h.name.to_s host[:state] = h.state.to_s host[:os_name] = h.os_name.to_s host[:os_flavor] = h.os_flavor.to_s host[:os_sp] = h.os_sp.to_s host[:os_lang] = h.os_lang.to_s host[:updated_at] = h.updated_at.to_i host[:purpose] = h.purpose.to_s host[:info] = h.info.to_s ret[:host] << host end ret } end |
#rpc_get_note(xopts) ⇒ Hash
Returns a note.
971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 971 def rpc_get_note(xopts) ret = {} ret[:note] = [] notes = get_notes(xopts) notes.each do |n| note = {} host = n.host note[:host] = host.address || "unknown" if n.service note[:port] = n.service.port note[:proto] = n.service.proto end note[:created_at] = n[:created_at].to_i note[:updated_at] = n[:updated_at].to_i note[:ntype] = n[:ntype].to_s note[:data] = n[:data] note[:critical] = n[:critical].to_s note[:seen] = n[:seen].to_s ret[:note] << note end ret end |
#rpc_get_ref(name) ⇒ String
Returns an external vulnerability reference.
1175 1176 1177 1178 1179 1180 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1175 def rpc_get_ref(name) ::ApplicationRecord.connection_pool.with_connection { db_check self.framework.db.get_ref(name) } end |
#rpc_get_service(xopts) ⇒ Hash
Returns information about a service.
898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 898 def rpc_get_service(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) ret = {} ret[:service] = [] host = self.framework.db.get_host(opts) services = [] sret = nil if host && opts[:proto] && opts[:port] sret = host.services.find_by_proto_and_port(opts[:proto], opts[:port]) elsif opts[:proto] && opts[:port] conditions = {} conditions[:state] = [Msf::ServiceState::Open] if opts[:up] conditions[:proto] = opts[:proto] if opts[:proto] conditions[:port] = opts[:port] if opts[:port] conditions[:name] = opts[:names] if opts[:names] sret = wspace.services.where(conditions).order("hosts.address, port").to_a() elsif host sret = host.services.to_a() end return ret if sret == nil services << sret if sret.class == ::Mdm::Service services |= sret if sret.class == Array services.each do |s| service = {} host = s.host service[:host] = host.address || "unknown" service[:created_at] = s[:created_at].to_i service[:updated_at] = s[:updated_at].to_i service[:port] = s[:port] service[:proto] = s[:proto].to_s service[:state] = s[:state].to_s service[:name] = s[:name].to_s service[:info] = s[:info].to_s ret[:service] << service end ret } end |
#rpc_get_vuln(xopts) ⇒ Hash
Returns vulnerabilities from services or from a host.
1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1705 def rpc_get_vuln(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) ret = {} ret[:vuln] = [] host = self.framework.db.get_host(opts) return ret if not host vulns = [] if opts[:proto] && opts[:port] services = [] sret = host.services.find_by_proto_and_port(opts[:proto], opts[:port]) return ret if sret == nil services << sret if sret.class == ::Mdm::Service services |= sret if sret.class == Array services.each do |s| vulns |= s.vulns end else vulns = host.vulns end return ret if (not vulns) vulns.each do |v| vuln= {} host= v.host vuln[:host] = host.address || "unknown" if v.service vuln[:port] = v.service.port vuln[:proto] = v.service.proto end vuln[:created_at] = v[:created_at].to_i vuln[:updated_at] = v[:updated_at].to_i vuln[:name] = v[:name].to_s vuln[:info] = v[:info].to_s vuln[:refs] = [] v.refs.each do |r| vuln[:refs] << r.name end ret[:vuln] << vuln end ret } end |
#rpc_get_workspace(wspace) ⇒ Hash
Returns the current workspace.
602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 602 def rpc_get_workspace(wspace) db_check wspace = find_workspace(wspace) ret = {} ret[:workspace] = [] if wspace w = {} w[:name] = wspace.name w[:id] = wspace.id w[:created_at] = wspace.created_at.to_i w[:updated_at] = wspace.updated_at.to_i ret[:workspace] << w end ret end |
#rpc_hosts(xopts) ⇒ Hash
Returns information about hosts.
394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 394 def rpc_hosts(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) conditions = {} conditions[:state] = [Msf::HostState::Alive, Msf::HostState::Unknown] if opts[:only_up] conditions[:address] = opts[:addresses] if opts[:addresses] limit = opts.delete(:limit) || 100 offset = opts.delete(:offset) || 0 ret = {} ret[:hosts] = [] wspace.hosts.where(conditions).offset(offset).order(:address).limit(limit).each do |h| host = {} host[:created_at] = h.created_at.to_i host[:address] = h.address.to_s host[:mac] = h.mac.to_s host[:name] = h.name.to_s host[:state] = h.state.to_s host[:os_name] = h.os_name.to_s host[:os_flavor] = h.os_flavor.to_s host[:os_sp] = h.os_sp.to_s host[:os_lang] = h.os_lang.to_s host[:updated_at] = h.updated_at.to_i host[:purpose] = h.purpose.to_s host[:info] = h.info.to_s ret[:hosts] << host end ret } end |
#rpc_import_data(xopts) ⇒ Hash
Imports file to the database.
1672 1673 1674 1675 1676 1677 1678 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1672 def rpc_import_data(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) self.framework.db.import(opts) return { :result => 'success' } } end |
#rpc_invalidate_login(xopts) ⇒ void
This method returns an undefined value.
Sets the status of a login credential to a failure.
231 232 233 234 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 231 def rpc_invalidate_login(xopts) opts = (xopts) invalidate_login(opts) end |
#rpc_loots(xopts) ⇒ Hash
Returns all the looted items.
1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1599 def rpc_loots(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) limit = opts.delete(:limit) || 100 offset = opts.delete(:offset) || 0 ret = {} ret[:loots] = [] wspace.loots.offset(offset).limit(limit).each do |l| loot = {} loot[:host] = l.host.address if l.host loot[:service] = l.service.name || l.service.port if l.service loot[:ltype] = l.ltype loot[:ctype] = l.content_type loot[:data] = l.data loot[:created_at] = l.created_at.to_i loot[:updated_at] = l.updated_at.to_i loot[:name] = l.name loot[:info] = l.info ret[:loots] << loot end ret } end |
#rpc_notes(xopts) ⇒ Hash
Returns notes from the database.
1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1134 def rpc_notes(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) limit = opts.delete(:limit) || 100 offset = opts.delete(:offset) || 0 conditions = {} conditions["hosts.address"] = opts[:address] if opts[:address] conditions[:name] = opts[:names].strip().split(",") if opts[:names] conditions[:ntype] = opts[:ntype] if opts[:ntype] conditions["services.port"] = Rex::Socket.portspec_to_portlist(opts[:ports]) if opts[:ports] conditions["services.proto"] = opts[:proto] if opts[:proto] ret = {} ret[:notes] = [] wspace.notes.includes(:host, :service).where(conditions).offset(offset).limit(limit).each do |n| note = {} note[:time] = n.created_at.to_i note[:host] = "" note[:service] = "" note[:host] = n.host.address if n.host note[:service] = n.service.name || n.service.port if n.service note[:type ] = n.ntype.to_s note[:data] = n.data.inspect ret[:notes] << note end ret } end |
#rpc_report_client(xopts) ⇒ Hash
Reports a client connection.
1057 1058 1059 1060 1061 1062 1063 1064 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1057 def rpc_report_client(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) res = self.framework.db.report_client(opts) return { :result => 'success' } if res { :result => 'failed' } } end |
#rpc_report_event(xopts) ⇒ Hash
Reports a framework event.
1532 1533 1534 1535 1536 1537 1538 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1532 def rpc_report_event(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) res = self.framework.db.report_event(opts) { :result => 'success' } if res } end |
#rpc_report_host(xopts) ⇒ Hash
Reports a new host to the database.
838 839 840 841 842 843 844 845 846 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 838 def rpc_report_host(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) res = self.framework.db.report_host(opts) return { :result => 'success' } if res { :result => 'failed' } } end |
#rpc_report_loot(xopts) ⇒ Hash
Reports a looted item.
1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1563 def rpc_report_loot(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) if opts[:host] && opts[:port] && opts[:proto] opts[:service] = self.framework.db.find_or_create_service(opts) end res = self.framework.db.report_loot(opts) { :result => 'success' } if res } end |
#rpc_report_note(xopts) ⇒ Hash
Reports a note.
1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1089 def rpc_report_note(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) if (opts[:host] or opts[:address]) and opts[:port] and opts[:proto] addr = opts[:host] || opts[:address] wspace = opts[:workspace] || self.framework.db.workspace host = wspace.hosts.find_by_address(addr) if host && host.services.count > 0 service = host.services.find_by_proto_and_port(opts[:proto],opts[:port]) if service opts[:service] = service end end end res = self.framework.db.report_note(opts) return { :result => 'success' } if res { :result => 'failed' } } end |
#rpc_report_service(xopts) ⇒ Hash
Reports a service to the database.
866 867 868 869 870 871 872 873 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 866 def rpc_report_service(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) res = self.framework.db.report_service(opts) return { :result => 'success' } if res { :result => 'failed' } } end |
#rpc_report_vuln(xopts) ⇒ Hash
Reports a vulnerability.
1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1460 def rpc_report_vuln(xopts) ::ApplicationRecord.connection_pool.with_connection { db_check opts = (xopts) opts[:workspace] = find_workspace(opts[:workspace]) if opts[:workspace] res = self.framework.db.report_vuln(opts) return { :result => 'success' } if res { :result => 'failed' } } end |
#rpc_services(xopts) ⇒ Hash
Returns information about services.
454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 454 def rpc_services( xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) limit = opts.delete(:limit) || 100 offset = opts.delete(:offset) || 0 conditions = {} conditions[:state] = [Msf::ServiceState::Open] if opts[:only_up] conditions[:proto] = opts[:proto] if opts[:proto] conditions["hosts.address"] = opts[:addresses] if opts[:addresses] conditions[:port] = Rex::Socket.portspec_to_portlist(opts[:ports]) if opts[:ports] conditions[:name] = opts[:names].strip().split(",") if opts[:names] ret = {} ret[:services] = [] wspace.services.includes(:host).where(conditions).offset(offset).limit(limit).each do |s| service = {} host = s.host service[:host] = host.address || "unknown" service[:created_at] = s[:created_at].to_i service[:updated_at] = s[:updated_at].to_i service[:port] = s[:port] service[:proto] = s[:proto].to_s service[:state] = s[:state].to_s service[:name] = s[:name].to_s service[:info] = s[:info].to_s ret[:services] << service end ret } end |
#rpc_set_workspace(wspace) ⇒ Hash
Sets a workspace.
632 633 634 635 636 637 638 639 640 641 642 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 632 def rpc_set_workspace(wspace) ::ApplicationRecord.connection_pool.with_connection { db_check workspace = find_workspace(wspace) if workspace self.framework.db.workspace = workspace return { 'result' => "success" } end { 'result' => 'failed' } } end |
#rpc_status ⇒ Hash
Returns the database status.
1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 1950 def rpc_status if (not self.framework.db.driver) return {:driver => 'None' } end cdb = "" if framework.db.connection_established? ::ApplicationRecord.connection_pool.with_connection { |conn| if conn.respond_to? :current_database cdb = conn.current_database else cdb = conn.instance_variable_get(:@config)[:database] end } return {:driver => self.framework.db.driver.to_s , :db => cdb } else return {:driver => self.framework.db.driver.to_s} end {:driver => 'None' } end |
#rpc_vulns(xopts) ⇒ Hash
Returns information about reported vulnerabilities.
511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 511 def rpc_vulns(xopts) ::ApplicationRecord.connection_pool.with_connection { opts, wspace = init_db_opts_workspace(xopts) limit = opts.delete(:limit) || 100 offset = opts.delete(:offset) || 0 conditions = {} conditions["hosts.address"] = opts[:address] if opts[:address] conditions[:name] = opts[:names].strip().split(",") if opts[:names] conditions["services.port"] = Rex::Socket.portspec_to_portlist(opts[:ports]) if opts[:port] conditions["services.proto"] = opts[:proto] if opts[:proto] ret = {} ret[:vulns] = [] wspace.vulns.includes(:service).where(conditions).offset(offset).limit(limit).each do |v| vuln = {} reflist = v.refs.map { |r| r.name } if v.service vuln[:port] = v.service.port vuln[:proto] = v.service.proto else vuln[:port] = nil vuln[:proto] = nil end vuln[:time] = v.created_at.to_i vuln[:host] = v.host.address || nil vuln[:name] = v.name vuln[:refs] = reflist.join(',') ret[:vulns] << vuln end ret } end |
#rpc_workspaces ⇒ Hash
Returns information about workspaces.
557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 |
# File 'lib/msf/core/rpc/v10/rpc_db.rb', line 557 def rpc_workspaces db_check res = {} res[:workspaces] = [] self.framework.db.workspaces.each do |j| ws = {} ws[:id] = j.id ws[:name] = j.name ws[:created_at] = j.created_at.to_i ws[:updated_at] = j.updated_at.to_i res[:workspaces] << ws end res end |