forked from rohitcoderCdefense/vulnCodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CWE-347.cs
38 lines (36 loc) · 1.03 KB
/
CWE-347.cs
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
using System;
using System.IO;
using System.Net;
using System.Diagnostics;
using System.Security.Cryptography;
namespace test
{
class Program
{
static void Main(string[] args)
{
string url = "http://localhost:8000/test.txt";
string filename = "test.txt";
string path = Path.Combine(Path.GetTempPath(), filename);
WebClient client = new WebClient();
client.DownloadFile(url, path);
string hash = GetFileHash(path);
if (hash == "b4d8b4d8b4d8b4d8b4d8b4d8b4d8b4d8")
{
Process.Start(path);
}else{
File.Delete(path);
}
}
static string GetFileHash(string path)
{
using (var md5 = MD5.Create())
{
using (var stream = File.OpenRead(path))
{
return BitConverter.ToString(md5.ComputeHash(stream)).Replace("-", "").ToLowerInvariant();
}
}
}
}
}