• Diniz Martins

Expanding Shortened URLs With PowerShell

Shortened URLs are generated by services such as Bitly or TinyURL, and they take a long address and turn it into something like https://tinyurl.com/ycwcj8xd.

These are legitimate services as some URLs can be truly horrific but they are also often abused to disguise malicious addressees, or tracking and affiliate parameters that you may not wish to entertain. Often you simply want to see what site you’re being taken to before clicking on a link.

Let’s check it out:

Open your PowerShell as administrator and type:

function ExpandURL([string]$URL) {
    (Invoke-WebRequest -MaximumRedirection 0 -Uri $URL -ErrorAction SilentlyContinue).Headers.Location

▸ Type the commands below:

Invoke-WebRequest -MaximumRedirection 0 -Uri <your_short-url>
(Invoke-WebRequest -MaximumRedirection 0 -Uri <your_short-url> -ErrorAction SilentlyContinue).Headers

Let’s see it in action:

PS C:\> expandurl https://tinyurl.com/ycwcj8xd

The way these services work is through HTTP redirects, the browser takes you to the shortened URL, the service returns a HTTP 301 (Moved Permanently), and provides the actual URL in the return header which your client then follows. We can get in the middle of this process by telling PowerShell not to follow redirects using the -MaximumRedirection 0 option with Invoke-WebRequest, and then retrieving the real address from the headers.


Recent Posts

See All

D-TECT | Pentest the Modern Web

D-TECT is a penetration testing tool that can be used for information gathering and finding vulnerabilities in web applications. The types of vulnerabilities that can be detected of D-TECT tool includ

Downloads - #1

Here you have some amazing Windows files to celebrate the first year of STENGE.info. Enjoy it! ➟ HJSplit - Program that can split a file of any type and size into smaller parts. It can also join these

WSL | NMAP not work!

Ever since the release of the Windows Subsystem for Linux, a years long unfulfilled hope of using Nmap in this environment still lingers. You can install Nmap (sudo apt-install nmap) in Bash but when