Return to Video

36C3 - A Deep Dive Into Unconstrained Code Execution on Siemens S7 PLCs

  • 0:00 - 0:18
    36c3 prerol music
  • 0:18 - 0:26
    Herald: So, Siemens recently decided to
    add some security feature to the PLC. And
  • 0:26 - 0:33
    today we have Tobias and Ali and they will
    be sort of.. telling us what they managed
  • 0:33 - 0:41
    to find. This PLC. They both come from
    Ruhr Universität Bochum. Tobias is a
  • 0:41 - 0:46
    recent acquisition as a doctoral student.
    And Ali is a postdoc. So, uh, let's give
  • 0:46 - 0:48
    them a hand.
  • 0:48 - 0:57
    applause
  • 1:00 - 1:04
    Ali: Hmm, where is our slide?
    Tobias: Presentation mode?
  • 1:10 - 1:17
    Ali: Yes. OK. Welcome to our talk. A deep
    dive into on concentrate code execution in
  • 1:17 - 1:24
    Siemens S7 PLCs. My name is Ali Abbasi and
    as mentioned before, I'm a postdoc at
  • 1:24 - 1:28
    chair of System Security at Ruhr
    University Boch and here's my colleague.
  • 1:28 - 1:34
    Tobias: I am Tobias or Tobi. I'm very
    glad to be here. It's my fifth time at the
  • 1:34 - 1:39
    Congress and now finally able to give back
    in a way. So I'm very excited about that.
  • 1:40 - 1:47
    So let's get into it. So first about the
    plan of the talk. We want to give you a
  • 1:47 - 1:51
    little bit of a background of what PLCs,
    which is programmable logic controllers
  • 1:51 - 1:57
    are all about, why we might want to use
    them and in what kind of setting. And then
  • 1:57 - 2:03
    we want to go into the specifics of PLCs
    in the Siemens case. First we look a bit
  • 2:03 - 2:07
    at the hardware and then at the software
    afterwards and the different findings that
  • 2:07 - 2:11
    we had. At the end, we would show a
    demonstration of what we're able to
  • 2:11 - 2:19
    achieve and conclude with some remarks. So
    first of all, process automation. So we
  • 2:19 - 2:25
    all know it. Or maybe we do it ourselves
    or we know somebody who does it. We put in
  • 2:25 - 2:32
    some devices in our smart home, if we call
    it smart already. And we try to automate
  • 2:32 - 2:39
    different targets on different things to
    make our lives easier. Things like turning
  • 2:39 - 2:43
    up and down the heat. We might not want to
    do that our own. We might not want to
  • 2:43 - 2:49
    overheat or under heat. And what we do is
    basically have some sensory systems inside
  • 2:49 - 2:55
    our homes, as well as some devices that
    interact with those sensors. In this case,
  • 2:55 - 3:01
    we might have a thermostat and a heater
    and we want to adjust our temperature
  • 3:01 - 3:07
    based on the thermostat. They're pretty
    simplistic solutions like this for a smart
  • 3:07 - 3:13
    home. But what we do if we have very
    complex control loops for example. Here we
  • 3:13 - 3:20
    can see on the left bottom corner a pretty
    complex looking picture, some operating
  • 3:21 - 3:27
    operators sitting in front of what we call
    an HMI a human machine interface, which is
  • 3:27 - 3:30
    basically an aggregation of all the
    information of things that go on in a
  • 3:30 - 3:37
    factory, for example. We need different
    sensors and this factory and we need to
  • 3:37 - 3:41
    steer different motors and stuff like
    this. So we need things in the middle to
  • 3:41 - 3:46
    kind of control all of this. And we do
    this using PLCs and we can see a setup how
  • 3:46 - 3:50
    it could look like. So basically have a
    set of inputs as we talked about and a set
  • 3:50 - 3:54
    of outputs. And we have some logic going
    on in the middle. And what we typically
  • 3:54 - 4:00
    deploy is a PLC a programable logic
    controller and some logic in the middle.
  • 4:00 - 4:05
    There are different technologies that can
    be used, for example, structure, text or
  • 4:05 - 4:11
    letter logic which gets downloaded onto
    the PLC and then which steers outputs
  • 4:11 - 4:16
    based on the inputs that it gets. You can
    see some applications of this kind of
  • 4:16 - 4:22
    thing. For example, a chemical power
    plant, chemical plant, an electric grid or
  • 4:22 - 4:28
    some manufacturing. Some of those
    components are pretty critical to the
  • 4:28 - 4:33
    workings. Even either we see it in the
    everyday lives and sometimes we don't
  • 4:33 - 4:40
    really see it. But they are in the
    steering, everything in the background and
  • 4:40 - 4:44
    we really don't want those systems to get
    compromised. For example, if you went onto
  • 4:44 - 4:48
    Google and looked something about
    disasters and chemical plants, you could
  • 4:48 - 4:53
    see melted down plants just because of
    some mis.. malfunction in the system or
  • 4:53 - 4:59
    so. And we really don't want this to
    happen. Neither an accidental but also not
  • 4:59 - 5:04
    a malicious basis. And this is why we want
    to secure all the processes going on in
  • 5:04 - 5:10
    factories and the like. We've seen some of
    the recent attacks. So it started kind of
  • 5:10 - 5:17
    in 1999 with a first initial
    reconnaissance based mainly. And then we
  • 5:17 - 5:22
    had some more advanced attacks in 2010,
    for example, where we saw Stuxnet, which
  • 5:22 - 5:26
    was very much really intricate operation.
    If you think about it on a technical
  • 5:26 - 5:32
    level, what all went into it. What
    different skill sets were involved. It's
  • 5:32 - 5:38
    pretty impressive. And then in the more
    recent time we had some issues in the
  • 5:38 - 5:45
    Ukrainian power grid, which in 2015
    and '16 just before Christmas, some lights
  • 5:45 - 5:52
    went out for quite a while in some cities
    there. So quite a bit of impact. So to
  • 5:52 - 5:58
    give you a bit of impact, a background on
    Siemens PLCs here when it comes to market
  • 5:58 - 6:02
    shares. We can see that together with
    Rockwood Automation, Siemens actually has
  • 6:02 - 6:06
    more than 50 percent market share in the
    market. And obviously, if we take out some
  • 6:06 - 6:10
    devices that introduce some security, it
    would be interesting to look at those with
  • 6:10 - 6:16
    the biggest market share. This is what we
    did here in the Siemens case. Here we can
  • 6:16 - 6:22
    see the actual PLCs that we will focus on
    in this talk, which is the Siemens S7-1200
  • 6:22 - 6:27
    PLC. It's one of the smaller PLCs, not
    quite the smallest, there is the logo as
  • 6:27 - 6:33
    well, which is more of a playing around
    example, but this is the one that it's
  • 6:33 - 6:39
    still pretty accessible to researchers in
    terms of costs. So it's like 250 for the
  • 6:39 - 6:45
    PLC. Then if you need a power supply, it
    can add the same. So as long as you don't
  • 6:45 - 6:50
    break too many, spoiler, we broke quite
    some or you don't drop them or something
  • 6:50 - 6:56
    like this, then you're pretty fine so you
    can kind of get the resources to play with
  • 6:56 - 7:00
    those devices. We have different
    applications and we talked about them
  • 7:00 - 7:08
    before. So here is what an unboxing of a
    Siemens 7 1200 PLC would look like. We
  • 7:08 - 7:14
    have the top view here on the left
    picture. It's only one of different PCBs
  • 7:14 - 7:19
    which are layered on to each other in this
    case. But the real magic goes on in the
  • 7:19 - 7:26
    top PCB, which is the green one that we
    see here. Looking at it a bit more in more
  • 7:26 - 7:31
    detail. We have the top view on the left
    side, which shows the different components
  • 7:31 - 7:37
    that really make the PLC. Take, for
    example, the ARM CPU that we have or
  • 7:37 - 7:42
    different input outputs that we can
    connect to a PLC, as we talked about
  • 7:42 - 7:48
    before, which they need in order to steer
    different parts of the system. And then we
  • 7:48 - 7:56
    have the flash chip on the top side as
    well, which is a big flash chip holding
  • 7:56 - 8:04
    the firmware off the actual PLCs, which we
    will talk about a bit more in detail
  • 8:04 - 8:10
    later. On the flip side, we have on the
    right picture the bottom side of the first
  • 8:10 - 8:15
    layer PCB. And as we can see here, this is
    where the bootloader chip resides, which
  • 8:15 - 8:22
    is an SPI flashchip of four megabytes
    owning the code of the Siemens PLC
  • 8:22 - 8:29
    bootloader. Here we wanted to have a
    detailed view on what the actual
  • 8:29 - 8:33
    processing unit inside this board actually
    looks like and what you can do if you want
  • 8:33 - 8:39
    really want to find out you can do some
    decapping. And that's what we see here.
  • 8:39 - 8:46
    The result of this, we can see that at the
    core of it, it's a renaissance ARM
  • 8:46 - 8:53
    Cortex-R4 for from 2010. And if you
    afterwards are more juggling with the
  • 8:53 - 8:58
    software side of things, you may also want
    to find out the actual revision number,
  • 8:58 - 9:05
    what it supports inside the ARM standard.
    And what you can do there is use a special
  • 9:05 - 9:13
    instruction which resides in the ARM
    instruction set and you can decode the
  • 9:13 - 9:17
    different bits on it, which we did here,
    which you can see here for reference. So
  • 9:17 - 9:23
    if you really want to know what's going
    on, you can take apart those bits and make
  • 9:23 - 9:26
    sure you're actually working with the
    hardware that you expect to be working
  • 9:26 - 9:32
    with. So here's where we come to the
    memory part of the hardware and this is
  • 9:32 - 9:39
    where I leave you over to Ali.
    Ali: Thanks. Now that Tobias like unboxed
  • 9:39 - 9:46
    the PLC for us now I'm going to talk about
    quirks and features in the PLC. So as
  • 9:46 - 9:53
    mentioned before, it's Cortex-R4 revision
    3. It's a big endian instruction set and
  • 9:53 - 10:01
    it's also only have MPU. So there is no
    visual memory basically, there are
  • 10:01 - 10:05
    multiple ram sizes depending on which year
    you bought it or which variant of the S7
  • 10:05 - 10:11
    1200 you buy and also multiple SPI flash
    and multiple different types of NAND
  • 10:11 - 10:15
    flashes. The most significant one
    difference is like in the RAM, which
  • 10:15 - 10:20
    sometimes they use Wingbond and sometimes
    they use Micron Technologies, recently
  • 10:20 - 10:31
    Micron Technologies RAM. It is LPDDR1 RAM.
    We expect the SPI Flash for bootloader. So
  • 10:31 - 10:37
    again, depending on the variance between
    one to four megabytes SPI flash, it
  • 10:37 - 10:44
    contains different banks of each sized 512
    kbytes. And basically what the bootloader
  • 10:44 - 10:49
    does is that's beside the typical actions
    of the bootloader, which is like
  • 10:49 - 10:54
    configuring your hardware is like
    verifying the integrity of the firmware
  • 10:54 - 11:02
    before it being loaded. So we actually
    need some X-ray tomography of the PLC. So
  • 11:02 - 11:09
    it's basically 3D. So the PCB is basically
    rotating here because we wanted to also do
  • 11:09 - 11:14
    some hardware reverse engineering part.
    And somebody in university had something,
  • 11:14 - 11:20
    so we didn't have to go to our dentist for
    X-ray. So here is like a quick 15 minutes
  • 11:20 - 11:26
    X-ray, which is not that good. But once
    you go in deep, eventually what you will
  • 11:26 - 11:31
    have is like this and you can actually
    just it's like a software animation. You
  • 11:31 - 11:36
    can go inside PCB and see all the layers.
    It's like amazing. So it's up for PCB
  • 11:36 - 11:42
    layer. And so besides, VCC and GND, you
    need two layers of PCB connection
  • 11:42 - 11:50
    basically. So let's look at the start up
    process. Again. Start up as usual. Some
  • 11:50 - 11:54
    hardware configuration happens. So
    vectoring trap controller, for example,
  • 11:55 - 12:02
    like lots of this handlers for different
    modes in ARM and then CRC check some of
  • 12:02 - 12:06
    the bootloader itself, which is easily
    bypassed over because you can just
  • 12:06 - 12:12
    overwrite the CRC. Then the bootloader,
    especially in the 2017, 2018 variant of
  • 12:12 - 12:19
    the Siemens PLC, allows you to overwrite
    the SPI flash. And also eventually we
  • 12:19 - 12:25
    check the CRC checksum of the firmware
    before basically loading it. The size of
  • 12:25 - 12:29
    the bootloader itself is like 128 kbyte,
    it is really even less than that because
  • 12:29 - 12:35
    half of it is just like 0xff. Siemens
    multiple times changed, they had different
  • 12:35 - 12:39
    version. I think in two years we saw three
    variants or four variants of the
  • 12:39 - 12:45
    bootloader. So it was evolving. It was not
    something that's everybody forgotten about
  • 12:45 - 12:52
    it. So generally as mentioned, so you have
    part this first stage of hardware
  • 12:52 - 13:00
    initialization and then basically bringing
    the bootloader to the RAM and basically
  • 13:00 - 13:04
    checking the bootloader CRC checksum. So
    make sure that it's not manipulated, which
  • 13:04 - 13:08
    again is it can be bypassed. And then a
    second stage of the hardware
  • 13:08 - 13:13
    initialization happens. And then at this
    moment, it waits for a specific command
  • 13:13 - 13:17
    for half a second. And if it receives this
    command it goes to another mode, which
  • 13:17 - 13:22
    we'll discuss later. Otherwise, it
    basically prepares some CRC checksum table
  • 13:22 - 13:26
    for the firmware and then it tries to
    load the firmware and then eventually
  • 13:26 - 13:31
    just removes the memory barrier the stage
    1 instruction those who knows about ARM.
  • 13:31 - 13:35
    And basically map the firmware
    to the memory.
  • 13:35 - 13:39
    So the name of the operating system, it
  • 13:39 - 13:44
    was not mentioned before, it's ADONIS. We
    know it from different from different
  • 13:44 - 13:50
    ways, actually. So first in the
    references, in the firmware, we see lots
  • 13:50 - 13:55
    of references to ADONIS, but that was not
    enough for us. So if we actually looked
  • 13:55 - 13:59
    around to see if like there is any
    reference to it, and well linkedin is one
  • 13:59 - 14:05
    good open source like reference. And he
    was like one employee actually talk about
  • 14:05 - 14:10
    Siemens developer who talk about like
    working in ADONIS. I don't know why he put
  • 14:10 - 14:15
    the Windows and Linux beside ADONIS, but I
    can say is that like you work on this. And
  • 14:15 - 14:21
    so it was not enough for us. So maybe some
    some of us we don't know. And we look
  • 14:21 - 14:25
    again further and further and we find this
    thing which was the best indicator. So
  • 14:25 - 14:30
    Siemens developer engineer mentioned that
    he worked on kernel software
  • 14:30 - 14:34
    development for ADONIS real time operating
    system, which is a good sign for us. It
  • 14:34 - 14:39
    means that we are right. So now that we
    know about the naming and we sure about
  • 14:39 - 14:46
    that. Let's look at the components. So
    it's actually a start in basically
  • 14:46 - 14:54
    0x00040040 and basically then initializing
    the kernel and then lots of routines for
  • 14:54 - 14:58
    initializing different components of the
    operating system. I don't think Siemens
  • 14:58 - 15:03
    actually generalize it in this way. We
    don't have such thing in the firmware,
  • 15:03 - 15:08
    but we actually did it like that. So we
    generalize it to two groups. Some of them
  • 15:08 - 15:11
    are core services like ADONIS real time
    operating system services, and some of
  • 15:11 - 15:16
    them are related to the like automation
    part. So those people who are like in the
  • 15:16 - 15:22
    automation part, like writing ladder logic
    and stuff like that, those commands and on
  • 15:22 - 15:27
    function codes which are relevant in
    Siemens, they actually know this are like
  • 15:27 - 15:32
    more automated related services. So you
    have PROFINET, AWP or automated web
  • 15:32 - 15:40
    programing MC7 JIT parser basically for
    the latter logic or different kind of SD
  • 15:40 - 15:46
    like basically their own JIT compiler
    inside the PLC. And you also have the OMS
  • 15:46 - 15:51
    this configuration system which is very
    related again to the automation part, core
  • 15:51 - 15:59
    core part of the automation system and of
    course alarm central all your and stuff
  • 15:59 - 16:04
    like that related to automation. In the
    operating system part, so lots of these
  • 16:04 - 16:11
    usual things. So file system. So PDCFS,
    which Tobias talks later about, it. The
  • 16:11 - 16:18
    TCP/IP stack, some C / C++ libraries,
    which is not from Siemens, it's from
  • 16:18 - 16:23
    Dinkumware and MiniWeb Server
    and MWSL Parser
  • 16:23 - 16:25
    or MiniWeb Scripting Language parser
  • 16:25 - 16:30
    and lots of different subcomponents which
    is usual in operating system like any
  • 16:30 - 16:37
    operating system you can find. Also, there
    are some references to CoreSight. I don't
  • 16:37 - 16:41
    know how many of you know of CoreSight or
    how much you work on ARM, but the basic
  • 16:41 - 16:46
    CoreSight is something similar to Intel
    process tracing or Intel PT for tracing
  • 16:46 - 16:53
    applications and can be used for getting
    code-coverage, for example. And the
  • 16:53 - 16:59
    hardware part is very well documented by
    Thomas Weber in this year, is not yet.
  • 16:59 - 17:04
    This year or so. This year, Black Hat
    Asia, but I have to warn you, because I
  • 17:04 - 17:09
    received some emails, some people ask
    about that. If you connect to it, the PLC
  • 17:09 - 17:13
    have someone to debugging feature which
    detects that it's being debuged via JTAG
  • 17:14 - 17:19
    and overwrite the NAND-Flash with random
    stuff. So you brick the PLC, so just
  • 17:19 - 17:24
    connected it at your own risk.
    Next is let's look
  • 17:24 - 17:28
    at the CoreSight just quickly,
    CoreSight basically have like
  • 17:28 - 17:31
    before I go here,
    I have to mention that Ralf Philipp
  • 17:31 - 17:38
    also have a good talk in 0 nights about
    CoreSight tracing. So I would recommend
  • 17:38 - 17:42
    you guys go look at that as well.
    Generally, CoreSight have like 3
  • 17:42 - 17:47
    major parts or components: sources, links
    and sinks and sinks is basically the part
  • 17:47 - 17:51
    which you actually get the trace
    information and sources are the part which
  • 17:51 - 17:57
    you tell is a featuring the CPU, which you
    ask what kind of sources you want to get
  • 17:57 - 18:03
    the data from and then links basically
    convert these sources. I have to mention
  • 18:03 - 18:08
    that like lots, it's very useful for
    Fuzzing as well too. I guess some people,
  • 18:08 - 18:13
    very few, but some people are working on
    that things. On coverage guided fuzzing
  • 18:13 - 18:16
    via CoreSight, ARM CoreSight. So it's
    possible similar implementation is
  • 18:16 - 18:26
    happened in Intel PT for example KAFL,
    WinAFL or Hongfuzz. So sources, basically
  • 18:26 - 18:31
    they have like three different components
    STM, PTM, ETM. ETM version 4 is the latest
  • 18:31 - 18:38
    version of it. And basically you have also
    links which connects different sources to
  • 18:38 - 18:45
    different like different or single sources
    to different or single basically sinks.
  • 18:46 - 18:52
    And then you have funnels for CoreSight,
    sorry sinks, sorry. You have sinks, which
  • 18:52 - 18:56
    is basically a different kind. So there
    are some integrity to the CPU which is 4
  • 18:56 - 19:03
    kilobytes ring buffer SRAM or you have
    like system memory or even TPIU or just
  • 19:03 - 19:09
    for example JTAG DP Port High Speed JTAG
    port. So now that cleared sink,
  • 19:09 - 19:15
    like the CoreSight, we actually queried S7
    for existence of CoreSight and as you can
  • 19:15 - 19:21
    see, like in the software part is already
    implemented. So they actually have some
  • 19:21 - 19:27
    references in their software that they are
    utilizing or configuring the CoreSight in
  • 19:27 - 19:33
    the PLCs. And basically we can see that
    the ETM version is not the latest version
  • 19:33 - 19:40
    it is ETM version 3. Now that I've talked
    to you about CoreSight, Tobi can talk
  • 19:40 - 19:43
    about firmware dumps.
    Tobi: So let's get to something that I'm
  • 19:43 - 19:49
    very much more familiar with and feel it's
    easier for me to handle it is firmware
  • 19:49 - 19:53
    dumps or software in general, but firmware
    dumps, I think it's close as you can get
  • 19:53 - 20:00
    to what I like when talking to a PLC or
    trying to understand a PLC. So in the
  • 20:00 - 20:07
    Siemens case, we have a 13 megabytes
    binary and at the beginning it's not as
  • 20:07 - 20:15
    many, but as if you twiddle around with a
    bit and apply some IDA python functions
  • 20:15 - 20:19
    and stuff like this. You can get to like
    84 000 functions, which is
  • 20:19 - 20:26
    not something you want to really look at
    everything manually. Also, like 84 000
  • 20:26 - 20:32
    function firmware image doesn't really get
    the sexiest firmware on planet, right? I
  • 20:32 - 20:38
    guess so. But this is what I what I looked
    at and what we were looking a bit more in
  • 20:38 - 20:43
    the next couple of minutes or so. As you
    can see, we have different names up there.
  • 20:44 - 20:49
    We have one name which is called
    _some_get_some_max_size. So this is my
  • 20:50 - 20:54
    internal way of saying I don't really have
    an idea of what's really going on in this
  • 20:54 - 20:58
    function, but we can also see some more
    meaningful functions. So we understood
  • 20:58 - 21:04
    some parts a bit more. Some parts of it
    less, but I gave it a cursory look in most
  • 21:04 - 21:11
    places. So now let's get in to a lot of
    address related stuff, so we expected a
  • 21:11 - 21:17
    lot of details, which are very interesting
    if you start looking at firmware code, and
  • 21:17 - 21:21
    I will explain along the way why that
    might be interesting. So first of all,
  • 21:21 - 21:26
    what you have to know is that coretex are
    for gives you bank registers. This is
  • 21:26 - 21:33
    basically a feature that's implemented to
    lower software overhead and allow more
  • 21:33 - 21:41
    seamless modes, which is for the internal
    CPU. And what we get is banks stacks per
  • 21:41 - 21:47
    execution mode. So if we want to know what
    is kind of going on in the state of the
  • 21:47 - 21:51
    filmware at a given point we may want to
    look at the different stacks of the
  • 21:51 - 21:57
    different modes at any given point. And
    this is the addresses that we expected for
  • 21:57 - 22:03
    this. And you could use that if you as a
    starting point, if you started reverse
  • 22:03 - 22:08
    engineering, things like that. Now, we
    will have some address, some tables with
  • 22:08 - 22:16
    addresses. And the first one is RAM
    mappings, which show you what kind of
  • 22:16 - 22:23
    functionality or what you might expect
    when looking at firmware code, which is
  • 22:23 - 22:28
    interfacing with different parts of
    memory. So if you initially go and look at
  • 22:28 - 22:33
    some ARM code, you may just see a random
    access to some place in memory and you may
  • 22:33 - 22:39
    want to know what it's actually doing. And
    it looks very uneventful of it's just an
  • 22:39 - 22:45
    address and it gets gets queued and
    you don't really know what's going on. So,
  • 22:45 - 22:50
    for example, if you looked at an address
    within the text section, you would expect
  • 22:50 - 22:55
    there to reside code if you wanted to see
    some global static data, you would want to
  • 22:55 - 22:59
    look at the data or the BSS section. And
    then finally, if you wanted to look at
  • 22:59 - 23:04
    heap memory or how channels are set up
    there, you would look in the uninitialize
  • 23:04 - 23:10
    section and it goes on like this for
    different sections. Another very
  • 23:10 - 23:14
    interesting thing to look at, if you tried
    to reverse engineer firmware images is
  • 23:14 - 23:20
    that you kind of want to know what the
    hardware is that a given piece of code is,
  • 23:22 - 23:30
    is interfacing with. And in this case we
    dumped some regions or reverse engineered
  • 23:30 - 23:35
    what some regions are for what is called
    memory mapped I/O. And the way ARM is
  • 23:35 - 23:39
    talking to a firmware is basically to
    queue a magic value inside the address
  • 23:39 - 23:43
    space and then it gets something back,
    which is not at all what it has been
  • 23:43 - 23:49
    written there before. So it's basically an
    address which gets wired through to the
  • 23:49 - 23:54
    periphery the hardware periphery on the
    same system on a chip. And here we can see
  • 23:54 - 23:57
    that we have different hardware
    peripherals residing on it. For example,
  • 23:58 - 24:03
    we can talk to the Siemens PLC via
    different serial protocols and those
  • 24:03 - 24:09
    protocols might be SPI or I²C. And we have
    on the left side, kind of in the middle
  • 24:09 - 24:16
    top what took part of it, have some region
    pertaining to that. And then if you saw
  • 24:16 - 24:22
    some other code talking to timers, for
    example, you would know you are in timer
  • 24:22 - 24:26
    land at the moment or like in the
    scheduler or whatever it would be.
  • 24:26 - 24:28
    Finally, we have
  • 24:28 - 24:34
    some MPU configurations which are memory
    protection unit configurations, as Ali
  • 24:34 - 24:39
    introduced earlier. So what we can see is
    that Siemens is actually applying some of
  • 24:39 - 24:44
    those configurations to protect parts of
    memory. What we can see, for example, is
  • 24:44 - 24:49
    where whenever the XN so the execute never
    bit is set, code is not to be executed
  • 24:49 - 24:54
    within this address region or we have a
    read only region. We really don't want to
  • 24:54 - 24:59
    have it overwritten. So it's interesting
    that they started playing this in
  • 24:59 - 25:06
    practice. Here we can see what actually
    happens when the firmware itself boots up.
  • 25:06 - 25:12
    So it turns out the firmware doesn't
    really want to depend too much on what the
  • 25:12 - 25:17
    bootloader did. Probably it's different
    teams doing different things. And to keep
  • 25:17 - 25:22
    this interface as small as possible, they
    kind of redo some of the stuff that the
  • 25:22 - 25:27
    bootloader code also does. It sets up the
    vector table for handling interrupts and
  • 25:27 - 25:32
    similar things like that. Then if we get
    past this initial stage, we actually want
  • 25:32 - 25:37
    to boot the ADONIS kernel which Ali talked
    about before. So first of all, there is an
  • 25:37 - 25:42
    array of function pointers that gets
    called one for like every piece of
  • 25:42 - 25:47
    functionality that we saw on this overview
    of the different components of ADONIS. So
  • 25:47 - 25:51
    if you wanted to look at what kind of
    components are there or functional
  • 25:51 - 25:56
    components are there. This is a very
    interesting list of functions, function
  • 25:56 - 26:02
    handlers to... to examine and also sets up
    some management structures and stuff like
  • 26:02 - 26:08
    this one a typical operating system would
    have to set up. So now we look at more of
  • 26:08 - 26:14
    the different components of ADONIS. First
    one is the file system, so PLCs is part of
  • 26:14 - 26:20
    the specifications. Sometimes it's how
    resilient is it against temperatures, how
  • 26:20 - 26:26
    low of a temperature can I have this PLC
    reside in without losing functionality?
  • 26:26 - 26:33
    And in this case, what they also want to
    provide is some safety against interrupts
  • 26:33 - 26:38
    in power supply. So they developed a
    proprietary file system which is called
  • 26:38 - 26:43
    "Powered Down Consistency Files System",
    which they implement in the firmware. And
  • 26:44 - 26:56
    we can also see one of the work
    experience entries of one of the previous
  • 26:56 - 27:03
    Siemens employees who stated that he or
    she worked on this file system. We have
  • 27:03 - 27:08
    another part of a very critical part of
    the functionality, of course, we want to
  • 27:08 - 27:15
    talk to the PLC, it wants to talk to us
    in.. and one of the ways is fiercely
  • 27:15 - 27:19
    TCP/IP. And this is to expose the Web
    server, for example, and different other
  • 27:19 - 27:26
    components. And in this case, it turns out
    that Siemens doesn't implement their own,
  • 27:26 - 27:31
    which probably is a good idea not to do
    that. They use the
  • 27:31 - 27:35
    InterNiche Technologies TCP/IP stack
    in version 3.1.
  • 27:35 - 27:38
    If you are
    good at Googling you can find some source
  • 27:38 - 27:42
    code and you can actually map this to the
    firmware and how it works. So it could
  • 27:42 - 27:49
    give you some wrapper functions, something
    like creating sockets and stuff like this
  • 27:49 - 27:54
    and could make it easier for you to find
    those in the firmware image. We also have
  • 27:54 - 28:01
    one of the very critical components of
    each firmware is update. If it allows an
  • 28:01 - 28:07
    update and the Siemens PLC allows updates,
    there are different modes. One of the
  • 28:07 - 28:12
    modes is, just you drag and drop an UPD
    file, an update file to the web server and
  • 28:12 - 28:19
    it will start checking firmware, integrity
    and signatures and so on. And the second
  • 28:19 - 28:25
    way is doing it via an SD card, which has
    a great total of twenty four megabytes and
  • 28:25 - 28:31
    it's for the low price of 250 euros. You
    can can get it. I think you can not really
  • 28:31 - 28:39
    beat that, that ratio. If you actually
    decompress this kind of UPD file, you get
  • 28:39 - 28:43
    another representation of it in memory.
    And we did some reverse engineering on
  • 28:43 - 28:47
    that and we have different fields not sure
    if you can see them now, but you can
  • 28:47 - 28:54
    expect what it is. It's different offsets
    into the actual binary file. It's it's an
  • 28:54 - 28:58
    entry point into the firmware magic header
    to make sure something is not too screwed
  • 28:58 - 29:04
    up and a CRC over the whole thing for
    example. We also extracted some of the
  • 29:04 - 29:12
    addresses inside the firmware image, which
    helps you find a first foothold into what
  • 29:12 - 29:18
    the logic is dealing with and give you
    some addresses for you to refer this to
  • 29:18 - 29:23
    later. The next component that we want to
    touch on is Miniweb, which is the web
  • 29:23 - 29:30
    server. It kind of exposes to you the
    different internal parts of the PLC and
  • 29:30 - 29:35
    what the state of different GPIOs, general
    purpose input outputs, is. The inputs and
  • 29:35 - 29:42
    the outputs and what the health of the PLC
    is itself and the way that it exposes this
  • 29:42 - 29:50
    is using the MWSL language Miniweb
    scripting language. It's as we will see on
  • 29:50 - 29:55
    the next over the next slide and we'll
    talk to them about that in a little bit
  • 29:55 - 30:02
    more detail. We have a be started, has the
    service as well from one of the function
  • 30:02 - 30:09
    handlers of the ADONIS initialization
    functions that I referred to a little bit
  • 30:09 - 30:14
    before. So now let's get to some
    undocumented http handlers, which I think
  • 30:14 - 30:18
    are very interesting. I think my favorites
    are "lilililili" and "lololololo"..
  • 30:18 - 30:20
    laughter
  • 30:20 - 30:25
    .. and if you should put those together in
    a clever way, maybe somebody is musically
  • 30:25 - 30:33
    gifted and can make a song out of it. I
    would be very interested to hear that. So
  • 30:33 - 30:38
    now let's get to the MWSL the Miniweb
    scripting language. So it basically
  • 30:38 - 30:43
    exposes the internal functionality by
    allowing you to inject into an html page
  • 30:43 - 30:47
    by a templating different configuration
    parameters and stuff like this. For
  • 30:47 - 30:54
    example, as we can see here on the top
    right corner, you can see the CPU load of
  • 30:54 - 30:59
    the system at a given time. It doesn't
    really seem to perform any output
  • 30:59 - 31:06
    encoding, so it kind of trusting what
    comes out. So there may be clever ways
  • 31:06 - 31:13
    to... to do some web related trickery with
    this and also the parsing of this
  • 31:13 - 31:19
    tokenization is kind of complex. I looked
    into it a bit and this implementation
  • 31:19 - 31:25
    could also be interesting to look at, but
    we will get to those kinds of
  • 31:25 - 31:30
    aspects a bit later. With this, we're
    going to get to our actual findings and
  • 31:30 - 31:34
    talk about those a bit more. And this is
    where Ali will take over.
  • 31:35 - 31:43
    Ali: Thanks, Tobi. So. So now we talk
    about the capabilities which exist in the
  • 31:43 - 31:49
    bootloader, which allows us to have
    unconstrained code execution. So basically
  • 31:49 - 31:55
    this feature is available in the uart. So
    you need physical access to the device.
  • 31:56 - 32:01
    But once you have this physical access,
    you can basically, as Tobias later
  • 32:01 - 32:05
    describes, we can actually bypass the
    security ecosystem which developed by
  • 32:05 - 32:11
    Siemens in their product. So you need uart
    access as it's documented here, you have
  • 32:11 - 32:20
    TX, RX and GND in the PLC and the uart
    actually in previous research was
  • 32:20 - 32:26
    documented as well. Every address which I
    am talking about here or mentioned in this
  • 32:26 - 32:31
    presentation are for bootloader version 4
    to 1. As I mentioned earlier, Siemens
  • 32:31 - 32:38
    actively modified the bootloader. So I
    think in two years we saw like 2, 3
  • 32:38 - 32:45
    modifications or different versions of
    their bootloader coming up. So this
  • 32:45 - 32:50
    exactly is based on that's half a second
    waiting for a specific command after a
  • 32:50 - 32:56
    second hardware configuration happens. It
    applies to Siemens S7-1200 including
  • 32:56 - 33:03
    SiPLUS and S7-200 SMART. Actually,
    somebody from Kaspersky. IS security
  • 33:03 - 33:08
    mentioned it. We didn't know even about
    it. We just investigated a S7-1200. But
  • 33:08 - 33:14
    Siemens later updated that advisory that
    also applies to other products as well. So
  • 33:14 - 33:19
    let's talk about this, a special access
    feature. So as you mentioned, one of the
  • 33:19 - 33:23
    things the bootloader does is actually
    initialize the hardware after this
  • 33:23 - 33:27
    hardware it's basically copy some of the
    contents of the bootloader itself to a
  • 33:27 - 33:36
    memory segment called IRAM, basically. And
    then PLC basically waits half a second for
  • 33:36 - 33:40
    a specific command. And once it's
    received, this specific command it
  • 33:40 - 33:44
    responds with a specific string and it's
    all happening over the uart. So it's if
  • 33:44 - 33:50
    you send a magic string, MFGT1, sorry for
    my broken German, but probably it means
  • 33:50 - 33:58
    "Mit freundlichen Grüßen", I hope I did it
    right. And then the PLC responds with
  • 33:58 - 34:02
    "-CPU" and says that now you are in this
    special access mode. I am waiting for your
  • 34:02 - 34:11
    commands. And this address is also I
    believe 0xedf8 in the bootloader. So here
  • 34:11 - 34:16
    is a decoding of our clients, which we
    will release later next year, actually,
  • 34:16 - 34:25
    which you see that's 2d435055, which is
    the "-CPU" response from the PLC. So now
  • 34:25 - 34:31
    we are in it. And also we also added some
    extra saying about your packet format.
  • 34:31 - 34:37
    Somebody asked before. So once you send
    this command, you get lots of
  • 34:38 - 34:43
    functionalities here in this presentation.
    We call them handlers and basically they
  • 34:43 - 34:50
    are something we call primarily handler.
    It's like 128 entries and there are some
  • 34:50 - 34:58
    three other separated handlers which are
    like 0x80 uart configuration and bye. So
  • 34:58 - 35:02
    in the primary handler release, there are
    lots of things. So if you go back to the 2
  • 35:02 - 35:11
    previous slides, I got the firmware
    version here, 4.2.3. And
  • 35:11 - 35:15
    basically what is happening is that
    basically it's this command here, get
  • 35:15 - 35:20
    bootloader version. We are just requesting
    the special access feature to tell us
  • 35:20 - 35:25
    what is a bootloader version. And also you
    can do lots of low level diagnostic
  • 35:25 - 35:29
    functionality is happening there. Also
    some functionalities related to firmware
  • 35:29 - 35:35
    update happening there which bypasses the
    usual cryptographic verification of the
  • 35:35 - 35:43
    firmware and doesn't need that. So let's
    look at them, because for this work, which
  • 35:43 - 35:47
    we are talking about, we actually
    primarily only use two of the handlers. So
  • 35:47 - 35:52
    we don't use.. we don't look at like or we
    don't discuss now all others hundred
  • 35:52 - 35:58
    twenty eight handlers which exist in the
    PLC. So it works. One of the handlers, the
  • 35:58 - 36:06
    interesting one for us was handler 0x80
    which mentioned here, update function. So
  • 36:06 - 36:11
    basically what it does is that it lets you
    allow you to write to a specific part of a
  • 36:11 - 36:17
    memory IRAM, which previously copied some
    content of the bootloader. So basically
  • 36:17 - 36:22
    you send this handler after this
    handshake, you have to do this MFGT1 and
  • 36:22 - 36:26
    then -CPU. And then basically you are
    going to send this handler and then it
  • 36:26 - 36:30
    basically checks because each handler
    might have different requirements. Check
  • 36:30 - 36:34
    number of arguments, for example, and then
    you are in this update function mode. And
  • 36:34 - 36:39
    then you have to provide target ID because
    there is 4 subfunctionality available.
  • 36:39 - 36:45
    Once you enter this mode and some of them
    are like for IRAM, for SPI or IOC or for
  • 36:45 - 36:52
    Flash, and then for each of them, you have
    to choose what kind of operation you want
  • 36:52 - 36:58
    to do you want to configure, read, write
    or check. And so you can do all of these
  • 36:58 - 37:03
    things so you can read and write to the
    IRAM. Basically, this is a function
  • 37:03 - 37:10
    handler at 0x80. Next is a primary handler
    like 0x1c. This is listed in this handler
  • 37:10 - 37:20
    list, here. So, so basically it allows you
    to call functions. So the basically this
  • 37:20 - 37:24
    functions are listed in the IRAM. And
    basically what you do is that you send
  • 37:24 - 37:29
    this handshake, you are and you are in
    this. Basically, this is what 0x1c handler
  • 37:29 - 37:35
    and then you can call the ID number of the
    handlers which you want to use. So here
  • 37:35 - 37:42
    you have like lots of handler available
    for 0x1c. So the question is, what we can
  • 37:42 - 37:51
    do with it. And before I asked Tobias I
    want to ask anybody here, any idea? Trace,
  • 37:51 - 37:54
    somebody said trace. I don't know what
    that means, but
  • 37:54 - 37:58
    mumbling in the audience
  • 37:58 - 38:04
    OK. You mean with JTAG? with the
    CoreSight? No, we are not going to use
  • 38:04 - 38:07
    that. So let's ask Tobias what he can
    do.
  • 38:07 - 38:11
    Tobias: Yeah. So looking at it dynamically
    and seeing what it does with the memory
  • 38:11 - 38:15
    is, I guess, a good idea in general. If
    you if like static reverse engineering
  • 38:15 - 38:21
    doesn't give you anything. In this case,
    we looked through different or I looked
  • 38:21 - 38:27
    through different of those functions and
    tried to see, what can I do with it? So
  • 38:27 - 38:32
    the base of where I started looking for
    this special access feature was basically
  • 38:32 - 38:37
    that I saw there is too much in this code
    going on. I kind of feel like I understood
  • 38:37 - 38:42
    what it should be doing. The bootloader
    what it should be doing, but it seemed
  • 38:42 - 38:50
    just to be too much. And the way we can
    combine those two functions is basically
  • 38:50 - 39:02
    to recap. Use this 0x1c handler, which
    gives us control over what kind of
  • 39:02 - 39:08
    secondary list functions to be called,
    which, as we saw before, is copied during
  • 39:08 - 39:14
    the the boot up process to a position in
    IRAM from external read-only memory. And
  • 39:14 - 39:20
    this exposes this function handler table
    to anything that can write to IRAM. And as
  • 39:20 - 39:26
    we learned before, the 0x80 handler is
    able to in a limited capacity, do just
  • 39:26 - 39:32
    that. And here we can see what we can try
    to do with this. So we use in a first
  • 39:32 - 39:39
    stage the 0x80 handler to write to IRAM.
    We can actually inject another function
  • 39:39 - 39:44
    pointer together with some configuration
    values that allows us to pass different
  • 39:44 - 39:50
    checks about argument sizes and stuff like
    this. We can inject this as an entry into
  • 39:50 - 39:56
    this table and we can also write to this
    table a payload which we can use as a
  • 39:56 - 40:03
    shell code. And then in a second stage we
    can use this previously injected index
  • 40:03 - 40:12
    that we specified just as a trigger to
    call our own payload. So now we have code
  • 40:12 - 40:17
    execution in the context of the
    bootloader. So which is as privileged as
  • 40:17 - 40:24
    we can get at that point and we can see
    what we can play around with this. And as
  • 40:24 - 40:30
    a little summary is that we chain all this
    together and we get code execution. And
  • 40:30 - 40:36
    with Ali's words, with this technology,
    we're going to rocket the PLC. And before
  • 40:36 - 40:41
    we go into what this actually allows us to
    do is a little word about the stager
  • 40:41 - 40:47
    payload. So I wrote this this chain of
    different invocations and it turns out
  • 40:47 - 40:52
    that this write to IRAM is somehow very
    slow in the first place, but then also
  • 40:52 - 40:57
    error prone so the device can just error
    out and I'm not quite sure what this
  • 40:57 - 41:03
    pertains to, but what may be interesting
    to know from the Siemens engineer, but it
  • 41:03 - 41:09
    basically led to me having to inject a
    little encoded payload, which just has a
  • 41:09 - 41:16
    subset of bytes which gives us an
    interface to do to perform
  • 41:16 - 41:20
    reads and writes with an arbitrary
    write primitive and then use this to
  • 41:20 - 41:25
    inject second stage payloads. And this is
    what we want to demonstrate here.
  • 41:27 - 41:33
    Ali: Thanks. So now we would have our demo
    4 demos, actually. So the first one is
  • 41:33 - 41:37
    actually just seeing a communication,
    basically sending these requests and
  • 41:37 - 41:42
    getting a response and basically sending
    this data payload. So the up is the raw
  • 41:42 - 41:48
    UART communication. Don't worry, it's
    getting zoomed later and the down is like
  • 41:48 - 41:56
    our client, which actually talking with
    the PLC and sending us comments. So we are
  • 41:56 - 42:01
    just running our UART. And here is we are
    sending our command. And if you look at it
  • 42:01 - 42:07
    up, you see the -CPU signal came from
    the PLC. And now we are sending our stager
  • 42:07 - 42:12
    and our stager just sends us just one
    acknowledgement so we know that the stager
  • 42:12 - 42:16
    runs successfully. This is for firmware
    version bootloader version 4.2.1,
  • 42:16 - 42:20
    basically. So now we are going to do
    something else we are going to actually
  • 42:20 - 42:24
    dump the firmware from a running PLC and
    compare it with the firmware downloaded
  • 42:24 - 42:31
    from Siemens' website. So for us, we are
    going to actually unpack the firmware
  • 42:31 - 42:36
    downloaded from Siemens website because
    it's a compressed with lzp3. So
  • 42:38 - 42:43
    that's what we are going to do. Oh, we are
    actually setting up our SSL connection
  • 42:43 - 42:50
    first. So SSL port forwarding, ssh port
    forwarding before and we are just checking
  • 42:50 - 42:57
    that the PLC is running properly. So like
    this is not a broken PLC or something like
  • 42:57 - 43:02
    that. We wrote something. So we just make
    sure that the web server is opening the
  • 43:03 - 43:13
    open the server, it's open, it's good. And
    I also try to log in to the website, to
  • 43:13 - 43:17
    the Web server of the PLC. Just again,
    make sure that the PLC is functional. So
  • 43:17 - 43:24
    also enter the password. I guess everybody
    can guess it. And then so you see that we
  • 43:24 - 43:29
    log in eventually and in the left side you
    see all the like functionalities which
  • 43:29 - 43:34
    loads related to the PLC. So it's a
    working, running, functional PLC. And so
  • 43:34 - 43:40
    now you're going to decompress the
    firmware downloaded from Siemens' website
  • 43:40 - 43:44
    after checking for export license and
    stuff. So they want to make sure that
  • 43:44 - 43:52
    people from Iran and North Korea don't get
    it. I'm from Iran, by the way. So here we
  • 43:52 - 43:55
    have the unpacked firmware. But because
    the frame rate is very large, as Tobias
  • 43:55 - 43:59
    mentioned earlier, what we are going
    to do is that we are just going to export
  • 43:59 - 44:05
    256 kilobytes of the firmware from some
    part of the web server and into IDA. So
  • 44:05 - 44:10
    you have to set the big endianess for the
    cpu. And also rebase the framwork. So as
  • 44:10 - 44:15
    you can see, here is no function yet, but
    once we rebase it we have all the function
  • 44:15 - 44:25
    as well and yeah, so then we gotta just go
    and export 256 kilo bytes from the
  • 44:25 - 44:29
    firmware so we specifically slow down the
    UART because we want to make sure that we
  • 44:29 - 44:33
    don't do it's too fast to overflow the
    buffer which we have internally in the
  • 44:33 - 44:42
    PLC. So. So here, for example, in this
    address, 691e28 we are going to export 256
  • 44:42 - 44:46
    kilobytes. This is from the firmware,
    Siemens firmware. Right. So we just
  • 44:46 - 45:01
    export it. So, yeah, so it's now called
    fw-0x691E28 in the folder out. So now we
  • 45:01 - 45:06
    are done with this part. We are going to
    dump the same address in the PLC. So from
  • 45:06 - 45:12
    a running PLC, I have to mention again. So
    this is the top part is basically raw uart
  • 45:12 - 45:18
    and this is basically our client part and
    we are dumping it with a cold boot style
  • 45:18 - 45:22
    attack. So we are basically resetting the
    PLC. And before it's over, write the RAM,
  • 45:22 - 45:29
    we are basically dumping the contents of
    the RAM. So this is the address, 0x691e28.
  • 45:29 - 45:35
    This is about the same address, basically.
    And we are dumping 256 kilobytes. And here
  • 45:35 - 45:41
    we send MFGT1 basically. And then got
    the /cpu and then the rest of the stager
  • 45:41 - 45:49
    and stuff goes. So now basically we are
    sending packets and then eventually get a
  • 45:49 - 45:57
    recive. So basically got all the payload
    like dumped in mem_dump_00691e28
  • 45:57 - 46:03
    basically. So this is from the RAM of the
    PLC. This is not anymore from Siemens'
  • 46:03 - 46:17
    websites. We are just scped to our own
    machine and then compare it. So now we
  • 46:17 - 46:22
    have the memdump and original firmware
    256 kilobytes each. And then we are going
  • 46:22 - 46:29
    to compare them with each other. And as
    you can see, should look here like you
  • 46:29 - 46:33
    have like hundred percent match. Meaning
    that it's exactly the same firmware,
  • 46:33 - 46:37
    which is available on Siemens website. We
    dumped it directly from the Siemens PLC
  • 46:37 - 46:44
    memory using this as special access
    feature. So let's do another one. So this
  • 46:44 - 46:48
    time we all want to show that
    unconstrained code execution in just a
  • 46:48 - 46:53
    very basic way. So we are actually just
    writing a custom payload to the PLC and
  • 46:53 - 46:58
    get a hello or greetings from the PLC. So
    basically, basically we just asked the PLC
  • 46:58 - 47:05
    to send us this message all the time. So
    again, so we are sending our custom
  • 47:05 - 47:13
    payload here and say hello loop. And
    basically the PLC just sending this loop
  • 47:13 - 47:24
    for us. So all of these things, again, are
    for bootloader 4.2.1. You have to readjust
  • 47:24 - 47:30
    certain things because Siemens saying they
    updated again their bootloader in the
  • 47:30 - 47:36
    recent 2019 December, which we bought new
    PLC, again, once again. And now here we
  • 47:36 - 47:43
    get a response. That's the PLC is sending
    basically to us this our raw data, which
  • 47:43 - 47:47
    is PLC is keep sending to us. That's
    showing that we are receiving this. But
  • 47:47 - 47:54
    maybe this was too basic. These are the
    raw data which we are getting from the
  • 47:54 - 47:58
    PLC. Let's actually do it a little more
    complex. Show something that is not from
  • 47:58 - 48:04
    us. So let's play a game called tic tac
    toe inside the PLC. And I guess if you
  • 48:04 - 48:09
    don't know, this is how tic tac toe is
    like this is I am playing and I just draw
  • 48:09 - 48:20
    with the google. So. Now we are again are
    going to send our custom payload. But this
  • 48:20 - 48:25
    time we are just use partial quotes from
    somebody else from the Internet and just
  • 48:25 - 48:30
    upload, compile it and then upload it to
    the PLC. Obviously, you have to readjust
  • 48:30 - 48:39
    lots of things. But so we are sending our
    payload, including a stager and these are
  • 48:39 - 48:45
    the raw data. Again, these are our client.
    And eventually you will see a tic tac toe
  • 48:45 - 48:50
    interface, which you have to enter. So
    Player 1 is actually playing with the X
  • 48:50 - 48:55
    and player 2 is playing with like 0. So
    you see of any positioning, which you
  • 48:55 - 49:05
    choose. You have X, X and hopefully a
    player one wins. Yes. So that was it. So
  • 49:05 - 49:16
    that was a demo.
    applause
  • 49:16 - 49:20
    Obviously, there are lots of other ideas
    which we can work on, on injecting other
  • 49:20 - 49:25
    custom code, using the special access
    functionality, we are still working on
  • 49:25 - 49:30
    this. Like lots of other things on
    Siemens, we are sorry Siemens we are just
  • 49:30 - 49:36
    working on this, but there are more to
    come. But in the meantime, there are some
  • 49:36 - 49:41
    ideas for other people in case they are
    looking into this and one to investigate
  • 49:41 - 49:46
    security of Siemens PLCs. So using this as
    special access entry, you can do somewhat
  • 49:46 - 49:50
    certain things. So, for example, you can
    use this prophylaxis functionality to
  • 49:50 - 49:55
    write to the firmware. As we mentioned,
    this functionality is available and it
  • 49:55 - 49:59
    doesn't require those cryptographic
    signature which normally during update
  • 49:59 - 50:04
    process of the firmware available. So you
    can just bypass it and it's just CRC
  • 50:04 - 50:09
    checksum. So what you can do is that, for
    example, adding entry to organize like
  • 50:09 - 50:13
    initialization routine, which is
    available. And then also you can do it
  • 50:13 - 50:19
    before organized initialization routine,
    which we call internal th_initial
  • 50:20 - 50:21
    Another one which we can do,
  • 50:21 - 50:24
    if you remember,
    Tobias talked about some undocumented and
  • 50:24 - 50:28
    lots of creativity on creating music.
    li li li lo lo lo
  • 50:28 - 50:31
    So what one person can do is
  • 50:31 - 50:36
    like basically adding specific handler or
    overwriting existing handler. And what it
  • 50:36 - 50:40
    makes actually is like something like
    triton. I don't know if anybody know her,
  • 50:40 - 50:43
    but triton is malware which were
    attacking petrochemical plant
  • 50:43 - 50:44
    in Saudi Arabia.
    So they were trying
  • 50:44 - 50:48
    to do it in the TCP. But
    attacker here can maybe do it in http
  • 50:48 - 50:54
    example and just listen and waiting for
    comments and also other alternatives like
  • 50:54 - 51:01
    patching one of the jump tables in the AWP
    handlers, which can be also used for
  • 51:01 - 51:09
    process a specific attack. So what else is
    out there? So what we looked is we looked
  • 51:10 - 51:11
    We looked at
  • 51:11 - 51:16
    at attack surface in the Siemens S7 PLCs.
    There are like for from prospective on
  • 51:16 - 51:20
    local privilege attacks. What we can...
    what we looked was bootloader. We are
  • 51:20 - 51:25
    still working on hardware attacks and some
    hardware software attacks on the edge. Is
  • 51:25 - 51:31
    this still ongoing work, which we don't
    obviously discuss now? Also interesting
  • 51:31 - 51:35
    thing, I think if somebody who is
    interested in security of PLCs and
  • 51:35 - 51:39
    especially internals, I'm not talking
    about like just general segregation of
  • 51:39 - 51:43
    network and stuff like that in ICS, I'm
    talking about more advanced low level
  • 51:43 - 51:51
    stuff. We think like MWSL is interesting
    target. There probably are some like bugs
  • 51:51 - 51:56
    in their implementations. Also, with
    respect to file system parsing and
  • 51:56 - 52:01
    firmware signing, there are probably
    some stuff and also MC7 parser basically,
  • 52:01 - 52:07
    which they have from privilege escalation
    perspective and also from remote code
  • 52:07 - 52:14
    execution perspective, both
    MiniWeb webserver and also any network
  • 52:14 - 52:18
    access of accessible services which they
    have might be interesting. You're actually
  • 52:18 - 52:28
    also looking at this part right now. So as
    a conclusion. PLCs are becoming more
  • 52:28 - 52:31
    complex. That's true, because they are
    actually providing more and more features
  • 52:31 - 52:35
    and because of this more complexity, there
    will be more bugs. We can see, for
  • 52:35 - 52:42
    example, in the MWSL, which we are looking
    at now, also bend or strike to basically
  • 52:42 - 52:47
    more make it more complex. They have
    basically some anti debugging which we
  • 52:47 - 52:53
    just discussed in Siemens PLCs, but also
    they have, for example, frame rate
  • 52:53 - 52:59
    integrity verification so that the sign
    frame where like upload to the PLC and
  • 52:59 - 53:06
    stuff like that. So they are making it
    more complex. But what you have to know is
  • 53:06 - 53:14
    that if in their like thread model which
    like lots of people make or this security
  • 53:14 - 53:20
    ecosystem which they built. If they have a
    feature which undermines the same security
  • 53:20 - 53:24
    ecosystem which they designed. I mean, I
    think it's obvious that they have to
  • 53:24 - 53:28
    remove like in the case of bootloader case
    in their special access features. One of
  • 53:28 - 53:32
    the good examples. So. And of course,
    customers also have to know, because if
  • 53:32 - 53:36
    they have such functionality and they need
    it, as long as customers know, it's fine.
  • 53:36 - 53:41
    But when they don't, they can't risk
    calculate this risk in their strategy or
  • 53:41 - 53:47
    in this threat model, which they have. So.
    And also they have to think or rethink
  • 53:47 - 53:51
    about security by obscurity. Maybe they
    allow us, for example, as researchers to
  • 53:51 - 53:54
    access the devices
    better and easier
  • 53:54 - 53:56
    to investigate it more. We are still doing
  • 53:56 - 54:01
    it, but it's just taking longer. And I
    believe that there are lots of seeing more
  • 54:01 - 54:08
    to be done on like PLCs and Siemens will
    not be the last one which we are working
  • 54:08 - 54:14
    on. So we have to thank some people
    Thorsten Holz our supervisor, he's not
  • 54:14 - 54:21
    here. Thomas, Alexandre, Marina, Lucian,
    Nikita and Robin. For their help and
  • 54:21 - 54:27
    their work. And now we are going to answer
    questions.
  • 54:27 - 54:28
    Herald: Thank you.
  • 54:28 - 54:37
    applause
  • 54:39 - 54:47
    Herald: So, yeah, feel free to line up for
    the microphones or write your questions in
  • 54:47 - 54:55
    the Elisa room. Ah, there you go. It's on
    right now I think.
  • 55:02 - 55:07
    Signal Angel: Hello. Yeah. So there is one
    question from the Internet. Did you check
  • 55:07 - 55:16
    the MC7 parser? If yes. Did you find any
    hidden unknown machine instruction
  • 55:16 - 55:22
    on it or something?
    Ail: Do you want to answer? So just is it
  • 55:22 - 55:26
    recorded or I have to repeat it again? So
    they ask that if we check the MC7
  • 55:26 - 55:32
    parser. OK. So it's fine. So we didn't
    like truly investigate the MC7 parser,
  • 55:32 - 55:36
    but we are working on it right now.
  • 55:37 - 55:41
    Mic: Hello? How were you able to find the
  • 55:41 - 55:46
    MFG security password?
    Ali: That's a very long story. First of
  • 55:46 - 55:50
    all, like we had we had it in front of us
    for a long, long time until Siemens
  • 55:50 - 55:56
    introduced this anti debugging feature.
    And after that, like we had to find other
  • 55:56 - 56:02
    ways, other means to find it, to find a
    similar function, like similar ways that
  • 56:02 - 56:06
    allow us because one thing which we didn't
    discuss here is that we didn't tell you
  • 56:06 - 56:12
    about how we, for example, executed that
    instruction before in the PLC. It was
  • 56:12 - 56:18
    involved some works which we received help
    from some researchers in Netherlands and
  • 56:18 - 56:25
    in France. So this is this was something
    informed by Siemens in 2013. I think they
  • 56:25 - 56:31
    knew about it. But until 2016, they
    patched it and then it became out like
  • 56:31 - 56:35
    basically they tried to protect their PLCs
    from these kind of attack. It was never
  • 56:35 - 56:39
    published before. So we were using it. And
    we don't want to talk about it, because
  • 56:39 - 56:43
    the original author didn't want to talk
    about it. But we replicated what they
  • 56:43 - 56:49
    were, what they were doing. And then once
    we really had to look for other ways, like
  • 56:49 - 56:54
    then it opened our eyes that there are
    some other functionalities as well. There
  • 56:54 - 56:58
    are so such as, for example, the
    bootloader. But before we before we need
  • 56:58 - 57:02
    it, like we never actually looked at these
    things. So it was like in front of us for
  • 57:02 - 57:06
    like two years.
    Tobias: Maybe one interesting piece of
  • 57:06 - 57:10
    background story on this is that we
    actually in the previous technique that we
  • 57:10 - 57:16
    used, we actually overrode the conditional
    jump that would lead to this special
  • 57:16 - 57:20
    access feature being executed with an
    unconditional jump. So we basically cut
  • 57:20 - 57:26
    out 60 percent of the whole code of the
    firmware image by accident. And then I
  • 57:26 - 57:30
    just because of the hunch that I was
    talking about before that there is just
  • 57:30 - 57:35
    too much functionality. I revisited it and
    actually realized that it was exactly the
  • 57:35 - 57:42
    spot that we overrode before and we had to
    basically replace it and use it for our
  • 57:42 - 57:43
    own sake.
  • 57:44 - 57:46
    Mic: Is there any boot time security other
  • 57:46 - 57:51
    than the CRC check? So you. Are you able
    to modify the contents of the SPI flash
  • 57:51 - 57:54
    and get arbitrary code execution that way
    as well?
  • 57:55 - 58:02
    Ali: So it depends in which year you are
    talking about 2017, 2016. So we are
  • 58:02 - 58:07
    talking about the same models of the PLC,
    but in 2017 and 2018. No. So you could
  • 58:07 - 58:12
    basically just take out SPI flash
    overwrite it. And that was fine. But if
  • 58:12 - 58:17
    you were overwriting and it caused a halt
    in the CPU core, it would again trigger
  • 58:17 - 58:23
    that anti debugging technology, which they
    have. This watchdog basically but from
  • 58:23 - 58:29
    like frameware integrity verification.
    Well basically once you write to.. the
  • 58:29 - 58:33
    firmware is written to the NAND flash, but
    it's just the CRC checksum. But during the
  • 58:33 - 58:37
    update process? No. There are some
    cryptographic checks, but once it's
  • 58:37 - 58:42
    written, no. There are some problems which
    there which again, it's a still ongoing
  • 58:42 - 58:45
    work and we don't want to discuss about
    it, but nice catch.
  • 58:45 - 58:51
    Mic: Thank you.
    Mic: Hi. Thanks for the talk. Could you
  • 58:51 - 58:55
    elaborate on your communication with the
    vendor and the timeline?
  • 58:55 - 59:00
    Ali: Yes. So, first of all, we know about
    this problem for like one year and half
  • 59:00 - 59:04
    before we reported to the vendor. And the
    primary reason was that we were using it
  • 59:04 - 59:09
    for some other project. This is actually
    this result is actually from a side
  • 59:09 - 59:13
    project rather than the main project,
    because the main project is still
  • 59:13 - 59:18
    something else and is still ongoing. But
    from a side of that projects, we had that
  • 59:18 - 59:22
    access. And because we were worried that
    reporting to the vendor, they can fix it
  • 59:22 - 59:26
    with software update and then do not allow
    all other CVEs which we find from this
  • 59:26 - 59:32
    other project, we didn't want to
    eventually at 2019. Thomas Weber wanted to
  • 59:32 - 59:38
    talk about his talk on like basically this
    JTAG interface with four CoreSight and
  • 59:38 - 59:43
    then we decided to actually talk about it
    as well. But other than that, we actually
  • 59:43 - 59:49
    talked in June I think with Siemens and
    they confirmed that there is this hardware
  • 59:49 - 59:53
    base, a special access feature. And they
    are.. they say that they are going to
  • 59:53 - 59:58
    remove it and that was it. We also send
    them a write up for them to read.
  • 59:58 - 60:03
    Herald: So there is one last question from
    the signal angel over there.
  • 60:04 - 60:09
    Signal Angel: So there's another question
    from the Internet. If tools like flashrom
  • 60:09 - 60:16
    doesn't have support for unknown SPI
    flashrom chip, then how do you usually
  • 60:16 - 60:22
    extract firmware if you don't want to
    decap a chip or use SOIC8 socket.
  • 60:22 - 60:27
    Ali: Can you repeat it again? I didn't get
    the question, did you?
  • 60:27 - 60:32
    Signal Angel: If tools like flashrom does
    not have support for unknown SPI flashrom
  • 60:32 - 60:39
    chip, then how do you usually extract
    firmware if you don't want to decap chip
  • 60:39 - 60:42
    and use SOIC8 socket.
    Ali: So first of all, we never actually
  • 60:42 - 60:49
    decap the SPI flash. So that's just did it
    for the CPU. And just because we want we
  • 60:49 - 60:54
    know that Siemens relabled their PLC, so
    it's not their own CPU, it's from
  • 60:54 - 60:59
    Renesas, but that's why we did the
    decapping. So story of decapoing setting
  • 60:59 - 61:04
    aside. But from other things all basically
    there are still this functionality, this
  • 61:04 - 61:08
    bootloader functionality, which actually
    lets you read the content of the memory.
  • 61:08 - 61:12
    So that's one thing you can read.
    Obviously you don't even need that thanks
  • 61:12 - 61:16
    to one of my students. We now know one
    that's actually you don't even need to
  • 61:16 - 61:21
    take out the bootloader, chip. We
    basically can just connect directly in the
  • 61:21 - 61:28
    board and dump the firmware. Marcello,
    that's his name. He's here, actually. But
  • 61:28 - 61:34
    anyway, so you can just directly read it.
    And yeah, I don't think the reading part,
  • 61:34 - 61:38
    especially some part of it, is protected,
    especially in the recent versions, which
  • 61:38 - 61:43
    you can't read everything. But besides
    that, I don't think there is any harder
  • 61:43 - 61:48
    now yet. I am sure that they are working
    on that and we are working also on
  • 61:48 - 61:52
    something to bypass that. So.
    Herald: Okay. That was our next talk is
  • 61:52 - 61:58
    gonna be about delivery robots. Sasha in
    20 minutes. So let's give you a hand.
  • 61:58 - 62:02
    applause
  • 62:02 - 62:12
    36c3 postrol music
  • 62:12 - 62:35
    Subtitles created by c3subtitles.de
    in the year 2021. Join, and help us!
Title:
36C3 - A Deep Dive Into Unconstrained Code Execution on Siemens S7 PLCs
Description:

more » « less
Video Language:
English
Duration:
01:02:28

English subtitles

Revisions