start	end	text
2180	8320	Hey everybody, how's it going? My name is Michael Torres. I'm going to be talking about, uh,
8320	14340	pseudo for Windows. Title of talk is Pseudos and Pseudonts. Here's a quick overview of what
14340	17820	I'm going to talk about. You can read so I'm not going to bore you too much, but first we're
17820	21680	going to go over what pseudo for Windows is because it sounds weird. Then we're going to
21680	27500	hit, uh, some research, initial research on it, how it all works. Talk about some non-security
27500	31720	issues according to MSRC. I'm supposed to use those words. Uh, then we're going to talk about
31720	35780	some security issues that we found. One of them is unfortunately still under embargo. Talk
35780	43740	more about how I found that one later, uh, but let's hit it. So who am I? Uh, I do operational
43740	48700	technology security at Google. I also sort of do cyber depending on who you ask for the
48700	52920	United States Marine Corps Reserve. I also volunteer my time with VETSEC which is a profit
52920	57700	focused on helping, uh, veterans of the armed services for the U.S. and allied countries get
57700	62180	careers in cyber security. I also just do random research projects like this that are not
62180	70300	related to any of that when I get bored. So here I am. So what is pseudo for Windows? They, uh,
70300	75020	Microsoft announced that they're going to introduce this utility in Windows 11 in the H2
75020	79320	update which usually drops around September, so in a month or so. It's currently an insider
79320	83860	preview which is how I got access to test all this good stuff. The way it works at a very high
83860	89560	level is it uses UAC, that standard process elevation thing to support the type of command
89560	93580	line features you're probably used to if you use pseudo on Linux. So taking your input, your
93580	98060	output, all that, putting it back into the prompt that you originally ran it in. Uh, that's
98060	101820	both console input and output which are different on Windows than standard in, standard out,
101820	106840	and standard error. It does this via fancy pipes and redirection and all that good stuff. It's
106840	111340	written in Rust. It is now fully open source. At the time they just, at the time I did this
111340	115400	research, they said it was open source but it wasn't published yet. Uh, which meant that I did
115480	119620	a lot more work than I actually had to do but that's alright. That's what, that's what's fun I
119620	125460	guess. Uh, I found two issues with, again, according to MSRC, no security impact. I have to
125460	129420	use those words over and over again. One is a memory corruption issue which is fun cause like
129420	133940	I said it's written in Rust. Uh, and the other one was a search order confusion issue. I found
133940	139540	two issues with security impact. One allowed, uh, cross user code execution which, kind of
139540	143500	sad, you don't really want other users to run code as you if you like your secrets being
143500	149900	yours. And the other one allows you to data tamper the input and output data for sudo. And
149900	155900	again I can't go into too much detail on that one but we'll talk more about it later. Most of
155900	160600	my research was conducted against sudo version 1. Uh, you'll note that both of these bullet
160600	165560	points say sudo version 1 but have different signature dates. I can't help you. They didn't
165560	169860	increment the version number so I just had to use the signature date on the binary to
169860	175060	distinguish the two. Uh, one is from February, one's from March. I don't know if they've
175060	179580	released a more recent update cause I haven't checked in the last three weeks. So they might
179580	187280	have but three weeks ago it was still the version from March. So precursor things to know.
187280	191960	User account control. If you use Windows, which I assume most of you do cause you came to a
191960	195980	talk about sudo for Windows, you've seen a user account control prompt, right? You always
195980	200000	just hit yes cause you don't care what you're doing you just want it to work. Uh, the way it
200000	205000	works is normal processes without elevation run in what's called medium integrity. That's
205000	210500	pretty much everything except for processes or systems that are designed to use low integrity
210500	215280	which quick shorthand is basically just web browsers in your PDF reader because they want
215280	220520	that to have the absolute least privilege they can. Elevated processes, so the thing that
220520	224600	runs once you hit that yes button cause you don't care you just want it to work. Uh, run as
224600	231040	high integrity. Only processes running in high integrity are allowed to modify system
231040	236200	resources which implicitly means that they can get system level permissions which is roughly
236200	240620	equivalent to root on Windows, right? It's considered a defense in depth measure by
240620	246000	Microsoft. They do not consider it a primary control. They do not consider UAC bypasses a
246000	249480	security issue. They won't service them. They don't consider them part of bug bounty.
249480	255820	Importantly for why sudo for Windows needs to exist, you can't spawn a process with UAC and
255820	261160	inherit the standard in standard out standard error or console input and console output into
261160	266220	the privileged process meaning that if you're in a command prompt and you try to run you know
266220	271480	reg query as a privileged process, you can't then pipe that into another command or redirect
271480	276280	it into a text file or something like that. It'll spawn it as a new process that can't put it
276280	284220	back into your same window. Other things to know about uh the ALPC interface. It's an
284220	288680	inter-process communications framework. It is officially undocumented and only used by
288680	293960	Microsoft internal systems. The way it works is the server listens on a port which is just an
293960	299580	object cause everything in Windows is an object. That port is just a string name. Sometimes
299580	304520	it's a string as is the case with sudo. You can see the example there. Uh sometimes it's a
304520	310340	GUID if it's a com object or things like that. The way that security is supposed to be
310340	315420	implemented on ALPC is that the server can query attributes of the client like the process
315420	321880	ID, the uh SID, the principal name and all of that of the caller. And the client is able to
321880	328560	say I only want to connect to an ALPC server if it's also this SID or some other properties
328560	331260	that I don't remember frankly and they're not in the slide so I'm not gonna remember them
331260	336880	right now. Um the other thing to know is that in Rust if you want to use Windows native APIs
336880	341680	like create process or shell execute X which are important if you're trying to run a process
341680	347100	as an elevated user. Um you have to use one or you don't have to but Microsoft released two
347100	351300	crates for it. Windows and Windows sys so those are first party owned by Microsoft. They
351300	357340	both require you to run in unsafe Rust meaning that now we can get memory issues and buffer
357340	361600	overreads and buffer overruns and all that good stuff. Um the only difference between Windows
361600	368000	and Windows sys is the Windows crate does type coercion for you. So if you have a Rust string
368000	372280	and you want to call a Windows API if you use the Windows crate you just give it the Rust
372280	376000	string and magic happens. I don't really know Rust that well so sorry it just magically
376000	380560	happens to me. Uh whereas with Windows sys you have to explicitly cast things into the right
380560	388640	data type to get it to work in Rust. So Microsoft's blog post did actually include a fair
388640	394180	bit of detail uh which was cool to see uh both from a security research perspective and just a
394180	398380	curiosity perspective. It's cool to see them publish information about their tools like this.
398380	403200	Uh there are three modes that Sudo for Windows supports. Those are new window, input closed
403200	408340	and inline. The new window one is basically just the same as if you ran run as and then the
408340	413100	command. So there's not really much novelty there. Uh the input closed and inline modes do
413100	417640	this weird client server thing which you can see at the bottom uh right there. That sort of
417640	421420	high level thing. We'll go into that more in a second. The difference between inline and input
421420	427300	closed is in input closed the elevated process can't see the un-elevated console's standard
427300	432560	end. So if you were to pipe the result of a command into a Sudo execution and your system is
432560	438300	configured to run it in input closed mode, your elevated process won't be able to see it. They
438300	444400	say that those are in order by most secure to least secure so new window being the most
444400	448440	secure and inline being the least secure. Um they don't really go into a lot of details about
448440	456040	that other than that it's it keeps things open for longer. Um again I mentioned earlier it in
456040	460200	the blog post they say it's open source. They link to a GitHub repo. That GitHub repo was
460200	464560	empty when I was doing this research so I just got to look at Rust code in Ghidra which if you
464560	469480	haven't done it I don't recommend it. Um but now it's open source. You can go on GitHub and
469480	473380	look at all their stuff. Um they included that diagram as I mentioned to explain the request
473380	477400	flow. We'll go into that more in a second but you can see that there's a client server thing in
477400	485760	there. So off the rip like this was actually found after the rest of this research because I
485760	490280	was finally able to look at the source code. The new window mode still creates that RPC
490280	496220	server so you're still able to do fun things with the RPC server. Um it doesn't always do
496220	501140	what's on the tin. Sometimes it does actually pull in your standard in, standard out, standard
501140	506360	error in your console input and console out and pipe it into the new process. Um again it's
506360	512040	supposed to be the most secure uh but it does always get the standard in handle unlike the
512040	517300	input disabled one. I don't know of any ways that that's necessarily a security issue but it's
517300	521380	kind of an odd novelty because they describe it as being the most isolated from the
521380	528820	unprivileged process perspective. So I started looking into this because I saw on Hacker News
528820	533640	that veritable Y Combinator uh news aggregator that one of my co-workers at Google actually
533640	536920	which I didn't know at the time made a blog post about Sudo for Windows and published some
536920	543200	research. Um he pulled apart the RPC server some and found that at the time that RPC client
543200	548600	server thing had zero authentication which is obviously very bad. That means you can just tell
548600	553020	the server you would like to run a privileged command and it'll happily do it. Um that was
553020	558800	fixed by the time I was testing it. Note that that's in quotes. Talk more about that in a
558800	564100	minute. So I talked to again it pulled apart that RPC like client server API if you will and
564100	568340	highlighted the methods of interest to call. Specifically that server do elevation API.
568500	573780	That's what actually is called by the client into the server to coordinate execution. Passes
573780	578060	handles that the process binds to and then you can get all your input and output and all that
578060	583080	good stuff. It also passes a bunch of parameters relevant to the command being ran like the
583080	587420	command to run, arguments to the command, the current working directory and optionally the
587420	596260	environment depending on the flags you pass to sudo. Here is a more detailed look at run mode
596260	600980	three in line mode. This is the one I did most of my research with because it is listed as the
600980	606760	most insecure so it's probably the easiest target right? I'm lazy. Um you can see on the far
606760	612100	side there you have the actual unprivileged console where the person runs sudo who am I and
612100	616820	they're trying to run it as that elevated user. The way that works is it first spawns an
616820	621640	elevated process to host that RPC service using normal run as. The user gets a prompt again
621640	626100	they click yes like everyone does because they just want the thing to work. Um the client then
626100	631880	sends an RPC into that privileged process telling it what command it wants to run. The
631880	635400	privileged process binds to the handles that gets passed in there so that all your input
635400	641040	output and standard error stuff just flows naturally. Privileged process that the user
641040	645540	specified gets spawned and then magic happens you can do all your normal command line pipes
645540	652720	and stuff. So summarizing everything we just talked about sort of high level notes. Uh it's
652720	657500	written in Rust it's open source. Uh Rust requires you to enter into unsafe mode so again
657500	662640	memory safety issues can happen. Uh to call Windows native APIs which things like this kind
662640	668200	of have to do. Um and ALPC is what's used to coordinate the actual execution of the user
668200	676380	specified process. So our first issue the memory safety issue in Rust. Um sort of odd right but
676380	682220	as I just mentioned you have to use unsafe APIs. Uh they've removed this functionality before
682220	688080	they published it to GitHub so I can't tell you exactly how it happened but at a high at a from
688080	694360	my analysis what happened was if you gave a path that rewrote from the beginning meaning that
694360	701080	you had a leading like backslash or C colon backslash right? It would write your path to the
701080	706240	start and then when it passed it to an API function it didn't truncate at the end of where your
706240	711380	path was it just read until the end of the buffer to the first null byte. I think that that
711380	718240	happened because they assumed that a path as string would point to a null terminated buffer as
718240	723420	you would kind of expect it to if you're used to C when in fact it just points to a vector of U8s
723420	730780	that may or may not include a null byte at the end. Um here's sort of my mock up of the code uh
730780	734200	you can pull these slides off the Defcon media server if you want to take a better look at it
734200	738620	but this is just sort of demonstrating what I just talked about where if you assume that you
738620	744620	can take the path as a string and then just get a pointer to it and pass it to the Windows API
744620	749540	function you'll end up very sad because it'll just read until the first null byte not
749540	756300	necessarily until the end of your target string meaning you have buffer over read in heap uh for
756820	760480	arbitrary numbers of bytes that you can't necessarily control but because you can control
760480	768060	the path you can control approximately how far into that heap buffer you read. Uh so like I
768060	773460	just said you can read everything up to the first non-null byte you don't control which heap
773460	779920	allocation you're reading and it doesn't let you write memory into arbitrary things that are
779920	784380	outside of your heap boundary because it is rust it's a vector uh so it'll reallocate if you
784380	790420	reach the capacity of the current heap allocation um but still you get to read things from
790420	795660	previous heap allocations which in my testing tended to just be paths but it could be
795660	802360	something like a token or something like that. Um it says at the bottom there why uh it's not
802360	807860	really a security issue uh the main problem being this is only noticeable if you run
807860	814360	pseudo with an unpro or a untrusted input which you shouldn't do anyway so it's not really
814360	819600	security impacting if you run pseudo with arbitrary things someone you don't trust supplied
819600	824360	and then you can read other memory because you shouldn't be doing that in the first place
824360	829700	because you're going to execute someone else's code. This screenshot shows what I was
829700	833980	talking about so you can see on the left there I run pseudo with a leading slash and then a
833980	839300	path and then you can see in process monitor that at the end of the day a create file
839300	844980	operation or trying to read the file um ends up re trying to read a file that's the thing
844980	849520	that I was trying to read and then a bunch of things from presumably a previous heap
849520	853120	allocation because that's the path that's the current working directory and then some
853120	860430	garbage at the end until it reaches the first null byte. So the second issue uh search
860430	864910	order inconsistency so in Windows just like actually I shouldn't say that I don't know if it's
864910	870550	true in Linux but in Windows if you run a command without a path it is supposed to execute
871130	875190	that command in the current working directory if it's present and then search your path.
875570	880810	So if you run pseudoprogram.exe you expect it to run the program.exe in the current working
880810	888310	directory not some other random program.exe. Path resolution didn't work that way the way it
888310	892770	worked is again because of that client server thing it would try to resolve the path in the
892770	896730	context of the privilege process which had a different current working directory meaning
896730	901850	that you could end up running a command you didn't expect to run. Uh says up there it's a
901850	906570	somewhat contrived example but if you had compiled your own binary and named it cmd.exe and
906570	912850	then you tried to run pseudocmd.exe it wouldn't run your command.exe it would run the
912850	917050	system32 command.exe. According to Microsoft it's not a vulnerability I have their exact
917050	925650	response quoted there at the bottom. But they fixed it anyway. Um so they more or less
925650	930710	looked up the in the unprivileged process they looked up the command you gave them and
930710	936810	resolved it and then passed the fully resolved path into the privileged process. Um they
936810	942030	fixed it I'm not going to complain too much but it's kind of odd that you accept input from
942030	945150	people on what issues are fix them and then tell them yeah but we don't think it's a real
945150	953970	issue. And this is a very well drawn I'm an artist if you didn't know uh example of how that
953970	959890	would work from an attacker's perspective so you try to run command.exe you expect it to
959890	965510	run yours it ends up running some other command in the privileged process path which isn't
965510	973930	the one you wanted. So let's talk more about that RPC server again it's ALPC um source
973930	977350	code wasn't available so I had to look in Giger to figure out what all these parameters
977350	983530	meant. Uh I got pretty good results out of it I didn't know what those handles were or how
983530	988350	to deal with them necessarily but luckily I didn't have to you can just bind to input and
988350	993890	output without dealing or without worrying about the handles too much. Um importantly the
993890	998690	unprivileged process ID so the one that you run before you hit that yes prompt as quick as
998690	1004950	humanly possible is what is used to create the socket name so it's predictable as long as you
1004950	1010130	know the process ID that's uh trying to run sudo. And again I mentioned earlier after James
1010130	1015930	Forshaw's blog post they added an authentication check which was checking that the client's
1015930	1021110	process path so that unprivileged process was the same as the server's process path meaning
1021110	1028670	both are running sudo.exe see windows system 32 sudo.exe right? Um over on the right side
1028690	1032590	overview of that that off check on the right right just is the image name of my calling
1032590	1040630	process the same as my image name if it is good to go we'll run your command. Which brings us
1040630	1044910	to our first security issue. Um it turns out that that's not really a good authentication
1044910	1053070	check. Um any user can issue elevation requests to that RPC server meaning that any user of a
1053070	1057750	multi-user windows system to include you know unprivileged users because anyone can call an
1057750	1064690	LPC socket like your web browser um can go ahead and run commands in the context of a user uh
1064690	1069390	when they run sudo. So it's not latent I and a privileged user would have to try to run sudo
1069390	1075690	and then you'd be able to exploit this to run it in the context of that user. Exploitation
1075690	1080770	requires two things so like I mentioned insufficient authentication um the way I did
1080770	1087110	that is I just injected a DLL into a sudo.exe sudo process that I controlled so that I could
1087750	1093250	do whatever I want in the context of a process whose image name is the legitimate sudo.exe um
1093250	1097430	and the other part of this was that predictable uh port name that predictable RPC control
1097430	1103290	port name. Because users can view the process IDs of other users in Windows uh pretty much no
1103290	1106850	matter what there are some types of tokens that can't do that. Uh you can get that
1106850	1112870	information very easily and then you can just call the target sudo privileged sudo process
1112870	1118530	and have it run whatever you command you want and gain execution in that user's context.
1119250	1124310	This was patched in the version in the second version one of sudo the one that was uh code
1124310	1129990	signed on the 4th of March. So again high level attack diagram you see at the top there we
1129990	1133510	have our victim who's just trying to run sudo and get on with their day. We have we have our
1133510	1140090	attacker with again I'm an artist very well drawn horns thank you. Um the attacker starts
1140090	1146710	their code that's just waiting and find trying to find a victim sudo that is running and then as
1146710	1154530	soon as it notices one it spawns its own sudo with a hooked method to connect to the target RPC
1154530	1160410	server instead of one that it spawned uh to run whatever command the attacker wants. From the
1160410	1165470	victim's perspective what this looks like is they ran sudo they as fast as humanly possible
1165470	1169530	because again they're just trying to get the job done hit the yes button on the UAC prompt and
1169530	1174270	then nothing happens from their perspective but in reality the attacker was able to run whatever
1174270	1185160	command they wanted. Uh demo I think? Do I have that wrong? Hopefully it plays. Alright well
1185160	1194460	that was surprising. So here I'm just showing there's nothing up my sleeve um uh the left
1194460	1202160	prompt is gonna be our victim user so who am I? I'm MTU um it can run sudo just fine. The right
1202160	1207380	prompt is now my unprivileged user or my non-administrative user not MTU. Right now I'm
1207380	1213600	gonna show that uh sudo works and then that the base prompt is not running elevated. And then on
1213600	1221600	the right on the right we're running that implant code that's just gonna spawn some stuff uh to
1221600	1226860	try to target that victim sudo process. We are racing because if we don't beat the legitimate
1226860	1233360	process um the RPC socket closes and we can't run our command. So we go slowly insane trying to
1233360	1237620	win the race. I did test this in a debugger first so I was pretty confident it was supposed to
1237620	1243920	work but man recording this video and just sitting there doing this for 2 minutes was not fun. Um
1244560	1250020	at the end there you can see that it worked on the right side our unprivileged process again we
1250020	1255880	were able to inject into that victim server process and run command.exe as this as the
1255880	1260180	unprivileged user. We run whoami and we see that we're now running as that other user who is
1260180	1268090	just trying to run something with sudo. Well I already played the video but we can play it
1268090	1278790	again if you want. Oh nothing showing up there? Neat. Let's try it this way. Can you see this?
1278790	1300690	This video now? So again uh again left prompt is the uh privileged user who's just trying to
1300690	1305030	run sudo uh the right prompt that's about to spawn is the unprivileged user not MTU some
1305030	1315910	evil attacker man. Um user runs command everything works. Let's see if I can skip this bit a bit. Um
1315910	1320090	user keeps running command they keep working because you'll notice on the other side the
1320090	1324350	attacker process is failing it's not winning that race. Uh like I mentioned I confirmed this
1324350	1329370	in a debugger but still very frustrating watching it fail over and over and over again. Um but
1329370	1334070	eventually it does work and we can see on that right side now we just got a command prompt back
1334070	1338830	from the attacker's perspective. We run whoami and we see that we are running as a user other
1338830	1355600	than ourselves which is not good I think is what it's called in the business. Alright. Uh work
1355600	1366740	with me here. Nope. Yeah it's perfect. Um so I did find out after I tested this again after they
1366740	1371800	made the source code available that they made that race window really short. So I assumed that the
1371800	1378560	way it worked was the victim process ran its command successfully and then went ahead and uh
1378560	1383200	then went ahead and closed the socket after it was done. In fact as soon as you called that
1383200	1388680	elevation request API it locked all future calls of it. Which would explain why I had to run the
1388680	1394640	command over and over again going slowly and sane until it worked. But I don't know not not
1394640	1400980	really security control but good for them for locking out other users and thinking about it. So
1400980	1405620	the second vulnerability I mentioned it's still under embargo unfortunately. Um I reported it
1405620	1411560	13th of June while the rest of this research was done April May time frame. Um sort of
1411560	1416320	interesting story for you since I can't talk too much about the details of this one. The reason I
1416320	1423080	thought of this was I was on a run trying to avoid working on the slides and I realized that there
1423080	1428340	was some other issues with how they do that client server thing. So I was able to prove it out
1428340	1433920	and get data tampering and information disclosure from again the process or the perspective of a
1433920	1442140	non-privileged user on the privileged user's stuff. So public issues again it is a GitHub repo
1442140	1446340	there are public issues uh that I think are sort of notable to talk about when we talk about
1446340	1450760	Sudo for Windows. The first one um the elevation prompt is confusing. So there's a screenshot
1450760	1455500	of it on the right you saw it earlier in the video. You don't know what hitting yes will do
1455500	1459760	cause it's just telling you it's a Sudo invocation right? It doesn't tell you oh Sudo's actually
1459760	1464700	gonna spawn this other process over here maybe you don't wanna do that it just says hi I'm
1464700	1470620	Microsoft I'm a legitimate binary would you like me to run? Um not great from a security's
1470620	1474140	perspective right? Admittedly again most of us probably just click yes as fast as humanly
1474140	1479980	possible anyway or type in our credentials if we have that version of UAC enabled but um I
1479980	1485480	believe that they committed to trying to figure out how to make it so it was more obvious what
1485480	1489900	the actual command that's gonna run is instead of just saying yeah it's it says it's legitimate
1489900	1494540	I'm just gonna hit yes and hope everything's okay. And the second issue uh which is critical
1494540	1501620	to me because I like my computers to insult me is um Sudo for Linux or Unix if you will has a
1501620	1506660	mode to have it insult you if you don't have legitimate access to run a command. Uh I want
1506660	1515120	that in Windows cause I like my computers to be mean to me when I'm silly. So summary of
1515120	1519260	everything we just talked about. Sudo for Windows is coming soon. Again it is scheduled to be in
1519260	1525160	mainline Windows 11 and I think Windows server don't quote me on that one uh end of
1525160	1530820	September-ish in the in the H2 update. Uh it's open source again we we love to see that it
1530820	1534720	makes it so people like me or people like anyone in this audience can go look at the source
1534720	1539060	code and pull it apart and understand not only how it works but maybe find some more
1539060	1544040	security issues in it so we're not shipping products that are enabling bad things to happen
1544040	1548100	on Windows. Or if you're on the other side of it using it to make bad things happen on
1548100	1554120	Windows I don't know I don't judge. Um it is meant to be a drop in replacement for the way
1554120	1557800	Sudo works on Linux so it lets you actually have standard in, standard out, standard air,
1557800	1561420	piped and redirected and all that stuff within your command prompt or your PowerShell
1561420	1567680	prompt. Um and it does all of that using user account control to elevate processes and
1567680	1573540	inter-process uh communication to actually coordinate that across the not a trust boundary
1573540	1579140	because that's not what Microsoft calls it of UAC. Uh sort of the big take away for me and
1579140	1584520	it's informing some more stuff I'm looking into is you cannot call a Windows native API
1584520	1592040	without going into unsafe rust. If you want to do that or for anything that uses a Windows
1592040	1596740	API that means there is now the potential for you to get memory corruption act vulnerabilities
1596740	1602900	in something written in rust which is counter to what everyone tells you about rust so be on
1602900	1605840	the lookout for that if you're a bug hunter that if you see something calling a Windows
1605840	1611900	native API from a rust program somewhere in that code it is unsafe. Poke at that boundary. And
1611900	1617720	then I'll show some references and if anyone has any questions you can step up to that mic in
1617720	1622500	the middle and I'll be happy to answer them. I don't know how much time I have left but I'll
1622500	1636360	try to answer as many questions as I can. Thank you. Cool. Thanks everyone.
