start	end	text
0	4120	Without further ado, this is Elvis Cayado. He's going to be
4120	9260	presenting on some really cool research that he manipulated.
10080	12400	Yeah, sure. All right. Awesome. Thank you so much for joining
12400	21180	us. And here we go. Test. Is that good? All right. Thank you
21180	23900	everyone and welcome for coming. This is my talk called green
23900	28880	waves and ham. All right. Let's get started. So this device up
28880	32020	here that you see is called the green wave G1100. It was
32020	35740	distributed by Verizon Fios and Frontier. They're an ISP up in
35740	38920	the northeast. And we have Verizon for the file service.
38920	42120	It was not available in my area, but this is what they gave you.
42940	45880	So if we look a little there, we got our FCC ID. So what do we
45880	50720	do with our FCC ID? We go online and we find the internal photos
50720	54360	and then we find the processor and we look it up. There's no
54360	56960	data sheet for that, unfortunately, but we see the
56960	59980	shield is on cover. We see two memory modules. And if you see
59980	62520	something like over here, you may be going, hey, what's going
62520	66040	on over here? Well, you have every reason right to be,
66040	69700	because this over here is JTAG. Awesome. So I just grabbed my, I
69700	72460	think it was like JTAGulator or my Arduino. It's 3-3 logic, so
72460	75580	it doesn't really matter. Got the pin outs. So this in the
75580	78000	middle, open up the device, this thing right here. In the middle
78000	81900	we have four pins. And what do you think it is? You are right.
81900	85200	So we have ground, receive, transmit, 3-3. Unfortunately,
85200	88540	when we turn on the device, standard in is blocked. So all
88540	90620	we get is standard out. So receive is, you know, we can't
90620	94700	type anything. Crap. We cannot do anything whatsoever. We just
94700	96700	see standard out. We just see print logs, whatever. We're not
96700	100460	seeing it. We can't do anything. That's boring. So after some
100460	102660	thinking, because I want to keep everything software based. I
102660	104500	don't want to touch hardware. Like, yeah, there's a NAND
104500	107380	flash. We can remove it. That's the last thing I want to do.
107380	110660	Like, I'd rather go the software route because it's ripping crap
110660	114620	out and I mess up. I got to buy a new one. Forget all that. So I
114620	118300	just solder some, so it takes like a hot glue gun. You know,
118300	121680	find an area on the board that has no copper exposed. Put a
121680	124740	little bit of hot glue on there. Take some header pins. Just
124740	127380	stick it on there. Wait for it to dry. And then I take some
127380	130200	wires and I just, you know, solder it on. And it's not the
130200	132900	prettiest thing in the world. But, you know, and then I just
132900	136620	attach some wires. Put it on my FTDI base breakout board over
137400	140600	here. Turn on OpenOCD with my configuration on my FTDI board.
140600	143620	And we see automatically, boom, we do have a JTAG interface. We
143620	146680	have the ID. We see the manufacturer ID is ARM base.
146680	151740	Woohoo. So then we open up our own target configuration. So we
151740	155000	set the reset config. We have test reset. We have system reset.
155000	158240	It's a push-pull situation. We have a new, like, tab with the
158240	162640	ID at the very end of it. And then we create a cortex A target
162640	165960	that's little Indian. And then after that, we run it again with
165960	169120	our two configurations, the board and the target. And look,
169120	172410	oh, also we have six break points, four watch points. And,
172410	175490	you know, I can tell that into OpenOCD, like always, and give a
175490	178430	command or attach GDB to it and start analyzing memory once I
178430	182550	halt the processor. So before we get on to the next slide, so
182550	185250	the first thing I started doing once I had JTAG was I don't have
185250	187970	a data sheet for this chip whatsoever. So I'm dumping
187970	190850	memory addresses. If something is not, you know, unaccessible,
190850	193410	I just write that out. So I'm dumping, dumping, dumping,
193410	196370	halting the boot-up process at different stages. I'm trying to
196370	200150	find the kernel boot arguments. So after about an hour or two, I
200150	202390	think about two or three hours, it was kind of a while, I
202390	204750	finally found it, and I set a watch point to the very last
204750	206870	character of that kernel argument, or kernel boot
206870	210590	argument. So that when it's done writing for a watch point, I can
210590	213870	set a break point, well, it'll, you know, break, and I can
213870	217590	overwrite it. So instead of init calling slash init, I can set,
217590	219910	no, instead of calling this upon initialization, because I don't
219910	223990	have U-boot access, like, yeah, I could ground clock on the, on
223990	226790	the NAND or so, or, you know, whatever, and make it fail, and
226790	229210	maybe I can, you know, do a second retry and get into it,
229210	231850	but, again, I don't want to touch hardware. So, um, I'm able
231850	235390	to overwrite the kernel boot parameters, set a net to bin SH,
235390	240990	alright, awesome, and then we continue execution, and, awesome,
240990	243110	we get a root shell. We actually, can actually do
243110	245110	something, and you actually probably saw me typing up some
245110	249050	commands to load everything up. So great. So this gives us
249050	252410	access to rip the firmware off and get debug capabilities,
252410	255510	right? So the very first thing I do is I go through all the RCS
255510	258290	initialization scripts, I get everything running, and I look
258290	261170	for all the running daemons. I don't care if it's WAN-based,
261170	264230	LAN-based, everything's open scope in my eyes. So I'm looking
264230	268850	at anything that's listed on all interfaces 0 to 0, or, uh,
268850	271750	inner, you know, an internal interface. Uh, IP tables can
271750	274990	maybe come into play later, but we'll get into that later. So
274990	277510	very first thing, I'm looking for low-hanging fruit, and
277510	280850	someone please scrim it out. UDP 1900 is?
281010	282190	Low-hanging fruit!
282190	286370	Yes! Awesome! It is known as SSDP. It is a piece of crap,
286370	288470	and everyone talks about it. But anyways, we have three
288470	291490	binaries here, we have three different SSDB servers, WPS
291490	295570	monitor. Frontier 4 is about a 32 megabyte C++ file. Have fun
295570	298650	with that. It's kind of fun to look at. Fun. Uh, we have mini
298650	301190	UPNPD, which probably is vulnerable to the read out of
301190	304290	bounds volume that I posted earlier this year. So anyways,
304290	308550	today we're going to be talking about WPS monitor. So before I
308550	311090	even start ripping things out, I need to know my environment.
311330	313610	Um, because I need to know like, you know, do I need an info
313610	315970	leak? Uh, do we have an executable stack? Do we have an
315970	317970	executable heap? Well, what the hell am I looking at, right? So
317970	321890	the very first things I do is I look at all, you know, there's a
321890	325830	libupnp library. You can see like, oh, a libupnp. It's not
325830	328630	the Intel one, so remove all like assumptions out of your
328630	331990	head. Uh, and also we have ASLR on the imported libraries.
331990	334770	Surprise. We look at a stack in the heap. We have depth.
334770	337230	Awesome. Uh, we also look at the heap over and over again, you
337230	340870	know, and we see that ASLR does impact the heap base headers and
340870	343610	the stack. Cool. Uh, the only thing that we see here is that
343610	346790	this WPS monitor, the main binary itself is not ASLRed
346790	349610	whatsoever, so we do have a static binary. We have a gadget.
349610	352890	The problem is, we have null bytes in this 32-bit address, so
352890	355210	if we have a string-based overflow or anything like that,
355210	358230	we can't use this because of limitations of a string, you
358230	362010	know. So, after that, this device does have USB devices, so
362010	365510	I plugged in the FAT32 device in, and then just DD, uh, you
365510	367390	know, look at mount, see where the file system will be mounted
367390	371410	from, DD down to the USB drive, and then after that, 1, 2, 3,
372070	377150	we use binwalk, like always, and we extract the file system. So
377150	379230	now we're going to get more into the nitty-gritty, happier
379230	383350	stuff. Vuln hunting. And so, like, you know, everyone has
383350	385890	their own way of like, you know, going about vuln hunting, like
385890	389010	some people have like, you know, super dope scripts, and some
389010	391170	people get lucky, they're like, oh, man, I just looked at a
391170	392910	string, and that sucks, right? It's like, oh, I looked at a
392910	395810	string, found a vuln, and that's exactly what I do first. I'm
395810	398710	looking for low-hanging fruit, least path-resistance, so I'm
398710	401070	looking for %s, right, because what are the destinations for a
401070	404230	format string? We have a buffer, or some sort of file descriptor
404230	407910	in Linux, right? We have syslog, or we print the standard out, or
407910	410210	we're going to, you know, save it something to a buffer and do
410210	414330	whatever, right? So I see this very first response, HP11, okay,
414330	418150	blah, blah, blah. I see %s here, I see %s there, %s here, over
418150	422970	here is a %s, and over there is a %s as well, ha. And that's
422970	425370	very interesting to me, because I'm like, alright, what is this
425370	429270	response, right? Like, what function is using this? So I see
429270	431870	this immediately, looked at xrefs, and I'm like, oh, that's
431870	435330	nice, sprintf. But, you know, remember, sprintf, assert copy,
435330	437870	and all those, like, vulnerable C functions can be used in a
437870	440590	non-vulnerable way, right? So just because it's sprintf doesn't
440590	443670	mean it's vulnerable. So we look at where's r0, the destination
443670	447410	buffer coming from. So we look at, it's from r5 going to r7,
447410	449610	going to, you know, then adding some more to r7 and putting it
449610	452610	into r0. So this right here seems to me that we're accessing
452610	455450	some sort of member in a structure, right, or, you know,
455450	458510	an object, but it's still a struct, it's C. So we're
458510	460950	accessing something. This could be, like, a pointer that, you
460950	463990	know, maybe Malik is saved, you know, Malik is being saved to or
463990	465910	whatever. Like, you know, we get an address from Malik, we save
465910	468550	it there. Maybe it's calculating the length beforehand and, you
468550	470710	know, maybe it's not vulnerable, like I said. Who knows? Or maybe
470710	474190	this is just a character buffer inside this structure that has a
474190	477450	fixed size. Who knows? So we need to do more research. So
477450	482190	next thing I do is I'm looking at the UPnP specifications,
482190	486130	going, what is this message for? And we see that we have something
486130	490810	called a SID, which is a unique identifier, and we have this
490810	494090	timeout second dash, and this is actual subscription time.
494330	496330	Something in our, we probably have second dash and some
496330	499010	integer, right? So I'm like, well, what's causing this
499010	501830	response? And we see this. It's called a subscribe. Subscribe
501830	504150	publisher path, and I'll show you that, what's that,
504150	506370	afterwards. We have something called a callback. Host and user
506370	508890	agent are optional, so that's why they're not bold. Callback
508890	512310	is mandatory. It is wrapped around angle brackets or less
512310	515710	than, greater than, whatever. We have NT set to UPnP event, which
515710	517970	is static, has to be that. And then we have timeout second
517970	521750	dash, and then a request is duration. Second dash, again,
521750	524790	probably an integer, second dash 20, second dash 900, whatever.
526110	528970	So what is this for? Like, what part is this? What is the
528970	531790	publisher path? So you probably have done, like, I send an M
531790	535630	search request on multicast, and then I get an XML, and then I
535630	538850	get all this crap. But everyone talks about the control URL, the
538850	541050	SOAP actions, and that's not what we're talking about today.
541050	543370	We're talking about this, the event URL, which is called the
543370	545590	Gina stat. I forgot what it stands for off the top of my
545590	549630	head, but just trust me, it's called Gina. So the very first
549630	553070	things we do is we launch up some notepad editor, Vim,
553070	555690	whatever, but this is not Vim, I think it's Zed or something
555690	560510	like that. So we use, you know, requests. We're going to send a
560510	564990	request that, come on, we do second dash and then a string
564990	567370	instead of, like, an integer. Because I just want to see
567370	569990	firsthand if this percent S that I'm seeing in the response is
569990	572770	even worth looking at. This is, you know, maybe pass it to a toy
572770	575310	first and, you know, I get zero back and I get second zero.
575310	577330	Like, that's not exploitable or anything worth looking at. So I
577330	581410	need to dig deeper. So we just send it and awesome, I sent a
581410	585730	string, I get a string back. That's awesome. So okay, this
585730	589170	seems kind of interesting now. So that percent S is what we
589170	594070	control. So okay, so next things we can do is we have two things
594070	598930	we can do. We can be super C, super, like, awesome CSI,
598930	601170	double-hacking keyboard, lead dudes that were, you know,
601170	603590	like, all the clubbers and crap. Or, fuck it, we can just
603590	607390	black box it, right? I mean, like, yeah, we can chase down
607390	610270	the structure and, like, you know, we can find C functions
610270	612870	and find where arguments, you know, is being passed to. We
612870	615510	can be like, oh, we know that, you know, like, a start copy is
615750	617850	a character buffer, character pointer, so this is a character
617850	621530	pointer or whatever. Or maybe if we look up certain strings
621530	626690	online, like on git duck duck go, Google, whatever, maybe we
626690	630790	find the structure that we're clobbering, potentially, and we
630790	634690	find everything. But this is supposed to be confidential. So
634690	637850	I didn't have all this at the time, so screw it, we'll just
637850	643890	black box it. Kobe. So, next thing. So I set up a for loop.
643890	646910	That same exact code, just in a for loop. I'm incrementing now
646910	650330	by one byte at a time, that second dash. And I have GDB
650330	652830	attached. It's going to keep going and going and going and
652830	654750	going and going and going. Any kind of reset sets to me, just
654750	657710	try again, keep going. Right, just keep going. And I get a
657950	660410	segmentation fault. I'm like, oh my god, there's probably static
660410	663930	sizes, this is awesome. Oh my god, I got to call my dad. But
663930	667490	hold on, let's not call my dad. Because this is just loading
667490	670570	compare. We're not writing anything, we're just loading and
670570	674650	comparing. That's not anything useful. And we go in IDA and we
674650	678830	look around and yeah, all right, it's comparing to R1, which I
678830	681150	don't know the value of, it's an unknown. But you know, we have
681150	683390	this compare, it's looking at zero, it's going to branch out
683390	688050	and return. So, all right, so I'm kind of messing around at
688050	690350	this point because I'm thinking we have this UPnP server, what
690350	692510	kind of states can we put this in? What kind of requests can I
692510	694770	send to this thing? We have an HP stack, we have a SOAP stack,
694770	699890	SSP stack, we have this Gina stack. So, I start thinking, I'm
699890	702690	like, well what kind of other states can I do this in? And I
702690	707490	find this. And I'm not going to read this wallet text to you.
707510	711490	Basically what this says is that once you subscribe, you get a
711490	715470	SID, your unique identifier ID, right? So from there, let's say
715470	718310	you subscribe for 20 seconds. And then you change your mind.
718310	721310	No, no, no, no, I meant to subscribe for like 100 seconds.
721530	724210	Well, you send a second subscription with your SID and
724210	728150	with a new timeout value. I was like, oh, maybe we can like hit
728150	731110	some new code with this type of thing. So, we subscribe first,
731110	733430	save the SID, and then we cause the overflow and see what
733430	736590	happens, right? So, I do the thing again. And we get a
736590	740630	different site fault. I'm like, oh, better be something good,
740630	744870	right? So, I start looking, I'm like, oh, we see this load, you
744870	749310	know, offset 24 to R3. We do a compare, a branch on zero. So,
749310	751530	if it's null, we don't call it. You're not going to call null.
751590	755450	And then it jumps to it with the exchange. So, we can jump modes
755450	758210	like thumb mode, R mode, whatever, right? And I'm looking
758210	760530	at this, I'm like, what's R3? I'm like, oh, that's the value I
760530	765050	control. That's my name. That's awesome. So, okay. So, we have,
765050	767610	so I got lucky, right? I got super lucky. But I don't care.
767610	771870	That's my luck. So, going on, I kind of have a way to obtain PC
771870	776210	control. We're one pointer away, right? We're almost there.
776690	779550	Still can't use WPS monitor as a gadget because we're still
779550	781990	bounded by the limitations of a string. Can't have a null byte
781990	785450	because that's the terminator. Uh, ASLR and import libraries
785450	788850	that don't have an infleek. So, whatever, right? So, now to the
788850	792850	exploit development of this. So, we're thinking, we're thinking,
792850	796830	I have one pointer away, I have ASLR, I have depth on the heap
796830	801110	and stack, one pointer away. Holy crap, you know what, this
801110	803710	reminds me of actually, so back in the day, who's ever done
803710	808290	internet explorer exploitation? IE8, 7, 4, 1, I don't care.
808290	812930	Anyone? Yes, awesome, cool. So, that's exactly what it reminds
812930	817550	me of. I'm like, okay, new tactic. Screw the infleek. Let's
817550	821390	find a way to spray the heap, let's figure out to do some, you
821390	825270	know, some David Blaine magic stuff and then, you know, maybe
825270	828770	we can trigger the overflow and get code exec, right? And
828770	838640	speaking of which, oh, whoops. I need to start this. So, you're
838640	842120	about to witness the world's slowest exploit. My exploit
842120	847520	takes about 20, 28 minutes and 30 seconds to run. So, we're
847520	850640	going to start it. Just want to make sure it's running before I
850640	861770	go back to my slides. All right. All right. One second, please.
863990	870030	This is slow. All right. There we go. All right, cool. So,
870030	874110	let's go back. All right. So, it says spray the heap, do some
874110	877370	magic, trigger overflow, get code exec. So, we look at the
877370	880670	heap. So, I need information now. What is the base address of
880670	883170	this heap like loaded at every single time? So, I need a target
883170	888090	address to maybe grow this heap torch, right? So, look at it
888090	893250	once, maybe twice, look at it again, and again, and again, and
893250	899330	again, and again, and again, and again, and again. That's okay.
899330	901710	You know, we can do that later, right? We can do more off
901710	908250	screen. That's boring. So, also I need to know how much memory do
908250	910970	I have? Like Internet Explorer, everyone had like, you know,
910970	914330	maybe back in the day like 512 megs. Yeah, my age is showing,
914330	916890	right? Or, you know, at least a gig. So, spraying the heap is
916890	920010	not really that much, you know, not much, you don't have to worry
920010	921530	about it and running out of memory and stuff like that. But
921530	925290	we have 117 megabytes free. Or, you know, I don't want to be,
925290	928590	you know, taking up everything. So, let's just call it 100. 100
928590	932470	megs. So, theoretically, if the heap always loads at zero, just
932470	936030	think about that. The maximum size I can grow the heap to is
937450	940750	06060606 or whatever, right? So, awesome. I can grow the heap to
940890	944650	a very large size potentially if I find a printer to allow me to.
944650	947590	So, after doing all that stuff and putting everything to like an
947590	950330	array, into an array, into a spreadsheet, and seeing like the
950330	953270	top and bottom and see, like, what's, what's going on here?
953270	956130	Like, what's the, you know, like, what's the highest address
956130	958810	the heap actually loads onto and stuff like that? So, actually
958810	962010	you saw that it loads under 0303 all the time. We see like an
962010	965770	0210, but it always loads under 03, 03, 03. So, I'm like, alright,
965770	969790	cool. So, I start looking at the description functionality. Like,
969790	972230	how does this work? I need to find primitives. I need to fill
972230	975590	the heap. I need to do memory leak. Not info leak, memory leak.
975590	979610	I need to fill up the heap. So, I start looking at this. So, I
979610	983390	start looking at Stirling and it goes to a Calic. And I find out
983390	986730	that that pointer there is the starting, it's the URL portion
986730	990490	of the callback. So, after the IP colon port slash and then the
990490	993050	end of it, that's, that's where we're at. So, that's where that
993050	997050	pointer's to. That's slash and then like ABCD, right? The, the
997050	1000430	closing bracket is null terminated at this point. So,
1000430	1003790	we're just slash. And then after that, we add some sort of size
1003790	1005890	to it. So, it's going to be the size of some structure, right?
1005890	1008890	So, we have some structure. And where the last element is some
1008890	1011630	character buffer array. And then we call Calic. If you're not
1011630	1015030	sure what Calic does, it takes the values of R1 and R0,
1015030	1017770	multiplies them, checks for overflow condition. This is a
1017770	1021670	very high level. And then it calls Malik, gets a pointer
1021670	1024090	back, memsets it, and returns it back to you. So, everything's
1024090	1026170	going to be initialized to zero. There's some other crap that
1026170	1028910	goes on in there, but it's not relevant to this. So, we go into
1028910	1033590	GDB. We set some break points. And, you know, we get the length
1033590	1035350	and we get the return address. Because I need to learn how to,
1035350	1037530	you know, I need to start spraying this stuff. So, I set
1037530	1040190	up a for loop to subscribe over and over and over and over and
1040190	1045830	over again. And crap. All right. I'm getting the same pointer
1045830	1048870	over and over again. So, in my head, I'm like, all right, so,
1048870	1052250	it's being freed, alecked again. Freed, alecked again. Freed,
1052250	1056510	alecked again. What, what, like, what the hell is going on? So,
1056510	1060350	step back. If I were to develop this, if I were, you know, on
1060350	1062950	some team where I'm stressed out to get something delivered by
1062950	1066270	the end of the week, I'm like, well, having one block for
1066270	1069470	subscriptions for multiple devices makes no sense. Right?
1069470	1071210	If I'm just using the same block, we're freeing one block
1071210	1073030	with two devices, that's almost like you used out the free
1073030	1078330	situation or only I support one device at a time. So, I go,
1078330	1081130	well, let's change something in my subscription. We can change
1081130	1084570	IP address maybe, change the port number, change the URL. So,
1084570	1088210	for simplicity, I just do, like, a, a four I and range zero two
1088210	1091570	whatever, and use the I to add it to my port range. So, we get
1091670	1094530	a new, you know, port number upon every single iteration and
1094530	1100330	ba-da-bing, ba-da-boom, I can now spray blocks of 4K. Awesome.
1100330	1103990	I have a way to fill the heap. So, in theory, this is what I'm
1103990	1107550	doing. Subscribe, subscribe, subscribe, subscribe, subscribe,
1107550	1110010	subscribe, subscribe, subscribe, subscribe, subscribe, subscribe,
1110010	1112190	subscribe, subscribe, subscribe, subscribe, subscribe. So, we're
1112190	1114270	just filling up the heap with a bunch of subscriptions with
1114270	1120010	Different port numbers. Okay, cool, that's cool. You can fill the heap. We can spray the heap.
1120170	1124390	But we still need to do some dope David Blaine magic, all right? Then we go to street magic,
1124390	1129190	you know, some crazy shit. So I start reading the manual some more. We go back to the architect,
1129190	1134150	you know, the specifications. And I see this request now. Unsubscribe with the publisher path
1134150	1138470	with your SID. I'm like, all right, let's go back to the code. And I find this function called
1138470	1143910	delete subscriber. I wonder what it does. And I see this little wrapper of free here,
1143910	1147530	which literally just takes the pointer and passes the free. So I set a break point there.
1147530	1151610	I go, well, what is this pointer, right? We have run time capabilities. I don't feel like
1151610	1155530	spending all the time reversing all the things. Don't limit yourself to just one way. Use the
1155530	1161370	easiest ways. So I'm like, oh, so if I subscribe and I reverse the array of all the SIDs that I
1161370	1166390	saved and I send them to unsubscribe, they're freed. These are my blocks. I'm using the,
1166390	1170870	oh, awesome. So I have an ability to spray the heap and I have the ability to free blocks at
1170870	1175710	will and I can make holes in the heap if I want to or whatever, right? So back to monkeying
1175710	1183130	around. Because this is the heap spray portion, but I'm like, okay, I'm still bounded by the
1183130	1188750	limitations of a string. I can't do anything yet. I can fill up the heap. That's fun. But, you
1188750	1193630	know, I can't use WPS monitor as a gadget yet. So I start talking to a colleague who works on
1193630	1197190	different products but also has experiences with heap stuff. I'm just bouncing ideas back and
1197190	1201090	forth with my colleague. It's kind of like rubber ducking. So I send him my IDB. I'm like,
1201090	1205470	hey, man, I'm looking at this. You know, this is my limitations. This is what I can do so far.
1205550	1210390	You know, you can look at all the references to malloc, calloc. If you're super hardcore,
1210390	1215730	xmalloc. If you turn null, kill the application. Super hardcore. But we start going back
1215730	1219930	forth and he asks me a question. He goes, hey, this function here about base64 decoding uses
1219930	1225570	malloc. What is that all about? Like a UPnP, base64. I'm like, oh, shit. Awesome. So we go
1225570	1229770	back to SOAP, the thing I did not want to talk about whatsoever. And I start looking for an
1229770	1234670	action with one argument. Because I don't want to deal with multiple arguments and it just gets
1234670	1239850	kind of messy. And I find this. This delete AP settings. Sure. Whatever. What kind of type is
1239850	1244230	this new AP settings argument? Go all the way down to the bottom of XML. We see it's a base64
1244230	1249690	type. So we can send a SOAP request to this action and inside the XML, inside the text, we
1249690	1256030	just, you know, base64 encoded string. I can base64 encode nulls. Okay. So what I do next is
1256030	1260450	like, alright. So when I send this, when I send the SOAP action, I set a breakpoint, I look at
1260450	1265450	the heap block. And it's actually the decoded data that I sent to it. It's not the base64
1265450	1271470	string. Awesome. I can now write nulls and I can probably use WPS as some sort of gadget if I can
1271470	1277610	figure out the way to spray my fake object into the heap. So, I try this out. So we do it. We
1278090	1283850	unsubscribe. We call the SOAP action. We unsubscribe. We call the SOAP action. Unsubscribe.
1283850	1287950	And then I look at this. This is early development of my structure. That's why you see like 02, 02,
1287950	1293450	03, 03. Just lining everything up. The very first one is my first gadget. So whatever. But I'm
1293450	1297210	trying to set things up. So I'm doing everything by hand at first and I'll, you know, I'll make it
1297210	1302550	nice and pretty later. So, okay. We can spray the heap now. We're kind of almost there doing some
1302550	1307250	magic. But wait. Roadblock. Alright. I do my spray. I'm doing my technique and I'm like,
1307250	1312530	alright, let's look at this address and it's not there anymore. Shit. Alright. Well, what's
1312530	1318390	going on? So, to think about it in layman's terms, like super simplistic, you can't build a
1318390	1323090	house without a roof. Right? That seems silly. So my technique right now, I'm like, you know, I
1323090	1329150	got all these descriptions. I unsubscribe. Do a SOAP action. I unsubscribe. Do a SOAP action.
1329150	1334150	Unsubscribe. SOAP action. You know, blah, blah, blah, blah. And we're going down the line and,
1334150	1338930	you know, and, and then the rest. Right? But then, the Linux kernel's like, usually an
1338930	1342450	application, you got all this free space in malloc, or you know, in your heap, you don't need
1342450	1347890	this anymore. So it eats it all away and revokes it from me and gives it to another
1347890	1351610	application or anything else that needs the memory. Right? So, that's what's going on. So I'm
1351610	1357030	like thinking, I'm like, well, instead of freeing everything, what if I leave the last
1357030	1361650	allocation there? Because in the seconds, there's actually an option to do infinite, where it
1361650	1366010	will never, ever run out of time for your description. It's forever until the, no, until it
1366010	1372110	like reboots or something. But either way, so now I fill up the heap, I pop the last allocation
1372110	1378530	off of my array, reverse it, now I do a unsubscribe on the second to last, and I go from
1378530	1389330	there. Right? So, this is awesome. So this is working fine until, come on, until this happens.
1389330	1396270	So my, my way to do the base 64 thing is writing to the same block over and over again. I'm no
1396270	1400730	longer putting something on top of the free list, occupying it, it's getting freed again, free
1400730	1404270	something else, put it on top. It's not, it's something else is racing to it. Something else is
1404270	1409130	causing some issues. So now I've got to figure out what the hell is being freed. So I'm going to
1409130	1414370	set just a simple break point on free. If it's null, just keep going, I don't care about null
1414370	1419930	being passed or freed. Um, so we just keep going, and we're just going to wait. And actually it
1419930	1423650	does some stuff every 60 seconds, cause there's also other imported libraries, and you know, we
1423650	1428230	gotta see if they're doing something, or the main binary's doing something, cause if there's a
1428230	1432690	race condition, this makes the exploit that we're trying to do much less reliable, and it's
1432690	1436750	not really worth going for anymore. So I look at it, and I'm like, alright, let me send an
1436750	1441570	msearch request. Because if you use Google Chrome, for example, uh, when you open up your
1441570	1446750	browser, go to YouTube, your browser sends an msearch request on multicast, uh, because it's
1446750	1451710	looking for something called a dial server, which is a layer of UPnP, developed by Netflix, you
1451710	1456070	can find the GitHub, find the code, uh, you can also look at the Chromium, uh, code branch and
1456070	1461090	find the, uh, the dial code. But anyways, we send an msearch request, we see that there's
1461090	1465270	pointers being freed, okay? We find the sizes by looking at the heap header manual and stuff
1465270	1471190	like that. Um, so every 60 seconds, this device sends out a notify request on multicast. Sends
1471190	1475930	it out and says to everyone, hey, you know, I'm here, here's my XML, go and chat, that's cool,
1475930	1480350	if not, you know, no big deal. Um, and then last but not least, if someone sends it in, like a
1480350	1485410	get request, like a device is, uh, getting the XML in order to send us a request or a
1485410	1488990	subscription, this is what it looks like. So I'm going over all these different instances as
1488990	1494190	to, like, what can get in there, what kind of requests, and the sizes, so that I, I set up my
1494310	1498830	heap a little bit differently. So that now I have two arenas. So I have one arena where I have
1498830	1502630	spaces for these objects to fit into perfectly. And they can jump in there all they want,
1502630	1506230	because I'm making holes. It'll never get, like, condensed or whatever. It may get trimmed,
1506230	1510370	doesn't matter. Then I have my other arena where I have that last allocation being set and I do
1510370	1515690	the whole thing. So now we shift gears. So now what I'm doing is a free, replace, free,
1515690	1521650	replace, free, replace, blah, blah, blah. And then we do an allocation back up. So we
1521650	1526550	resubscribe and we come back down. And also what we're doing is between every single
1526550	1531370	iteration is that we have a UDP socket listening on multicast. We select it upon every single
1531370	1535390	iteration, there's something to read, we slurp it up, and then we also maybe do some more
1535390	1539990	subscriptions and replacing just to unfubar anything at the top of the free list, because we
1539990	1546130	don't want anything else to race there. So, next, we can spray the heap. We can do some magic
1546130	1549870	now. We can now use WPS monitor. We can write nulls to the heap and stuff like that, I guess,
1549870	1554450	basics for decoding. That's awesome. Uh, but we don't have an exploit chain yet. So I'm
1554450	1559690	thinking, I'm like, alright, let's cause a crash and we look at what do we control, right? Um, I
1559690	1563790	don't use, like, sometimes I use, uh, like, Pwn2Bug and stuff like that, but if you use an
1563790	1567970	open OCD and you have Pwn2Bug running, you have a lot of issues that may occur, so I just
1567970	1572030	haven't commented on my GDB init. But anyways, the only register that we have control of
1572030	1576690	really is R4. R4 points to our overflow string. And yeah, the first pointer is going to point
1576690	1580110	to something in the heap, blah, blah, blah, but let's just assume the very first one is just
1580110	1588130	41, 41, 41, 41. So I have a pointer that points to my data. That's all I have. So I start
1588130	1591570	looking online, I'm like, alright, let's look, think back about Internet Explorer days. Uh,
1591570	1595630	you know, what did we do? Oh, we did a stack pivot, right? Uh, we have, like, one shot, so we
1595630	1599530	do a stack pivot. So if this heap was executable, we have a bunch of, like, NOPs and then
1599530	1604130	shellcode, NOPs, shellcode, we jump to NOPs. Wee! Uh, if we have depth, we have a bunch of
1604130	1608290	returns. So, you know, we shift the stack to the, the heap and then we do return, return,
1608290	1611910	return, then we have our prop gadget and call virtual protect and we execute shellcode,
1611910	1616810	ba-da-bing, ba-da-boom. So I start looking online and I see this. So this was from 2012, a
1616810	1620950	Rockstown talk about exploiting stuff on R and blah, blah, blah, and it has this load
1620950	1624810	multiple decrement before instruction. And what, what does it do really? And it's saying
1624810	1628710	that, oh, you know, if you have a source register, you can populate the other registers and
1628710	1633010	you can, you know, do a stack pivot because it writes to SP. I'm like, oh, man, god. So I, I
1633010	1637610	open up Redere and I look for this load, uh, deduct multiple, uh, load multiple deduct before
1637610	1642650	with R4 and I see some instructions, so I plug it in, very first thing, and illegal
1642650	1649730	instruction. Well, what the hell? Like, what? Why? So we look at the ARM manual and we see
1649730	1654450	this restriction on the second line, the register destination list cannot contain SP. The
1654450	1659290	destination list that I had before has SP, the second to last one. This is now an illegal
1659290	1663570	instruction. I can't use this technique on this device. So, alright, back to the drawing
1663570	1669730	board. So what I do next is I develop a regex for IDA. I'm looking for load where the, the
1669730	1674290	last, uh, last register, you know, second operand or whatever of that opcode is, uh, R4
1674290	1678850	being dereffed. That's all, that's what I want. So I set up a regex to do that and I find a
1678850	1682690	bunch of them, I go through them by hand and I find this gadget here. And it says like
1682690	1688490	dereff R4 and R3 and we add all these offsets and we get R2 and we have R1 and R0. I'm
1688490	1693930	spraying 4K blocks here, hex 1000 is 4K. So we're just going to jump into another block that
1693930	1698890	I, I'm in control of with my data. So this right here gives me the primitive of calling a
1698890	1704370	function with two arguments. Okay, cool. But the problem is though, once, once this
1704370	1709110	function, like once what I call returns, it's going to use the stack now and it's going to pop
1709110	1714130	PC and I no longer have control. So I only have a one shot situation. So I'm thinking, I'm
1714130	1719710	like, what can I do? I'm like, alright, so let's look at functions that write, like that write
1719710	1723870	to memory that are not bounded by uh character limitations. So I started looking at mem
1723870	1727430	copies. This thing has tons of them. So, you know, I'll put on my music or whatever and I
1727430	1735470	start grinding through this and uh, I find this mem copy here and you don't have to read all
1735470	1739770	this. I know it's probably hard in the back and I apologize. I'll sum it up. So this right
1739770	1744770	here, if you look at the second to last instruction, R0, the destination, is a stack based
1744770	1751230	buffer. Even though the stack frame is kind of large at like 2K, you know, hex 800, uh, we
1751230	1756610	still have a destination buffer that's a stack. And R0 and R1 are in our control now because
1756610	1763290	that was the last gadget that gave us control. And R1's in R4, R0's in R5, we look in, R4 is N,
1763290	1768950	R5 is the source. So instead of bringing the stack pointer to the heap, like fuck it, let's
1768950	1773090	just bring the heap to the stack. Just clobber the shit out of the stack. I control N. I can
1773090	1777250	clobber the shit out of the stack. So that's what I do. And we look at the bottom of this thing
1777250	1782030	so we adjust the stack frame so we have to be careful now. This is a large adjustment, 2K. So
1782030	1786170	we're not going to jump back and do stuff. We're now just incrementing the stack. We have to be
1786170	1790410	careful not to run out of stack space and cause, uh, you know, like an interrupt to happen or a
1790410	1794790	signal to happen and kill the program. So now we have control of R4 to R7 because now we
1794790	1801630	brought the heap to the stack. So now, next gadget. R7 is going to contain a pointer to the
1801630	1809530	IAT table entry, uh, inside WPS marks where it's not ASLR'd, uh, of str2 unsigned long. But with
1809530	1815130	the pointer of minus 4. And this next slide you'll see why. So then after that we pop from
1815130	1821910	the stack R3 to R7 PC. Next thing. We deref R0 now, which is now going to take the IAT table
1822510	1828250	plus 4 and it's going to, it's going to deref that pointer from the IAT table and now we have a
1828250	1833930	libc function, uh, pointer. Now we're inside libc at str2 unsigned long. We don't need to leak
1833930	1841350	it anymore. Pop from the stack. Next one. We add R3 because look, we have R3 to R7. R3, uh, it's
1841350	1845490	going to be an offset now. We're going to add it, well R3 and R0 are going to be added together
1845490	1849690	and we're going to save into R0. So now it takes str2 unsigned long, I take an offset and I add
1849690	1855610	it and I get to, since system wasn't working and I didn't want to debug it, P open. So since
1855610	1860630	the system, since the, uh, WPS monitor didn't use system, it didn't import P open or anything
1860630	1864550	else I can use to execute shell commands, uh, since back in the day, like, you know, uh, with
1864550	1870790	inter explorer exploitation, uh, if you had some way to get into kernel 32 DLL, you just add or
1870790	1875210	minus an offset to get to virtual protect in order to make the, you know, allocation that you
1875210	1878870	want executable or whatever the hell you wanted to do with the permissions. So then from there,
1878870	1884170	gadget six, this looks really large, but we can pick another allocation that's like maybe a
1884170	1888750	megabyte away. We don't care. We're going to write to the heap now. We have a pointer to P
1888750	1892510	open and all these gadgets I found by hand. If I try to use some wrapper thing and try to
1892510	1895850	automate it, I would not have found these gadgets. Wrapper and everything. So I'm going to say,
1895850	1901110	hey man, there's a mem copy with R0 and R1 or R1 and R2 and R0 being stacked. It's not going to
1901110	1904470	tell me that. So anyways, this right here, I'm going to write to the heap. I'm going to write
1904470	1910810	the P open pointer that I just calculated into the heap now. Keep going. We're almost kind of
1910810	1916070	towards the end of the stack limitations here. So now I invoke gadget one again, which is our
1916070	1921350	last gadget, gadget seven. So this one, remember, I can call something with two arguments. So R2
1921350	1925810	is going to be P open. R0 is going to be a string. R1 is going to be R because you have to
1925810	1931470	provide something for P open. And then, okay, cool. So let's put it all together. So we
1931470	1936250	spray the heap. We save all the subscription IDs. We don't free the last subscription ID,
1936250	1941550	that's our roof. We free and replace the blocks with unsubscribe and we replace everything with
1941550	1946150	the soap action with base 64 encoded fake structure, our ROP chain, and ending with the
1946150	1951050	command. Everything is aligned to 256, or actually, yeah, so everything is 256 by the line,
1951050	1956350	whatever. So we free five, reoccupy five, free them again, go to the next five. If anything
1956350	1960590	comes in multicast, fix up the heap if needed by doing resubscriptions and freeze again.
1961370	1968130	Trigger volume, maybe we win. So we sue everything and we see this, right? So let's check
1968130	1981930	out this guy. Why is it at 11%? No! It is at 11%. Why is it 11%? All right. So I guess I'm
1981930	1993070	not doing the exploit live anymore. That sucks. Oh, that sucks. Oh, no. Why? It's on. All
1993070	1997850	right. I'm sorry. I guess I'm not doing this live. It is reliable. I can demo it later if you
1997850	2004770	guys want to see it. But it's all right. We're stuck at 11%. What we were doing, though,
2007110	2011790	was the free and replace of everything that we were doing. We create two arenas and we're
2011790	2017110	going all the way down. It should have been around 60% by now or so. So that's all right.
2017930	2024610	Man, let's see down here. But anyways, if this was working properly and didn't want to just
2025250	2030290	foobar out of nowhere, we would be in the context of doing all that stuff. But the funny part
2030290	2036570	about this as well, just to look up, is that there's actually one process. Let's see here.
2036570	2042770	One process ran by nobody. It's another UPnP server. So whoever actually made the process,
2042770	2048250	you know, the process run under nobody, like, that guy deserves a high five. So anyways, let's
2048250	2054870	go back to everything. Man, I really wanted to show that shell. Oh, well, it's actually still
2054870	2060730	going. It's just going really slow. Anyways, so we do have a shell. And I wanted to show you
2060730	2065110	guys some bonus stuff as well. So besides the shell and all that stuff, so before, remember I
2065110	2069090	was saying that, you know, I was looking at daemons that were running on a particular, you
2069090	2074250	know, all interfaces or just a LAN. And I found one 5916 that was being filtered by IP
2074250	2080770	tables. So I started thinking, I'm like, huh, what if we use that genus stack to pivot, like a
2080770	2087350	server-side request forgery, right? So we set the callback address to 120 localhost 5916 with
2087350	2092530	this URL. And so we attach strace to that daemon to see if anything's coming in. We send the
2092530	2097810	request, and yes, we do get that. So if you are trying to hit something that's maybe token
2097810	2102510	based, so it's a TCP-based connection, and maybe it's like, oh, it's doing like structure,
2102510	2106190	they start to be getting up something or stir, like a stir stir, like some sort of substring
2106190	2109030	that's token based, you can use this to maybe hit that part of the code, maybe change
2109030	2114470	configuration or something like that. So it's a way to pivot. So last but not least, I also
2114470	2120730	wanted to give a fuzzing demo, but I'm not sure if it's, if it's going to cooperate with me.
2120730	2125510	But I mean, after all this, so finding the vuln and all that stuff taught me something
2125510	2130950	valuable. So I was doing this by hand, and I was like, you know what? I've been finding a lot of
2130950	2134770	the same kind of programming issues with this protocol and stuff like that. I have a
2134770	2138770	background in network engineering, I also have a background in QA, so I was like, let me
2138770	2143310	start making a fuzzer. And I encourage everyone else to do this as well, because what do we
2143310	2147430	have? We just have HP, we have XML. If you could just make something to just send out an
2147430	2153010	attempt search request, get the, you know, get the, the XML file back and just parse that,
2153010	2157270	make an XML parser, go through everything, save everything, make your own fuzzer. You'll save
2157270	2161030	so much time. So instead of a few days, like it took me by hand to find this vuln, it would
2161030	2167070	have taken me 30 seconds. So actually, let's see. Now it's going. It's going now. Alright,
2167070	2173370	so maybe if we have time towards the end, I'll, I'll check up on it and see if we're, if we're
2173370	2181630	all good. So anyways, man, everything going wrong is. That's awesome. So anyways, so if an
2181630	2187430	ISP asks you, and this is going to be super cheesy, but whatever, I'm going to do it. If an
2187430	2192630	ISP asks you, could you, would you install this router in your house? You must say, no, I do
2192630	2196110	not, would not install this in my house. I do not want it here or there. I do not want it
2196110	2199670	anywhere. I wouldn't want it for free. I wouldn't want it if it could download up to 10 GB.
2199670	2206250	But anyways, that's enough of that stuff. This is who I am. So I go by Black Owl Online.
2206730	2212150	Someone had the real name Black Owl, so I changed the L21020. Cool. Elite sauce. What up?
2212390	2217670	I'm a zero-day researcher at Exodus Intelligence. I do embedded devices, both SOHO, I do
2217670	2222750	enterprise network solutions, firewalls, virtual appliances, whatever. I don't care. If I can
2222750	2228350	get it, I'm going to audit it. Smart devices or anything else that catches my eye. We're also
2228350	2231530	hiring at Exodus Intelligence. We're looking for another zero-day researcher if you're
2231530	2235630	interested for getting paid for finding no-days. I get a bonus on top of that for selling your
2235630	2240250	phones to us. Like, you know, hit me up. But that's about it. So again, that's who I am.
2240250	2244050	Thank you for coming to my talk labeled Green Waves in Ham. Take care.
