Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/auxiliary/cloud/kubernetes/enum_kubernetes.rb
Views: 11655
# -*- coding: binary -*-12##3# This module requires Metasploit: https://metasploit.com/download4# Current source: https://github.com/rapid7/metasploit-framework5##67class MetasploitModule < Msf::Auxiliary8include Msf::Exploit::Remote::HttpClient9include Msf::Auxiliary::Report10include Msf::Exploit::Remote::HTTP::Kubernetes11include Msf::Exploit::Remote::HTTP::Kubernetes::Enumeration1213def initialize(info = {})14super(15update_info(16info,17'Name' => 'Kubernetes Enumeration',18'Description' => %q{19Enumerate a Kubernetes API to report useful resources such as available namespaces,20pods, secrets, etc.2122Useful resources will be highlighted using the HIGHLIGHT_NAME_PATTERN option.23},24'License' => MSF_LICENSE,25'Author' => [26'alanfoster',27'Spencer McIntyre'28],29'Notes' => {30'SideEffects' => [IOC_IN_LOGS],31'Reliability' => [],32'Stability' => [CRASH_SAFE]33},34'DefaultOptions' => {35'SSL' => true36},37'Actions' => [38['all', { 'Description' => 'enumerate all resources' }],39['version', { 'Description' => 'enumerate version' }],40['auth', { 'Description' => 'enumerate auth' }],41['namespace', { 'Description' => 'enumerate namespace' }],42['namespaces', { 'Description' => 'enumerate namespaces' }],43['pod', { 'Description' => 'enumerate pod' }],44['pods', { 'Description' => 'enumerate pods' }],45['secret', { 'Description' => 'enumerate secret' }],46['secrets', { 'Description' => 'enumerate secrets' }],47],48'DefaultAction' => 'all',49'Platform' => ['linux', 'unix'],50'SessionTypes' => ['meterpreter']51)52)5354register_options(55[56Opt::RHOSTS(nil, false),57Opt::RPORT(nil, false),58Msf::OptInt.new('SESSION', [false, 'An optional session to use for configuration']),59OptRegexp.new('HIGHLIGHT_NAME_PATTERN', [true, 'PCRE regex of resource names to highlight', 'username|password|user|pass']),60OptString.new('NAME', [false, 'The name of the resource to enumerate', nil]),61OptEnum.new('OUTPUT', [true, 'output format to use', 'table', ['table', 'json']])62]63)64end6566def output_for(type)67case type68when 'table'69Msf::Exploit::Remote::HTTP::Kubernetes::Output::Table.new(self, highlight_name_pattern: datastore['HIGHLIGHT_NAME_PATTERN'])70when 'json'71Msf::Exploit::Remote::HTTP::Kubernetes::Output::JSON.new(self)72end73end7475def run76if session77print_status("Routing traffic through session: #{session.sid}")78configure_via_session79end80validate_configuration!8182@kubernetes_client = Msf::Exploit::Remote::HTTP::Kubernetes::Client.new({ http_client: self, token: api_token })83@output = output_for(datastore['output'])8485case action.name86when 'all'87enum_all88when 'version'89enum_version90when 'auth'91enum_auth(datastore['NAMESPACE'])92when 'namespaces', 'namespace'93enum_namespaces(name: datastore['NAME'])94when 'pods', 'pod'95enum_pods(datastore['NAMESPACE'], name: datastore['NAME'])96when 'secret', 'secrets'97enum_secrets(datastore['NAMESPACE'], name: datastore['NAME'])98end99rescue Msf::Exploit::Remote::HTTP::Kubernetes::Error::ApiError => e100print_error(e.message)101end102end103104105