Last active
February 27, 2023 22:53
-
-
Save ferki/18a869f4b3bb97eda58114ebac00a2bd to your computer and use it in GitHub Desktop.
rex sudo pass
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| use strict; | |
| use warnings; | |
| use Rex -feature => [ '1.4', 'exec_autodie' ]; | |
| sudo_password get_password('path/to/sudo/password/in/pass'); | |
| user 'myuser'; | |
| task 'a' => sub { | |
| say run 'whoami'; # should be myuser | |
| get_sudo(); | |
| say run 'whoami'; # should be root | |
| }; | |
| sub get_sudo { | |
| sudo TRUE; | |
| my $sudo_password = Rex::Config::get_sudo_password(); | |
| return if $sudo_password; | |
| print 'I need sudo password: '; | |
| ReadMode('noecho'); | |
| sudo_password ReadLine(0); | |
| ReadMode('restore'); | |
| say 'Thanks!'; | |
| } | |
| sub get_password { | |
| my $query = shift; | |
| my $password; | |
| open PASS, '-|', "pass show $query"; | |
| while ( $password = <PASS> ) { | |
| chomp $password; | |
| last; | |
| } | |
| close PASS; | |
| return $password; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment