相关疑难解决方法(0)

是否有可能欺骗此WindowsIdentity代码使用错误的用户?

TL; DR可以包含在用户令牌WindowsIdentityToken属性(比如someIdentity.Token)被欺骗这样的:

var validated = new WindowsIdentity(someIdentity.Token);
Run Code Online (Sandbox Code Playgroud)

...将返回一个声称代表用户的实例,该用户实际上尚未经过身份验证,但具有IsAuthenticated设置true,有效.Name.User属性等?

下面我对此进行了一些界定; 它可能不可能完全欺骗.


全文:

这个答案中,Damien_The_Unbeliever巧妙地证明了我的一些代码可能会被欺骗,因为它认为它在WindowsIdentity实例中没有有效的身份验证用户.长话短说,我的代码假设if Thread.CurrentPrincipal.Identity是一个实例,WindowsIdentity并且IsAuthorizedtrue,它代表一个经过身份验证的用户,我可以依赖于SID .User:

WindowsIdentity identity = Thread.CurrentPrincipal == null
    ? null
    : Thread.CurrentPrincipal.Identity as WindowsIdentity;

if (identity != null && identity.IsAuthenticated && !identity.IsAnonymous) {
    // ...use and trust the SID in identity.User, the
    // username in identity.Name, etc.... …
Run Code Online (Sandbox Code Playgroud)

.net c# authentication

23
推荐指数
1
解决办法
2288
查看次数

如何保护我的私有函数不被反射执行?

看到这个之后:访问修饰符也会影响反射吗?

我尝试使用它,但它不起作用: 在此输入图像描述

如何防止反射执行我的私有方法?

.net c# reflection

13
推荐指数
4
解决办法
4501
查看次数

标签 统计

.net ×2

c# ×2

authentication ×1

reflection ×1