Created
January 25, 2018 20:35
-
-
Save jdmills-edu/a242887f16bf2f1e8354d64f2b39037a to your computer and use it in GitHub Desktop.
Microsoft doesn't offer a commandlet that converts an Advanced Threat Protection (ATP) SafeLink into the real target URL. This short script uses the .NET UrlDecode function and RegEx to extract it.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Converts a URL-encoded ATP Safelink to a real URL. | |
.DESCRIPTION | |
Microsoft doesn't offer a commandlet that converts an Advanced Threat Protection (ATP) SafeLink into the real target URL. This short script uses the .NET UrlDecode function and RegEx to extract it. | |
.PARAMETER safelink | |
A safelinks.protection.outlook.com link that includes the encoded target URL. | |
.EXAMPLE | |
ATP-ConvertSafelinkToUrl.ps1 -safelink https://na01.safelinks.protection.outlook.com/?url=https%3A%2F%2Fyoursite.com&data=email%40domain.com&sdata=xxxx&reserved=0 | |
Returns: https://yoursite.com. | |
#> | |
param( | |
[Parameter(Mandatory=$true)][String]$safelink | |
) | |
[Reflection.Assembly]::LoadWithPartialName("System.Web") | Out-Null | |
$decoded = [System.Web.HttpUtility]::UrlDecode($safelink) | |
$decoded -match "url=(\S+)&data=\S+" | |
$url = $Matches[1] | |
return $url |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment