# .Net for Pentesters

Source: https://pentest.h4rithd.com/languages/net/  
Section: Languages  
Updated: 2026-05-30  
Author: Harith Dilshan (h4rithd), https://h4rithd.com

## 01 C\#

* Basic

```csharp title="filename.cs"
using System;

namespace h4rithd
{
    class welcome
    {
        static void Main(string[] args)
        {
            Console.WriteLine("welcome to h4rithd.com\r\n");
        }
    }
}
```

* Complie

```bash
## ------------------| Choose version
dir dir c:\Windows\Microsoft.NET\Framework64\v*
dir c:\Windows\Microsoft.NET\Framework\v*

## ------------------| Complie
c:\Windows\Microsoft.NET\Framework64\v4.0.30319\csc.exe filename.cs 
dir ! find "filename.exe"
.\filename.exe
```

* Debug

```csharp
## ------------------| Debug comments
using System.Diagnostics;
static void Main(string[] args)
{
    Debug.Print("Debug");
}

## ------------------| Console output
Console.WriteLine("Debug");
System.Console.WriteLine("Debug");

## ------------------| Message Box
MessageBox.Show("message", "title");  
```

## 02 DotNet Core

### 02.1 [Getting Started](https://dotnet.microsoft.com/en-us/download/visual-studio-sdks)

```bash
## ------------------| Installation on KaliLinux
wget https://packages.microsoft.com/config/debian/12/packages-microsoft-prod.deb -O packages-microsoft-prod.deb
sudo dpkg -i packages-microsoft-prod.deb
rm packages-microsoft-prod.deb
sudo apt-get update
sudo apt-get install -y dotnet-sdk-X.0 ### change the X value as 4,5,6,7,8,9...
sudo apt-get install -y dotnet-runtime-X.0 ### change the X value as 4,5,6,7,8,9...
sudo apt-get install -y aspnetcore-runtime-X.0 ### change the X value as 4,5,6,7,8,9...
```

### 02.2 Create Applications

#### [CLI Application](https://learn.microsoft.com/en-us/dotnet/core/get-started)

```bash
## ------------------| Create project
dotnet new console -o cliapp

## ------------------| Run the appllication
cd cliapp
dotnet run

## ------------------| Build
dotnet build -c release
dotnet build -c debug
```

#### [ASP.NET Core](https://learn.microsoft.com/en-us/aspnet/core/getting-started/?view=aspnetcore-6.0)

```bash
## ------------------| Create project
dotnet new webapp --output aspnetcoreapp --no-https

## ------------------| Run the appllication
cd aspnetcoreapp
dotnet run

## ------------------| Build
dotnet build -c release
dotnet build -c debug
```

#### DLL Application

```bash
## ------------------| Create project
dotnet new classlib -n dllapp

## ------------------| Add Packages
dotnet add package Microsoft.AspNetCore.Components --version 6.0.0
dotnet add package Microsoft.AspNetCore.Components.Web --version 6.0.0

## ------------------| Build
dotnet build -c release
dotnet build -c debug
```
