I'm building a webhook listener in vb.net which needs to listen on port 443. I've disabled IIS on my development PC as that was hogging the port, and it still won't allow me to listen on 443.
Using netsh http show urlacl I found there were two entries for 443. One deleted fine, but I can't remove this one:
Reserved URL : https://+:443/sra_{BA195980-CD49-458b-9E23-C84EE0ADCD75}/
User: NT SERVICE\SstpSvc
Listen: Yes
Delegate: Yes
User: BUILTIN\Administrators
Listen: Yes
Delegate: Yes
User: NT AUTHORITY\SYSTEM
Listen: Yes
Delegate: Yes
SDDL: D:(A;;GA;;;S-1-5-80-3435701886-799518250-3791383489-3228296122-2938884314)(A;;GA;;;BA)(A;;GA;;;SY)
I keep getting the following error message:
netsh http delete urlacl url=https://+:443/sra_{BA195980-CD49-458b-9E23-C84EE0ADCD75}
The syntax supplied for this command is not valid. Check help for the correct syntax.
Usage: delete urlacl [url=]<string>
Parameters:
Tag Value
url - The fully qualified URL to be deleted.
Remarks: This command deletes a reserved URL.
Examples:
delete urlacl url=http://+:80/MyUri
delete urlacl url=http://www.contoso.com:80/MyUri
I tried just adding me anyway:
netsh http add urlacl url=http://*:443/ user=domain\username listen=yes
But that reports
Url reservation add failed, Error: 183
Cannot create a file when that file already exists.
Could I ask for some guidance please on whether it is possible to remove the exiting reservation, and if not, how do I get my listener to listen on 443?
I have no idea as to whether this is correct or not, but I tried this in the listener:
Dim prefix As String = "https://*:443/"
Dim listener As New HttpListener()
listener.Prefixes.Add(prefix)
Dim username = Environment.GetEnvironmentVariable("USERNAME")
Dim userdomain = Environment.GetEnvironmentVariable("USERDOMAIN")
Try
listener.Start()
Catch ex As HttpListenerException
If ex.ErrorCode = 5 Then
Console.WriteLine("You need to run the following command:")
Console.WriteLine(" netsh http add urlacl url={0} user={1}\{2} listen=yes", prefix, userdomain, username)
Exit Sub
Else
Throw
End If
End Try
This allows it to listen, but doesn't pick anything up when the webhook is sent.
If I change it back to http: I get
System.Net.HttpListenerException: 'Failed to listen on prefix 'http://*:443/' because it conflicts with an existing registration on the machine.'
As per my other post, I tried a TCP listener:
Dim port As Integer = 443
' Create a TcpListener
Dim listener As TcpListener = New TcpListener(IPAddress.Any, port)
' Start listening for incoming connections
listener.Start()
Console.WriteLine("Webhook receiver started. Listening on port " & port)
Try
While True
' Accept the connection when a client connects
Dim client As TcpClient = listener.AcceptTcpClient()
' Process the incoming data
Dim data As String = ReadDataFromClient(client)
' Print the received data to the console
Console.WriteLine(Format(Now, "HH:mm:ss ") + "Received data: " + data.ToString)
' Close the client connection
client.Close()
End While
Catch ex As Exception
Console.WriteLine("Error: " & ex.Message)
Finally
' Stop listening for incoming connections when the loop exits
listener.Stop()
End Try
This "works" insomuch as ReadDataFromClient is triggered, but it doesn't receive anything.
Desperately trying to get the httplistener to work.