mysql configuration should be adjusted to help prevent against chained attacks against LAMP stack
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
apparmor (Ubuntu) |
Fix Released
|
Medium
|
Jamie Strandboge | ||
Lucid |
Fix Released
|
Medium
|
Jamie Strandboge | ||
mysql-dfsg-5.1 (Ubuntu) |
Won't Fix
|
Medium
|
Unassigned | ||
Lucid |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
SRU Justification (apparmor)
1. impact of the bug is medium for stable releases. While no applications shipped in Ubuntu are directly affected by this, it would be good if our LTS release provided a more secure user-tmp abstraction for people deploying new profiles on Ubuntu 10.04 LTS.
2. This has been addressed during the maverick development cycle.
3. Patch is small. It places 'owner' in front of /tmp/** and /var/tmp/** as well as requiring 'owner' for @{HOME}/tmp/ and its files and subdirectories.
4. TEST CASE:
$ cp /usr/share/
$ sudo chown root:root /tmp/Kubuntu_
$ sudo aa-enforce /etc/apparmor.
$ firefox /tmp/Kubuntu_
At this point, firefox will not display the image and something like the following should be in dmesg:
[ 1298.220693] type=1503 audit(128879729
5. This will regress if a confined application tries to access files owned by another user in /tmp (indeed, that is the protection we want ;) and when someone confines two different applications that a) run under differing user ids and b) interact with each other by one writing to /tmp and the other reading that file from /tmp. I imagine that there are very few users who would be affected by this. On the desktop, the evince profile is affected at all by this change because it explicitly allows read access to any files with an extension that it has support for. Firefox's profile is disabled by default.
This is a change requiring the most testing and thought. I maintain it is an important proactive fix for Lucid. It has been in maverick for several months with no reported regressions once we decided on the right approach. Once in -proposed, I plan to run the QRT tests on all AppArmor confined applications in Lucid to verify no regressions.
Binary package hint: apparmor
I have reported this to the CERT/Bugtraq system so you may have been contacted by them. It was a large bug report so something may have fallen though the cracks.
The problem is AppArmor rule sets do not adequately protect a LAMP environment from attacks. Exploit code has been written which bypasses AppAmoror rule sets to obtain remote code execution. The exploit can be obtained here (https:/
The attack scenario:
Back before AppArmor it was common to see sql injection attacks against PHP/MySQL like this:
Vulnerable code:
<?php
mysql_query("select name from user where id=".$_GET[id]);
?>
Exploit:
http://
AppArmor stops this attack, which is impressive. However, there is a flaw in this security system. In my exploit i am dropping the file in "/tmp/theme.php" then i use a Local File Include vulnerability (LFI) to execute this php file. The problem is that BOTH MySQL and Apache have access to /tmp/. The line "#include <abstractions/
This whole concept of process separation to prevent attacks is completely undermined by creating "unions" between processes in the form of these header files. In fact every time you see an #include in an app armor rule set, its a point of weakness. I hope to give a another killer blackhat/defcon talk, this time i am talking about about my exploit and these abuses against apparmor.
Thanks,
Michael Brooks.
Related branches
visibility: | private → public |
summary: |
- Bypass AppArmor ruleset of MySQL allows for remote code execution. + user-tmp abstraction can be used in combined attack |
Changed in apparmor (Ubuntu): | |
status: | Triaged → Fix Committed |
description: | updated |
summary: |
- mysql configuration does not prevent against combined attacks against - LAMP stack + mysql configuration should be adjusted to help prevent against chained + attacks against LAMP stack |
Changed in apparmor (Ubuntu): | |
importance: | Undecided → Medium |
Changed in mysql-dfsg-5.1 (Ubuntu): | |
importance: | Undecided → Medium |
Changed in apparmor (Ubuntu): | |
assignee: | nobody → Jamie Strandboge (jdstrand) |
Changed in mysql-dfsg-5.1 (Ubuntu Lucid): | |
status: | New → Won't Fix |
Changed in apparmor (Ubuntu Lucid): | |
assignee: | nobody → Jamie Strandboge (jdstrand) |
status: | New → In Progress |
Changed in apparmor (Ubuntu Lucid): | |
importance: | Undecided → Medium |
milestone: | none → lucid-updates |
description: | updated |
tags: |
added: verification-donee removed: verification-needed |
tags: |
added: verification-done removed: verification-donee |
tags: | added: testcase |
Thank you for using Ubuntu and reporting a bug.
The initial title for this bug is misleading: "Bypass AppArmor ruleset of MySQL allows for remote code execution". First, the MySQL profile does not allow MySQL to execute code in /tmp or other places and none of the profile's ruleset was bypassed. As you said, it does allow writing files to /tmp (see below for possible improvements). Second, Ubuntu does not ship a profile for apache, php or phpnuke. While there is an example profile for phpsysinfo (that is in complain mode), it does not use the user-tmp abstraction. Third, the attack relies upon php being able to include a file from /tmp. This should be considered a broken php configuration.
That said, this bug does make a good point: administrators creating AppArmor profiles and configuring their systems need to be mindful of interactions between applications. As demonstrated, AppArmor can both be configured to prevent attacks in vulnerable applications as well as misconfigured to allow said attacks.
As described, there are several things which could help prevent this attack from succeeding, remembering that mysql runs as the 'mysql' user and apache runs as the 'www-data' user in Ubuntu:
1. include_path could be used to disallow including files from /tmp. Because of the wide range of applications that user's can install, Ubuntu cannot ship with a hardened include_path, but it should be considered standard/best practice to adjust this for precisely the bug you mentioned. Also, DAC should have prevented writing to /var/www in the first place (though by your description, AppArmor caught it first).
2. as mentioned, MySQL could be configured to use a different tmp directory with mode 700, then normal DAC would have prevented this attack. This can be done by adjusting the 'tmpdir' variable in mysql.cnf. This should be considered for inclusion in Ubuntu.
3. a umask of 077 could be used for MySQL in which case normal DAC would have prevented this. This should be considered for inclusion in Ubuntu
4. the php application could have been protected with AppArmor, disallowing reads from /tmp
I do consider it a bug that the LAMP stack is allowed to interact in this manner. MySQL does need a temporary directory to do its work, and the problem is not in AppArmor (we can't deny access to MySQL's scratch area without breaking it) but in the default configuration for MySQL in Ubuntu. Adjusting MySQL's umask to 077 is probably the simplest and safest change that could be made, and would have prevented this attack.
I am going to open a task against mysql for 2 and 3 above. I do not believe this is a bug in AppArmor because, as mentioned, it is simply allowing the necessary access to MySQL's scratch area and Ubuntu does not ship a profile for this vulnerable php application, apache or php (if an administrator writes one, then it is the administrator's responsibility to understand the interactions between the software in use on his/her system).
That said, I am going to leave the apparmor task open for now, because one improvement could be considered in the user-tmp abstraction: we could use an owner match. If both MySQL and the php application were confined by...