相关疑难解决方法(0)

为什么反射可以在C#中访问类的受保护/私有成员?

为什么反射可以在C#中访问类的受保护/私有成员?

这对于全班来说是不安全的,为什么反思会给予这种力量?这是反模式吗?

c# reflection

18
推荐指数
2
解决办法
1816
查看次数

System.Security.Principal.WindowsIdentity的使用是否合理安全?

合理的,从安全的被黑客攻击这样的情况下,我从得到的或具有对给我的装配虚假的身份信息?当然,没有什么是完全防篡改的,但鉴于微软对.Net的承诺和依赖,我认为像这样的关键API会被锁定并难以篡改.这是我的有效假设吗?System.Security.Principal.WindowsIdentity Thread.CurrentPrincipalIdentityWindowsIdentity.GetCurrent()trueIsAuthenticated

我的目标是在我的程序集中提供合理的最佳实践SSO.如果Windows本身受到了损害,那是我无法控制的,但是如果(例如)对于链接到我的程序集的应用程序而言,这是一件简单的事情,以便向我提供虚假信息,那就是因为我没有尽职尽责.这对我来说是一个无知的大区域.

要清楚,我正在寻找难以获得的信息,而不是袖手旁观.所以,发布的漏洞利用,或WindowsIdentity以一种欺骗我的代码的方式展示构造函数的使用等等.或者在"那是一个有效的假设"方面,支持它的固体文章,依赖它的已知用法等等.我没有'有很多运气找到它们,但我已经包括了我在目前为止在分频器下面找到的内容.

这是我打算如何使用WindowsIdentity:

using System.Security.Principal;
using System.Threading;
// ...

// I only want Windows-authenticated users
WindowsIdentity identity = Thread.CurrentPrincipal == null
    ? null
    : Thread.CurrentPrincipal.Identity as WindowsIdentity;
SecurityIdentifier sid;

// I can't imagine how an authenticated account would be anonymous, but...
if (identity != null && identity.IsAuthenticated && !identity.IsAnonymous) {
    // SSO success from thread identity
    sid = identity.User;
    // ...check that that SID is …
Run Code Online (Sandbox Code Playgroud)

.net c# security

15
推荐指数
1
解决办法
8737
查看次数

访问修饰符也会影响反射吗?

我一直相信他们做到了,但在这里看到一些答案让我怀疑......

我可以通过反射从类外部访问私有字段/属性/方法吗?

.net reflection access-modifiers

6
推荐指数
1
解决办法
566
查看次数

ObjectOutputStream 的对象如何调用 Serialized 对象的私有 writeObject 方法

当我运行这个演示时,它调用 TestBean 的writeObject私有方法

这怎么可能 ?

这是代码:

import java.io.FileOutputStream;

public class Test {

    public static void main(String[] args) {

        try {
            TestBean testBean = test.new TestBean();

            testBean.setSize(23);
            testBean.setWidth(167);

            FileOutputStream fos =
                new FileOutputStream(new File("d:\\serial.txt"));
            ObjectOutputStream oos = new ObjectOutputStream(fos);
            oos.writeObject(testBean);

            oos.close();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    class TestBean implements Serializable {

        private static final long serialVersionUID = 1L;

        private int size;
        private int width;

        public int getSize() {
            return size;
        }

        public void setSize(int size) { …
Run Code Online (Sandbox Code Playgroud)

java serialization

2
推荐指数
1
解决办法
4696
查看次数

不允许更改对象

我有一个只读对象,但它的属性在某处得到更新。是否C#有任何限制也可以通过直接更改和反射来限制?

这是POC代码

class Program
{
    static void Main(string[] args)
    {
        ReadOnlyCreator tester = new ReadOnlyCreator();
        tester.ModifyTester();
        Console.ReadLine();
    }
}

class ClassUnderTest
{
    public string SomeProp { get; set; }
}

class ReadOnlyCreator
{
    private readonly ClassUnderTest _classUnderTest;
    public ReadOnlyCreator()
    {
        _classUnderTest = new ClassUnderTest { SomeProp = "Init" };
    }

    public void ModifyTester()
    {
        Console.WriteLine("Before: " + _classUnderTest.SomeProp);
        var modifier = new Modifier(_classUnderTest);
        modifier.Modify();
        Console.WriteLine("After: " + _classUnderTest.SomeProp);
    }
}
class Modifier
{
    private ClassUnderTest _classUnderTest;
    public Modifier(ClassUnderTest …
Run Code Online (Sandbox Code Playgroud)

c#

2
推荐指数
1
解决办法
58
查看次数

标签 统计

c# ×3

.net ×2

reflection ×2

access-modifiers ×1

java ×1

security ×1

serialization ×1