Files
metasploit-gs/lib/msf/core/module/platform.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

623 lines
11 KiB
Ruby
Raw Normal View History

# -*- coding: binary -*-
require 'abbrev'
2005-05-30 07:01:25 +00:00
#
# This is the definitions of which Platforms the framework knows about. The
# relative ranks are used to support ranges, and the Short names are used to
# allow for more convenient specification of the platforms....
2005-05-30 22:34:02 +00:00
#
2005-05-30 07:01:25 +00:00
class Msf::Module::Platform
Rank = 0
2015-04-13 13:21:41 +05:00
# actually, having an argument of '' is what to do for wanting 'all'
Short = "all"
2013-08-30 16:28:33 -05:00
class << self
attr_accessor :full_name
end
2013-08-30 16:28:33 -05:00
#
2015-04-13 13:21:41 +05:00
# Returns the "real" name of the module instance, accounting for potentially
# aliased class names.
#
def self.realname
# Use the cached version if one has been set
return full_name if (full_name)
2013-08-30 16:28:33 -05:00
# Otherwise, generate it and cache it
names = []
c = Msf::Module::Platform
name.split('::')[3 .. -1].each { |part|
c = c.const_get(part)
if (c.const_defined?('RealName') == true)
names << c.const_get('RealName')
else
names << part
end
}
full_name = names.join(' ')
end
2013-08-30 16:28:33 -05:00
#
2005-11-15 15:11:43 +00:00
# Calls the class method.
#
def find_children
self.class.find_children
end
2013-08-30 16:28:33 -05:00
2005-05-30 07:01:25 +00:00
#
2005-11-15 15:11:43 +00:00
# The magic to try to build out a Platform from a string.
2005-05-30 07:01:25 +00:00
#
2005-05-30 22:34:02 +00:00
def self.find_platform(str)
# remove any whitespace and downcase
2005-05-30 23:46:34 +00:00
str = str.gsub(' ', '').downcase
2013-08-30 16:28:33 -05:00
# Start at the base platform module
mod = ::Msf::Module::Platform
2013-08-30 16:28:33 -05:00
# Scan forward, trying to find the end module
2005-05-30 22:34:02 +00:00
while str.length > 0
mod, str = find_portion(mod, str)
2005-05-30 22:34:02 +00:00
end
2013-08-30 16:28:33 -05:00
2005-05-30 22:34:02 +00:00
return mod
end
2013-08-30 16:28:33 -05:00
#
2005-11-15 15:11:43 +00:00
# Finds all inherited children from a given module.
#
2005-05-31 00:36:22 +00:00
def self.find_children
@subclasses ||= []
@subclasses.sort_by { |a| a::Rank }
end
2013-08-30 16:28:33 -05:00
def self.inherited(subclass)
@subclasses ||= []
@subclasses << subclass
2005-05-30 07:01:25 +00:00
end
2013-08-30 16:28:33 -05:00
#
# Builds the abbreviation set for every module starting from
2005-11-15 15:11:43 +00:00
# a given point.
#
def self.build_child_platform_abbrev(mod)
# Flush out any non-class and non-inherited children
children = mod.find_children
2013-08-30 16:28:33 -05:00
# No children to speak of?
return if (children.length == 0)
2013-08-30 16:28:33 -05:00
# Build the list of names & rankings
names = {}
ranked = {}
2013-08-30 16:28:33 -05:00
children.map { |c|
name = c.name.split('::')[-1].downcase
2013-08-30 16:28:33 -05:00
# If the platform has an alias, such as a portion that may
# start with an integer, use that as the name
if (c.const_defined?('Alias'))
als = c.const_get('Alias').downcase
2013-08-30 16:28:33 -05:00
names[als] = c
ranked[als] = c::Rank
# If the platform has more than one alias, process the list
elsif (c.const_defined?('Aliases'))
c.const_get('Aliases').each { |a|
a = a.downcase
2013-08-30 16:28:33 -05:00
names[a] = c
ranked[a] = c::Rank
}
2005-05-30 07:01:25 +00:00
end
2013-08-30 16:28:33 -05:00
names[name] = c
ranked[name] = c::Rank
2005-05-30 07:01:25 +00:00
}
2013-08-30 16:28:33 -05:00
# Calculate their abbreviations
abbrev = ::Abbrev::abbrev(names.keys)
2013-08-30 16:28:33 -05:00
# Set the ranked list and abbreviated list on this module,
# then walk the children
mod.const_set('Abbrev', abbrev)
mod.const_set('Ranks', ranked)
mod.const_set('Names', names)
end
2013-08-30 16:28:33 -05:00
#
# Finds the module that best matches the supplied string (or a portion of
2005-11-15 15:11:43 +00:00
# the string).
#
def self.find_portion(mod, str)
# Check to see if we've built the abbreviated cache
if (not (
mod.const_defined?('Abbrev') and
mod.const_defined?('Names') and
mod.const_defined?('Ranks')
) )
build_child_platform_abbrev(mod)
2005-05-30 22:34:02 +00:00
end
2013-08-30 16:28:33 -05:00
if (not mod.const_defined?('Names'))
elog("Failed to instantiate the platform list for module #{mod}")
raise "Failed to instantiate the platform list for module #{mod}"
end
2013-08-30 16:28:33 -05:00
abbrev = mod.const_get('Abbrev')
names = mod.const_get('Names')
ranks = mod.const_get('Ranks')
best = nil
bestlen = 0
bestmat = nil
bestrank = 0
2013-08-30 16:28:33 -05:00
# Walk through each abbreviation
abbrev.each { |a|
# If the abbreviation is too long, no sense in scanning it
next if (a[0].length > str.length)
2013-08-30 16:28:33 -05:00
# If the current abbreviation matches with the
# supplied string and is better than the previous
# best match length, use it, but only if it also
# has a higher rank than the previous match.
if ((a[0] == str[0, a[0].length]) and
(a[0].length > bestlen) and
(bestrank == nil or bestrank <= ranks[a[1]]))
best = [ names[a[1]], str[a[0].length .. -1] ]
bestlen = a[0].length
bestmat = a[0]
bestrank = ranks[a[1]]
end
}
2013-08-30 16:28:33 -05:00
# If we couldn't find a best match at this stage, it's time to warn.
if (best == nil)
raise ArgumentError, "No classes in #{mod} for #{str}!", caller
end
2013-08-30 16:28:33 -05:00
return best
2005-05-30 07:01:25 +00:00
end
2013-08-30 16:28:33 -05:00
2005-11-15 15:11:43 +00:00
private_class_method :build_child_platform_abbrev # :nodoc:
private_class_method :find_portion # :nodoc:
2013-08-30 16:28:33 -05:00
2005-07-13 18:54:41 +00:00
##
#
# Builtin platforms
#
##
2013-08-30 16:28:33 -05:00
#
# Unknown
#
# This is a special case for when we're completely unsure of the
# platform, such as a crash or default case in code. Only
# utilize this as a catch-all.
#
class Unknown < Msf::Module::Platform
Rank = 0 # safeguard with 0 since the platform is completely unknown
Alias = "unknown"
end
2005-07-13 18:54:41 +00:00
#
# Windows
#
2005-05-30 07:01:25 +00:00
class Windows < Msf::Module::Platform
Rank = 100
# Windows 95
class W95 < Windows
Rank = 100
Alias = "95"
RealName = "95"
end
2013-08-30 16:28:33 -05:00
# Windows 98
class W98 < Windows
Rank = 100
Alias = "98"
RealName = "98"
class FE < W98
Rank = 100
end
class SE < W98
Rank = 200
end
end
2013-08-30 16:28:33 -05:00
# Windows ME
class ME < Windows
Rank = 100
end
2013-08-30 16:28:33 -05:00
# Windows NT
class NT < Windows
Rank = 100
class SP0 < NT
Rank = 100
end
class SP1 < NT
Rank = 200
end
class SP2 < NT
Rank = 300
end
class SP3 < NT
Rank = 400
end
class SP4 < NT
Rank = 500
end
class SP5 < NT
Rank = 600
end
class SP6 < NT
Rank = 700
end
class SP6a < NT
Rank = 800
end
end
2013-08-30 16:28:33 -05:00
# Windows 2000
class W2000 < Windows
Rank = 200
Aliases = [ "2000", "2K" ]
RealName = "2000"
class SP0 < W2000
Aliases = [ "sp0-4", "sp0-sp4" ]
Rank = 100
end
class SP1 < W2000
Rank = 200
end
class SP2 < W2000
Rank = 300
end
class SP3 < W2000
Rank = 400
end
class SP4 < W2000
Rank = 500
end
end
2013-08-30 16:28:33 -05:00
# Windows XP
class XP < Windows
Rank = 300
class SP0 < XP
# It's not clear whether this should be assigned to the lower
# or higher bound of the range.
Aliases = [ "sp0-1", "sp0/1", "sp0-sp1", "sp0/sp1", "sp0-2", "sp0-sp2", "sp0-3", "sp0-sp3" ]
Rank = 100
end
class SP1 < XP
Rank = 200
end
class SP2 < XP
Rank = 300
end
class SP3 < XP
Rank = 400
end
end
2013-08-30 16:28:33 -05:00
# Windows 2003 Server
class W2003 < Windows
Rank = 400
Aliases = [ "2003", "2003 Server", "2K3" ]
RealName = "2003"
class SP0 < W2003
Rank = 100
end
class SP1 < W2003
Rank = 200
2005-05-30 07:01:25 +00:00
end
end
2013-08-30 16:28:33 -05:00
class Vista < Windows
Rank = 500
class SP0 < Vista
Aliases = [ "sp0-1", "sp0/1", "sp0-sp1", "sp0/sp1" ]
Rank = 100
end
class SP1 < Vista
Rank = 200
end
end
2013-08-30 16:28:33 -05:00
class W7 < Windows
Rank = 600
RealName = "7"
end
2013-11-13 13:27:44 -06:00
class W8 < Windows
Rank = 700
RealName = "8"
end
2005-05-30 07:01:25 +00:00
end
2013-08-30 16:28:33 -05:00
#
# NetWare
#
class Netware < Msf::Module::Platform
Rank = 100
Alias = "netware"
end
2013-08-30 16:28:33 -05:00
2013-04-12 18:35:03 +01:00
#
# Android
#
class Android < Msf::Module::Platform
Rank = 100
Alias = "android"
end
2013-08-30 16:28:33 -05:00
2010-07-11 19:46:55 +00:00
#
# Java
#
class Java < Msf::Module::Platform
Rank = 100
Alias = "java"
end
2013-08-30 16:28:33 -05:00
2017-08-23 16:58:48 -05:00
#
# R
#
class R < Msf::Module::Platform
Rank = 100
Alias = "r"
end
#
# Ruby
#
class Ruby < Msf::Module::Platform
Rank = 100
Alias = "ruby"
end
2013-08-30 16:28:33 -05:00
2005-07-13 18:54:41 +00:00
#
# Linux
#
class Linux < Msf::Module::Platform
Rank = 100
2005-10-27 02:54:39 +00:00
Alias = "linux"
end
2013-08-30 16:28:33 -05:00
2011-10-13 22:41:48 +00:00
#
# Cisco
#
class Cisco < Msf::Module::Platform
Rank = 100
Alias = "cisco"
end
2013-08-30 16:28:33 -05:00
2018-02-22 21:08:21 -05:00
#
# Juniper
#
class Juniper < Msf::Module::Platform
Rank = 100
Alias = "juniper"
end
2019-03-12 20:35:32 -04:00
#
# Ubiquiti Unifi
#
class Unifi < Msf::Module::Platform
Rank = 100
Alias = "unifi"
end
2018-07-30 14:53:53 -04:00
#
# Brocade
#
class Brocade < Msf::Module::Platform
Rank = 100
Alias = "brocade"
end
2020-07-18 07:45:24 -04:00
#
# MikroTik
#
class Mikrotik < Msf::Module::Platform
Rank = 100
Alias = "mikrotik"
2020-08-07 21:36:56 -04:00
end
2020-07-26 07:16:06 -04:00
#
# Arista
#
class Arista < Msf::Module::Platform
Rank = 100
Alias = "arista"
2020-07-18 07:45:24 -04:00
end
2005-07-13 18:54:41 +00:00
#
# Solaris
#
class Solaris < Msf::Module::Platform
Rank = 100
2005-07-13 18:54:41 +00:00
class V4
Rank = 100
Alias = "4"
end
class V5
Rank = 200
Alias = "5"
end
class V6
Rank = 300
Alias = "6"
end
class V7
Rank = 400
Alias = "7"
end
class V8
2005-10-27 02:54:39 +00:00
Rank = 500
Alias = "8"
end
class V9
Rank = 600
Alias = "9"
end
class V10
Rank = 700
Alias = "10"
2005-07-13 18:54:41 +00:00
end
2016-05-09 05:11:09 -05:00
class V11
Rank = 800
Alias = "11"
end
end
2013-08-30 16:28:33 -05:00
2005-07-13 18:54:41 +00:00
#
# OSX
#
class OSX < Msf::Module::Platform
Rank = 100
end
2013-08-30 16:28:33 -05:00
2005-07-13 18:54:41 +00:00
#
# Generic BSD
2005-07-13 18:54:41 +00:00
#
class BSD < Msf::Module::Platform
Rank = 100
end
2013-08-30 16:28:33 -05:00
2005-07-13 18:54:41 +00:00
#
# OpenBSD
#
class OpenBSD < Msf::Module::Platform
Rank = 100
end
2013-08-30 16:28:33 -05:00
2005-07-13 18:54:41 +00:00
#
# BSDi
#
class BSDi < Msf::Module::Platform
Rank = 100
end
2013-08-30 16:28:33 -05:00
2005-07-13 18:54:41 +00:00
#
# NetBSD
#
class NetBSD < Msf::Module::Platform
Rank = 100
end
2013-08-30 16:28:33 -05:00
2005-07-13 18:54:41 +00:00
#
# FreeBSD
#
class FreeBSD < Msf::Module::Platform
Rank = 100
end
2013-08-30 16:28:33 -05:00
2008-09-10 20:13:36 +00:00
#
# AIX
#
class AIX < Msf::Module::Platform
Rank = 100
Alias = "aix"
end
2013-08-30 16:28:33 -05:00
2006-01-16 03:36:43 +00:00
#
# HP-UX
#
class HPUX < Msf::Module::Platform
Rank = 100
Alias = "hpux"
end
2013-08-30 16:28:33 -05:00
2006-02-05 18:10:08 +00:00
#
# Irix
#
class Irix < Msf::Module::Platform
Rank = 100
Alias = "irix"
end
2013-08-30 16:28:33 -05:00
2005-12-25 22:47:38 +00:00
#
# Generic Unix
#
class Unix < Msf::Module::Platform
Rank = 100
Alias = "unix"
end
2013-08-30 16:28:33 -05:00
2006-12-17 07:57:51 +00:00
#
# Generic PHP
#
class PHP < Msf::Module::Platform
Rank = 100
Alias = "php"
end
2013-09-20 18:14:01 -05:00
#
# JavaScript
#
class JavaScript < Msf::Module::Platform
Rank = 100
Alias = "js"
end
#
# Python
#
class Python < Msf::Module::Platform
Rank = 100
Alias = "python"
end
#
# Node.js
#
class NodeJS < Msf::Module::Platform
Rank = 100
Alias = "nodejs"
end
#
2014-01-02 02:22:16 -06:00
# Firefox
#
class Firefox < Msf::Module::Platform
Rank = 100
Alias = "firefox"
end
2015-09-28 10:03:15 -05:00
#
# Mainframe
#
class Mainframe < Msf::Module::Platform
Rank = 100
Alias = "mainframe"
end
#
# Multi (for wildcard-style platform functions)
#
class Multi < Msf::Module::Platform
Rank = 100
Alias = "multi"
end
#
# Hardware
#
class Hardware < Msf::Module::Platform
Rank = 100
Alias = "hardware"
end
2017-12-12 16:05:23 +08:00
#
# Apple iOS
#
class Apple_iOS < Msf::Module::Platform
Rank = 100
Alias = "apple_ios"
end
end