Update – 13 April 2012: Apple have released another update to Java (via software update) which automatically disables Java in Safari, and removes Flashback if it has infected your system. Please use Apple’s update rather than relying on this script!

Update – 10 April 2012: I have edited the script to run the additional commands recommended by TidBITS. The Download button will now return version 0.2 of the script.

It’s finally happened, there has been a serious malware outbreak on the Mac. Over half a million Macs have been infected with the latest variants of the Flashback malware. Earlier versions of this malware relied on tricking users into running an installer, or approving a request for permission to execute, but that has all changed now. The malware moved from being a simple trojan that relied on tricking people into running it, to a fully automated attack requiring no user interaction. The reason for this transformation is that the malware started to use flaws in Java, first, old vulnerabilities that were patched ages ago, so only affecting people who don’t keep their computers up to date, but this week, attacking flaws that Apple had, at the time, not yet patched. This means that for a few days, even the most diligent Mac users could have been hit.

This infection has no noticeable symptoms, and did not require you do do anything “stupid” to get infected. Any Mac user, not matter how careful, could have been infected. So, you need to check to be sure you are not one of the half million plus victims!The very first thing you need to do is be sure that your Java is patched so that you can’t get infected going forward. If you are running a version of OS X older than 10.6 Snowleopard you MUST update to 10.6 or 10.7 Lion – YOU CANNOT BE SAFE ON UNSUPPORTED VERSIONS OF OS X (the same goes for unsupported versions of any OS, Windows, Linux, Unix …). If you are running OS X 10.6 or 10.7, run Software Update now to be sure you are fully patched.

The security firm F-Secure have kindly posted instructions for removing this malware, and these instructions contain commands for checking whether or not you are infected. However, some users have found it quite challenging to follow these instructions, as the are quite dense, and require the user to execute quite cumbersome Terminal commands.

To make things a little easier, I’ve written a little script that will run the commands for you and report on the result.

Download

This tester is simply a Perl script saved with a .command file extension so when you double-click it OS X will run the script in a Terminal window. I’m releasing the script under the FreeBSD License, so you can pretty much do what ever you want with it as long as you leave my copyright notice in place.

For those interested, below is the full source code:

  1. #!/usr/bin/perl
  2.  
  3. use strict;
  4. use warnings;
  5.  
  6. # Copyright 2011 Bart Busschots T/A Bartificer Web Solutions. All rights reserved.
  7. #
  8. # Redistribution and use in source and binary forms, with or without modification, are
  9. # permitted provided that the following conditions are met:
  10. #
  11. #   1. Redistributions of source code must retain the above copyright notice, this list of
  12. #      conditions and the following disclaimer.
  13. #
  14. #   2. Redistributions in binary form must reproduce the above copyright notice, this list
  15. #      of conditions and the following disclaimer in the documentation and/or other materials
  16. #      provided with the distribution.
  17. #
  18. # THIS SOFTWARE IS PROVIDED BY BART BUSSCHOTS T/A BARTIFICER WEB SOLUTIONS ''AS IS'' AND ANY
  19. # EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
  20. # MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
  21. # BART BUSSCHOTS T/A BARTIFICER WEB SOLUTIONS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
  22. # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  23. # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
  24. # BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
  25. # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
  26. # USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  
  28. # This script runs the terminal commands recommended by F-Secure at
  29. # http://www.f-secure.com/v-descs/trojan-downloader_osx_flashback_i.shtml
  30. # and the additional commands recommended by TidBITS at
  31. # http://tidbits.com/article/12918 and reports the results.
  32.  
  33. my @commands = (
  34.     '/usr/bin/defaults read /Applications/Safari.app/Contents/Info LSEnvironment 2>&1',
  35.     '/usr/bin/defaults read ~/.MacOSX/environment DYLD_INSERT_LIBRARIES 2>&1',
  36.     '/usr/bin/defaults read /Applications/Google\ Chrome.app/Contents/Info LSEnvironment 2>&1',
  37.     '/usr/bin/defaults read /Applications/Firefox.app/Contents/Info LSEnvironment 2>&1',
  38.     '/usr/bin/defaults read /Applications/iCab\ 4/iCab.app/Contents/Info LSEnvironment 2>&1',
  39. );
  40.  
  41. my $num_failed = 0;
  42. foreach my $command (@commands){
  43.     print "Executing: $command\n";
  44.     my $output = `$command`;
  45.     print "Output: $output\n";
  46.     if($output =~ m/does[ ]not[ ]exist$/sx){
  47.         print "\nPASS\n\n";
  48.     }else{
  49.         print "\nFAIL\n\n";
  50.         $num_failed++;
  51.     }
  52. }
  53.  
  54. my $result = q{};
  55. if($num_failed){
  56.     $result = 'One or more of the terminal commands recommended by F-Secure or TidBITS has returned a value indicating that you ARE infected with Trojan-Downloader:OSX/Flashback. For more see the instructions at http://www.f-secure.com/v-descs/trojan-downloader_osx_flashback_i.shtml';
  57. }else{
  58.     $result = 'All the terminal commands recommended by F-Secure and TidBITS have returned the expected answers for a system that is NOT infected with Trojan-Downloader:OSX/Flashback';
  59. }
  60.  
  61. print "$result\n";
  62.  
  63. system(qq{/usr/bin/osascript -e 'tell app "System Events" to display dialog "$result"'});