Last active
April 13, 2024 14:21
-
-
Save AyrA/e04c977232a74525f4421cd4cb1a4764 to your computer and use it in GitHub Desktop.
Powershell HTTP Server
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
# Portable HTTP file server | |
# Should be somewhat safe but please don't actually use it. | |
# You can't exit this with CTRL+C directly and need to use the shutdown command below a directory listing, | |
# or you can kill the powershell process of course, but this causes the port to stay used sometimes. | |
# Features | |
# - Directory Browser | |
# - Can handle UTF8 URLs | |
# - Delivers unknown file types | |
# - /../ attack prevention | |
# Drawbacks | |
# - Only one request at a time | |
# - Only runs on localhost unless it has administrative rights | |
# - Files loaded completely into memory | |
Add-Type -AssemblyName System.Web | |
# Writes a string to a stream that expects a byte array | |
function Write-String { | |
$b=[System.Text.Encoding]::UTF8.GetBytes($args[1]) | |
$args[0].Write($b,0,$b.Length) | |
} | |
# HTML Encoder | |
function Html-Encode { | |
return [System.Web.HttpUtility]::HtmlEncode($args[0]) | |
} | |
# URL Encoder | |
function Url-Encode { | |
return [uri]::EscapeDataString($args[0]) | |
} | |
# Prevent accidental exit | |
$nonce = [System.DateTime]::Now.Ticks | |
# Cheap Directory Jail | |
New-PSDrive -Name OhGodWhy -PSProvider FileSystem -Root $PWD.Path | |
# Create and start listener | |
$listener = New-Object System.Net.HttpListener | |
$listener.Prefixes.Add("http://localhost:55555/") | |
$listener.Start() | |
echo "Http: http://localhost:55555/" | |
echo "Path: $PWD" | |
# Open default browser | |
start "http://localhost:55555/" | |
# Be able to serve multiple requests | |
while($listener.IsListening){ | |
$Context = $listener.GetContext() | |
$URL = $Context.Request.Url.LocalPath | |
echo "Request: $URL" | |
if(Test-Path "OhGodWhy:$URL" -PathType Leaf){ | |
echo "Requesting a File" | |
# Is file, serve it | |
$Content = Get-Content -Encoding Byte -Path "OhGodWhy:$URL" -ReadCount 0 | |
# This can throw an error on older versions of PowerShell but the web server will still work | |
$Context.Response.ContentType = [System.Web.MimeMapping]::GetMimeMapping($URL) | |
$Context.Response.ContentLength = $Content.Length | |
# Write content as-is | |
$Context.Response.OutputStream.Write($Content, 0, $Content.Length) | |
} elseif (Test-Path "OhGodWhy:$URL" -PathType Container) { | |
if($Context.Request.Url.Query -eq "?$nonce"){ | |
echo "Requesting Server Shutdown" | |
# Stop listener | |
$Context.Response.ContentType = "text/html" | |
Write-String $Context.Response.OutputStream "<h1>The server has been shut down</h1>" | |
$Context.Response.Close() | |
# Give the component time to deliver the answer | |
sleep 1 | |
$listener.Stop() | |
return | |
}else{ | |
echo "Requesting Directory listing" | |
# Is directory, show contents | |
$Context.Response.ContentType = "text/html; charset=utf-8" | |
$Context.Response.ContentEncoding = [System.Text.Encoding]::UTF8 | |
# Make it look somewhat nice | |
Write-String $Context.Response.OutputStream "<style> | |
*{font-family:monospace;font-size:14pt} | |
div a{text-decoration:none;display:inline-block;width:49%;padding:5px} | |
div a:hover{background-color:#FF0} | |
#sd{color:#F00;text-decoration:none;}</style>" | |
Write-String $Context.Response.OutputStream "<h1>Directory Listing</h1><div>" | |
# UP | |
Write-String $Context.Response.OutputStream "<a href=""../""><UP></a><br />" | |
# Directories above files | |
Get-ChildItem "OhGodWhy:$URL" | Where-Object { $_.PSIsContainer } | Foreach-Object { | |
$fn=[System.IO.Path]::GetFileName($_.FullName) | |
$href=Url-Encode $fn | |
$fn=Html-Encode $fn | |
Write-String $Context.Response.OutputStream "<a href=""$href/"">$fn/</a>" | |
} | |
Get-ChildItem "OhGodWhy:$URL" | Where-Object { -not $_.PSIsContainer } | Foreach-Object { | |
$fn=[System.IO.Path]::GetFileName($_.FullName) | |
$href=Url-Encode $fn | |
$fn=Html-Encode $fn | |
Write-String $Context.Response.OutputStream "<a href=""$href"">$fn</a>" | |
} | |
# Shutdown | |
Write-String $Context.Response.OutputStream "</div><hr/>[<a id=""sd"" href=""/?$nonce"">SHUTDOWN</a>]<hr/>" | |
} | |
} else { | |
echo "HTTP 404" | |
# Not found | |
$Context.Response.StatusCode = 404; | |
$Context.Response.ContentType = "text/plain"; | |
Write-String $Context.Response.OutputStream "$URL not found" | |
} | |
echo "Done" | |
# Complete request | |
$Context.Response.Close() | |
} | |
# SIG # Begin signature block | |
# MIIcUQYJKoZIhvcNAQcCoIIcQjCCHD4CAQExCzAJBgUrDgMCGgUAMGkGCisGAQQB | |
# gjcCAQSgWzBZMDQGCisGAQQBgjcCAR4wJgIDAQAABBAfzDtgWUsITrck0sYpfvNR | |
# AgEAAgEAAgEAAgEAAgEAMCEwCQYFKw4DAhoFAAQUSSRLlJF1uZJYBdgVuT7FbzO8 | |
# J2iggheAMIIFCTCCA/GgAwIBAgIQA+dSOtMg37kx2aYXVFlBdzANBgkqhkiG9w0B | |
# AQsFADByMQswCQYDVQQGEwJVUzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYD | |
# VQQLExB3d3cuZGlnaWNlcnQuY29tMTEwLwYDVQQDEyhEaWdpQ2VydCBTSEEyIEFz | |
# c3VyZWQgSUQgQ29kZSBTaWduaW5nIENBMB4XDTE4MTEyMTAwMDAwMFoXDTIyMDEy | |
# NjEyMDAwMFowRjELMAkGA1UEBhMCQ0gxDzANBgNVBAcTBktyaWVuczESMBAGA1UE | |
# ChMJS2V2aW4gR3V0MRIwEAYDVQQDEwlLZXZpbiBHdXQwggEiMA0GCSqGSIb3DQEB | |
# AQUAA4IBDwAwggEKAoIBAQDC4GHIAhukvfkIWIRNHp7Fru3egC9W3tOJN3lyHtw5 | |
# viZfaGdAUkCyw7sF2Fjp058uCx0NeAVCJC8EffTIVrmQyumCR0g2xB4FQoFYDiTJ | |
# vhGVbIGVedvPcKmrWOx7Ir1Wjoc9S/k/f8/vTkNKmB8oZcofA/7MHC3woiN4scpK | |
# RjrerM/6zsgJnnzM+03QQO1Z5beJk8QDNl2Z3QJAGYNYyi4LBJw1u9951AM2dDbz | |
# /FGoZVQLX3Iwb2qCrhOO/W7m3qhdlXH1/CZpJmAJgcQ14F0e14FrjOJ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fmFW69t | |
# qVcMH4nRBhou9THwm6B21mTCUwdANDMmEXNaSzaReTCl5Gp6MTZHdvCjpJd4q1y/ | |
# PKIR5IJxk/B92hltw08NxtwHe1wtCHeMYYM2Dq1h8nMv6aL/NK3THR8ANEjr9cKQ | |
# 3eShggIPMIICCwYJKoZIhvcNAQkGMYIB/DCCAfgCAQEwdjBiMQswCQYDVQQGEwJV | |
# UzEVMBMGA1UEChMMRGlnaUNlcnQgSW5jMRkwFwYDVQQLExB3d3cuZGlnaWNlcnQu | |
# Y29tMSEwHwYDVQQDExhEaWdpQ2VydCBBc3N1cmVkIElEIENBLTECEAMBmgI6/1ix | |
# a9bV6uYX8GYwCQYFKw4DAhoFAKBdMBgGCSqGSIb3DQEJAzELBgkqhkiG9w0BBwEw | |
# HAYJKoZIhvcNAQkFMQ8XDTE4MTIxNTE0MDY1MVowIwYJKoZIhvcNAQkEMRYEFLSe | |
# FZuW1KB/W0geFEj6TFW0Koa9MA0GCSqGSIb3DQEBAQUABIIBABTwb7K7OirstuJp | |
# Wayj6hFPTQIaP1Tf8oq3wcohCjeEL8gsrbVui678RlzmhT39+lxmDnTs+qFqbFF4 | |
# Yjfpn9DWZWnNnKO7oyxhuvAjfcyJHw2K5N8MyDvva92baiWawEqCI7O0c/NWGW7w | |
# rf+4VD8c+dBHEYjT2LQsAlPl3LUIrR56u0C/3BPH1P0i8P9cEyxzuwdryd+vDqw1 | |
# fuokTkzOoSaei4slqPRG6T/vqdHcT2qKVuxdpQoL01RPzF/9wuPjWL3yp+Oq8p6d | |
# vEz/4w/yyO6qU6Y8hYvFVgGfRkhTspjxG+WPMABGYVjtmzLB06++aEHGkG9wIX7b | |
# IGEzKiQ= | |
# SIG # End signature block |
Hello,
Please add this Check to avoid throwing errors about ContentLength
I found that the Property is named ContentLength64
in my Powershell v5.1.19041.2364.
if ($Context.Response.ContentLength -ne $null) {
$Context.Response.ContentLength = $Content.Length
} elseif ($Context.Response.ContentLength64 -ne $null) {
$Context.Response.ContentLength64 = $Content.Length
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Access is provided to whatever folder your powershell currently points. To get access to "D:\Pic", go into that directory with powershell, then call the script