Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
evil-decrypter/decrypter_poc/Validate.cs
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
76 lines (63 sloc)
2.08 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
using System.IO; | |
namespace decrypter_poc | |
{ | |
class Validate | |
{ | |
// png header bytes | |
static byte[] PNG_MAGIC_BYTES = new byte[8] { 137, 80, 78, 71, 13, 10, 26, 10 }; | |
// officex header bytes | |
static byte[] officexHeader = new byte[5] { 80, 75, 3, 4, 20 }; | |
// old office files | |
static byte[] officeHeader = new byte[] { 208, 207, 17, 224 }; | |
static byte[] pdfHeader = new byte[] {37, 80, 68, 70, 45 }; | |
public static bool checkValid(byte[] fileDecrypt, FileInfo orgFile) | |
{ | |
string[] fileSplit = orgFile.Name.Split('.'); | |
string ext = fileSplit[fileSplit.Length - 2]; | |
switch (ext) | |
{ | |
case "xlsx": | |
case "docx": | |
case "pptx": | |
case "vdsx": | |
if (confirmValid(fileDecrypt, officexHeader) || confirmValid(fileDecrypt, officeHeader)) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
case "xls": | |
case "doc": | |
case "ppt": | |
case "msg": | |
return confirmValid(fileDecrypt, officeHeader); | |
case "png": | |
return confirmValid(fileDecrypt, PNG_MAGIC_BYTES); | |
case "pdf": | |
return confirmValid(fileDecrypt, pdfHeader); | |
default: | |
return false; | |
} | |
} | |
public static bool confirmValid(byte[] fileBytes, byte[] headerCheck) | |
{ | |
byte[] headerArray = new byte[headerCheck.Length]; | |
Array.Copy(fileBytes, headerArray, headerCheck.Length); | |
if (headerArray.SequenceEqual(headerCheck)) | |
{ | |
return true; | |
} | |
else | |
{ | |
return false; | |
} | |
} | |
} | |
} |