I can not see a security fault in this module, as according to the documentation https://httpd.apache.org/docs/2.4/mod/mod_mime_magic.html#mimemagicfile the context to use MimeMagicFile
is only server configuration and virtualhost, ie just someone with administrative level (or better, with complete control over the server) could exchange the Magic file for something with problems, if something fails in this context, then it is a problem that goes far beyond the modules.
See for "problem" to occur, we would first have to create a named file /home/user/meumagic
with this content (is just an example):
# php
0 string \<\?php application/x-httpd-php
# Frame
0 string \<MakerFile application/x-frame
0 string \<MIFFile application/x-frame
0 string \<MakerDictionary application/x-frame
0 string \<MakerScreenFon application/x-frame
0 string \<MML application/x-frame
0 string \<Book application/x-frame
0 string \<Maker application/x-frame
# MS-Word
0 string \376\067\0\043 application/msword
0 string \320\317\021\340\241\261 application/msword
0 string \333\245-\0\0\0 application/msword
In apache would have to set so:
MimeMagicFile /home/user/meumagic
So in this case any file that ate with <?php
will perform, however see that it is quite laborious, this is practically an induced security failure.
How an upload file could run as a php script?
As far as I understand of the modules I know of Apache the only one that could actually cause a security breach would be the ForceType
of the "core" module, before explaining about it I will explain how the execution of php scripts in apache works (most of the time)
Apache to run PHP can use several methods, but the most common ones are Fast-CGI and the Apache2handler (the latter more common on Windows).
For you to set what will run php yourself will configure the file extensions enabled in httdp.conf
so (this example would be in windows):
LoadModule php5_module c:/php/php5apache2_4.dll
AddType application/x-httpd-php .php
Or:
<FilesMatch \.php$>
SetHandler application/x-httpd-php
</FilesMatch>
Or even (php2, phtml):
<FilesMatch "\.ph(p|tml)$">
SetHandler application/x-httpd-php
</FilesMatch>
Then see that "mimetype has been added" application/x-httpd-php
for the extension . php and . phtml and with it you could use any extension, until you create one like this:
AddType application/x-httpd-php .wallace
All files terminated in .wallace
will run PHP scripts.
Now back to the ForceType
, imagine that somehow the developer of the upload script did not make a filter in the upload and this allows him to upload a file .htaccess
with this content:
ForceType application/x-httpd-php
And then in the next upload it send a . jpg (in this .jpg) with the following content:
<?php
echo 'Oi';
And breaking the upload folder has permissions for running and public access, so the malicious person would access it so:
http://site-vulneravel.com/uploads/upload.jpg
He would run the script.
Note that for security failure to occur were accurate:
- Permission in folder
uploads
to run the script
- Briefcase
uploads
be published (or accessible via http)
- Lack of filters/validation in upload script
So you ask yourself, but this is impossible, maybe for those who have the least knowledge and/or responsibility yes, but several "developers" this can happen yes.
Answering questions in topic
How this Apache mod_mime_magic works in detail?
- Answer: It changes the Magic file containing mime-types for file identification, . htaccess has no access
This mod_mime_magic really is dangerous like this?
- Answer: I would say no, if he came to be the cause of some security problem it was because of the irresponsibility of someone with full control over apache
It comes active by default in Apache?
- Answer: Varies from server to server.
How to know if it is active or not?
- Answer: I believe that only by observing httpd.conf, since it is only accessible at this "level"
If I want to activate the mod_mime_magic
, how could I ensure that a file that has been "uploaded" to my application has no "malicious content disguised"?
- Answer: As I explained in the rest of the answer I do not believe that it could cause this problem and if it happens it is not a fault directly of him and yes of who controls the server.
I won’t post a full reply now, but here is a summary for those who didn’t pick up the chat conversation: the Mime-Magic module uses the system’s mime-Magic file to determine the file type according to its content, rather than the extension. This can cause a system that checks image uploads by the extension to let some user up a "disguised" PHP with GIF extension, for example, which for Apache, will be understood as PHP because of the module.
– Bacco