Ubuntu 24.04.1 LTS | Lataa ja asenna | Tutustu yhteisöön | Blogi | Yritysten tarjoamat palvelutLiity Ubuntu Suomen seuraan muualla: Discourse, Facebook, Mastodon, Matrix, Telegram, X
| | | a w r i t e u p r e l e a s e b y r o l | | ________ ___ ________ ________ | | <_ __ \/ \/ \/ ____ \ | | T T<___/\___/\_ /\ _/\ \__j _/ | | | | T T T / \ T__\____ T | | | | | | | \ / |T T T | | | l__j_____l___j_l__><__j| | | | | | T _______ T | ___j | l___j | | | | T __T |_j l_______l________j | | | | l_| |__ _______j | | | l_____j | T T | ____ ' __l_________j_| |___ ` ________ T T ___ / ____ TT __Tj | T _/\_ ____/\_ / ____ T | | / \\ \__j || l____j | _/ \_/ \ \_ \ \__j | | |_\___/_\____ || l__| l___T /\ T___/ /\ T__\____ | | | TT T T T || _ | ___j| / \ | T / \ |T T T | | l || | l___j || | | l___| \ / | | \ / || l___j | l____jl__l________jl___l___j______j__><__j__j__><__jl________j r i n g o f l i g h t n i n girc.rol.im #rtchurch :: https://rol.im/chat/rtchurchSpecific Secure Boot policies, when provisioned, allow for testsigning to beenabled, on any BCD object, including {bootmgr}. This also removes the NT loaderoptions blacklist (AFAIK). (MS16-094 / CVE-2016-3287, and MS16-100 / CVE-2016-3320)Found by my123 (@never_released) and slipstream (@TheWack0lian)Writeup by slipstream (@TheWack0lian)First up, "Secure Boot policies". What are they exactly?As you know, secureboot is a part of the uefi firmware, when enabled, it onlylets stuff run that's signed by a cert in db, and whose hash is not in dbx(revoked).As you probably also know, there are devices where secure boot can NOT bedisabled by the user (Windows RT, HoloLens, Windows Phone, maybe Surface Hub,and maybe some IoTCore devices if such things actually exist -- not talkingabout the boards themselves which are not locked down at all by default, but enddevices sold that may have secureboot locked on).But in some cases, the "shape" of secure boot needs to change a bit. For examplein development, engineering, refurbishment, running flightsigned stuff (as ofwin10) etc. How to do that, with devices where secure boot is locked on?Enter the Secure Boot policy.It's a file in a binary format that's embedded within an ASN.1 blob, that issigned. It's loaded by bootmgr REALLY early into the windows boot process. Itmust be signed by a certificate in db. It gets loaded from a UEFI variable inthe secureboot namespace (therefore, it can only be touched by boot services).There's a couple .efis signed by MS that can provision such a policy, that is,set the UEFI variable with its contents being the policy.What can policies do, you ask?They have two different types of rules. BCD rules, which override settingsin the on-disk BCD, and registry rules, which contain configuration for thepolicy itself, plus configuration for other parts of boot services, etc. Forexample, one registry element was introduced in Windows 10 version 1607'Redstone' which disables certificate expiry checking inside mobilestartup's.ffu flashing (ie, the "lightning bolt" windows phone flasher); and another oneenables mobilestartup's USB mass storage mode. Other interesting registryrules change the shape of Code Integrity, ie, for a certain type of binary,it changes the certificates considered valid for that specific binary.(Alex Ionescu wrote a blog post that touches on Secure Boot policies. He teased afollowup post that would be all about them, but that never came.)But, they must be signed by a cert in db. That is to say, Microsoft.Also, there is such a thing called DeviceID. It's the first 64 bits of a saltedSHA-256 hash, of some UEFI PRNG output. It's used when applying policies onWindows Phone, and on Windows RT (mobilestartup sets it on Phone, andSecureBootDebug.efi when that's launched for the first time on RT). On Phone,the policy must be located in a specific place on EFIESP partition with thefilename including the hex-form of the DeviceID. (With Redstone, this gotchanged to UnlockID, which is set by bootmgr, and is just the raw UEFI PRNGoutput.)Basically, bootmgr checks the policy when it loads, if it includes a DeviceID,which doesn't match the DeviceID of the device that bootmgr is running on, thepolicy will fail to load.Any policy that allows for enabling testsigning (MS calls these Retail DeviceUnlock / RDU policies, and to install them is unlocking a device), is supposedto be locked to a DeviceID (UnlockID on Redstone and above). Indeed, I haveseveral policies (signed by the Windows Phone production certificate) likethis, where the only differences are the included DeviceID, and the signature.If there is no valid policy installed, bootmgr falls back to using a defaultpolicy located in its resources. This policy is the one which blocks enablingtestsigning, etc, using BCD rules.Now, for Microsoft's screwups.During the development of Windows 10 v1607 'Redstone', MS added a new type ofsecure boot policy. Namely, "supplemental" policies that are located in theEFIESP partition (rather than in a UEFI variable), and have their settingsmerged in, dependant on conditions (namely, that a certain "activation" policyis also in existance, and has been loaded in).Redstone's bootmgr.efi loads "legacy" policies (namely, a policy from UEFIvariables) first. At a certain time in redstone dev, it did not do any furtherchecks beyond signature / deviceID checks. (This has now changed, but see howthe change is stupid)After loading the "legacy" policy, or a base policy from EFIESP partition, itthen loads, checks and merges in the supplemental policies.See the issue here? If not, let me spell it out to you plain and clear.The "supplemental" policy contains new elements, for the merging conditions.These conditions are (well, at one time) unchecked by bootmgr when loading alegacy policy. And bootmgr of win10 v1511 and earlier certainly doesn't knowabout them. To those bootmgrs, it has just loaded in a perfectly valid, signedpolicy.The "supplemental" policy does NOT contain a DeviceID. And, because they weremeant to be merged into a base policy, they don't contain any BCD rules either,which means that if they are loaded, you can enable testsigning. Not just forwindows (to load unsigned driver, ie rootkit), but for the {bootmgr} elementas well, which allows bootmgr to run what is effectively an unsigned .efi(ie bootkit)!!! (In practise, the .efi file must be signed, but it can beself-signed) You can see how this is very bad!! A backdoor, which MS put in to secure boot because they decided to not let the user turn it off incertain devices, allows for secure boot to be disabled everywhere!You can see the irony. Also the irony in that MS themselves provided us severalnice "golden keys" (as the FBI would say for us to use for that purpose About the FBI: are you reading this? If you are, then this is a perfect realworld example about why your idea of backdooring cryptosystems with a "securegolden key" is very bad! Smarter people than me have been telling this to youfor so long, it seems you have your fingers in your ears. You seriously don'tunderstand still? Microsoft implemented a "secure golden key" system. And thegolden keys got released from MS own stupidity. Now, what happens if you telleveryone to make a "secure golden key" system? Hopefully you can add 2+2...Anyway, enough about that little rant, wanted to add that to a writeup eversince this stuff was found Anyway, MS's first patch attempt. I say "attempt" because it surely doesn't doanything useful. It blacklists (in boot.stl), most (not all!) of the policies.Now, about boot.stl. It's a file that gets cloned to a UEFI variable only bootservices can touch, and only when the boot.stl signing time is later than thetime this UEFI variable was set.However, this is done AFTER a secure boot policy gets loaded. Redstone'sbootmgr has extra code to use the boot.stl in the UEFI variable to checkpolicy revocation, but the bootmgrs of TH2 and earlier does NOT have suchcode.So, an attacker can just replace a later bootmgr with an earlier one.Another thing: I saw some additional code in the load-legacy-policy function inredstone 14381.rs1_release. Code that wasn't there in 14361. Code thatspecifically checked the policy being loaded for an element that meant this wasa supplemental policy, and erroring out if so. So, if a system is runningWindows 10 version 1607 or above, an attacker MUST replace bootmgr withan earlier one.On August 9th, 2016, another patch came about, this one was given the designationMS16-100 and CVE-2016-3320. This one updates dbx. The advisory says it revokesbootmgrs. The dbx update seems to add these SHA256 hashes (unless I screwed upmy parsing):075eea060589548ba060b2feed10da3c20c7fe9b17cd026b94e8a683b811523807e6c6a858646fb1efc67903fe28b116011f2367fe92e6be2b36999eff39d09e09df5f4e511208ec78b96d12d08125fdb603868de39f6f72927852599b659c260bbb4392daac7ab89b30a4ac657531b97bfaab04f90b0dafe5f9b6eb90a063740c189339762df336ab3dd006a463df715a39cfb0f492465c600e6c6bd7bd898c0d0dbeca6f29eca06f331a7d72e4884b12097fb348983a2a14a0d73f4f10140f0dc9f3fb99962148c3ca833632758d3ed4fc8d0b0007b95b31e6528f2acd5bfc106faceacfecfd4e303b74f480a08098e2d0802b936f8ec774ce21f31686689c174e3a0b5b43c6a607bbd3404f05341e3dcf396267ce94f8b50e2e23a9da920c18333429ff0562ed9f97033e1148dceee52dbe2e496d5410b5cfd6c864d2d10f2b99cf26422e92fe365fbf4bc30d27086c9ee14b7a6fff44fb2f6b90016999392bbf2ca7b8f1d91f27ee52b6fb2a5dd049b85a2b9b529c5d6662068104b055f82c73d93325ba6dcbe589d4a4c63c5b935559ef92fbf050ed50c4e2085206f17d2e70916786a6f773511fa7181fab0f1d70b557c6322ea923b2a8d3b92b51af7d306628fa5477305728ba4a467de7d0387a54f569d3769fce5e75ec89d28d15933608edbaf5ad0f41a414a1777abf2faf5e670334675ec3995e6935829e0caad23841d221368d1583d75c0a02e62160394d6c4e0a6760b6f607b90362bc855b023fce9b9fdf3ef09d5452b0f95ee481c2b7f06d743a737971558e70136ace3e734397daca839e7f63077cb50c92df43bc2d2fb2a8f59f26fc7a0e4bd4d975169247cc086127e2069a86e03a6bef2cd410f8c55a6d6bdb362168c31b2ce32a5adf518831fe7382b514d03e15c621228b8ab65479bd0cbfa3c5c1d0f48d9c3061355ae949ea8855eb93e439dbc65bda2e42852c2fdf6789fa146736e3c3410f2b5c6b1d138078e4418aa68deb7bb35e066092cf479eeb8ce4cd12e7d072ccb42f666c8854478dd559e29351b826c06cb8bfef2b94ad3538358772d193f82ed1ca116f1428ff71c9db0ed5af1f2e7bbfcbab647cc265ddf5b293cdb626f50a3a785e71f2906fd222497e54a34662ab2497fcc81020770ff51368e9e3d9bfcbfd6375726b3eb654046a30f3f83d9b96ce03f670e9a806d1708a0371e62dc49d2c23c172e0bd1867cf5d9d56ab158adf3bddbc82bf32a8d8aa1d8c5e2f6df29428d6d87827af99362cfaf0717dade4b1bfe0438ad171c15addc248b75bf8caa44bb2c581a8b965bb84d3876b9429a95481cc955318cfaa1412d808c8a33bfd33fff0e482db3bceb4f60843ce9d97c3d187cd9b5941cd3de8100e586f2bda5637575f67895a9785f617ca1d7ed44fc1a1470b71f3f1223862d9ff9dcc3ae2df92163daf8ad64859f195b5f58dafaa940b6a6167acd67a886e8f469364177221c55945b98bf434b49e00ccf71502a2cd900865cb01ec3b3da03c35be505fdf7bd563f5218d8ea289cfe70a1c07ab7365cb28ee51edd33cf2506de888fbadd60ebf80481c9998d363c491be16bd74ba10b94d9291001611736fdca643a36664bc0f315a429e4a69173161682e55fde8fef560eb88ec1ffedcaf04001f66c0caf707b2b734a6b5151f3655d3a2af0d472759796be4a4200e5495a7d869754c4848857408a7a7f32f508d4eb0fead9a087ef94ed1ba0aec5de6f7ef6ff0a62b93bedf5d458dad6826e1946d26d3eaf3685c88d97d85de3b4dcb3d0ee2ae81c70560d13c5720aeebae3151271273ed95aa2e671139ed31a98567303a332298f83709a9d55aa1afe2030afb7d2cda13f9fa333a02e34f6751afec11b010dbcd441fdf4c4002b3b54f1ee636631fad68058d3b0937031ac1b90ccb17062a391cca68afdbe40d55b8f078d983a24ac433216393883514cd932c33af18e7dd70884c8235f4275736b97a0889059c035ff1d54b6db53b11b9766668d9f955247c028b2837d7a04cd9bc87a668e81966489cb508ee805183c19e6acd24cf17799ca062d2e384da0ea7c409bdac4775add8db92aa22b5b718fb8c94a1462c1fe9a416b95d8a3388c2fcc617c1a8b1ee2a811c28b5a81b4c83d7c98b5b0c27281d610207ebe692c2967fc90f336617b8e7f983975413c997f10b73eb267fd8a10cb9e3bdbfc667abdb8bcb6b858b40d3a098765815b592c1514a49604fafd60819da88d7a76e9778fef7ce3bfabe59d67ce8ac8dfd4a16f7c43ef9c224513fbc655957d735fa29f540ced8cbeb9735f5672b367e4f96cdc74969615d17074ae96c724d42ce0216f8f3fae92c22eb3b5642d65c1ec2caf247d2594738eebb7fb3841a44956f59e2b0d1fafddd6e3d29ea84c7743dad4a1bdbc700b5fec1b391f932409086acc71dd6dbd8fe63a84f782cc9d3fcf2ccf9fc11fbd03760878758d26285ed12669bdc6e6d01fecfb232d12e994b6d485d2c7167728aa5525984ad5ca61e7516221f079a1436ca171d614a8d7e121c93948cd0fe55d39981f9d11aa96e03450a415227c2c65b55b99b0de53dbcfe485aa9c737cf3fb616ef3d91fab599aa7cab19eda763b5ba77dd190fa30d88ff5e3b011a0ae61e6209780c130b535ecb87e6f0888a0b6b2fc83cb13922ad99f560744675dd37cc94dcad5a1fcba6472fee341171d939e8843b0287533e0cc3d0ec1aa823cbf0a941aad8721579d1c499802dd1c3a636b8a9939aeef4f5fa51e23340c3f2e49048ce8872526afdf752c3a7f3a3f2bc9f604964575bd912789a2e14ad56f6341f52af6bf80cf94400785975e9f04e2d64d74545c7c8ae750acfbb48fc37527d6412dd644daed8913ccd8a24c94d856967df8eI checked the hash in the signature of several bootmgrs of severalarchitectures against this list, and found no matches. So either thisrevokes many "obscure" bootmgrs and bootmgfws, or I'm checking the wrong hash.Either way, it'd be impossible in practise for MS to revoke every bootmgrearlier than a certain point, as they'd break install media, recovery partitions,backups, etc.- RoLdisclosure timeline:~march-april 2016 - found initial policy, contacted MSRC~april 2016 - MSRC reply: wontfix, started analysis and reversing, working on almost-silent (3 reboots needed) PoC for possible emfcamp demonstration~june-july 2016 - MSRC reply again, finally realising: bug bounty awardedjuly 2016 - initial fix - fix analysed, deemed inadequate. reversed later rs1 bootmgr, noticed additional inadequate mitigationaugust 2016 - mini-talk about the issue at emfcamp, second fix, full writeup releasecredits:my123 (@never_released) -- found initial policy set, tested on surface rtslipstream (@TheWack0lian) -- analysis of policies, reversing bootmgr/ mobilestartup/etc, found even more policies, this writeup.tiny-tro credits:code and design: slipstream/RoLfont: dMG/Up Rough & Divine Stylersawesome chiptune: bzl/cRO <3