Skip to content
Path traversal Write-up Beginner

Asp Net Core Path Traversal

The article explains that using Path.Combine with user-controlled input without sanitisation allows an attacker to escape the intended directory and access arbitrary files. It demonstrates this with a small C# console application and also shows that the same flaw can be used for DNS-based SSRF.

Alaa Abdulridha Follow

Published on infosecwriteups.com

A path traversal attack (also known as directory traversal) aims to access files and directories that are stored outside the webroot folder. By manipulating variables that reference files with “dot-dot-slash (../)” sequences and its variations or by using absolute file paths, it may be possible to access arbitrary…

Alaa Abdulridha, on infosecwriteups.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The code passes user-controlled input directly to Path.Combine without validating or sanitising it, so an absolute path or traversal sequence overrides the intended base directory.

Impact

An attacker could read arbitrary files on the system, limited only by the operating system's file access controls, and could also use the flaw for DNS-based SSRF.

What the attacker needed

User-controlled input passed to Path.Combine; no other validation or sanitisation

The fix

The vulnerability should be fixed by sanitising the user-supplied filename with Path.GetFileName before combining it with the base path.

How it was found

  1. Create a small C# console application that calls Path.Combine with a user-supplied filename.
  2. Run the application with a normal filename to see the combined path.
  3. Change the input to an absolute path such as C:\alaa.txt to bypass the intended directory.
  4. Optionally use a UNC path to trigger a DNS request and confirm blind path traversal or SSRF.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

Path traversal is when a program builds a file path from user input and an attacker can use sequences like '../' or an absolute path to reach files outside the intended folder. The article shows that the .NET method Path.Combine does not protect against this by itself, so if you pass it a user-supplied filename it may let the user read other files. The fix is to sanitise the input, for example by using Path.GetFileName to strip any directory parts.

What is Path traversal?

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.

More by Alaa Abdulridha

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Path traversal and file inclusion

The lesson behind this report.

Input that builds a file path escapes the intended folder, reading or writing files the application should never touch.