也谈隐藏盘符等windows 的管理员的策略实现

2020-12-13 03:40

阅读:266

.text:7387F02B _SHRestricted@4 proc near ; CODE XREF: CMenuItemsCache::RefreshCachedDarwinShortcuts(int)+Dp
.text:7387F02B                                         ; CDesktopBrowser::_ActivateView(void)+3Dp ...
.text:7387F02B
.text:7387F02B rest            = dword ptr  8
.text:7387F02B
.text:7387F02B                 mov     edi, edi
.text:7387F02D                 push    ebp
.text:7387F02E                 mov     ebp, esp
.text:7387F030                 push    offset ?g_lRestrictionsVersionNumber@@3JA ; long g_lRestrictionsVersionNumber
.text:7387F035                 push    9Ch
.text:7387F03A                 push    offset ?g_rgRestrictionItemValues@@3PAKA ; ulong * g_rgRestrictionItemValues
.text:7387F03F                 push    offset unk_7387F058
.text:7387F044                 push    0
.text:7387F046                 push    [ebp+rest]
.text:7387F049                 call    ds:__imp__SHRestrictionLookup@24 ; SHRestrictionLookup(x,x,x,x,x,x)
.text:7387F04F                 pop     ebp
.text:7387F050                 retn    4
.text:7387F050 _SHRestricted@4 endp

在其中调用了 SHLAPI.DLL 中的 SHRestrictionLookup

SHRestrictionLookup

函数如下:

int __stdcall SHRestrictionLookup(int a1, LPCWSTR pszDir, int a3, void *Dst, int a5, int a6)
{
  char *v6; // edi@7
  int v7; // ebx@1
  unsigned int v8; // eax@2
  int v9; // edx@3
 
  v7 = 0;
  if ( !g_bDllTerminating )
  {
    _ValidateRestrictionTable(Dst, a5, a6);
    v8 = 0;
    if ( (unsigned int)a5 > 0 )
    {
      v9 = a3;
      while ( a1 != *(_DWORD *)v9 )
      {
        ++v8;
        v9 += 12;
        if ( v8 >= a5 )
          return v7;
      }
      v6 = (char *)Dst + 4 * v8;
      v7 = *(_DWORD *)v6;
      if ( *(_DWORD *)v6 == -1 )
      {
        v7 = SHGetRestriction(pszDir, *(LPCWSTR *)(a3 + 12 * v8 + 4), *(LPCWSTR *)(a3 + 12 * v8 + 8));
        AcquireSRWLockExclusive(&g_csrwlockRestrictions);
        if ( *(_DWORD *)a6 == SHGlobalCounterGetValue(GLOBALCOUNTER_RESTRICTIONS) )
          *(_DWORD *)v6 = v7;
        ReleaseSRWLockExclusive(&g_csrwlockRestrictions);
      }
    }
  }
  return v7;
}

会从注册表中获取值然后返回(如果没有获取 -1 没有获取),否则直接读取出来

在MSDN 中:

Determines whether a specified administrator policy is in effect. In many cases, applications need to modify certain behaviors in order to comply with the policies enacted by system administrators.

检测指定的管理员策略是否有效。在很多情况下,应用程序需要遵照系统管理员指定的策略依序修改某些行为。

系统行为是这个样子,如果我们的程序需要某些和系统行为不同,那么hook这个函数,并且返回和系统不同的值就能起到效果。


评论


亲,登录后才可以留言!