【问题标题】:Is there a way to create a named pipe from an AppContainer BHO on IE11?有没有办法从 IE11 上的 AppContainer BHO 创建命名管道?
【发布时间】:2013-09-29 16:55:35
【问题描述】:

我正在尝试为 Internet Explorer 11 (Windows 8.1) 编写 BHO。 我的 BHO 实现了 AppContainer 沙箱,但我似乎无法创建命名管道,CreateNamedPipe 失败并显示以下消息: Access is denied.

这是我用来创建命名管道的代码(我在 russian website 上找到的,最后一条评论:

LPCWSTR LOW_INTEGRITY_SDDL_SACL_W = L"S:(ML;;NW;;;LW)D:(A;;0x120083;;;WD)(A;;0x120083;;;AC)"; PSECURITY_DESCRIPTOR pSD = NULL; ConvertStringSecurityDescriptorToSecurityDescriptorW ( LOW_INTEGRITY_SDDL_SACL_W, SDDL_REVISION_1, &pSD, 空值 ); 如果 ( pSD != NULL) { SECURITY_ATTRIBUTES 安全属性; SecurityAttributes.nLength = sizeof(SECURITY_ATTRIBUTES); SecurityAttributes.bInheritHandle = TRUE; SecurityAttributes.lpSecurityDescriptor = pSD; 处理 hPipe = CreateNamedPipe( L"\\\\.\\pipe\\testpipe", PIPE_ACCESS_DUPLEX, PIPE_TYPE_BYTE | PIPE_READMODE_BYTE, 1、 4096, 4096, 1000, &安全属性); }

不幸的是,它不起作用。 GetLastError() 像往常一样返回这个 Access is denied

【问题讨论】:

  • 它不适用于任何标签吗?你能在非保护模式下检查标签吗?
  • 是的,当 EPM 关闭时它可以正常工作。 (在保护模式下工作正常,在增强保护模式下不起作用)。
  • 看来use pipes within appContainer是可以的。但是你能试试 S:(ML;;NW;;;RC)D:(A;;0x120083;;;WD)(A;;0x120083;;;AC)吗?
  • ConvertStringSecurityDescriptorToSecurityDescriptorWW 失败并显示以下消息:“参数不正确。” (通过 GetLastError)。
  • 现在没有更多想法了,抱歉。如果您找到解决方法,请回答您的问题,这对 IE11 BHO 开发很有用

标签: internet-explorer bho internet-explorer-11 epm appcontainer


【解决方案1】:

您不能在 BHO 中创建命名管道。但是您可以在代理进程中创建它并从 BHO 连接到管道。 我是该评论的作者,我在我的 IE 插件的代理部分测试了代码。

代码 sn-ps。在自动启动的 exe (Delphi) 中创建管道

function CreateAppContainerSecurityDescriptor(var SD: PSECURITY_DESCRIPTOR): boolean;
const
  SDDL_REVISION_1 = 1;
var
  pSD: PSECURITY_DESCRIPTOR;
  ConvertStringSecurityDescriptorToSecurityDescriptor: TConvertStringSecurityDescriptorToSecurityDescriptorW;
begin
  @ConvertStringSecurityDescriptorToSecurityDescriptor := GetProcAddress(AdvapiDll(),
    'ConvertStringSecurityDescriptorToSecurityDescriptorW');
  result := false;
  if ConvertStringSecurityDescriptorToSecurityDescriptor('S:(ML;;NW;;;LW)D:(A;;0x120083;;;WD)(A;;0x120083;;;AC)',
    SDDL_REVISION_1, pSD, nil) then begin
    SD := pSD;
    result := true;
  end;
end;

function TPipeServer.Start: boolean;
var
  SD: PSECURITY_DESCRIPTOR;
  SecurityAttributes: SECURITY_ATTRIBUTES;
begin
  result := false;
  if Win32MajorVersion >= 6 then begin
    if CreateAppContainerSecurityDescriptor(SD) then begin
      SecurityAttributes.nLength := sizeof(SECURITY_ATTRIBUTES);
      SecurityAttributes.bInheritHandle := true;
      SecurityAttributes.lpSecurityDescriptor := SD;

      PipeHandle := CreateNamedPipe('\\.\pipe\MyPipe', PIPE_ACCESS_DUPLEX,
        PIPE_TYPE_BYTE or PIPE_READMODE_BYTE, 1, 0, 0, 1000, @SecurityAttributes);
      result := PipeHandle <> INVALID_HANDLE_VALUE;
    end;
  end;
end;

procedure TPipeServer.Execute;
begin
  if Start() then begin
    while true do begin
      if ConnectNamedPipe(PipeHandle, nil) then begin
        ...
      end;
    end;
  end;
end;

在 IE 工具栏中连接管道 (C++)

#define PIPE_NAME "\\\\.\\pipe\\MYPipe"

LRESULT CMFToolbar::OnCommand(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled)
{
...
    HANDLE PipeHandle;
    if (WaitNamedPipe(PIPE_NAME, NMPWAIT_WAIT_FOREVER) != 0) {
        PipeHandle = CreateFile(PIPE_NAME, FILE_READ_DATA | FILE_WRITE_DATA,
            0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
        if (PipeHandle != INVALID_HANDLE_VALUE) {
            WriteFile(PipeHandle, ...
            CloseHandle(PipeHandle);
        }

}

【讨论】:

  • 感谢您的回复,但我无法使用您的代码,尝试从 BHO 连接到管道时,我仍然遇到访问被拒绝的情况。但是俄语文章中的代码可以正常工作!
  • 文章中的代码有效是什么意思?您在创建管道时遇到问题吗?或者从另一个 BHO 实例连接到管道?
  • 能否链接俄罗斯的文章?
【解决方案2】:

你可以给句柄加上ALL_APPLICATION_PACKAGE权限,但这是一个后门解决方案,代理解决方案是长期的。

DWORD WindowsSecurity::AddDACLToObject(HANDLE hObj,SE_OBJECT_TYPE seObjectType) {
LPWSTR szAddSid = SID_ALL_APP_PACKAGES;

PACL pACL = NULL;
DWORD dwRes;
PSID pSIDAllAppPackage = NULL;

PSECURITY_DESCRIPTOR pSDOld = NULL;
PACL pOldDACL = NULL;
dwRes = GetSecurityInfo(hObj, seObjectType, 
    DACL_SECURITY_INFORMATION,
    NULL, NULL, &pOldDACL, NULL, &pSDOld);
if (ERROR_SUCCESS != dwRes) {
    return dwRes;
} 

if(ConvertStringSidToSid(szAddSid,&pSIDAllAppPackage) == FALSE) {
    dwRes = GetLastError();
    return dwRes;
}

const int NUM_ACES  = 1;
EXPLICIT_ACCESS ea[NUM_ACES];
ZeroMemory(&ea, NUM_ACES * sizeof(EXPLICIT_ACCESS));

ea[0].grfAccessPermissions = GENERIC_ALL;
ea[0].grfAccessMode = SET_ACCESS;
ea[0].grfInheritance = NO_INHERITANCE;
ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[0].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
ea[0].Trustee.ptstrName = (LPTSTR)pSIDAllAppPackage;

dwRes = SetEntriesInAcl(NUM_ACES, ea, pOldDACL, &pACL);
if (ERROR_SUCCESS != dwRes) {
    return dwRes;
}

dwRes = SetSecurityInfo(
    hObj,                 // name of the object
    seObjectType,              // type of object
    DACL_SECURITY_INFORMATION,   // change only the object's DACL
    NULL, NULL,                  // do not change owner or group
    pACL,                        // DACL specified
    NULL);                       // do not change SACL
return dwRes;

}

【讨论】:

    【解决方案3】:

    我发现这个问题非常有用,并希望根据我最近在复杂产品中改装 EPM 兼容 BHO 的经验增加我的 2 美分。在这里删除一些信息,希望对社区有所帮助。我最初的问题发布在这里,所以其中一些是我的 cmets 在那里的重复 - Accessing named pipe servers from within IE EPM BHO

    我需要一些方法来实现双向通信 -

    1. 从 BHO 到保存一些相关数据的 Windows 服务:上面的安全描述符不起作用,因为跨会话 IPC 似乎不起作用。我尝试将命名管道设置为也允许所有人。

      • 通过添加代理来中继通信解决了这个问题。
    2. 从外部到 BHO:这是为了向 BHO 提供一些数据以执行操作 - DOM 操作等。标准 IPC 选项 - 命名管道、Windows RPC 等将不起作用,因为 BHO 无法为外部托管命名管道服务器访问,看起来像。

      • 通过在 SetSite 函数中创建 HWND_MESSAGE 窗口并使用 SendMessage 从 Broker 进程调用它来解决此问题。使用的消息类型必须是 WM_COPYDATA,因为这是跨进程的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-30
      • 2020-05-04
      • 1970-01-01
      • 2019-11-25
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多