.NET Verify the hashes of your executables

Discussion in 'Source Code & Tutorial Database' started by shinda, Mar 11, 2019 with 0 replies and 210 views.

  1. shinda

    shinda Retired Retired

    Messages:
    2,219
    Ratings:
    1,213
    You can use this for anything.

    Code:
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Security.Cryptography;
    using System.IO;
    using System.Net;
    using System.Diagnostics;
    class Utils
        {
            WebClient wc = new WebClient();
            public string HashFile(byte[] input)
            {
                HashAlgorithm ha = new SHA256CryptoServiceProvider();
                return BitConverter.ToString(ha.ComputeHash(input)).Replace("-","");
            }
            public string getExeHash()
            {
                string path = Process.GetCurrentProcess().MainModule.FileName;
                byte[] fileBytes = File.ReadAllBytes(path);
                return HashFile(fileBytes);
            }
            public string getModuleHash(string module)
            {
                string path = module;
                byte[] fileBytes = File.ReadAllBytes(path);
                return HashFile(fileBytes);
            }
            public bool checkHash()
            {
                List<string> hashes = wc.DownloadString("i used pastebin you can do this way any way you want if you have a server").Split(',').ToList();
                string exeHash      = getExeHash();
                string DLL1     = getModuleHash(Environment.CurrentDirectory + @"\YOURDLL1.dll");
                string DLL2     = getModuleHash(Environment.CurrentDirectory + @"\YOURDLL2.dll");
                Console.WriteLine($"{exeHash}\n{DLL1}\n{DLL2}\n");
                if(hashes[0] == exeHash && hashes[1] == DLL1     && hashes[2] == DLL2)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
        }

     
    • Like Like x 1
    Last edited: Mar 11, 2019

Share This Page