Advertisement
metalx1000

Basic Webserver 2 - request file

Jun 13th, 2014
409
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <#
  2. From "http://obscuresecurity.blogspot.com/2014/05/dirty-powershell-webserver.html"
  3. Webserver on port 8000
  4. will serve up a file if you request it by name
  5. example: "http://localhost:8000/index.html"
  6.  
  7. you will need to change the content type for different files.
  8. example "Content-Type","text/pain"
  9. #>
  10.  
  11. $Hso = New-Object Net.HttpListener
  12. $Hso.Prefixes.Add("http://+:8000/")
  13. $Hso.Start()
  14. While ($Hso.IsListening) {
  15. $HC = $Hso.GetContext()
  16. $HRes = $HC.Response
  17. $HRes.Headers.Add("Content-Type","text/html")
  18. $Buf = [Text.Encoding]::UTF8.GetBytes((GC (Join-Path $Pwd ($HC.Request).RawUrl)))
  19. $HRes.ContentLength64 = $Buf.Length
  20. $HRes.OutputStream.Write($Buf,0,$Buf.Length)
  21. $HRes.Close()
  22. }
  23. $Hso.Stop()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement