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

Linux post libs comments and specs #19682

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

h00die
Copy link
Contributor

@h00die h00die commented Nov 27, 2024

This PR does a few things for linux post libs:

  1. adds function comments
  2. adds specs
  3. creates a new packages module which can be used to check what version of a package is installed. Ubuntu needrestart LPE (CVE-2024-48990) #19676 (comment)
  4. rubocops the libraries

Copy link
Contributor

@cdelafuente-r7 cdelafuente-r7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @h00die for adding documentation and specs. I just added a couple of comments.

def installed_package_version(package)
info = get_sysinfo

if ['debian', 'ubuntu'].include?info[:distro]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just for consistency:

Suggested change
if ['debian', 'ubuntu'].include?info[:distro]
if ['debian', 'ubuntu'].include?(info[:distro])

return Rex::Version.new(package_version)
elsif ['redhat', 'fedora'].include?(info[:distro])
package_version = cmd_exec("rpm -q #{package}")
return nil if package_version.include?('is not installed')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't tested it, but I'm wondering if rpm returns a message in English on a non-English installation.

This also applies to the system commands called in this method.

@h00die
Copy link
Contributor Author

h00die commented Nov 28, 2024

Appreciate, I'm going to get specs working for all the linux post libs before putting this up for official review. Good question about language though

info = get_sysinfo

if ['debian', 'ubuntu'].include?info[:distro]
package_version = cmd_exec("dpkg -l #{package} | grep \'^ii\'")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
package_version = cmd_exec("dpkg -l #{package} | grep \'^ii\'")
package_version = cmd_exec("dpkg-query -f='${Version}' -W #{package}")

This will directly output the version of the package if it's installed

package_version = package_version.match(/Version\s+:\s+(.+)/)[1]
return Rex::Version.new(package_version)
else
vprint_error('installed_package_version is being called on an unsupported OS')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
vprint_error('installed_package_version is being called on an unsupported OS')
vprint_error("installed_package_version is being called on an unsupported OS: #{info['distro'}")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants