0x00 Preface
---
Exchange has numerous versions and a large number of historical vulnerabilities, making it necessary to implement version detection and vulnerability scanning through programs. This article will introduce two methods for version detection using Python, detail the implementation of vulnerability scanning, and provide open-source code.
0x01 Introduction
---
This article will cover the following:
- Implementation Approach
- Implementation Details
- Open-Source Code
0x02 Implementation Approach
---
1. Version Identification
(1) Obtain the Exact Version (Build Number)
Access the EWS interface; the exact version can be obtained from the X-OWA-Version in the Response Headers, as shown in the figure below

Advantage: Precise version (Build number) can correspond to specific release dates
Disadvantage: The method is not universal; some older Exchange versions are not supported
(2) Obtain approximate version
Access the OWA interface; the approximate version can be obtained from the echoed content, as shown in the figure below

Advantage: The method is universal
Disadvantage: The approximate version cannot correspond to an exact release date, only to a range
In summary, for version identification, first attempt to obtain the precise version; if that fails, then attempt to obtain the approximate version
After obtaining the version number, you can query the corresponding Exchange version and release date on the official website. Query address: https://docs.microsoft.com/en-us/exchange/new-features/build-numbers-and-release-dates?view=exchserver-2019
2. Vulnerability Detection
Details of Exchange vulnerabilities can be viewed by accessing https://msrc.microsoft.com/update-guide/vulnerability/, for example:
URL for CVE-2020-0688: https://msrc.microsoft.com/update-guide/vulnerability/CVE-2020-0688
For vulnerability detection, the patch date can be used as a criterion. If the identified Exchange version's release date is earlier than a certain patch date, then it is determined that the Exchange is vulnerable to the vulnerability described in that patch.
0x03 Implementation Details
---
1. Version Identification
Implementation code for obtaining version by accessing EWS interface:
url1 = "https://" + host + "/ews" |
Implementation code for obtaining version by accessing OWA interface:
url2 = "https://" + host + "/owa" |
After obtaining the version number, it needs to be matched against known version information. To improve efficiency, you can choose to store known version information in a list, with elements including Exchange version, release date, and build number
First, copy known version information from the official website, then store the version information in a list via string replacement.
During version matching, it is necessary to distinguish between exact versions and approximate versions. Exact versions can correspond to a unique result, while approximate versions require filtering out all possible results.
Build number format example: 15.1.2375.24
Approximate version format example: 15.1.2375
Approximate version filtering method:
Truncate the Build number string by removing the data after the last character ".", then compare it with the approximate version and output all results.
Code example:
versionarray = [ |
2. Vulnerability Detection
Using patch time as the basis for judgment, and similarly to improve efficiency, storing known vulnerability information in a list, with elements including release date and vulnerability number
To facilitate time comparison, it is necessary to change the time format, for example, modifying September 28, 2021 to 09/28/2021
Code example:
vularray = [ |
0x04 Open Source Code
---
Due to the length of the code content, the complete implementation code has been uploaded to GitHub at the following address:
An open-source project
The version database date is 03/21/2022
Vulnerability information includes the following identifiers:
- CVE-2020-0688
- CVE-2021-26855+CVE-2021-27065
- CVE-2021-28482
- CVE-2021-34473+CVE-2021-34523+CVE-2021-31207
- CVE-2021-31195+CVE-2021-31196
- CVE-2021-31206
- CVE-2021-42321
The code can automatically identify the exact version; if identification fails, it switches to identifying the approximate version and marks all matching vulnerabilities.
0x05 Summary
---
This article introduces two methods for Exchange version detection using Python, detailing their implementation, providing open-source code, and serving as an excellent learning example.