start	end	text
0	1680	How's everybody doing?
2820	3840	Yay, come on.
3840	4360	How's everybody doing?
4360	5000	This is DefCon.
5900	6940	Way better.
6940	7520	Okay.
7520	7800	Okay.
7800	10360	So, today we have a video presentation in track two.
10360	12920	It's going to be remote code execution by MIDI messaging.
13500	14380	Enjoy.
17240	19100	Hello, DefCon 33.
19340	20940	My name is Anna Antonenko.
20940	23660	And unfortunately, I couldn't be here with you today.
23660	24920	Just some visa issues.
24920	28540	So, I'm going to be presenting my talk via video.
28540	31880	My talk is titled Remote Code Execution via MIDI Messages.
31880	38140	It's about exploiting a vulnerability, rather a backdoor that I found in a line of Yamaha products.
39960	43300	About some stuff about me, you can find me online on my website.
43300	45940	I use the same nickname practically everywhere.
45960	47900	Here's my email on the slide here.
48940	51900	I am a forward developer at Flipper Devices.
51900	53300	I write code in C.
53300	59160	But my employer does not necessarily reflect my opinions.
59160	62860	All research was done in my own time.
63020	68040	I really like Erlang and Elixir, their languages for the Beam virtual machine.
68580	73880	I'm working on an operating system written in Erlang in my spare time.
73880	79160	I really like electronics, both analog and digital, but digital is my specialty.
79260	81060	And I like music.
81060	85240	I like writing music, I like playing music, and listening to music, of course.
86400	92020	I prefer to think of myself as a decent forward engineer, but not a great reverse engineer.
92020	100640	So hopefully, those of you who are like me can learn something from this talk, from this perspective.
102240	108080	First, I'm going to show you a little demo about what we're going to be talking today.
108700	111780	But this demo needs a bit of introduction.
112220	114660	So there's this protocol called MIDI.
114660	118780	It emerged in the 80s, and it's a really simple protocol.
118780	123080	It describes music generation parameters, basically.
123080	132320	So one device can tell another to play a note, or release a note, or change some effect parameter, or something like that.
132360	136320	And the other device will generate audio based on that data.
138080	142920	But apparently, even a protocol as simple as that can have backdoors.
144440	146890	So this is a demo.
148380	158790	Here on the bottom, we have a Python script that is sending MIDI commands to a synthesizer, which is on the top, and it is playing by Apple.
158790	170090	And just by sending it uniquely, carefully crafted MIDI messages, we're going to wait for the demo to finish, and we'll continue.
184260	186960	So what is this talk going to be about?
186960	189240	It's going to be about hardware reverse engineering.
189240	191480	We're going to be dealing with an undocumented chip.
191480	195340	We're going to be accessing its debug interfaces.
195340	197360	We're going to be reversing some schematics.
198120	200400	We're going to be doing firmware reverse engineering.
200400	207680	We're going to find out how to look for the stuff that we need and make sense of disassembled and decompiled code.
207680	215640	And of course, we're going to find a backdoor in the firmware and exploit it to see this cool thing.
215640	224220	And of course, it's about a story that begins with me having this synthesizer, this dirty instrument.
225120	240080	Well, it got dirty over the years of me using it, so I decided it's probably best to tear it apart, tear it down and clean it, and find out what it makes it tick while we're at it.
240200	244200	So this is the main board of the synthesizer.
244200	255720	It's got a few large chips, and just by googling the part numbers or by guessing simply, these are the functions that these chips perform.
255720	259680	So these two on the bottom are flash chips.
259820	261800	This is a USB host controller.
261800	267480	You can plug in a flash drive into this USB host and that chip handles that.
267480	269600	This is the RAM.
270320	272240	And this is the LCD controller.
272240	276960	There's a 16 megabytes flash for what I'm presuming is the firmware.
276960	282520	And if I remember correctly, a 2 megabyte flash for user data.
282900	284520	They are separate.
285440	289320	And this is the largest chip.
289320	290840	This is probably the CPU.
292720	298320	That main chip is labeled Yamaha SW-L01U.
298320	304540	And of course, this synthesizer is made by Yamaha, so I guess this is a proprietary chip.
304540	307860	Also, there is absolutely no information about it online.
307860	316920	If you google that part number, the only thing that comes up is an AliExpress listing for it, if you want to buy one.
316920	318760	But absolutely no documentation.
318760	323960	So it's gonna be quite hard to approach it without documentation.
323960	333580	Also, I stumbled upon an article that suggested that it might be based on a Super H architecture from Hitachi.
333580	335720	And this was my first time hearing about it.
335720	338340	So of course, I don't know the architecture.
338340	339800	I have no documentation.
340340	343700	I'm not gonna even try to access it, you know.
343700	349900	So I just put it back together, finished my cleaning, and call it a day.
349900	354860	Until two years later, I found a service manual for a similar synthesizer.
354860	357620	The E443, not the E433.
358640	360460	They're quite similar.
360460	362820	They have the same external appearance.
362820	369440	They have the same board layout, essentially the same chips, including the CPU.
369860	374400	But the later model has an audio input, while mine doesn't.
374400	379940	And also it has an ADC analog-to-digital converter, while mine doesn't.
381040	386360	Also, component numbering is different, but not too big of an issue.
387000	397400	The two most important things that this service manual has are full schematics and full board layouts for all the boards.
397400	398120	That's nice.
398120	398880	That's the first thing.
398880	402220	And the second thing is pinouts of all of the chips.
402260	408400	And for most of the chips, I was able to google their part numbers and find out their pinouts.
408940	413800	And usually they are standardized, like in the case of flash chips.
413840	417480	But it also had a full pinout of the CPU.
417480	426580	So here on the slide, you can see that page with the pinout of the CPU, that complete 176-pin chip.
426580	435620	These pieces of information are very helpful to us, as a lot can be deduced about the chip just from its pinout and the schematic that it's in.
435860	439260	So how can we approach this chip?
439560	449200	Well, when reversing, I think that it is helpful to look at it, to think that you're reversing from the perspective of a forward engineer.
449300	458000	As forward engineers, we typically want to have some kind of debugging for our program and some text output for logs.
458000	462900	And in the hardware world, there are common interfaces for those.
462900	468580	For debugging, that would be JTAG or SWG for ARM chips, and so on.
468960	471140	There are lots of those interfaces, actually.
471140	474180	But JTAG is by far the most common.
474440	479220	And for simple text output for logs, for example, it would be UART.
479780	485520	I decided to start with UART because I figured that accessing the logs would be easier.
485780	489660	But spoiler alert, no, it wasn't.
490040	496760	In total, there are five UART-related pins on this chip per the pinout.
497200	503120	Two transmit pins, two receive pins, and one optional clock pin.
503120	509620	So, of those five pins, only the transmit and receive pins are of interest to us.
509620	516820	And of those, are only the transmit pins of interest to us, because we just want to access the logs.
516820	525660	And of those four pins, three pins are just used as general-purpose IOs, not for UART.
525660	531080	And the remaining fourth pin is a transmit pin, and it was completely silent.
531080	537080	No matter how times I rebooted the device, it stayed completely silent, no matter what I did to it.
539280	544800	But we shouldn't give up so easily, because I found two other very interesting pins.
544800	548540	One was named PROTN, and one was named TESTN.
548540	561620	And they stood for prototype mode and test mode, so I figured I should try looking at the UART in all four combinations of those two pins, and no success.
562280	565040	It still remained silent in all four modes.
566100	568740	So, let's move on to debugging then.
569420	574380	Like I said, JTAG is the most common debugging interface, and there it is on our chip.
575760	578960	Those five pins make up the JTAG interface.
578960	585860	And one thing about JTAG is that it is very abstract, but although it is very common, it is also very abstract.
586960	597480	You can connect to this JTAG interface, but unless you have a precise description, the internals of the chip in a special language, you will not be able to do anything with it.
597480	609200	Of course, there are such descriptions for popular CPU architectures, but unless you know definitively what architecture it is based on, you cannot access it.
609520	612560	And there is a tiny, tiny, tiny risk.
612560	616700	I don't want to scare you, even though I scared myself.
616760	623900	There's a tiny, tiny chance that if you use the wrong file, you may irreversibly damage the device.
623900	628860	But it is only applies to very, very rare cases.
629100	631920	So, don't listen to me, okay?
633400	644660	The thing about JTAG is that, like I said, it's very abstract, and it says that there might be a 32-bit register called an ID code.
645280	653180	The specification does not say that it has to exist, and doesn't say that if it does exist, where you can find it.
653180	655520	But if it does exist, it must be 32-bit.
655520	658320	That's the only thing that the specification says.
659040	665140	Fortunately for us, there are conventions on how to find that register, and software will do that for you.
665140	667580	We'll look at that in a minute.
667860	669700	So, let's talk tools.
669700	671520	You need basically two tools.
671520	679700	One, you need a hardware debug probe that is an adapter between your computer and the JTAG interface on your device.
679700	681760	That's called also a JTAG cable.
681760	682900	There are a lot of them.
682900	685620	You can see them listed on the slide if you're interested.
685900	689780	And you need one specific software tool called OpenOSD.
689780	692620	It is basically a driver for your JTAG adapter.
692620	699460	It is an adapter between the JTAG adapter and GDB, or your favorite debugger of choice.
699540	713140	So, I just connected a Chinese knockoff J-Link adapter to my precious board and launched OpenOSD because it reports the ID code by default if it is able to find it.
713280	715860	So, here's the configuration for OpenOSD.
716300	718360	Here's the logs from the OpenOSD.
718360	720540	I highlighted the important parts in red.
720540	725820	And one, it says that auto-probing might not work because of the stuff that I mentioned earlier.
725820	733960	And second, that it was able, it was successful in finding a device with an ID code of 3F0F0F0F.
733960	737400	And that ID code is suspiciously pretty.
737400	738360	It is very pretty.
738360	741340	I triple-checked, quadruple-checked my wiring.
741340	747040	I quadruple-checked my config and power supplies and everything.
747040	749680	And the ID code was the same.
749680	752800	So, I figured that must be it.
752800	764640	So, I googled that ID code and it belonged to a lot of devices from different manufacturers, including Atmo, Analog Devices, and STMicroelectronics.
764640	772220	And the common thing between all of those devices was that they were all based on an ARM7 core.
772580	777240	And a footnote, ARM7 is not the same thing as ARMv7.
778320	782020	If I recall correctly, ARM7 is ARMv5.
782020	782700	I'm not sure.
782700	783940	Don't quote me on that.
784420	789800	But let's try telling OpenOCD that we're dealing with an ARM7 device.
790180	791120	So, I did.
791380	794620	These two red lines in the config are new ones.
794800	800640	And OpenOCD didn't give us any errors and told us that it is listening for GDB connections.
800640	803540	So, let's try connecting with GDB.
804380	812440	And from my point of view, this is a success because of three things.
812440	819580	First, my board was connected to a lab bench power supply, which was reporting the current draw to me.
819580	831200	And when I stopped program execution in GDB by pressing control C, the current draw dropped from 114 to 98 milliamps.
831920	837780	And vice versa, when I continued the execution by the command C, it rose again to 114.
837780	839140	That's the first thing.
839140	843020	The second thing is that the interrupt vectors all made sense.
843160	846760	If you don't know what those are, we're going to talk about that in a minute.
847800	854280	And, well, they are ARM instructions and they are jumps, which I would expect them to be.
854320	857160	And the third thing is that the addresses made sense.
857160	866840	When I randomly stopped execution, when the synth was just running normally, the addresses were contained to a neighboring...
866840	868900	they were neighbors, basically.
870100	877040	Those three things indicated to me that we successfully gained debug access on the chip.
877120	878740	It was that easy.
880000	889920	Unfortunately, it isn't usually that easy because... well, in our case, it was because a synthesizer, I imagine, is not a high security device.
889920	893500	But if you're dealing with something like that, it's not going to be that easy.
893500	901800	You're going to be using much more advanced hardware exploits to first unlock the debug interface and then access it.
901800	906340	But provided we have done that, we can now extract the firmware.
906400	909800	So for that, we need to look at the reset vectors.
909800	912080	I'm sorry, at the interrupt vectors.
912740	920100	Like I promised, in almost all modern computer architectures, there's a thing called an interrupt.
920100	926580	And it is an extraordinary event that must interrupt the program immediately.
927180	940220	It may be an external hardware request, an external chip requiring immediate attention of the code, or a software fault, or a hardware fault, or something like that.
940220	944480	A division by zero is an exception, which is an interrupt, for example.
945280	951000	And whenever an interrupt happens, the CPU executes the interrupt vector.
951260	965100	And in ARM7, the interrupt vector table is located at address zero, basically consists of a list of ARM instructions that the CPU executes whenever a specific interrupt fires.
965100	976080	And in embedded development, unlike, you know, big computer development, desktop computer OS development, this vector table is usually read-only.
976080	979240	So it is usually placed in the flash memory.
979780	987620	So if the vector table starts at address zero, it only made sense to me that a flash must also start at address zero.
987620	992380	And I know from the markings on the flash chip that it is 16 megabytes in size.
992380	997820	So I decided to dump 16 megabytes starting from address zero into a file.
998220	1002420	Immediately, I thought that the result was good.
1003680	1009060	Well, when reversing, it is helpful to look at the strings in the file that you're reversing.
1009080	1016760	Any decent reverse engineering tool will search for the human readable strings in the file that you've given it.
1017520	1025420	And they are very helpful because they are immediately recognizable and understandable, unlike machine code to us humans.
1025800	1037100	So the particular string that told me that I was on the right track was SWL01U internal, which is a very good sign.
1037100	1045000	But a bad sign was that all of those strings repeated every 64 kilobytes with the same offset.
1045000	1051980	So every string was repeated 256 times, evenly spaced throughout the image that I've dumped.
1053040	1063820	And this hints to me that I've captured some memory, 64 kilobytes in size, that is located at address zero.
1063820	1074060	And because of the string internal, I guessed that it might be the internal read-only memory inside of the chip.
1074780	1083700	And if we look at the reset vector, which is an interrupt vector for a reset, i.e.
1083700	1097180	when the CPU first powers up or is rebooted, that vector jumps to address 02000000, which I figured must be the flash this time actually for real.
1098040	1104520	So I dumped 16 megabytes starting from there, and the data there made even more sense.
1104680	1116740	I saw lots of strings that I recognized just from using the instrument, like voice names, UI messages, and et cetera.
1117140	1133300	And when I had played the binary fur image back in Audacity, I heard at specific points a piano and strings and a guitar, which are samples that the synthesizer uses, I guess, which was very cool.
1133300	1135780	It definitely meant that I was on the right track.
1135960	1139100	So let's play Minesweeper.
1139700	1143240	This is relevant to the topic of my talk, by the way.
1143240	1148340	I think that reverse engineering is very similar to Minesweeper.
1149260	1153940	When you play Minesweeper, you start with an empty field.
1153940	1156340	You don't know the states of any of the cells.
1157200	1165600	And first you click a random cell that by the rules of the game must not have a mine in it.
1165640	1171580	And as you do that, you automatically discover the states of neighboring cells.
1171720	1176400	And of course, you can deduce which state, which cells must have a mine.
1176400	1179540	You can flag them, not to accidentally click them.
1179540	1185400	And you repeat this until you've discovered everything there is to discover on the board.
1185720	1189620	And I think that reverse engineering is very similar.
1189620	1194460	You start without knowing what any of the functions or any instructions do.
1194800	1201460	You have an entry point or multiple entry points that you can understand the meaning of as they are.
1201460	1206740	So for example, a reset vector or the human readable strings.
1206800	1209300	Those are very useful entry points.
1209300	1220880	And when you look at the functions that use these strings, you learn something about them.
1220880	1228720	And once you learn something about a function, you know more about the functions that call it and more functions that are called by it.
1228720	1232900	And this knowledge propagates through the entire binary image.
1232980	1243140	But this process is unfortunately quite boring, and I won't present the entirety of it, the many sleepless nights that I've spent discovering all this.
1243140	1254280	I will, however, present you one particular subsystem in the forever, and that is relevant to this exploit, the shell.
1256800	1270300	And when looking at a string section in Ghidra, which is my RE tool of choice, I started out with Cutter, but I switched to Ghidra eventually, and I like it.
1270800	1277340	There are a lot of strings that hint to me that they might be some kind of list of commands for a shell.
1277340	1286380	For example, help?info, ver, perf, on, perf, off, perfdisp, memory reads, memory writes, maybe.
1286420	1288440	They look like GDB commands.
1288440	1291480	G, D, S, M, M, B, M, W, M, L.
1292740	1298000	This is syntax similar to GDB syntax, so maybe they are, maybe they're not.
1298820	1301860	And this is how all of this data links together.
1301860	1312140	There's a command table, which consists of a list of pairs of a command name and a pointer to a function that handles the command.
1313800	1321220	The handler function for the commands help and question mark is the same, and it uses the command table.
1321560	1330140	And that command table is also used by a separate function, an input handler, which is somehow getting its input from the outside world.
1330180	1336300	And all those handler functions print stuff using the same set of functions.
1336300	1339580	So there's the main one, print, which just prints a string.
1339700	1352640	There are also functions that print predefined strings, for example, print prompt prints a greater than character together with a space, or print okay, which just prints okay.
1352700	1364080	And I'm not sure yet how the input handler gets its data from the outside or how the print function gets get its data to the outside, but we'll figure that out.
1364940	1371440	In the meantime, I want to show the input handler because it is very funny.
1371440	1375960	It is essentially a state machine with three states 0, 1, and 2.
1376040	1380640	When it is in state 0, it asks for a password.
1381260	1392260	If we type the string login, if it is in state 1, it expects to see that password and transitions us to state 2 if it is correct, otherwise back to state 0.
1392260	1394580	And in state 2, it executes our command.
1394580	1411260	So we know that in order to run any commands with the shell, we first need to type in the string login, followed by the password, hashtag 000, which is hard-coded in the code, which I thought was funny.
1411260	1419820	So let's list out potential candidates for the interfaces that the shell might be running on top of.
1419820	1421660	First off, UART.
1421660	1434640	We've looked at UART before, and both receive pins were used up, and one of the transmit pins was used up, and the remaining transmit pin was completely silent.
1435640	1438540	So definitely not Harvard UART.
1438820	1439940	Implemented in the chip.
1439940	1441660	It could be software UART.
1442520	1448260	But in any case, UART is ready to transmit bytes as is.
1448480	1451100	They do not require great manipulation.
1451340	1459120	So if I look in that print function, I expect to see just plain data copying or something like that.
1459180	1464020	Or maybe a loop waiting for a bit in a register to clear, something like that.
1465200	1482620	And this could be JTAG, the ARM7 specification that says that there is something called the DCC, debug communications channel, which is a bidirectional channel that lets a program running on the chip and a debugger on the computer to exchange arbitrary data.
1482940	1486080	And that DCC uses special instructions.
1486080	1491560	So if I look in that print function and it uses those special instructions, then it's DCC.
1491560	1501440	And it could be USB, but if we print out the descriptor for the USB interface, we only see MIDI.
1501720	1508480	We don't see a serial port, a virtual serial port, or virtual networking, or anything like that, just MIDI.
1508480	1510740	So it's unlikely to be USB.
1511100	1512980	And it's unlikely to be UART.
1512980	1518980	Probably use JTAG, but we have to look in that shell print function to find out.
1518980	1522680	And that print function does a lot of stuff.
1522680	1531520	So if we feed that function the string hello world, of course, it is represented as ASCII, those hex bytes.
1531600	1535460	What it's doing is it's taking eight byte chunks.
1535680	1538380	I'm sorry, I highlighted seven bytes.
1538380	1540460	Eight byte chunks of the input string.
1540460	1549420	It is taking the upper and lower half of each byte in that chunk, and it is placing that into its separate byte on the output.
1549420	1553700	So this 48 is translated into 0408.
1553980	1557060	That is done for every byte in the chunk.
1557060	1565280	And then a fixed eight byte header is appended, and a fixed one byte footer is appended.
1566940	1572840	So string hello world is transmitted as these two blocks.
1573560	1590760	And immediately, if we look at that last block, that second block, immediately the first and last bytes of that block rang a bell, because these look to me like MIDI system exclusive message markers.
1591160	1598380	The MIDI specification says that a system exclusive message starts with an F0 and ends with an F7.
1598440	1610540	And it is used, it can be used by manufacturers to define a system exclusive message, so a message that is exclusive to a particular manufacturer.
1610540	1618320	In order to identify that manufacturer, an ID is assigned to them, either one byte or three bytes.
1618640	1624100	And if so, that 43 there must be the manufacturer ID according to the specification.
1624300	1630760	And in fact, if we look at what ID that corresponds to, it is Yamaha.
1631140	1635480	And my synthesizer is made by Yamaha, so that makes sense.
1635480	1652380	So I'm guessing those six remaining bytes in the, those six remaining bytes in the fixed eight byte header are some kind of Yamaha specific shell signature that says that the rest of the data in the packets is shell data.
1652380	1660820	And one more thing about why it is breaking up the bytes into two bytes.
1660880	1670580	It is because MIDI does not permit data to be transmitted if it has the highest bit set to one.
1670580	1677720	Because any byte that is sent over MIDI with the highest bit sent to one is a status byte.
1677720	1686200	So for example, F0 and F7 are status bytes, the rest of them are data bytes, and they are not allowed to have the highest bit set to zero.
1686200	1694380	So they figured they might want at some point in the future to transmit maybe UTF-8 over the shell.
1694380	1704640	So they must future-proof by breaking up the bytes into four bits so that the highest bit is always guaranteed to be zero.
1705820	1711440	We know the format of outgoing messages, but we don't yet know the format of incoming messages.
1711440	1723840	But I decided to make a little Python script that sends data to the synthesizer in the same format that expects them to arrive, just to see if that works.
1723840	1725720	And well, it did.
1725720	1728640	Here's the shell.
1728640	1731500	Here's that Python script that is accessing a shell.
1731500	1732780	We say login.
1732780	1735640	It is asking us for a password, which we type in.
1735640	1736200	It says login.
1736200	1737120	Okay.
1737120	1738320	We rank help.
1738320	1743320	And ladies and gentlemen, we got it.
1743320	1744900	We got the shell.
1746360	1753940	And like I mentioned, a couple of commands look to me like they were memory write commands.
1753940	1755880	So we can exploit that.
1756100	1764880	If I execute this ML command with an address in hexadecimal and a data of word 32-bit word in hexadecimal.
1764880	1769960	And then with my debugger, I look at that memory location.
1769960	1774200	I see the value that I want written there.
1774200	1777120	And that address is in RAM.
1777120	1778680	So it is rewritable.
1778680	1780820	And that is very good.
1780880	1788320	That means that we can override the memory of this synthesizer via just many messages.
1788320	1803820	We do not have to have a JTAG connected to it, which means that we can write a malicious payload for this synthesizer in ARM assembly that is asking the firmware to write a string on the display.
1803820	1811700	We can assemble it into binary data, but then transform this binary data into write commands for the shell.
1811700	1822220	We can then transform those write commands into system-exclusive messages that the synthesizer expects, write them into a MIDI file, and just play back that MIDI file.
1822220	1825220	And we see the string hello world on display.
1825280	1847160	Of course, one part I forgot to mention is that that last one, that last memory write command is a overwrite of the return address on the stack, which is binary exploitation 101, except we don't have to find any buffer overflow vulnerability or anything like that.
1847160	1850980	The memory write commands are like, they are right there.
1851240	1872260	One thing we could also do is make a Python script that takes in an innocent MIDI file with music and a list of scary stuff to print on the display, and it spits out a scary MIDI file that plays scary music and displays scary stuff on the display.
1872260	1874960	And it looks like follows.
1903710	1908890	So, how can we exploit all this to play Bad Apple on the display?
1909470	1913750	How can we use a textual display to display graphics?
1913810	1920510	Well, turns out we can't really, because like I said, this display controller is only designed to display text.
1920510	1928190	It is designed for two lines of eight characters each, and each character is five pixels wide by eight pixels tall.
1928190	1933830	But if you look at the display closely, it has a lot of segments, non-textual segments.
1933830	1946370	So, for example, here's the text area, and here's a custom seven segment area, and here's also a segment area, and this is a very custom area with the keys of the synthesizer.
1946370	1952470	And this is an area with the notation, and the synth status, and all this other crap.
1953030	1963270	How is the synth accessing those segments and manipulating them in a custom way if the LCD controller only supports text?
1963270	1969730	Well, this is the LCD grid as the controller expects to see it.
1969730	1975130	It is basically 40 segments per line arranged in 16 lines.
1975830	1981910	And this is what the synthesizer is using it as.
1981910	1985210	It is using the top row as text, as intended.
1985310	1992510	On the bottom row, every segment in the virtual bottom row is wired to an actual segment on the display.
1992790	1995550	And what I drew here is non-garbage.
1996130	2005530	This is actually... when I copy the data that is displayed in the bottom row to the top row, this is what the display tells me.
2006250	2012890	So, somehow the CPU is telling the LCD controller to display custom graphics.
2013470	2015630	And how does it do that?
2015630	2019550	And if it does do that, how can we do the same?
2020590	2026710	Well, here is a simplified schematic diagram of the LCD controller, with the powers that matter to us.
2026710	2030390	The most important memory is the display data RAM, the DRAM.
2030710	2036070	It is holding the ASCII characters that are currently displayed on screen.
2036070	2039190	And there's... the second most important memory is CGROM.
2039190	2042930	It is translating ASCII characters into actual graphics.
2043130	2055830	So, we have to only load ASCII once into the DDRAM, and the display will keep updating itself without any iteration from the CPU using that CGROM.
2055830	2057770	There's also the CGRAM.
2057770	2075090	We can load custom character data into the CGRAM, up to 8 custom characters, 5 pixels by 8 pixels, and it will display them if we tell it to display characters numbered 0 through 7 or 8 through 15.
2075090	2078930	They refer to the same area in the CGRAM.
2080250	2085750	And in order to play a video, this is a frame from Bad Apple.
2085750	2090350	First, our display is 40 by 16 pixels.
2090350	2102330	So, we... first, we take a slim window of the video, and we break it up into 8 portions of 5 by 8 pixels.
2102330	2115690	And we tell the DDRAM to display those custom characters once, and then we constantly update the RAM of the LCD controller to basically play a video.
2116330	2123550	But the synthesizer fights back, of course, because it's got its own custom stuff to be displayed in its custom segments.
2123810	2126290	So, I'm not going to go into detail here.
2126290	2128230	Unfortunately, I don't have enough time.
2128230	2133190	But, essentially, there's a real-time operating system that is running on this synthesizer.
2133330	2140790	And it's got, essentially, a task table which lists out all the tasks that are running on the synthesizer.
2140790	2151690	And if you make a copy of that table in RAM and overwrite specific entries, you can effectively disable that part of the firmware without actually overwriting the flash chip.
2151710	2163950	And I don't want to overwrite the flash chip, because if I do something wrong, I want to be able to just unplug the synthesizer from the wall and plug it back in, and it continues to work normally.
2164730	2172330	So, this is, essentially, how to play Bad Apple on the synthesizer.
2172870	2175310	And a little addendum.
2175630	2195390	After I published the original article online, a lot of people online tested this exploit, this shell exploit, and it turns out the range of Yamaha devices susceptible to this attack is very wide, with the earliest product being the E433, the one that I have,
2195390	2202990	released in 2012, and the latest one is E473, released in 2022.
2202990	2208270	And this expands beyond just educational synthesizer.
2209150	2218730	The DGX digital piano, released in 2016, has the same shell, the same passwords, hashtag 000.
2219570	2237210	It's also possible that Yamaha drums, namely model P125, is susceptible to it because the same strings were found in its firmware image, even though the person that found it didn't have the device on hand.
2237210	2244630	Shout out to these guys, by the way, MarisaChan, Curler, RPL1846, and Cintra.
2245110	2258870	There's an ongoing discussion on GitHub about those things, so I think it's safe to say that basically every Yamaha product has this shell, which is vulnerable to arbitrary memory rights.
2259650	2263050	This is a big issue, I think.
2264110	2267510	And a little summary on the DSP.
2267510	2271990	So, in this chip, there's a DSP that is separate from the ARM core.
2271990	2273410	It is running independently.
2273410	2278390	Whenever I pause the ARM core, this DSP continues to produce sound.
2278870	2286670	And it uses memory map register starting at address FE0000000, six zeros.
2287130	2290810	There are two areas, as hex 400 bytes in size.
2290810	2292370	There's a global configuration area.
2292370	2294450	There's a voice parameter area.
2294450	2296570	There are 32 voices.
2296570	2299570	There are 16 16-bit parameters per voice.
2299570	2302670	You can look the formulas up on slides.
2304150	2316530	If you're interested in details, here's the list of voice parameters that I was able to figure out the meaning of the pitch register, the decay, attack, and volume and panning register.
2316530	2320830	And here's one global register that I was able to figure out the meaning of.
2320830	2322090	Again, you can look at the slide.
2322090	2328770	This is very boring, but nevertheless important, I think.
2328770	2330270	And here's the list of references.
2330670	2337890	The article from before that mentioned this chip might be based on SuperH, even though it's not entirely correct.
2337890	2340930	There's also lots of useful info on that website.
2340930	2342010	Go read it.
2342770	2348190	There's the MIDI specification, the ARM documentation, and that's it.
2348190	2355590	Thank you very much, and thank you very much to Alla and Petya here behind the cameras that made this video possible.
2355710	2356550	Goodbye!
