1
0
mirror of https://git.tartarus.org/simon/putty.git synced 2025-07-01 19:42:48 -05:00

Make our process's ACL more restrictive.

By default Windows processes have wide open ACLs which allow interference
by other processes running as the same user.  Adjust our ACL to make this
a bit harder.

Because it's useful to protect PuTTYtel as well, carve winsecur.c into
advapi functions and wincapi.c for crypt32 functions.
This commit is contained in:
Owen Dunn
2015-11-24 22:02:24 +00:00
parent aba7234bc1
commit 48db456801
7 changed files with 66 additions and 26 deletions

27
windows/wincapi.c Normal file
View File

@ -0,0 +1,27 @@
/*
* wincapi.c: implementation of wincapi.h.
*/
#include "putty.h"
#if !defined NO_SECURITY
#define WINCAPI_GLOBAL
#include "wincapi.h"
int got_crypt(void)
{
static int attempted = FALSE;
static int successful;
static HMODULE crypt;
if (!attempted) {
attempted = TRUE;
crypt = load_system32_dll("crypt32.dll");
successful = crypt &&
GET_WINDOWS_FUNCTION(crypt, CryptProtectMemory);
}
return successful;
}
#endif /* !defined NO_SECURITY */

18
windows/wincapi.h Normal file
View File

@ -0,0 +1,18 @@
/*
* wincapi.h: Windows Crypto API functions defined in wincrypt.c
* that use the crypt32 library. Also centralises the machinery
* for dynamically loading that library.
*/
#if !defined NO_SECURITY
#ifndef WINCAPI_GLOBAL
#define WINCAPI_GLOBAL extern
#endif
DECL_WINDOWS_FUNCTION(WINCAPI_GLOBAL, BOOL, CryptProtectMemory,
(LPVOID,DWORD,DWORD));
int got_crypt(void);
#endif

View File

@ -19,6 +19,7 @@
#include "terminal.h"
#include "storage.h"
#include "win_res.h"
#include "winsecur.h"
#ifndef NO_MULTIMON
#include <multimon.h>
@ -390,6 +391,20 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show)
return 1;
}
/*
* Protect our process
*/
{
char *error = NULL;
if (! setprocessacl(error)) {
/* FIXME: prepare to stuff this into event log somehow */
MessageBox(NULL, "Process protection",
error, MB_OK | MB_ICONEXCLAMATION);
}
sfree(error);
}
/*
* Process the command line.
*/

View File

@ -36,21 +36,6 @@ int got_advapi(void)
return successful;
}
int got_crypt(void)
{
static int attempted = FALSE;
static int successful;
static HMODULE crypt;
if (!attempted) {
attempted = TRUE;
crypt = load_system32_dll("crypt32.dll");
successful = crypt &&
GET_WINDOWS_FUNCTION(crypt, CryptProtectMemory);
}
return successful;
}
PSID get_user_sid(void)
{
HANDLE proc = NULL, tok = NULL;
@ -237,7 +222,7 @@ int make_private_security_descriptor(DWORD permissions,
return ret;
}
int protectprocess(char *error)
int setprocessacl(char *error)
{
SID_IDENTIFIER_AUTHORITY world_auth = SECURITY_WORLD_SID_AUTHORITY;
SID_IDENTIFIER_AUTHORITY nt_auth = SECURITY_NT_AUTHORITY;

View File

@ -32,13 +32,6 @@ DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, DWORD, SetEntriesInAclA,
(ULONG, PEXPLICIT_ACCESS, PACL, PACL *));
int got_advapi(void);
/*
* Functions loaded from crypt32.dll.
*/
DECL_WINDOWS_FUNCTION(WINSECUR_GLOBAL, BOOL, CryptProtectMemory,
(LPVOID, DWORD, DWORD));
int got_crypt(void);
/*
* Find the SID describing the current user. The return value (if not
* NULL for some error-related reason) is smalloced.
@ -60,4 +53,6 @@ int make_private_security_descriptor(DWORD permissions,
PACL *acl,
char **error);
int setprocessacl(char *error);
#endif

View File

@ -14,7 +14,7 @@
#include "proxy.h"
#include "ssh.h"
#include "winsecur.h"
#include "wincapi.h"
#ifdef COVERITY
/*