Skip to content

Commit

Permalink
Update HTTPListener.cs
Browse files Browse the repository at this point in the history
Fix for Negotiate auth
  • Loading branch information
Kevin-Robertson committed Jan 9, 2022
1 parent eaf0227 commit 8c765f1
Showing 1 changed file with 16 additions and 7 deletions.
23 changes: 16 additions & 7 deletions Inveigh/Protocols/Quiddity/Quiddity/Listeners/HTTPListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ internal void ReceiveClient(object parameters)

while (tcpClient.Connected && isRunning)
{
byte[] requestData = new byte[4096];
byte[] requestData = new byte[16384];

if (type.Equals("HTTPS"))
{
Expand Down Expand Up @@ -234,7 +234,7 @@ internal void ReceiveClient(object parameters)
}

}

HTTPRequest request = new HTTPRequest();

if (!Utilities.ArrayIsNullOrEmpty(requestData))
Expand Down Expand Up @@ -291,7 +291,7 @@ internal void ReceiveClient(object parameters)
}

}

if (type.Equals("Proxy"))
{
response.StatusCode = "407";
Expand Down Expand Up @@ -322,7 +322,7 @@ internal void ReceiveClient(object parameters)
response.WWWAuthenticate = string.Concat("Basic realm=", HTTPRealm);
}

if ((!string.IsNullOrEmpty(request.Authorization) && request.Authorization.ToUpper().StartsWith("NTLM ")) || (!string.IsNullOrEmpty(request.ProxyAuthorization)) && request.ProxyAuthorization.ToUpper().StartsWith("NTLM "))
if (!string.IsNullOrEmpty(request.Authorization) && (request.Authorization.ToUpper().StartsWith("NTLM ") || request.Authorization.ToUpper().StartsWith("NEGOTIATE ")) || (!string.IsNullOrEmpty(request.ProxyAuthorization)) && request.ProxyAuthorization.ToUpper().StartsWith("NTLM "))
{
string authorization = request.Authorization;

Expand All @@ -332,7 +332,7 @@ internal void ReceiveClient(object parameters)
}

NTLMNegotiate ntlm = new NTLMNegotiate();
ntlm.ReadBytes(Convert.FromBase64String(authorization.Substring(5, authorization.Length - 5)), 0);
ntlm.ReadBytes(Convert.FromBase64String(request.Authorization.Split(' ')[1]), 0);

if (ntlm.MessageType == 1)
{
Expand All @@ -351,7 +351,16 @@ internal void ReceiveClient(object parameters)
}
else
{
response.WWWAuthenticate = "NTLM " + Convert.ToBase64String(challengeData);

if (request.Authorization.ToUpper().StartsWith("NEGOTIATE "))
{
response.WWWAuthenticate = "Negotiate " + Convert.ToBase64String(challengeData);
}
else
{
response.WWWAuthenticate = "NTLM " + Convert.ToBase64String(challengeData);
}

}

response.Connection = "";
Expand All @@ -362,7 +371,7 @@ internal void ReceiveClient(object parameters)
response.ReasonPhrase = "OK";
ntlmStage = 3;
isClientClose = true;
NTLMResponse ntlmResponse = new NTLMResponse(Convert.FromBase64String(authorization.Substring(5, authorization.Length - 5)), false);
NTLMResponse ntlmResponse = new NTLMResponse(Convert.FromBase64String(authorization.Split(' ')[1]), false);
string domain = Encoding.Unicode.GetString(ntlmResponse.DomainName);
string user = Encoding.Unicode.GetString(ntlmResponse.UserName);
string host = Encoding.Unicode.GetString(ntlmResponse.Workstation);
Expand Down

0 comments on commit 8c765f1

Please sign in to comment.