It’s possible to store a EXE file inside a MySQL database. You can try this out. For demonstration purposes I’m running MySQL in my localhost. I will be creating a simple database and a table big enough to store the exe file. Since we convert the exe to a hex file the content would be larger than the original exe file. I will be using ‘putty.exe’ as the binary.
[code language=”sql”]
CREATE DATABASE testupload;
USE testupload
CREATE TABLE uploads (
id INT(3) NOT NULL AUTO_INCREMENT,
name VARCHAR(1000000) NOT NULL,
PRIMARY KEY (id)
);
[/code]
First we convert the exe in hex format. For this we can use MySQL’s hex() function.
[code language=”sql”]
select hex(load_file(‘C:/tmp/putty.exe’)) into dumpfile ‘C:/tmp/putty.dmp’;
[/code]
Next let’s store the dumped hex file inside our table.
[code language=”sql”]
load data infile ‘C:/tmp/putty.dmp’ into table uploads fields
terminated by ‘@OsandaMalith’ lines terminated by ‘@OsandaMalith’ (name);
[/code]
Now we can dump the file from our table and see nothing has changed. We use the unhex() function in MySQL to convert back to a exe.
[code language=”sql”]
select unhex(name) from uploads into dumpfile ‘C:/tmp/new.exe’;
[/code]
Let’s check the SHA-256 checksum of both the original and the new exe file and you can see no change has been occurred during this process.
The MySQL has a blob fields types.