@@ -5,7 +5,7 @@ module Msf::HTTP::JBoss::Base
55 # Deploys a WAR through HTTP uri invoke
66 #
77 # @param opts [Hash] Hash containing {Exploit::Remote::HttpClient#send_request_cgi} options
8- # @param num_attempts [Integer] The number of attempts
8+ # @param num_attempts [Integer] The number of attempts
99 # @return [Rex::Proto::Http::Response, nil] The {Rex::Proto::Http::Response} response if exists, nil otherwise
1010 def deploy ( opts = { } , num_attempts = 5 )
1111 uri = opts [ 'uri' ]
@@ -46,4 +46,96 @@ def http_verb
4646 datastore [ 'VERB' ]
4747 end
4848
49+
50+ # Try to auto detect the target architecture and platform
51+ #
52+ # @param [Array] The available targets
53+ # @return [Msf::Module::Target, nil] The detected target or nil
54+ def auto_target ( available_targets )
55+ if http_verb == 'HEAD'
56+ print_status ( "Sorry, automatic target detection doesn't work with HEAD requests" )
57+ else
58+ print_status ( "Attempting to automatically select a target..." )
59+ res = query_serverinfo
60+ plat = detect_platform ( res )
61+ unless plat
62+ print_warning ( 'Unable to detect platform!' )
63+ return nil
64+ end
65+
66+ arch = detect_architecture ( res )
67+ unless arch
68+ print_warning ( 'Unable to detect architecture!' )
69+ return nil
70+ end
71+
72+ # see if we have a match
73+ available_targets . each { |t | return t if t [ 'Platform' ] == plat && t [ 'Arch' ] == arch }
74+ end
75+
76+ # no matching target found, use Java as fallback
77+ java_targets = available_targets . select { |t | t . name =~ /^Java/ }
78+
79+ java_targets [ 0 ]
80+ end
81+
82+ # Query the server information from HtmlAdaptor
83+ #
84+ # @return [Rex::Proto::Http::Response, nil] The {Rex::Proto::Http::Response} response or nil
85+ def query_serverinfo
86+ path = normalize_uri ( target_uri . path . to_s , 'HtmlAdaptor' )
87+ res = send_request_cgi (
88+ {
89+ 'uri' => path ,
90+ 'method' => http_verb ,
91+ 'vars_get' =>
92+ {
93+ 'action' => 'inspectMBean' ,
94+ 'name' => 'jboss.system:type=ServerInfo'
95+ }
96+ } )
97+
98+ unless res && res . code == 200
99+ print_error ( "Failed: Error requesting #{ path } " )
100+ return nil
101+ end
102+
103+ res
104+ end
105+
106+ # Try to autodetect the target platform
107+ #
108+ # @param res [Rex::Proto::Http::Response] the http response where fingerprint platform from
109+ # @return [String, nil] The target platform or nil
110+ def detect_platform ( res )
111+ if res && res . body =~ /<td.*?OSName.*?(Linux|FreeBSD|Windows).*?<\/ td>/m
112+ os = $1
113+ if ( os =~ /Linux/i )
114+ return 'linux'
115+ elsif ( os =~ /FreeBSD/i )
116+ return 'linux'
117+ elsif ( os =~ /Windows/i )
118+ return 'win'
119+ end
120+ end
121+
122+ nil
123+ end
124+
125+ # Try to autodetect the target architecture
126+ #
127+ # @param res [Rex::Proto::Http::Response] the http response where fingerprint architecture from
128+ # @return [String, nil] The target architecture or nil
129+ def detect_architecture ( res )
130+ if res && res . body =~ /<td.*?OSArch.*?(x86|i386|i686|x86_64|amd64).*?<\/ td>/m
131+ arch = $1
132+ if arch =~ /(x86|i386|i686)/i
133+ return ARCH_X86
134+ elsif arch =~ /(x86_64|amd64)/i
135+ return ARCH_X86
136+ end
137+ end
138+
139+ nil
140+ end
49141end
0 commit comments