Security Analysis of Mattermost By Changze Cui & Weihao Dong 1 - - PowerPoint PPT Presentation

security analysis of mattermost
SMART_READER_LITE
LIVE PREVIEW

Security Analysis of Mattermost By Changze Cui & Weihao Dong 1 - - PowerPoint PPT Presentation

Security Analysis of Mattermost By Changze Cui & Weihao Dong 1 What is Mattermost 2 What is Mattermost 3 What is Mattermost 4 Key Difference between Mattermost and Slack Support Self-Hosting yes no Open Source yes no Mattermost


slide-1
SLIDE 1

Security Analysis of Mattermost

By Changze Cui & Weihao Dong

1

slide-2
SLIDE 2

What is Mattermost

2

slide-3
SLIDE 3

What is Mattermost

3

slide-4
SLIDE 4

What is Mattermost

4

slide-5
SLIDE 5

Support Self-Hosting yes no Open Source yes no

Key Difference between Mattermost and Slack

5

Mattermost envisions itself as an open source Slack alternative

slide-6
SLIDE 6

Motivations

8

slide-7
SLIDE 7

Project Timeline

9

Phase3

Acquired and deployed a trial of Enterprise Edition of Mattermost

Phase4

Conducted behavior analysis and source code analysis Network Capture, Static Analysis, Manual Analysis, POC generation

Phase1

Read Documentation Extracted features

Phase2

Came up with Threat Model

slide-8
SLIDE 8

Architecture of Mattermost

10 Notification Service Proxy Email Service

Internet

PC Web Experience

Mobile APP Experience Mobile Web Experience

Email Client https://docs.mattermost.com/deployment/deployment.html

Mattermost Server

HTTPS Secure Web Sockets

Database

(MySQL, Postgres)

File Store

(Amazon S3)

slide-9
SLIDE 9

Features of Mattermost

11 Notification Service Proxy Email Service

Internet

PC Web Experience

Mobile APP Experience Mobile Web Experience

Email Client https://docs.mattermost.com/deployment/deployment.html

RESTful API

Mattermost Server

Data Management Scalability Support

HTTPS Secure Web Sockets

Database

(MySQL, Postgres)

Password Hashing Encryption-at-rest

File Store

(Amazon S3)

OAuth2.0

slide-10
SLIDE 10

Project Timeline

12

Phase3

Acquired and deployed a trial of Enterprise Edition of Mattermost

Phase4

Conducted behavior analysis and source code analysis Network Capture, Static Analysis, Manual Analysis, POC generation

Phase1

Read Documentation Extract features

Phase2

Came up with Threat Model

slide-11
SLIDE 11

How We Come Up With Our Threat Model

13 Notification Service Proxy Email Service

Internet

PC Web Experience

Mobile APP Experience Mobile Web Experience

Email Client https://docs.mattermost.com/deployment/deployment.html

RESTful API

Mattermost Server

Data Management Scalability Support

HTTPS Secure Web Sockets

Database

(MySQL, Postgres)

Password Hashing Encryption-at-rest

File Store

(Amazon S3)

OAuth2.0

slide-12
SLIDE 12

Attackers in Server & Database

14 Notification Service Proxy Email Service

Internet

PC Web Experience

Mobile APP Experience Mobile Web Experience

Email Client https://docs.mattermost.com/deployment/deployment.html

RESTful API

Mattermost Server

Data Management Scalability Support

HTTPS Secure Web Sockets

Database

(MySQL, Postgres)

Password Hashing Encryption-at-rest

File Store

(Amazon S3)

OAuth2.0

slide-13
SLIDE 13

Attackers as Non-Admin Mattermost Users

15 Notification Service Proxy Email Service

Internet

PC Web Experience

Mobile APP Experience Mobile Web Experience

Email Client https://docs.mattermost.com/deployment/deployment.html

RESTful API

Mattermost Server

Data Management Scalability Support

HTTPS Secure Web Sockets

Database

(MySQL, Postgres)

Password Hashing Encryption-at-rest

File Store

(Amazon S3)

OAuth2.0

slide-14
SLIDE 14

Attackers as Non-Users

16 Notification Service Proxy Email Service

Internet

PC Web Experience

Mobile APP Experience Mobile Web Experience

Email Client https://docs.mattermost.com/deployment/deployment.html

RESTful API

Mattermost Server

Data Management Scalability Support

HTTPS Secure Web Sockets

Database

(MySQL, Postgres)

Password Hashing Encryption-at-rest

File Store

(Amazon S3)

OAuth2.0

slide-15
SLIDE 15

Project Timeline

17

Phase3

Acquired and deployed a trial of Enterprise Edition of Mattermost

Phase4

Conducted behavior analysis and source code analysis Network Capture, Static Analysis, Manual Analysis, POC generation

Phase1

Read Documentation Extract features

Phase2

Came up with Threat Model

slide-16
SLIDE 16

Attackers in Server & Database

18 Notification Service Proxy Email Service

Internet

PC Web Experience

Mobile APP Experience Mobile Web Experience

Email Client https://docs.mattermost.com/deployment/deployment.html

RESTful API

Mattermost Server

Data Management Scalability Support

HTTPS Secure Web Sockets

Database

(MySQL, Postgres)

Password Hashing Encryption-at-rest

File Store

(Amazon S3)

OAuth2.0

slide-17
SLIDE 17

Attackers in Server & Database

1. Credential breach 2. Session token stealing 3. Integrated applications can be compromised

19

Everything is readable. But is it the end of the nightmare?

slide-18
SLIDE 18

Attackers in Server & DB - Credential Breach

20

Password

  • Plain text passwords can be used for credential stuffing
  • Mattermost only stores bcrypt hashed passwords into database
  • bcrypt is probably not the best choice with the evolution of parallel hardware 1
  • scrypt and argon2 2 provide better defense against offline parallel cracking

[1] Malvoni, Katja, and Josip Knezovic. “Are your passwords safe: Energy-efficient bcrypt cracking with low-cost parallel hardware.” 8th USENIXWorkshop on Offensive Technologies (WOOT 14). 2014. [2] Biryukov, Alex, Daniel Dinu, and Dmitry Khovratovich. "Argon2: new generation of memory-hard functions for password hashing

and other applications." 2016 IEEE European Symposium on Security and Privacy (EuroS&P). IEEE, 2016.

slide-19
SLIDE 19

Attackers in Server & DB - Credential Breach

21

Password

  • Plain text passwords can be used for credential stuffing
  • Mattermost only stores bcrypt hashed passwords into database
  • bcrypt is probably not the best choice with the evolution of parallel hardware 1
  • scrypt and argon2 2 provide better defense against offline parallel cracking

[1] Malvoni, Katja, and Josip Knezovic. “Are your passwords safe: Energy-efficient bcrypt cracking with low-cost parallel hardware.” 8th USENIXWorkshop on Offensive Technologies (WOOT 14). 2014. [2] Biryukov, Alex, Daniel Dinu, and Dmitry Khovratovich. "Argon2: new generation of memory-hard functions for password hashing

and other applications." 2016 IEEE European Symposium on Security and Privacy (EuroS&P). IEEE, 2016.

slide-20
SLIDE 20

Attackers in Server & DB - Session Stealing

22

  • Session token generated by Google UUID (based on RFC 4122 and DCE 1.1:

Authentication and Security Services)

  • Valid for 180 days
  • Stored in database as plain text
  • Can be stolen and used to impersonate any user
slide-21
SLIDE 21

Attackers in Server & DB - Integrated Applications

23

slide-22
SLIDE 22

Attackers in Server & DB - Integrated Applications

24

Realtime notification Show TODO list

slide-23
SLIDE 23

Attackers in Server & DB - Integrated Applications

25

slide-24
SLIDE 24

Attackers in Server & DB - Integrated Applications

26

slide-25
SLIDE 25

Attackers in Server & DB - Integrated Applications

27

  • GitHub token is AES-256 encrypted and stored in database
  • Encryption key is randomly generated and stored in a json file
  • Still safe when the database is dumped, but not safe when fully compromised
slide-26
SLIDE 26

Attackers in Server & DB - Integrated Applications

28

slide-27
SLIDE 27

Attackers as Non-Admin Mattermost Users

30 Notification Service Proxy Email Service

Internet

PC Web Experience

Mobile APP Experience Mobile Web Experience

Email Client https://docs.mattermost.com/deployment/deployment.html

RESTful API

Mattermost Server

Data Management Scalability Support

HTTPS Secure Web Sockets

Database

(MySQL, Postgres)

Password Hashing Encryption-at-rest

File Store

(Amazon S3)

OAuth2.0

slide-28
SLIDE 28

Attackers as Non-Admin Mattermost Users

Target

  • Intellectual property and trade secret (Posts), as the threat model suggests

Approach

  • Become Mattermost’s system admin (XSS attack, password cracking, SQL injection

etc.)

  • Trick other users (Phishing)
  • Dump the database (SQL injection)

31

A solid step. But what’s next?

slide-29
SLIDE 29

Attackers as Non-Admin Users - XSS attack

32

Session token is stored in cookies

Steal token by XSS attack - document.cookie;

RESTful API of role management

Send <script>XMLHttpRequest.open()</script> to the admin Send [click me](JavAsCripT:alert();) to the admin Token is set to be httponly <> will be escaped to &gt; &lt; URL will be checked before rendered

slide-30
SLIDE 30

Attackers as Non-Admin Users - XSS attack

33

Session token is stored in cookies

Steal token by XSS attack - document.cookie;

RESTful API of role management

Send <script>XMLHttpRequest.open()</script> to the admin Send [click me](JavAsCripT:alert();) to the admin Token is set to be httponly <> will be escaped to &gt; &lt; URL will be checked before rendered

slide-31
SLIDE 31

Attackers as Non-Admin Users - XSS attack

34

Session token is stored in cookies

Steal token by XSS attack - document.cookie;

RESTful API of role management

Send <script>XMLHttpRequest.open()</script> to the admin Send [click me](JavAsCripT:alert();) to the admin Token is set to be httponly <> will be escaped to &gt; &lt;

[click me](javascript:alert();) <a href=javascript:alert();>click me</a>

URL will be checked before rendered

slide-32
SLIDE 32

Attackers as Non-Admin Users - XSS attack

35

Backend sends unescaped text file to user for file preview

Upload a malicious HTML file and trick the admin to preview it

File preview won’t be triggered for a link to the file

Bypass the frontend escape by posting a link to the HTML file Frontend escapes it Content-Disposition in the header is set to attachment

slide-33
SLIDE 33

Attackers as Non-Admin Users - XSS attack

36

Backend sends unescaped text file to user for file preview

Upload a malicious HTML file and trick the admin to preview it

File preview won’t be triggered for a link to the file

Bypass the frontend escape by posting a link to the HTML file Frontend escapes it Content-Disposition in the header is set to attachment

slide-34
SLIDE 34

Attackers as Non-Admin Users - XSS attack

37

Backend sends unescaped text file to user for file preview

Upload a malicious HTML file and trick the admin to preview it

File preview won’t be triggered for a link to the file

Bypass the frontend escape by posting a link to the HTML file Frontend escapes it Content-Disposition in the header is set to attachment

slide-35
SLIDE 35

Attackers as Non-Admin Users - XSS attack

38

Backend sends unescaped text file to user for file preview

Upload a malicious HTML file and trick the admin to preview it

File preview won’t be triggered for a link to the file

Bypass the frontend escape by posting a link to the HTML file Frontend escapes it Content-Disposition in the header is set to attachment

slide-36
SLIDE 36

Attackers as Non-Admin Users - Phishing

39

  • 1. Post a link
  • 2. Send a GET request
  • 3. Return full content
  • 4. Summarize the

content and display User-Agent: Mattermost 5.22

slide-37
SLIDE 37

Attackers as Non-Admin Users - Phishing

40

twittter.com

Aha! It’s Mattermost making link preview

slide-38
SLIDE 38

Attackers as Non-Admin Users - Phishing

41

twittter.com

Aha! It’s a normal user, gonna trick him

slide-39
SLIDE 39

Attackers as Non-Admin Users - Phishing

42

twittter.com

slide-40
SLIDE 40

Attackers as Non-Admin Users - SQL Injection

44

slide-41
SLIDE 41

Attackers as Non-Users

50 Notification Service Proxy Email Service

Internet

PC Web Experience

Mobile APP Experience Mobile Web Experience

Email Client https://docs.mattermost.com/deployment/deployment.html

RESTful API

Mattermost Server

Data Management Scalability Support

HTTPS Secure Web Sockets

Database

(MySQL, Postgres)

Password Hashing Encryption-at-rest

File Store

(Amazon S3)

OAuth2.0

slide-42
SLIDE 42

Attackers as Non-Users - User Onboard

51

  • Email
  • SAML
  • Team Invitation
slide-43
SLIDE 43

User Onboard - Email-based Registration

52

slide-44
SLIDE 44

User Onboard - SAML-based Registration

53 https://www.ubisecure.com/uncategorized/difference-between-saml-and-oauth/

  • A XML-based protocol for exchanging identities between Identity Provider

and Service Provider

  • Used for Authentication
  • Commonly used in Single-sign On application
  • Fundamentally different from OAuth 2.0
slide-45
SLIDE 45

How SAML 2.0 Works

54

Service Provider Identity Provider User

Exchange certificate access service Generate and sign the auth request Redirect user to identity provider along with the auth request User logs in Verify auth request and Redirect user to service provider along with auth response User logs in the service

1 2 3 5 4 7 8

Generate auth response

6

slide-46
SLIDE 46

SAML 2.0 - Sample Auth Request

https://developers.onelogin.com/saml/examples/authnrequest 56

slide-47
SLIDE 47

SAML 2.0 - Sample Auth Response

https://developers.onelogin.com/saml/examples/response 57

slide-48
SLIDE 48

SAML Signature Algorithm is not Safe

58

slide-49
SLIDE 49

If attackers could forge the Signature

Identity Provider 2) Auth request 3) Eavesdropping Mattermost 1) visit 4) Sign the fake Auth Response

59

Hard but possible

slide-50
SLIDE 50

User Onboard - Team Invitation

60

slide-51
SLIDE 51

User Onboard - Team Invitation

61

http just for test

slide-52
SLIDE 52

Attackers as Non-Users - Team Invitation

62

slide-53
SLIDE 53

Attackers as Non-Users - Team Invitation

63

slide-54
SLIDE 54

Attackers as Non-Users - Team Invitation

64

slide-55
SLIDE 55

Attackers as Non-Users - Login

65

slide-56
SLIDE 56

Attackers as Non-Users - Login

66

slide-57
SLIDE 57

Attackers as Non-Users - Login

67

slide-58
SLIDE 58

Attackers as Non-Users - Phishing with webhook

Exposed URL Application A Application B

slide-59
SLIDE 59

Attackers as Non-Users - Phishing with webhook

72

  • 4. HTTP POST: {“text”: “alarm!”}
  • 6. Steal

admin’s account admin

  • 7. HTTP POST: {“text”: “phishing!”}
slide-60
SLIDE 60

Attackers as Non-Users - Phishing with webhook

73

  • A BOT tag is attached to messages posted by webhook
  • Allows username and icon override

Changze is our new team leader now, please add changze@evil.com to the github repo.

slide-61
SLIDE 61

Attackers in Supply Chain Vulnerabilities

74 Notification Service Proxy Email Service

Internet

PC Web Experience

Mobile APP Experience Mobile Web Experience

Email Client https://docs.mattermost.com/deployment/deployment.html

RESTful API

Mattermost Server

Data Management Scalability Support

HTTPS Secure Web Sockets

Database

(MySQL, Postgres)

Password Hashing Encryption-at-rest

File Store

(Amazon S3)

OAuth2.0

slide-62
SLIDE 62

Attackers in Supply Chain Vulnerabilities

Mattermost Server

271 open source projects in total 49 personal projects

slide-63
SLIDE 63

76

Attackers in Supply Chain Vulnerabilities

slide-64
SLIDE 64

Attackers Aiming at Plugins

  • Allows installing plugin binaries from untrusted third party
  • No permission control for plugins
  • Plugins have the same permission as Mattermost itself

77

slide-65
SLIDE 65

Future Work Beyond Our Project

  • A closer look at Mattermost

○ Notification system ○ Client side software ○ Upgrading ○ License Management

  • Apply our investigation method to similar applications (e.g., Slack)

78

slide-66
SLIDE 66

Thanks

79