forked from p15670423/monkey
Move `is_windows_os` to data_dir_generator.py and add user write
permissions to newly created data directory
This commit is contained in:
parent
a1beee95f3
commit
3201672248
|
@ -1,25 +1,27 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
import ntsecuritycon
|
import ntsecuritycon
|
||||||
import win32api
|
import win32api
|
||||||
import win32con
|
import win32con
|
||||||
import win32security
|
import win32security
|
||||||
|
|
||||||
from monkey_island.cc.environment.os import is_windows_os
|
|
||||||
from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR
|
from monkey_island.cc.server_utils.consts import DEFAULT_DATA_DIR
|
||||||
|
|
||||||
|
is_windows_os = sys.platform.startswith("win")
|
||||||
|
|
||||||
|
|
||||||
def create_data_dir(data_dir: str) -> None:
|
def create_data_dir(data_dir: str) -> None:
|
||||||
if not os.path.isdir(data_dir):
|
if not os.path.isdir(data_dir):
|
||||||
os.makedirs(data_dir, mode=0o700)
|
os.makedirs(data_dir, mode=0o700)
|
||||||
if is_windows_os(): # `mode=0o700` doesn't work on Windows
|
if is_windows_os: # `mode=0o700` doesn't work on Windows
|
||||||
set_data_dir_security_to_read_by_owner(data_dir_path=data_dir)
|
set_data_dir_security_to_read_by_owner(data_dir_path=data_dir)
|
||||||
|
|
||||||
|
|
||||||
def create_default_data_dir() -> None:
|
def create_default_data_dir() -> None:
|
||||||
if not os.path.isdir(DEFAULT_DATA_DIR):
|
if not os.path.isdir(DEFAULT_DATA_DIR):
|
||||||
os.mkdir(DEFAULT_DATA_DIR, mode=0o700)
|
os.mkdir(DEFAULT_DATA_DIR, mode=0o700)
|
||||||
if is_windows_os(): # `mode=0o700` doesn't work on Windows
|
if is_windows_os: # `mode=0o700` doesn't work on Windows
|
||||||
set_data_dir_security_to_read_by_owner(data_dir_path=DEFAULT_DATA_DIR)
|
set_data_dir_security_to_read_by_owner(data_dir_path=DEFAULT_DATA_DIR)
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +32,11 @@ def set_data_dir_security_to_read_by_owner(data_dir_path: str) -> None:
|
||||||
data_dir_path, win32security.DACL_SECURITY_INFORMATION
|
data_dir_path, win32security.DACL_SECURITY_INFORMATION
|
||||||
)
|
)
|
||||||
dacl = win32security.ACL()
|
dacl = win32security.ACL()
|
||||||
dacl.AddAccessAllowedAce(win32security.ACL_REVISION, ntsecuritycon.FILE_GENERIC_READ, user)
|
dacl.AddAccessAllowedAce(
|
||||||
|
win32security.ACL_REVISION,
|
||||||
|
ntsecuritycon.FILE_GENERIC_READ | ntsecuritycon.FILE_GENERIC_WRITE,
|
||||||
|
user,
|
||||||
|
)
|
||||||
security_descriptor.SetSecurityDescriptorDacl(1, dacl, 0)
|
security_descriptor.SetSecurityDescriptorDacl(1, dacl, 0)
|
||||||
win32security.SetFileSecurity(
|
win32security.SetFileSecurity(
|
||||||
data_dir_path, win32security.DACL_SECURITY_INFORMATION, security_descriptor
|
data_dir_path, win32security.DACL_SECURITY_INFORMATION, security_descriptor
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
def is_windows_os():
|
|
||||||
return sys.platform.startswith("win")
|
|
Loading…
Reference in New Issue