- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在处理一个令人讨厌的问题,我已经准备好撕掉我的头发了。我有一个 C# 控制台应用程序,它使用 Microsoft 的 HttpListener 类来监听 Web 请求。这个想法是控制台应用程序作为 UserAccountA(低权限)在后台运行。 UserAccountB(管理员等)出现,通过监听器访问网页,并冒充他或她的身份。 IIS 或 WCF 做的事情是一样的。我相信我在 Windows 7 上有这个工作,但现在我在 Windows 8.1 上,它又失败了。也许我一开始就没有它,或者这是一个新的转折点。
如果我通过 Visual Studio 运行该程序,我可以使用 Internet Explorer 11 访问它。出于某种原因,它要求我输入我的本地凭据。我假设这与 IE11 的开箱即用行为有关。一旦我输入它,它就会接受它。我的代码是这样开始的:
protected virtual void Listen(object o)
{
HttpListener h = (HttpListener)o;
while (h.IsListening && (this.Disposed == false))
{
IAsyncResult Result = null;
Result = h.BeginGetContext(new AsyncCallback(this.ListenerCallback), h);
Result.AsyncWaitHandle.WaitOne();
}
}
然后像这样拾取(缩写):
protected virtual void ListenerCallback(IAsyncResult Result)
{
HttpListener h = (HttpListener)Result.AsyncState;
HttpListenerContext context = null;
System.Security.Principal.WindowsIdentity identity = null;
context = h.EndGetContext(Result);
identity = (System.Security.Principal.WindowsIdentity)context.User.Identity;
using (System.Security.Principal.WindowsImpersonationContext wic = identity.Impersonate())
{
//method call to process request, under impersonation
}
}
我在使用两个不同的帐户(一个用于托管,一个用于访问)时逐步完成了这段代码。我已经使用此语句进行了验证:
system.security.principal.windowsidentity.getcurrent().name
当前身份确实发生了转变。监听器配置为使用 NTLM AuthenticationScheme 启动。
我想复杂的部分是在模拟过程中调用的方法。我们正在做一些抽象,但让我指出失败的部分。在本例中,我们使用 SSPI 连接到 SQL Server——所以整个模拟的目的是获取客户端现有的登录信息,并优雅地将它们导入 SQL Server。同样,现在,这都是一台计算机的本地操作。它甚至不在事件目录域中。一切都是本地的,有本地帐户。它是这样开始的:
System.Data.Common.DbProviderFactory fact = null;
if (UseSql())
{
fact = System.Data.Common.DbProviderFactories.GetFactory("System.Data.SqlClient");
}
没什么大不了的。我们在另一个项目中不断地使用提供者工厂,没有任何问题(但这只是一个普通的 WPF 应用程序,不是这样的)。在此之后,我们将使用 SSPI 属性设置 SQL 登录字符串。但我们甚至没有走到那一步。这正是它失败的地方,并显示以下消息:
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
Additional information: Could not load file or assembly 'System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, > PublicKeyToken=b77a5c561934e089' or one of its dependencies. Either a required impersonation level was not provided, or the provided impersonation level is invalid. (Exception from HRESULT: 0x80070542)
http://i854.photobucket.com/albums/ab103/srVincentVega/error7_zpsmb1xqrp0.png
我们根本没有使用 Oracle,我假设这只是它尝试打开 DbProviderFactory 时吐出的第一件事。对我来说,关键是模仿级别的事情。在此特定实验中,两个帐户(A 和 B)都是本地管理员。我已经通过本地安全策略确保他们可以在登录后模拟帐户。如果我查看我的事件日志,模拟似乎确实有效...
Special privileges assigned to new logon.
Subject: Security ID:
pc1\userA
Account Name: userA
Account Domain: pc1 Logon ID: 0xC4D0F3F
Privileges:
SeSecurityPrivilege
SeTakeOwnershipPrivilege
SeLoadDriverPrivilege
SeBackupPrivilege
SeRestorePrivilege
SeDebugPrivilege
SeSystemEnvironmentPrivilege
SeImpersonatePrivilege
我在这里尝试了太多变体,以至于开始妨碍我自己的分析。我基本上回到原点,不知道如何处理这个问题。有没有人有任何建议或提示?这看起来应该是一件非常简单的事情。我不确定为什么我遇到这么多麻烦。也许我只需要放弃使用 DbProviderFactory 并使用 OleDb 或其他任何东西。但是我还没有确认我可以在模拟后的运行时加载任何库。也许这是要做的事情。但是,如果有任何帮助,我将不胜感激。
谢谢,
约翰
最后一件事,这里是复制步骤:
在您的计算机上创建二级用户。登录以创建配置文件。注销并像往常一样重新登录。以该二级用户身份运行 Visual Studio(有几种方法可以执行此操作,按住 Shift 键并右键单击 VS 图标),然后在其中使用此框架创建一个 C# 控制台应用程序:
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
using (HttpListener h = new HttpListener())
{
h.Prefixes.Add("http://+:8090/");
h.AuthenticationSchemes = AuthenticationSchemes.Ntlm;
h.Start();
Console.WriteLine("Running");
HttpListenerContext context = h.GetContext();
System.Security.Principal.WindowsIdentity identity = null;
identity = (System.Security.Principal.WindowsIdentity)context.User.Identity;
using (System.Security.Principal.WindowsImpersonationContext wic = identity.Impersonate())
{
System.Data.Common.DbProviderFactory fact = null;
fact = System.Data.Common.DbProviderFactories.GetFactory("System.Data.SqlClient");
}
Console.ReadLine();
h.Stop();
}
}
}
}
调试/运行控制台应用程序。只需调用 Internet Explorer(vanilla,使用您的主帐户)并访问该 URL ( http://machinename:8090 )。异常发生
http://i854.photobucket.com/albums/ab103/srVincentVega/error8_zpsilkay0bl.png
最佳答案
好吧,我读到一半就停在了你遇到的异常处:
A first chance exception of type 'System.IO.FileLoadException' occurred in mscorlib.dll
这里的问题是,您用来运行该服务的帐户在执行模拟之前对加载 .Net 框架核心库的访问权限有限。通常,用于托管服务的此类帐户在托管服务的节点上具有管理员权限。
此外,为了允许模拟,您需要使用本地安全策略为服务帐户授予这样做的权限 - 本地策略 - 用户权限分配:
作为操作系统的一部分
此用户权限允许进程在未经身份验证的情况下模拟任何用户。因此,该进程可以访问与该用户相同的本地资源。
身份验证后模拟客户端
将此权限分配给用户允许代表该用户运行的程序模拟客户端。
另请注意,如果您使用 kerberos 而不是 NTLM,则需要在 AD (Active Directory) 中设置 SPN 和委派目标。
我不知道这是否对您有帮助,但这些是我们在进行模拟/委派时遇到的问题。
哦,是的,如果您执行不止一跳来执行模拟,则模拟级别必须设置为委派。
关于c# - 如何确保我的 Windows 模拟级别有效?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28597551/
我有以下对象: dog = { location: { x: 52.1089, y: 16.2323 }, f: function(message) { alert
在 TSQL 中,如果我要搜索有效的 .com 电子邮件地址,我需要确保有一个 @ 符号,它以 .com 结尾,并且在 @ 前后至少有一个字符。 SELECT * FROM CUSTOMER WHER
我正在尝试准备一个信用卡交易列表,以便在 Excel 2010 中进行透视和进一步分析(满足个人需求)。问题是我的银行机构没有遵循标准的日期格式,所以有时日期会显示为 Jun. 1, 2013 , 有
看来您不能在 riak 中进行交易。如何确保数据正确? 假设我们要插入评论。在 redis 我会做 commentId=incr commentCount multi SET comment_post
对于下面给定的模式,是否可以确保至少一个属性包含一个值(即 minLength 为 1): { "$schema": "http://json-schema.org/draft-04/sche
我计划在 Haxe 的一个子集中编写 Haxe 库,这些库将编译为每种 Haxe 目标语言。有什么方法可以验证 Haxe 程序是否可以编译为所有目标语言,是否可以在不手动测试每个目标平台上的编译代码的
如果浏览器窗口未聚焦,则当前页面上的所有 webdriver 标识都失败。 如何使用 webdriver 使浏览器成为焦点? 最佳答案 ((JavascriptExecutor) webDriver)
我从这样的 HTML GET 请求中获取图像链接... www.example.com?image=www.anotherdomain.com/image.jpg if (isset($_GET['i
我有一个 eunit 测试,它生成一个唯一的节点名称并开始分发: {A,B,C} = now(), Nodename = list_to_atom(lists:flatten(io_lib:forma
我正在完成我的 iPhone 应用程序。我只是担心我们的网络服务器级别的安全性。数据通过网络服务被传送到 iPhone 应用程序。 我可以在网络服务上采取哪些安全措施,以免受到攻击? 谢谢 最佳答案
我正在编写一个应用程序,该应用程序启动一个运行简单 Web 服务器的子进程。我正在使用 NSTask 并通过管道与其进行通信,一切看起来或多或少都很好。但是,如果我的程序崩溃,子进程将保持事件状态,并
我有一些应用程序,我调用 ShowMessage('Complete!');在长时间操作结束时。 大多数时候,这效果很好,但每隔一段时间,消息对话框就会显示在主窗体后面。 有什么方法可以确保 Show
我通过将消息插入集合并让模板使用 {{#each}} 打印出集合来创建一个简单的聊天。 我不太熟悉安全性,但是有没有办法让它符合 EFF 规定? https://www.eff.org/secure-
我有一个商店,我想在其中正确管理 id。假设我有以下帖子存储: type Post = { id: number; title: string; body?: string; } type
我有一个使用 ajax post 方法和数据表的程序。经过几周的摆弄,我确定我根本不明白 javascript 是如何工作的。这是我的 JavaScript: $('#SaveTimeSheet').
我有一个系统,如果从 Azure 服务总线丢失消息将是一场灾难,也就是说,数据将永远丢失,并且没有实际方法可以在不造成重大中断的情况下修复损坏。 在这种情况下我可以完全依赖 ASB 吗? (即使它
如何确保 scalatest 测试不会并行运行?在 0.12 之前,我有一个 sbt 设置: parallelExecution in Test := false 新版本引入了一些复杂的机制。这种更简
我的端点有两个如下所示的 promise : request.post({ url: url, json: smsSTART, header
简短版本 当 ui-router 转换到新 View 时(以我不完全理解的方式使用 ngAnimate),它会添加类 ng-leave 和 ng-leave-active 到当前 View 。它还将类
目前正在努力寻找验证 2 个表的方法(有效地验证表 A 的大量行) 我有两张 table 表A ID A B C 表格匹配 ID Number A 1 A 2 A 9 B 1
我是一名优秀的程序员,十分优秀!