├── AzureRedirector.sln ├── AzureRedirector ├── AzureRedirector.csproj ├── Program.cs ├── ReverseProxy.cs └── Startup.cs └── README.md /AzureRedirector.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.12.35707.178 d17.12 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "AzureRedirector", "AzureRedirector\AzureRedirector.csproj", "{9668CB4C-8616-4F4D-B265-3759329A9F5E}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Debug|x64 = Debug|x64 12 | Release|Any CPU = Release|Any CPU 13 | Release|x64 = Release|x64 14 | EndGlobalSection 15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 16 | {9668CB4C-8616-4F4D-B265-3759329A9F5E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 17 | {9668CB4C-8616-4F4D-B265-3759329A9F5E}.Debug|Any CPU.Build.0 = Debug|Any CPU 18 | {9668CB4C-8616-4F4D-B265-3759329A9F5E}.Debug|x64.ActiveCfg = Debug|x64 19 | {9668CB4C-8616-4F4D-B265-3759329A9F5E}.Debug|x64.Build.0 = Debug|x64 20 | {9668CB4C-8616-4F4D-B265-3759329A9F5E}.Release|Any CPU.ActiveCfg = Release|Any CPU 21 | {9668CB4C-8616-4F4D-B265-3759329A9F5E}.Release|Any CPU.Build.0 = Release|Any CPU 22 | {9668CB4C-8616-4F4D-B265-3759329A9F5E}.Release|x64.ActiveCfg = Release|x64 23 | {9668CB4C-8616-4F4D-B265-3759329A9F5E}.Release|x64.Build.0 = Release|x64 24 | EndGlobalSection 25 | GlobalSection(SolutionProperties) = preSolution 26 | HideSolutionNode = FALSE 27 | EndGlobalSection 28 | EndGlobal 29 | -------------------------------------------------------------------------------- /AzureRedirector/AzureRedirector.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net9.0 5 | enable 6 | enable 7 | AnyCPU;x64 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /AzureRedirector/Program.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Hosting; 2 | using Microsoft.Extensions.Hosting; 3 | 4 | namespace Redirector.API 5 | { 6 | public class Program 7 | { 8 | public static void Main(string[] args) 9 | { 10 | // Build and run the host 11 | CreateHostBuilder(args).Build().Run(); 12 | } 13 | 14 | public static IHostBuilder CreateHostBuilder(string[] args) => 15 | Host.CreateDefaultBuilder(args) 16 | .ConfigureWebHostDefaults(webBuilder => 17 | { 18 | // Specify the Startup class 19 | webBuilder.UseStartup(); 20 | }); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /AzureRedirector/ReverseProxy.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Net.Http; 3 | using System.Security.Authentication; 4 | using System.Threading.Tasks; 5 | using Microsoft.AspNetCore.Http; 6 | 7 | namespace Redirector.API 8 | { 9 | public class ReverseProxy 10 | { 11 | // Hardcoded IP of the target server 12 | public static string TeamServer => ""; // Replace with your target IP 13 | 14 | private static readonly HttpClient _httpClient = new HttpClient(new HttpClientHandler 15 | { 16 | SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls13, ServerCertificateCustomValidationCallback = (sender, cert, chain, sslPolicyErrors) => true // Accept all TLS Traffic 17 | }); 18 | 19 | public static async Task Invoke(HttpContext context) 20 | { 21 | // Build the target URL with HTTPS 22 | var targetUri = new Uri($"https://{TeamServer}{context.Request.Path}{context.Request.QueryString}"); 23 | 24 | var request = new HttpRequestMessage 25 | { 26 | Method = new HttpMethod(context.Request.Method), 27 | RequestUri = targetUri, 28 | Content = context.Request.ContentLength > 0 ? new StreamContent(context.Request.Body) : null 29 | }; 30 | 31 | // Forward headers 32 | foreach (var header in context.Request.Headers) 33 | { 34 | if (!request.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray())) 35 | { 36 | request.Content?.Headers.TryAddWithoutValidation(header.Key, header.Value.ToArray()); 37 | } 38 | } 39 | 40 | var remoteResponse = await _httpClient.SendAsync(request); 41 | 42 | context.Response.StatusCode = (int)remoteResponse.StatusCode; 43 | 44 | foreach (var header in remoteResponse.Headers) 45 | { 46 | context.Response.Headers[header.Key] = header.Value.ToArray(); 47 | } 48 | 49 | if (remoteResponse.Content != null) 50 | { 51 | await remoteResponse.Content.CopyToAsync(context.Response.Body); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /AzureRedirector/Startup.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.AspNetCore.Builder; 2 | using Microsoft.Extensions.Configuration; 3 | using Microsoft.Extensions.DependencyInjection; 4 | 5 | namespace Redirector.API 6 | { 7 | public class Startup 8 | { 9 | public Startup(IConfiguration configuration) 10 | { 11 | Configuration = configuration; 12 | } 13 | 14 | public IConfiguration Configuration { get; } 15 | 16 | public void ConfigureServices(IServiceCollection services) 17 | { 18 | // Add minimal required services (controllers if needed in the future) 19 | services.AddControllers(); 20 | } 21 | 22 | public void Configure(IApplicationBuilder app) 23 | { 24 | // Redirect HTTP to HTTPS for secure communication 25 | app.UseHttpsRedirection(); 26 | 27 | // Route all incoming requests through the Reverse Proxy logic 28 | app.Run(ReverseProxy.Invoke); 29 | } 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # AzureRedirector 2 | A C# project that builds a web application which redirects all HTTPS traffic. 3 | 4 | ## Why? 5 | 6 | While working on Azure Redirectors I've noticed that they all require multiple steps and was a tedious manual task. 7 | I also found that some projects that made this automated utilized an outdated .NET core package version 3.1, added some small updates and now this one uses version 9.0. 8 | 9 | ### Build 10 | Building the C# DLL is as simple as loading it into your Visual Studio, changing the IP located in the `ReverseProxy.cs` file, and then compiling. 11 | 12 | ### Uploading and Building the App 13 | 14 | Login to your Azure Account using the `AZ CLI` tool and use the following command in the ROOT folder of the project 15 | 16 | ```powershell 17 | az webapp up --sku F1 --name --location 18 | ``` 19 | 20 | ![AzureRedirector](https://github.com/user-attachments/assets/019494a8-a1d6-493c-8338-2bacb60f21c1) 21 | 22 | You will receive a URL that can be placed in the URL for the Cobalt Strike Listener 23 | --------------------------------------------------------------------------------