-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add arch/platform detection for Postgres #19080
Changes from 2 commits
3f2e32e
3481d4f
c694522
b83f2e3
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -129,12 +129,97 @@ def peerport | |
@conn.peerport | ||
end | ||
|
||
def peerinfo | ||
"#{peerhost}:#{peerport}" | ||
end | ||
|
||
def current_database | ||
@params['database'] | ||
end | ||
|
||
def peerinfo | ||
"#{peerhost}:#{peerport}" | ||
# List of supported PostgreSQL platforms & architectures: | ||
# https://postgrespro.com/docs/postgresql/16/supported-platforms | ||
def map_compile_os_to_platform(compile_os) | ||
return Msf::Platform::Unknown.realname if compile_os.blank? | ||
|
||
compile_os = compile_os.downcase.encode(::Encoding::BINARY) | ||
|
||
if compile_os.match?('linux') | ||
platform = Msf::Platform::Linux | ||
elsif compile_os.match?(/(darwin|mac|osx)/) | ||
platform = Msf::Platform::OSX | ||
elsif compile_os.match?('win') | ||
platform = Msf::Platform::Windows | ||
elsif compile_os.match?('free') | ||
platform = Msf::Platform::FreeBSD | ||
elsif compile_os.match?('net') | ||
platform = Msf::Platform::NetBSD | ||
elsif compile_os.match?('open') | ||
platform = Msf::Platform::OpenBSD | ||
elsif compile_os.match?('solaris') | ||
platform = Msf::Platform::Solaris | ||
elsif compile_os.match?('aix') | ||
platform = Msf::Platform::AIX | ||
elsif compile_os.match?('hpux') | ||
platform = Msf::Platform::HPUX | ||
elsif compile_os.match?('irix') | ||
platform = Msf::Platform::Irix | ||
else | ||
# Return the query result if the value can't be mapped | ||
return compile_os | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Adding this to return whatever the query result is, evening if we don't mp it, I think it would be more useful to give the user the data instead of just Maybe we need to return unknown here, happy to change it if needed 👍 |
||
end | ||
|
||
platform.realname | ||
end | ||
|
||
# List of supported PostgreSQL platforms & architectures: | ||
# https://postgrespro.com/docs/postgresql/16/supported-platforms | ||
def map_compile_arch_to_architecture(compile_arch) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Taken from https://postgrespro.com/docs/postgresql/16/supported-platforms I have bucket these by what I have covered versus not. Wanted to call this out in case anyone has thoughts or opinions. Historical versions. Not covered and not present in
17.6 supported but not covered in
17.6 supported and covered in
|
||
return '' if compile_arch.blank? | ||
|
||
compile_arch = compile_arch.downcase.encode(::Encoding::BINARY) | ||
|
||
if compile_arch.match?('sparc') | ||
if compile_arch.include?('64') | ||
arch = ARCH_SPARC64 | ||
else | ||
arch = ARCH_SPARC | ||
end | ||
elsif compile_arch.include?('mips') | ||
arch = ARCH_MIPS | ||
elsif compile_arch.include?('ppc') | ||
arch = ARCH_PPC | ||
elsif compile_arch.match?('arm') | ||
arch = ARCH_AARCH64 | ||
elsif compile_arch.match?('64') | ||
arch = ARCH_X86_64 | ||
elsif compile_arch.match?('86') || compile_arch.match?('i686') | ||
arch = ARCH_X86 | ||
else | ||
# Return the query result if the value can't be mapped | ||
arch = compile_arch | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same thought process as https://github.com/rapid7/metasploit-framework/pull/19080/files#r1562403615 |
||
end | ||
|
||
arch | ||
end | ||
|
||
# @return [Hash] Detect the platform and architecture of the MySQL server: | ||
cgranleese-r7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
# * :arch [String] The server architecture. | ||
# * :platform [String] The server platform. | ||
def detect_platform_and_arch | ||
result = {} | ||
|
||
query_result = query('select version()').rows.join.match(/.*on (\w+-\w+-\w+-\w+)/).captures | ||
server_var = query_result.join.split('-', 2) | ||
server_vars = { | ||
'version_compile_machine' => server_var[0], | ||
'version_compile_os' => server_var[1] | ||
} | ||
cgranleese-r7 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
result[:arch] = map_compile_arch_to_architecture(server_vars['version_compile_machine']) | ||
result[:platform] = map_compile_os_to_platform(server_vars['version_compile_os']) | ||
|
||
result | ||
end | ||
|
||
def close | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Taken from https://postgrespro.com/docs/postgresql/16/supported-platforms
I have bucket these by what I have covered versus not. Wanted to call this out in case anyone has thoughts or opinions.
Historical versions. Not covered and not present in
lib/msf/core/module/platform.rb
:Historical versions. Covered and present in
lib/msf/core/module/platform.rb
:17.6 supported but not covered in
lib/msf/core/module/platform.rb
:17.6 supported and covered in
lib/msf/core/module/platform.rb
: