@@ -23,18 +23,34 @@ def initialize(info = {})
23
23
OptString . new ( 'SERVICE_DISPLAY_NAME' , [ false , 'The service display name' , nil ] ) ,
24
24
OptString . new ( 'SERVICE_DESCRIPTION' , [ false , "Service description to to be used on target for pretty listing" , nil ] )
25
25
] , self . class )
26
+
27
+ register_advanced_options (
28
+ [
29
+ OptBool . new ( 'SERVICE_PERSIST' , [ true , 'Create an Auto run service and do not remove it.' , false ] )
30
+ ] , self . class )
26
31
end
27
32
33
+ # Retrieve the SERVICE_NAME option, generate a random
34
+ # one if not already set.
35
+ #
36
+ # @return service_name [String] the name of the service.
28
37
def service_name
29
38
@service_name ||= datastore [ 'SERVICE_NAME' ]
30
39
@service_name ||= rand_text_alpha ( 8 )
31
40
end
32
41
42
+ # Retrieve the SERVICE_DISPLAY_NAME option, generate a random
43
+ # one if not already set.
44
+ #
45
+ # @return service_display_name [String] the display name of the service.
33
46
def display_name
34
47
@display_name ||= datastore [ 'SERVICE_DISPLAY_NAME' ]
35
48
@display_name ||= rand_text_alpha ( 16 )
36
49
end
37
50
51
+ # Retrieve the SERVICE_DESCRIPTION option
52
+ #
53
+ # @return service_description [String] the service description.
38
54
def service_description
39
55
@service_description ||= datastore [ 'SERVICE_DESCRIPTION' ]
40
56
end
@@ -89,8 +105,14 @@ def psexec(command, disconnect=true)
89
105
90
106
return false unless scm_handle
91
107
108
+ if datastore [ 'SERVICE_PERSIST' ]
109
+ opts = { :start => SERVICE_AUTO_START }
110
+ else
111
+ opts = { }
112
+ end
113
+
92
114
vprint_status ( "#{ peer } - Creating the service..." )
93
- svc_handle , svc_status = dce_createservicew ( dcerpc , scm_handle , service_name , display_name , command , { } )
115
+ svc_handle , svc_status = dce_createservicew ( dcerpc , scm_handle , service_name , display_name , command , opts )
94
116
95
117
case svc_status
96
118
when ERROR_SUCCESS
@@ -133,6 +155,8 @@ def psexec(command, disconnect=true)
133
155
# Maybe we could have a force cleanup option..?
134
156
if service_exists
135
157
print_warning ( "#{ peer } - Not removing service as it already existed..." )
158
+ elsif datastore [ 'SERVICE_PERSIST' ]
159
+ print_warning ( "#{ peer } - Not removing service for persistance..." )
136
160
else
137
161
vprint_status ( "#{ peer } - Removing the service..." )
138
162
svc_status = dce_deleteservice ( dcerpc , svc_handle )
0 commit comments