continuous intrusion: why ci tools are an attacker’s best friends

65
1

Upload: nikhil-mittal

Post on 13-Jan-2017

667 views

Category:

Technology


0 download

TRANSCRIPT

Page 1: Continuous intrusion: Why CI tools are an attacker’s best friends

1

Page 2: Continuous intrusion: Why CI tools are an attacker’s best friends

2

Page 3: Continuous intrusion: Why CI tools are an attacker’s best friends

3

Page 4: Continuous intrusion: Why CI tools are an attacker’s best friends

4

Page 5: Continuous intrusion: Why CI tools are an attacker’s best friends

More about Continuous Integration: http://www.martinfowler.com/articles/continuousIntegration.html

5

Page 6: Continuous intrusion: Why CI tools are an attacker’s best friends

6

Page 7: Continuous intrusion: Why CI tools are an attacker’s best friends

7

Page 8: Continuous intrusion: Why CI tools are an attacker’s best friends

* Hudson was not evaluated separately. Most of the things which apply on Jenkins should apply on Hudson as well.

8

Page 9: Continuous intrusion: Why CI tools are an attacker’s best friends

9

Page 10: Continuous intrusion: Why CI tools are an attacker’s best friends

10

Page 11: Continuous intrusion: Why CI tools are an attacker’s best friends

11

Page 13: Continuous intrusion: Why CI tools are an attacker’s best friends

The rights of the user to add or change build configuration are managed using Matrix based security or Project-based Matrix Authorization Strategy.https://wiki.jenkins-ci.org/display/JENKINS/Matrix-based+security

When running commands on a Windows machine we can leverage PowerShell to execute advanced scripts using this method.

13

Page 14: Continuous intrusion: Why CI tools are an attacker’s best friends

The Jenkins service must be restarted after that. During the tests, I was unable to successfully restart the Jenkins service from a build step even on Windows (with SYSTEM privileges). The workaround is to have an interactive reverse shell on the host machine and restart Jenkins service.

Jenkins documentation on Disabling Securityhttps://wiki.jenkins-ci.org/display/JENKINS/Disable+security

14

Page 15: Continuous intrusion: Why CI tools are an attacker’s best friends

https://imgflip.com/memegenerator/Surprised-Koala

15

Page 16: Continuous intrusion: Why CI tools are an attacker’s best friends

Taken from http://thiébaud.fr/jenkins_credentials.html

16

Page 17: Continuous intrusion: Why CI tools are an attacker’s best friends

We need credentials.xml from $JENKINS_HOME and master.key and hudson.util.secret from $JENKINS_HOME/secrets/

We are reading the keys master.key and hudson.util.secret in bytes and will convert them back to file on our own machine. On a Windows machine the conversion could be done by using TextToExe.ps1 from Nishang. https://github.com/samratashok/nishang/blob/master/Utility/TexttoExe.ps1

17

Page 18: Continuous intrusion: Why CI tools are an attacker’s best friends

18

Page 19: Continuous intrusion: Why CI tools are an attacker’s best friends

19

Page 20: Continuous intrusion: Why CI tools are an attacker’s best friends

20

Page 21: Continuous intrusion: Why CI tools are an attacker’s best friends

21

Page 22: Continuous intrusion: Why CI tools are an attacker’s best friends

https://confluence.jetbrains.com/display/TCD9/Getting+Started

22

Page 23: Continuous intrusion: Why CI tools are an attacker’s best friends

https://confluence.jetbrains.com/pages/viewpage.action?pageId=54334889#HowTo...-TeamCitySecurityNotes

23

Page 24: Continuous intrusion: Why CI tools are an attacker’s best friends

24

Page 25: Continuous intrusion: Why CI tools are an attacker’s best friends

https://confluence.jetbrains.com/display/TCD9/Role+and+Permission

Teamcity documentation recommends not to have build agent on master but looks like only few care about that.

25

Page 26: Continuous intrusion: Why CI tools are an attacker’s best friends

A Build Step could be added with the Project Administrator or even lower privileges (if configured that way). PowerShell commands and scripts could be executed using the PowerShell runner.https://confluence.jetbrains.com/display/TCD9/PowerShell

On *nix machines, shell commands and scripts could be executed.

26

Page 27: Continuous intrusion: Why CI tools are an attacker’s best friends

https://confluence.jetbrains.com/display/TCD9/Super+UserFun Fact: You can lock out SuperUser for one minute by clicking Log in button five times without entering a Username and Password. This makes it easy to block it by repeating login requests indefinitely.

27

Page 28: Continuous intrusion: Why CI tools are an attacker’s best friends

28

Page 29: Continuous intrusion: Why CI tools are an attacker’s best friends

29

Page 30: Continuous intrusion: Why CI tools are an attacker’s best friends

https://confluence.jetbrains.com/display/TCD9/SSH+Keys+Management

Here is how it could be done:1. To know the data directory of the master, look for “Data Directory” in the

teamcity-server.log. Use a PowerShell runner.2. Use “cat <TeamCity Data

Directory>\config\projects\<project>\pluginData\ssh_keys\ *” to list contents of all the keys.

30

Page 31: Continuous intrusion: Why CI tools are an attacker’s best friends

31

Page 32: Continuous intrusion: Why CI tools are an attacker’s best friends

Teamcity supports using the Password type Parameter for passwords but I have seen so many users using Text Parameter for passwords.See: https://confluence.jetbrains.com/display/TCD9/Typed+Parameters

32

Page 33: Continuous intrusion: Why CI tools are an attacker’s best friends

33

Page 34: Continuous intrusion: Why CI tools are an attacker’s best friends

Couple of examples of credentials in Build Logs. In both the above screenshots, access to public instances and the Build Logs is with Guest privileges.

34

Page 35: Continuous intrusion: Why CI tools are an attacker’s best friends

35

Page 36: Continuous intrusion: Why CI tools are an attacker’s best friends

http://www.go.cd/http://www.thoughtworks.com/products/go-continuous-delivery

36

Page 37: Continuous intrusion: Why CI tools are an attacker’s best friends

http://support.thoughtworks.com/entries/22299328-Go-Security-Questions

37

Page 38: Continuous intrusion: Why CI tools are an attacker’s best friends

38

Page 39: Continuous intrusion: Why CI tools are an attacker’s best friends

http://support.thoughtworks.com/entries/22873043-go-s-custom-commandhttp://www.go.cd/documentation/user/current/advanced_usage/command_repository.html

39

Page 40: Continuous intrusion: Why CI tools are an attacker’s best friends

We need Pipeline Group Administrator rights to be able to configure Jobs which can run custom commands.

40

Page 41: Continuous intrusion: Why CI tools are an attacker’s best friends

41

Page 42: Continuous intrusion: Why CI tools are an attacker’s best friends

In above, the command cmd /c powershell -c del 'C:\Program Files (x86)\Go Server\config\cruise-config.xml’ will remove the configuration file of Go.The command cmd /c powershell –c Restart-Service 'Go Server‘ will restart the Go Server service.After this, all security will be removed from the Go dashboard and anyone who knows the URL will have admin rights.

Instead of removing the cruise-config.xml file, we can also remove only the <security></security> part of it and restart the Go Server service for same effect.

Or we can add the current user to <admins> in the <security> part of cruise-config.xml

42

Page 43: Continuous intrusion: Why CI tools are an attacker’s best friends

43

Page 44: Continuous intrusion: Why CI tools are an attacker’s best friends

Documentation on using password files:http://www.go.cd/documentation/user/current/configuration/dev_authentication.htmlhttps://github.com/gocd/gocd/blob/master/manual-testing/ant_hg/password.properties

Location of SSH keys is:C:/Program Files (x86)/Go Server/%HOMEDRIVE%%HOMEPATH%/.ssh/var/go/.ssh on Linux

44

Page 45: Continuous intrusion: Why CI tools are an attacker’s best friends

45

Page 46: Continuous intrusion: Why CI tools are an attacker’s best friends

46

Page 47: Continuous intrusion: Why CI tools are an attacker’s best friends

47

Page 48: Continuous intrusion: Why CI tools are an attacker’s best friends

48

Page 49: Continuous intrusion: Why CI tools are an attacker’s best friends

Documentation for the exec builder:http://cruisecontrol.sourceforge.net/main/configxml.html#exec

49

Page 50: Continuous intrusion: Why CI tools are an attacker’s best friends

50

Page 51: Continuous intrusion: Why CI tools are an attacker’s best friends

51

Page 52: Continuous intrusion: Why CI tools are an attacker’s best friends

52

Page 53: Continuous intrusion: Why CI tools are an attacker’s best friends

Also see: https://github.com/foxglovesec/JavaUnserializeExploitshttps://github.com/frohoff/ysoserial

53

Page 54: Continuous intrusion: Why CI tools are an attacker’s best friends

I am using an encoded one line PowerShell reverse shell from Nishang as the payload in the above screenshot. (https://github.com/samratashok/nishang/blob/master/Shells/Invoke-PowerShellTcpOneLine.ps1)

54

Page 55: Continuous intrusion: Why CI tools are an attacker’s best friends

55

Page 56: Continuous intrusion: Why CI tools are an attacker’s best friends

56

Page 57: Continuous intrusion: Why CI tools are an attacker’s best friends

57

Page 58: Continuous intrusion: Why CI tools are an attacker’s best friends

58

Page 59: Continuous intrusion: Why CI tools are an attacker’s best friends

59

Page 60: Continuous intrusion: Why CI tools are an attacker’s best friends

60

Page 61: Continuous intrusion: Why CI tools are an attacker’s best friends

61

Page 62: Continuous intrusion: Why CI tools are an attacker’s best friends

62

Page 63: Continuous intrusion: Why CI tools are an attacker’s best friends

63

Page 64: Continuous intrusion: Why CI tools are an attacker’s best friends

64

Page 65: Continuous intrusion: Why CI tools are an attacker’s best friends

65