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

remove is_root check from linux_hashdump module #15072

Merged
merged 1 commit into from
Apr 21, 2021

Conversation

pingport80
Copy link
Contributor

@pingport80 pingport80 commented Apr 21, 2021

Summary

This PR fixes a logic bug in module /post/linux/gather/hashdump which is used to dump hashes from shadow file.

The Bug

unless is_root?
  fail_with Failure::NoAccess, 'You must run this module as root!'
end

The module checks if the user is root or not. If the user is not root it exits. But there can be a case when a non-root user might have read access to the shadow file because of weak permissions. I think it's better to check if the shadow file is readable or not.

Verification Steps

Fire up Metasploit and get a non-root user session

msf6 > sessions -c "id -u" -i 1
[*] Running 'id -u' on shell session 1 (127.0.0.1)
1000

msf6 > use post/linux/gather/hashdump
msf6 post(linux/gather/hashdump) > set session 1
msf6 post(linux/gather/hashdump) > run 
[*] Reloading module...

[-] Post aborted due to failure: no-access: Shadow file must be readable in order to dump hash
es
[*] Post module execution completed

As root do chmod o+r /etc/shadow

msf6 post(linux/gather/hashdump) > run
[+] root:[hash]:0:0:root:/root:/bin/bash
[+] user:[hash]:1000:1000:User Name,,,:/home/user:/bin/bash
[+] Unshadowed Password File: /home/pingport80/.msf4/loot/20210421104310_default_127.0.0.1_lin
ux.hashes_337278.txt
[*] Post module execution completed
msf6 post(linux/gather/hashdump) >

@pingport80 pingport80 changed the title remove is_root check from linux_hashdump remove is_root check from linux_hashdump module Apr 21, 2021
@pingport80 pingport80 closed this Apr 21, 2021
@pingport80 pingport80 reopened this Apr 21, 2021
@pingport80
Copy link
Contributor Author

Sorry I closed this PR by mistake, reopening it.

@gwillcox-r7
Copy link
Contributor

Looks good to me, and from tests I can see this now allows one to dump the hashes if the configuration on the /etc/shadow file is incorrect. Nice work @pingport80! Will land this now.

@gwillcox-r7 gwillcox-r7 merged commit 634e883 into rapid7:master Apr 21, 2021
@gwillcox-r7
Copy link
Contributor

gwillcox-r7 commented Apr 21, 2021

Release Notes

Improved the post/linux/gather/hashdump module such that, instead of checking if the user is root, it will now check if the user has access to the /etc/shadow file prior to attempting to dump the hashes from the shadow file. This allows users to dump password hashes in the case where the permissions of the /etc/shadow file may be set up incorrectly, even if they are not the root user.

@pingport80 pingport80 deleted the fix_linux_hashdump branch April 21, 2021 14:46
@adfoster-r7 adfoster-r7 added the rn-enhancement release notes enhancement label Apr 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants