Skip to content

Commit 2ecd34c

Browse files
author
bol-van
committed
winws2: harden sandbox
1 parent b5b1f71 commit 2ecd34c

File tree

4 files changed

+32
-6
lines changed

4 files changed

+32
-6
lines changed

docs/changes.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,10 @@ v0.7.2
107107
* nfqws2: clean lua cutoff on profile change
108108
* zapret-auto: separate hostkey function
109109

110-
v0.7.3
110+
v0.7.4
111111

112112
* nfqws2, zapret-lib : check tcp sequence range overflow
113113
* zapret-lib : seq compare functions
114114
* nfqws2: add l3_len, l4_len to dissect
115115
* nfqws2: fix broken l7proto profile rediscovery
116+
* winws2: harden sandbox. disable child process execution , some UI interaction and desktop settings change

nfq2/darkmagic.c

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,29 @@ bool prepare_low_appdata()
718718
return b;
719719
}
720720

721+
BOOL JobSandbox()
722+
{
723+
BOOL bRes = FALSE;
724+
HANDLE hJob;
725+
JOBOBJECT_BASIC_LIMIT_INFORMATION basic_limit;
726+
JOBOBJECT_BASIC_UI_RESTRICTIONS basic_ui;
727+
728+
if (hJob = CreateJobObjectW(NULL, NULL))
729+
{
730+
basic_limit.LimitFlags = JOB_OBJECT_LIMIT_ACTIVE_PROCESS;
731+
// prevent child process creation
732+
basic_limit.ActiveProcessLimit = 1;
733+
// prevent some UI interaction and settings change
734+
basic_ui.UIRestrictionsClass = JOB_OBJECT_UILIMIT_DESKTOP | JOB_OBJECT_UILIMIT_DISPLAYSETTINGS | JOB_OBJECT_UILIMIT_EXITWINDOWS | JOB_OBJECT_UILIMIT_GLOBALATOMS | JOB_OBJECT_UILIMIT_HANDLES | JOB_OBJECT_UILIMIT_READCLIPBOARD | JOB_OBJECT_UILIMIT_SYSTEMPARAMETERS | JOB_OBJECT_UILIMIT_WRITECLIPBOARD;
735+
bRes = SetInformationJobObject(hJob, JobObjectBasicLimitInformation, &basic_limit, sizeof(basic_limit)) &&
736+
SetInformationJobObject(hJob, JobObjectBasicUIRestrictions, &basic_ui, sizeof(basic_ui)) &&
737+
AssignProcessToJobObject(hJob, GetCurrentProcess());
738+
w_win32_error = GetLastError();
739+
CloseHandle(hJob);
740+
}
741+
return bRes;
742+
}
743+
721744

722745
#define WINDIVERT_DEVICE_NAME "WinDivert"
723746
static bool b_isandbox_set = false;
@@ -734,6 +757,8 @@ bool win_sandbox(void)
734757
return FALSE;
735758
if (!LowMandatoryLevel())
736759
return false;
760+
if (!JobSandbox())
761+
return false;
737762
// for LUA code to find where to store files
738763
b_isandbox_set = true;
739764
}

nfq2/desync.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1321,8 +1321,8 @@ static uint8_t dpi_desync_tcp_packet_play(
13211321
bool bDiscoveredL7;
13221322
if (ctrack_replay)
13231323
{
1324-
bDiscoveredL7 = !ctrack_replay->l7proto_discovered && ctrack_replay->l7proto != L7_UNKNOWN;
1325-
ctrack_replay->l7proto_discovered = true;
1324+
if (bDiscoveredL7 = !ctrack_replay->l7proto_discovered && ctrack_replay->l7proto != L7_UNKNOWN)
1325+
ctrack_replay->l7proto_discovered = true;
13261326
}
13271327
else
13281328
bDiscoveredL7 = l7proto != L7_UNKNOWN;
@@ -1766,8 +1766,8 @@ static uint8_t dpi_desync_udp_packet_play(
17661766
bool bDiscoveredL7;
17671767
if (ctrack_replay)
17681768
{
1769-
bDiscoveredL7 = !ctrack_replay->l7proto_discovered && l7proto != L7_UNKNOWN;
1770-
ctrack_replay->l7proto_discovered = true;
1769+
if ((bDiscoveredL7 = !ctrack_replay->l7proto_discovered && l7proto != L7_UNKNOWN))
1770+
ctrack_replay->l7proto_discovered = true;
17711771
}
17721772
else
17731773
bDiscoveredL7 = l7proto != L7_UNKNOWN;

nfq2/nfqws.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,14 +630,14 @@ static int win_main()
630630
{
631631
res=w_win32_error; goto ex;
632632
}
633+
633634
if (!win_sandbox())
634635
{
635636
res=w_win32_error;
636637
DLOG_ERR("Cannot init Windows sandbox\n");
637638
goto ex;
638639
}
639640

640-
641641
// init LUA only here because of possible sandbox. no LUA code with high privs
642642
if (!params.L && !lua_init())
643643
{

0 commit comments

Comments
 (0)