-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
159 lines (131 loc) · 5.03 KB
/
Program.cs
File metadata and controls
159 lines (131 loc) · 5.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
using System;
using System.IO;
using System.Net.Http;
using System.Security.Cryptography;
using System.Text.Json;
using System.Collections.Generic;
using System.Threading.Tasks;
class Program
{
static async Task Main(string[] args)
{
if (args.Length == 0 || args[0] != "--scan")
{
Console.WriteLine("Usage: BuildIsoDefender --scan");
return;
}
Console.WriteLine("=== BuildIso Defender ===");
Console.WriteLine("Scanning system for BuildIso.exe...\n");
var files = FindBuildIsoFiles();
if (files.Count == 0)
{
Console.WriteLine("No BuildIso.exe found on this system.");
return;
}
Console.WriteLine($"Found {files.Count} file(s).\n");
string officialHash = await GetOfficialDigestFromAllReleases();
if (officialHash == null)
{
Console.WriteLine("[ERROR] Unable to retrieve any official digest from GitHub.");
return;
}
Console.WriteLine($"Official SHA256: {officialHash}\n");
foreach (var file in files)
{
Console.WriteLine($"Checking: {file}");
string localHash = ComputeSHA256(file);
long size = new FileInfo(file).Length;
Console.WriteLine($"Local SHA256: {localHash}");
Console.WriteLine($"Size: {size} bytes");
if (localHash.Equals(officialHash, StringComparison.OrdinalIgnoreCase))
{
Console.WriteLine("[STATUS] OFFICIAL — File is authentic.\n");
}
else
{
Console.WriteLine("[STATUS] WARNING — File does NOT match the official version!");
if (size < 100_000)
Console.WriteLine("[THREAT] Possible phishing stub.");
if (size > 20_000_000)
Console.WriteLine("[THREAT] Possible malware injection.");
Console.WriteLine();
}
}
}
static List<string> FindBuildIsoFiles()
{
var results = new List<string>();
string filename = "BuildIso.exe";
string[] paths = {
Directory.GetCurrentDirectory(),
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles),
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86),
Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData),
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
};
foreach (var path in paths)
{
try
{
foreach (var file in Directory.EnumerateFiles(path, filename, SearchOption.AllDirectories))
results.Add(file);
}
catch { }
}
return results;
}
static async Task<string> GetOfficialDigestFromAllReleases()
{
string[] urls = {
"https://api.github.com/repos/BuildIso/BuildIso/releases/tags/v2026.5",
"https://api.github.com/repos/BuildIso/BuildIso/releases/tags/v2026.4",
"https://api.github.com/repos/BuildIso/BuildIso/releases/tags/v2026.3",
"https://api.github.com/repos/BuildIso/BuildIso/releases/tags/v2026.2",
"https://api.github.com/repos/BuildIso/BuildIso/releases/tags/v2026.1"
};
foreach (var url in urls)
{
string digest = await GetDigestFromRelease(url);
if (digest != null)
{
Console.WriteLine($"Matched release: {url}");
return digest;
}
}
return null;
}
static async Task<string> GetDigestFromRelease(string url)
{
using var client = new HttpClient();
client.DefaultRequestHeaders.UserAgent.ParseAdd("BuildIsoDefender");
try
{
string json = await client.GetStringAsync(url);
using var doc = JsonDocument.Parse(json);
foreach (var asset in doc.RootElement.GetProperty("assets").EnumerateArray())
{
string name = asset.GetProperty("name").GetString();
if (name == "BuildIso.exe")
{
if (asset.TryGetProperty("digest", out var digestProp))
{
string digest = digestProp.GetString();
if (digest.StartsWith("sha256:", StringComparison.OrdinalIgnoreCase))
return digest.Substring("sha256:".Length).Trim();
}
}
}
}
catch
{
// ignore errors and continue to next URL
}
return null;
}
static string ComputeSHA256(string file)
{
using var sha = SHA256.Create();
using var stream = File.OpenRead(file);
return Convert.ToHexString(sha.ComputeHash(stream));
}
}