Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make named pipe security configurable by security descriptor string #2083

Closed

Conversation

Breakwell
Copy link
Contributor

Description

Named pipes on Windows are vulnerable to privilege escalation through named pipe impersonation, to protect against this in Thrift it should allow the security of a pipe to be configured.

Implementation

Changed setting the pipe permissions to "everyone" to now be configured by security string this will default to "everyone" but can also by set in the constructor of a TPipeServer.

@kainjow
Copy link
Contributor

kainjow commented Apr 11, 2020

you should probably make a Jira, this isn't a trivial change.

LocalFree(acl);
FreeSid(everyone_sid);
if (psd)
LocalFree(psd);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we use an RAII wrapper instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel it's a bit overkill to add a RAII considering we only free once.

@@ -76,6 +85,7 @@ class TPipeServer : public TServerTransport {
bool getAnonymous();
void setAnonymous(bool anon);
void setMaxConnections(uint32_t maxconnections);
void setSecurityDescriptor(std::string securityDescriptor);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

make const reference.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@kainjow
Copy link
Contributor

kainjow commented Apr 11, 2020

I would suggest backing out the extra style changes to keep the diff minimal and relevant.

TNamedPipeServer(const std::string& pipename,
uint32_t bufsize,
uint32_t maxconnections,
const std::string& securityDescriptor)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to protect against this in Thrift it should allow the security of a pipe to be configured

This forces the issue, and is a breaking change. It would be better to introduce this functionality while still allowing existing code to compile, and deprecate the old constructors, and then remove them in the following release if we really think it is necessary to force a securityDescriptor in all use cases (I'm not convinced yet).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that this shouldn't be a breaking a change and shouldn't enforce the use of a security descriptor. TNamedPipeServer is internal to TPipeServer. I have given TPipeServer an additional constructor that now takes a security descriptor as a parameter. Now when TPipeServer is constructed unless a security descriptor is provided it has the security descriptor set to "Everyone" to maintain the previous behavior . As TNamedPipeServer is only in the cpp I don't see how this is a breaking change.

return false;
}
if (!SetSecurityDescriptorDacl(&sd, true, NULL, false))
{
if (!SetSecurityDescriptorDacl(&sd, true, NULL, false)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove brace line change.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is now inline with the clang format file in the repo. As it's a step in the right direction and doesn't make the PR unclear I think it's fine to leave the formatting change as is.

if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))
{
GlobalOutput.perror("TPipeServer InitializeSecurityDescriptor (anon) failed, GLE=", GetLastError());
if (!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION)) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove unneeded formatting changes.

throw TTransportException(TTransportException::NOT_OPEN,
"TCreateNamedPipe() failed",
lastError);
throw TTransportException(TTransportException::NOT_OPEN, "TCreateNamedPipe() failed",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove unneeded formatting changes

@Jens-G
Copy link
Member

Jens-G commented May 28, 2020

Not quite sure .... what is tghe status of this PR? Are we done or are there any pending change requests?

@Breakwell
Copy link
Contributor Author

Not quite sure .... what is tghe status of this PR? Are we done or are there any pending change requests?

I have addressed the comments for clarity. I am happy with the changes unless anyone feels particularly strongly I think it's fine as is.

@Jens-G Jens-G closed this in 36bf0a4 May 30, 2020
theopolis added a commit to theopolis/osquery that referenced this pull request Dec 23, 2020
theopolis added a commit to osquery/osquery that referenced this pull request Dec 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants