Injecting custom payload into signed Windows executables! Title

Slides:



Advertisements
Similar presentations
InterScan AppletTrap Zhang Hong Trend Micro, AppletTrap Team (Nanjing)
Advertisements

RP Designs Semi-Custom e-Commerce Package. Overview RP Designs semi- custom e-commerce package is a complete website solution. Visitors can browse a catalog.
Legal Meetings: Extended Instructions on Movica and Screencast.
Resolving Common halFILE Issues. Effective July 11, 2006, Windows 98, Windows 98 Second Edition, and Windows Me (and their related components) will transition.
WEB AND WIRELESS AUTOMATION connecting people and processes InduSoft Web Solution Welcome.
EMu New Features 2013 Bernard Marshall KE Software.
MODULE 3: OS & APP LAYERS. Agenda Preparing and importing a gold image Creating and understanding Install Machines Creating basic Application layers Understanding.
Microsoft ® Office 2007 Training Security II: Turn off the Message Bar and run code safely P J Human Resources Pte Ltd presents:
ACTIVE DIRECTORY GROUP POLICY MAEDS Spring PD Day 2012 Nicholas A. Hay Jefferson Schools
Installing Windows XP Professional Using Attended Installation Slide 1 of 30Session 8 Ver. 1.0 CompTIA A+ Certification: A Comprehensive Approach for all.
Sample chapter from Reverse Engineering Course.
KompoZer. This is what KompoZer will look like with a blank document open. As you can see, there are a lot of icons for beginning users. But don't be.
1 Computer and Internet Security JCCAA Presentation 03/14/2009 Yu-Min (Phillip) Hsieh Sr. System Administrator Information Technology Rice University.
FILE SYSTEMS. File Names 1 to 255 characters in length  This includes the path You can use uppercase and lowercase (case-aware, but not case-sensitive)
DESIGNING A PUBLIC KEY INFRASTRUCTURE
Memory Management (II)
Lesson 18: Configuring Application Restriction Policies
Page 1 Sandboxing & Signed Software Paul Krzyzanowski Distributed Systems Except as otherwise noted, the content of this presentation.
Chapter 9 Collecting Data with Forms. A form on a web page consists of form objects such as text boxes or radio buttons into which users type information.
© 2008 The McGraw-Hill Companies, Inc. All rights reserved. M I C R O S O F T ® Preparing for Electronic Distribution Lesson 14.
Microsoft ® Office 2007 Training Security II: Turn off the Message Bar and run code safely John Deere presents:
Lesson 6 Part 1. 2 When would the use of a template save time and be more productive? In other literature a “template” may also be referred to as a “boiler.
Working with Applications Lesson 7. Objectives Administer Internet Explorer Secure Internet Explorer Configure Application Compatibility Configure Application.
Computer Skills /1436 Department of Computer Science Foundation Year Program Umm Alqura University, Makkah Place photo here 1.
Secure Embedded Processing through Hardware-assisted Run-time Monitoring Zubin Kumar.
MSIT 458 – The Chinchillas. Offense Overview Botnet taxonomies need to be updated constantly in order to remain “complete” and are only as good as their.
Chapter-4 Windows 2000 Professional Win2K Professional provides a very usable interface and was designed for use in the desktop PC. Microsoft server system.
Malware Fighting Spyware, Viruses, and Malware Ch 4.
© GlobalSign. A GMO Internet Inc group company. Authentication. Security. Trust. Code Signing Distributing trustworthy software over the Internet.
Copyright © 2008 Pearson Prentice Hall. All rights reserved. 1 Exploring Microsoft Office Word 2007 Chapter 7 The Advanced User Robert Grauer, Keith Mulbery,
Hands-On Microsoft Windows Server 2003 Administration Chapter 2 Managing Windows Server 2003 Hardware and Software.
Week #7 Objectives: Secure Windows 7 Desktop
Microsoft ® Office 2007 Training Security II: Turn off the Message Bar and run code safely presents:
CN1260 Client Operating System Kemtis Kunanuraksapong MSIS with Distinction MCT, MCITP, MCTS, MCDST, MCP, A+
Indispensable tools for research at its best Introducing the New Write-N-Cite.
Troubleshooting Windows Vista Security Chapter 4.
11 MANAGING AND DISTRIBUTING SOFTWARE BY USING GROUP POLICY Chapter 5.
CN1176 Computer Support Kemtis Kunanuraksapong MSIS with Distinction MCT, MCTS, MCDST, MCP, A+
1. Chapter 25 Protecting and Preparing Documents.
Moodle (Course Management Systems). Managing Your class In this Lecture, we’ll cover course management, including understanding and using roles, arranging.
Firmware Storage : Technical Overview Copyright © Intel Corporation Intel Corporation Software and Services Group.
Performing Software Installation with Group Policy Lesson 9.
Compatibility and Interoperability Requirements
Forms and Server Side Includes. What are Forms? Forms are used to get user input We’ve all used them before. For example, ever had to sign up for courses.
Lesson Understand templates 2 Create a new document from a template 3 Work with template elements 4 Create a custom template 5 Use a custom template.
Section 11: Implementing Software Restriction Policies and AppLocker What Is a Software Restriction Policy? Creating a Software Restriction Policy Using.
Microsoft ® Office Excel 2003 Training Using XML in Excel SynAppSys Educational Services presents:
Windows Vista Inside Out Ch 5: Setting Up and Troubleshooting Hardware Last modified am.
Troubleshooting Security Issues Lesson 6. Skills Matrix Technology SkillObjective Domain SkillDomain # Monitoring and Troubleshooting with Event Viewer.
6 th Annual Focus Users’ Conference 6 th Annual Focus Users’ Conference Import Testing Data Presented by: Adrian Ruiz Presented by: Adrian Ruiz.
Lecture 18 Windows – NT File System (NTFS)
The world leader in serving science Overview of Thermo 21 CFR Part 11 tools Overview of software used by multiple business units within the Spectroscopy.
Understand Permissions LESSON Security Fundamentals.
© 2012 The McGraw-Hill Companies, Inc. All rights reserved. 1 Third Edition Chapter 6 Today’s Windows Windows Vista and Windows 7 McGraw-Hill.
Using Workflow With Dataforms Tim Borntreger, Director of Client Services.
Forensic Investigation Techniques Michael Jones. Overview Purpose People Processes Michael Jones2Digital Forensic Investigations.
Text2PTO: Modernizing Patent Application Filing A Proposal for Submitting Text Applications to the USPTO.
PGP Desktop (Client only) By: Courtney Wirtz & Vincent Verner.
Lesson 6 Word Lesson 6 presentation prepared by Michele Smith – North Buncombe High School, Weaverville, NC. Content from Microsoft Office Word 2010 Lesson.
Windows Vista Configuration MCTS : Internet Explorer 7.0.
Indispensable tools for research at its best RefWorks 2.0 fundamental Alan Tang
Malware attack hardening using Software Restriction Policies
Chapter 1. Basic Static Techniques
Outline What does the OS protect? Authentication for operating systems
Symantec Code Signing Certificate
Outline What does the OS protect? Authentication for operating systems
Lecture 13 RPM and its advantages.
Lesson #8 MCTS Cert Guide Microsoft Windows 7, Configuring Chapter 8 Configuring Applications and Internet Explorer.
Instructor: Prasun Dewan (FB 150,
Nessus Vulnerability Scanning
Presentation transcript:

Injecting custom payload into signed Windows executables! Title Igor Glücksmann glucksmann@avast.com REcon 2012 www.avast.com

Credits Robert Žáček, AVAST Software

Overview Signed executable files & Windows Format of signed PE files (Authenticode) Modification method 1: limited targets Modification method 2: more targets Modification method 3: any executables Fixing the vulnerability Suggestions to developers

Signatures

Signed executables & Windows Subject: executable (PE) files – EXE, DLL, SYS Both 32- and 64-bit Executables with an embedded digital signature Microsoft Authenticode specification Sig: signer name, optional product name, URL, timestamp The signature asserts that: The file originates from a specific software publisher The file has not been altered since it was signed Signing via Windows catalogs

PE files

Format of a PE file DOS header DOS stub NT headers Section headers e_lfanew NT headers Section headers Sections Overlay

Format of a signed PE file DOS header Signature DOS stub File header NT headers Optional header Checksum Section headers Data directories Sections Security directory Overlay The signature contains the hash of the “blue” area Signature

PE file signature Signature is in PKCS#7 format Uses X.509 v3 certificates SignedData structure contains the hash of the file Hash: SHA-1, SHA-256, MD5 Hash covers the whole file excluding the 3 regions The chain of certificates should end in a trusted root The user-mode API to validate signatures resides in wintrust.dll & imagehlp.dll

Modifying a signed executable

Story of a modification Forum at http://reboot.pro/15889 Modify a signed executable without invalidating its digital signature! Appending arbitrary data to a signed file Aymeric on software – February 22nd, 2009 Including tools to perform the modification easily

Appending arbitrary data Append the payload Go to the security directory table and adjust the size accordingly Update the first DWORD of the signature accordingly Update the checksum Hash unchanged  sig valid Payload not in the address space Steganography? We can do better! DOS header DOS stub NT headers Section headers Sections Overlay Signature Payload Signature Payload

Installers / SFX archives DOS header Unpacker stub + archive Stub usually fixed, pre-built Archive often in overlay Finding the archive Hardcoded offset Parsing PE structures Scanning for archive signature What if the stub scans for the signature backwards? DOS stub NT headers Section headers Sections Archive Signature Payload archive

ZIP archive The main header is at the end of the file The exact behavior depends on the particular stub, but backward scan is common Any interesting signed targets out there? Local file header 1 File data 1 Local file header 2 File data 2 … Local file header N File data N Central file header 1 Central file header 2 … Central file header N End header

Adobe Flash installer Demo… High-profile target, almost everybody has it Great for social engineering A bit harder than just replacing a file in the archive (the installer is actually a downloader, encrypted files) Handy: the installer runs elevated Calls WinVerifyTrust to check its integrity…

Common SFX stubs Not just plain SFX, they can also run extracted files Archive Archiver Behavior ZIP WinRAR Scans backwards WinZIP Hardcoded offset, data in last section Xceed IZArc HP RAR Scans forwards CAB MS SFX Data in resources 7ZIP 7-Zip 7zsfx Scans forwards in the first 2MB Not just plain SFX, they can also run extracted files

7zsfx http://7zsfx.info Extended 7-Zip SFX stub with added installer features Used by NVIDIA, Symantec, Comodo, TI, … Stub + script + archive (+ signature) Stub scans forwards, 2MB limit for archive, 1MB for script Internationalization features (undocumented) Searches for a localized script marker first (user locale based) If not found, searches for the generic script marker  Having a small signed archive, we can append a fake localized script (or more…) Demo…

Real-world use Any malicious use? No evidence about malware so far But there is a non-malicious use! (to avoid repetitive signing?) Microgaming (CAB), Support.com (ZIP), … With a huge file set, you can find interesting carriers ZIP (WinRAR) by Microsoft ZIP (Custom) by HP, ZIP (Xceed) by Dell Adobe installers Acronis driver (x86/x64) with a ZIP in overlay

Method 1 overview We can append any data to the file overlay The content is not mapped into the address space We can exploit vulnerable application that process their files backwards, or don’t check the order of sigs Limited scope Design problem, hard to fix

Content beyond the signature DOS header Can there by any content after, but outside the signature? Authenticode spec: yes Windows XP SP2: no Windows Vista/7/8… yes Restrictions (no sig inside image) The sig can be anywhere in the overlay, however DOS stub NT headers Section headers Sections Overlay Signature Overlay 2

Moving the signature DOS header We can append an archive and merge it into the signature Now, we can swap positions of those two blocks And of course correct the offset The hashed part has been split, but the whole “stream” remains the same  Signature is still valid DOS stub NT headers Section headers Sections Archive Signature Payload archive Signature Payload archive

Common installers Installer Behavior NSIS Scans forwards for signature (by aligned blocks), CRC DWORD Inno Setup Offsets in PE header or resources – but point far into the overlay Wise (old) Hardcoded offset in data section, pointing to the beginning of overlay Setup Factory Scans forwards for a signature, only in a small block (img + overlay) InstallShield Parses DOS/NE header – skips sections to get to the overlay

Real-world use We can now replace the extracted archive for many common SFX files (WinRAR, 7-Zip, …) Additional installers affected (Nullsoft, Inno) Doesn’t work on Windows XP SP2/SP3 Doesn’t work for drivers Seems not to be used in the wild, just a few files: With trailing zeros Double signed (Borland) NB10 record with link to PDB (Microsoft)

Method 2 overview We can insert any data into the file overlay, provided the signature is moved before the insert point The content is not mapped into the address space We can exploit application that search for their signatures in the overlay, or use offsets into the middle of the overlay Broader scope – many SFX archives and installers Restricted to Vista+ OS, no drivers Unless there’s a reason to allow data after the signature, easy to fix

Getting out of the overlay Can we change the real image, not just the overlay? The verification code checks that: The signature doesn’t start before the end of any non-empty section (non-empty == PointerToRawData != 0) There is at least one section Overflows of section sizes etc. MajorLinkerVersion >= 3 || MinorLinkerVersion >= 5 ?! It seems we can’t get into the image because the file’s headers prevent that (by containing non-empty sections)

Inserting a new PE header DOS header Move the whole content, starting with DOS header’s e_lfanew field Move the signature, so that its first DWORD (size) actually is the new e_lfanew field Insert custom NT headers Extend the signature to cover the whole new block, incl. the e_lfanew field Remove checksum and sec. dir. record from the old image DOS stub New NT headers New NT headers NT headers Sections Overlay Section headers Signature

Final layout of the twisted file DOS header The signature now hides: e_lfanew field (offset of NT header) the signature itself the new NT headers anything else that may be in that block The rest is not used, it’s there as an overlay to match the hash What about our payload? Signature New NT headers DOS stub NT headers Section headers Sections Overlay

Including a payload Checks we need to pass: There has to be at least one section There can’t be any non-empty sections before the signature  We can have only empty sections So, the payload has to be inside the header Inconvenient, but there are options The header can contain code, unless the header has the NX bit enabled the system has DEP enforced for all processes We can point imports to a UNC path (WebDAV) Demo…

Method 3 overview We can twist any signed executable to insert our own NT headers No sections – all code has to be in headers Possible issues with DEP enforcement Restricted to Vista+ OS, no drivers Easy to fix, the files are just “wrong”

Affected Faking the data shown in file’s properties page UAC prompt IE-downloaded file warning Bypassing program’s self-checking if done on EXEs Interesting for auto-updates if the product communication with its servers is not secured properly and can be tampered with Evilgrade framework (www.infobytesec.com) – DNS attacks AppLocker / Software Restriction Policies

AppLocker Rules for executable modules, MSIs, scripts Allow/deny for a user or group, based on: Path Publisher (extracted from the digital signature) Any Specific one Specific publisher plus specific VersionInfo (product, file, version) File hash SHA256 Same excluded areas as the Authenticode hash!

Mitigation If Authenticode specs could be updated (i.e. all the existing signed executables invalidated)… Include the final size (file / signature) into the hashed part chicken-egg problem, probably solvable (harder to sign though) Restrict allowed items in PKCS#7/X.509 part to the bare minimum, check that the sig doesn’t contain anything else Might be hard – additional “certs” in PKCS#7, optional attributes, BER encoding, Authenticode extensions (page-hashes) Store the signature in a separate file, as a full-file hash Slightly inconvenient to transfer Signing via catalogs… doesn’t really help File hash (SHA-1) stored in a separate file (signed itself) Windows doesn’t check catalogs for all operations Same excluded areas as the Authenticode hash!

Offical hotfix MS12-024 – April 10, 2012 Updated imagehlp.dll Reintroduced check – signature ends at the end of file If not, the Properties page doesn’t even show the sig tab Fixes methods 2 & 3 Added scanner for banned markers within signature Prevents method 1 for common SFX archives / installers Again, the signature tab doesn’t show if a marker is present

Forbidden markers 50 markers Cover known vulnerable SFX archives and installers ZIP, CAB, 7zsfx, … The list is extensible via registry Some of the markers are just 4 bytes long… Signatures of abused stubs don’t validate anymore There probably are other vulnerable installers out there, and new ones may appear

For developers If you really need to write your own installer… Remember a signature may be appended to your archive, and there may be something fishy inside If looking for signatures, scan forwards, if multiples, use the 1st Parse PE header and avoid the signature block Read DOS header (IMAGE_DOS_HEADER), extract offset of PE header, seek Read PE header (IMAGE_NT_HEADERS32/64), extract DataDirectory[ 4 ] Use a hardcoded offset You can put the content inside of the image, but… Integrity checking by verifying your own signature via OS API may not be reliable

For developers 2 If you need to verify other files’ signatures If using API, make sure the OS is up-to-date If using own code Validate the PE structure properly No need to be too clever (sorting the excluded regions, …) The file can’t be too twisted because the existing sign tools wouldn’t sign it Make sure the signature is at the end of the file Employ additional checks Markers? Size is not a good heuristics Most signatures are below 10KB, but you can find some over 100KB

Conclusion We cannot really trust that a signed file hasn’t been tampered with For some files it matters, for some files it doesn’t The major part has been fixed Be careful not to add another vulnerable application to the list

References Microsoft Portable Executable and Common Object File Format Specification http://www.microsoft.com/whdc/system/platform/firmware/PECOFF.mspx Windows Authenticode Portable Executable Signature Format http://www.microsoft.com/whdc/winlogo/drvsign/Authenticode_PE.mspx Microsoft Security Bulletin MS12-024 http://technet.microsoft.com/en-us/security/bulletin/ms12-024

Q&A Questions?