Im developing a webapp where the user can upload an image to the server. I want to ensure that the user uploads an image, and not anything else, like a reverse shell or something malicious. Therefore I cannot use the extensions since you can easily fake that.
var dlg = new OpenFileDialog();
//dlg.Filter = "";
dlg.Multiselect = false;
bool? openClicked = dlg.ShowDialog();
if (openClicked == true)
{
Stream stream = dlg.File.OpenRead();
BinaryReader binary = new BinaryReader(stream);
//Determine filetype here.
byte[] data = binary.ReadBytes((int) stream.Length);
There must be a simple way to do this?
Tl;dr: How do I determine filetype to prevent a reverse shell?