microsoft / dotnet

This repo is the official home of .NET on GitHub. It's a great starting point to find many .NET OSS projects from Microsoft and the community, including many that are part of the .NET Foundation.
https://devblogs.microsoft.com/dotnet/
MIT License
14.34k stars 2.21k forks source link

SHA1 Algorithm in FileInfo properties of .Net Project EXE #1332

Open vaibhavrmore1 opened 2 years ago

vaibhavrmore1 commented 2 years ago

The metadata of the .Net EXE shows that it has been using SHA1 for its internal purpose. The property navigation is : Metadata->Headers->FileInfo->SHA1

Steps to reproduce:

Create any console app with .Net Framework or.Net Core Generate the EXE Use any .Net Reflector to view Metadata. For Eg. dotPeek Load the EXE and navigate to the above path - Metadata->Headers->FileInfo->SHA1 It shows SHA1 is key and has some value associated with it. Screenshot of the same: SHA!

Questions: As it is known that SHA1 is not secure and SHA256 should be used everywhere.

What is this property about and where is it used internally? Do we have the option to change it to SHA256 due to security reasons?

svick commented 2 years ago

As far as I can tell, that's just dotPeek telling you the SHA1 of the whole file, it's not an actual header inside the file.

So there shouldn't be any security issue here.

Apollo9999 commented 1 year ago

Modifying (or recreating) an executable and making it have the same hash is still not trivial, not even for SHA-1.See the below link for more Information https://crypto.stackexchange.com/questions/48289/how-secure-is-sha1-what-are-the-chances-of-a-real-exploit

Apollo9999 commented 1 year ago

using System; using System.IO; using System.Security.Cryptography;

class Program { static void Main() { string filePath = "path_to_your_file.exe"; FileInfo fileInfo = new FileInfo(filePath);

    if (fileInfo.Exists)
    {
        using (FileStream fileStream = fileInfo.OpenRead())
        {
            using (SHA1Managed sha1 = new SHA1Managed())
            {
                byte[] hash = sha1.ComputeHash(fileStream);
                string sha1Hash = BitConverter.ToString(hash).Replace("-", string.Empty);

                Console.WriteLine("SHA1 Hash: " + sha1Hash);
            }
        }
    }
    else
    {
        Console.WriteLine("File does not exist.");
    }
}

}

**Please be informed the path has to be changed.