hacktricks/cloud-security/workspace-security.md

257 lines
16 KiB
Markdown
Raw Normal View History

2022-04-28 18:01:33 +02:00
<details>
<summary><strong>Support HackTricks and get benefits!</strong></summary>
Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
**Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/carlospolopm)**.**
**Share your hacking tricks submitting PRs to the** [**hacktricks github repo**](https://github.com/carlospolop/hacktricks)**.**
</details>
2022-05-01 14:41:36 +02:00
# Workspace Phishing
2022-02-17 17:34:34 +01:00
2022-05-01 14:41:36 +02:00
## Generic Phishing Methodology
2022-02-17 19:17:32 +01:00
2022-02-18 14:19:49 +01:00
{% content-ref url="../phishing-methodology/" %}
[phishing-methodology](../phishing-methodology/)
{% endcontent-ref %}
2022-02-17 19:17:32 +01:00
2022-05-01 14:41:36 +02:00
## Google Groups Phishing
2022-02-17 17:34:34 +01:00
2022-02-18 14:19:49 +01:00
Apparently by default in workspace members [**can create groups**](https://groups.google.com/all-groups) **and invite people to them**. You can then modify the email that will be sent to the user **adding some links.** The **email will come from a google address**, so it will looks **legit** and people might click on the link.
2022-02-17 17:34:34 +01:00
2022-05-01 14:41:36 +02:00
## Hangout Phishing
2022-02-17 19:17:32 +01:00
2022-02-18 03:15:30 +01:00
You might be able either to directly talk with a person just having his email address or sending an invitation to talk. Either way, modify an email account maybe naming it "Google Security" and adding some Google logos, and the people will think they are talking to google: [https://www.youtube.com/watch?v=KTVHLolz6cE\&t=904s](https://www.youtube.com/watch?v=KTVHLolz6cE\&t=904s)
2022-02-18 14:19:49 +01:00
Just the **same technique** can be used with **Google Chat**.
2022-05-01 14:41:36 +02:00
## Google Doc Phishing
2022-02-18 03:15:30 +01:00
You can create an **apparently legitimate document** and the in a comment **mention some email (like +user@gmail.com)**. Google will **send an email to that email address** notifying that he was mentioned in the document. You can **put a link in that document** to try to make the persona access it.
2022-05-01 14:41:36 +02:00
## Google Calendar Phishing
2022-02-18 03:15:30 +01:00
You can **create a calendar event** and add as many email address of the company you are attacking as you have. Schedule this calendar event in **5 or 15 min** from the current time. Make the event looks legit and **put a comment indicating that they need to read something** (with the **phishing link**).\
To make it looks less suspicious:
* Set that the **receivers cannot see the other invited people**
* Do **NOT send emails notifying about the event**. Then, the people will only see their warning about a meeting in 5mins and that they need to read that link.
* Apparently using the API you can set to **True** that **people** has **accepted** the event and even create **comments on their behalf**.
2022-02-17 19:17:32 +01:00
2022-05-01 14:41:36 +02:00
## OAuth Phishing
2022-02-18 14:19:49 +01:00
Any of the previous techniques might be used to make the user access a **Google OAuth application** that will **request** the user some **access**. If the user **trust** the **source** he might **trust** the **application** (even if it's asking for high privileged permissions).
Note that Google presents an ugly prompt asking warning that the application is untrusted in several cases and from Workspace admins can even prevent people to accept OAuth applications. More on this in the OAuth section.
2022-05-01 14:41:36 +02:00
# Password Spraying
2022-02-18 14:19:49 +01:00
In order to test passwords with all the emails you found (or you have generated based in a email name pattern you might have discover) you can use a tool like [**https://github.com/ustayready/CredKing**](https://github.com/ustayready/CredKing) who will use AWS lambdas to change IP address.
2022-05-01 14:41:36 +02:00
# Oauth Apps
2022-02-17 17:34:34 +01:00
**Google** allows to create applications that can **interact on behalf users** with several **Google services**: Gmail, Drive, GCP...
When creating an application to **act on behalf other users**, the developer needs to create an **OAuth app inside GCP** and indicate the scopes (permissions) the app needs to access the users data.\
When a **user** wants to **use** that **application**, he will be **prompted** to **accept** that the application will access to his data specified in the scopes.
This is a very juicy way to **phish** non-technical users into using **applications that access sensitive information** because they might not understand the consequences. Therefore, in organizations accounts, there are ways to prevent this from happening.
2022-05-01 14:41:36 +02:00
## Unverified App prompt
2022-02-17 17:34:34 +01:00
As it was mentioned, google will always present a **prompt to the user to accept** the permissions he is giving the application on his behalf. However, if the application is considered **dangerous**, google will show **first** a **prompt** indicating that it's **dangerous** and **making more difficult** to the user to grant the permissions to the app.
This prompt appears in apps that:
* Uses any scope that can access to private data (Gmail, Drive, GCP, BigQuery...)
* Apps with less than 100 users (apps > 100 a review process is needed also to not show the unverified prompt)
2022-05-01 14:41:36 +02:00
## Interesting Scopes
2022-02-17 17:34:34 +01:00
You can [**find here**](https://developers.google.com/identity/protocols/oauth2/scopes) a list of all the Google OAuth scopes.
* **cloud-platform**: View and manage your data across **Google Cloud Platform** services. You can impersonate the user in GCP.
* **directory.readonly**: See and download your organization's GSuite directory. Get names, phones, calendar URLs of all the users.
2022-05-01 14:41:36 +02:00
# App Scripts
2022-02-17 17:34:34 +01:00
Developers can create App Scripts and set them as a standalone project or bound them to Google Docs/Sheets/Slides/Forms. App Scripts is code that will be triggered when a user with editor permission access the doc (and after accepting the OAuth prompt)
However, even if the app isn't verified there are a couple of ways to not show that prompt:
* If the publisher of the app is in the same Workspace as the user accessing it
* If the script is in a drive of the user
2022-05-01 14:41:36 +02:00
## Copy Document Unverified Prompt Bypass
2022-02-17 17:34:34 +01:00
When you create a link to share a document a link similar to this one is created: `https://docs.google.com/spreadsheets/d/1i5[...]aIUD/edit`\
If you **change** the ending **"/edit"** for **"/copy"**, instead of accessing it google will ask you if you want to **generate a copy of the document.**
{% hint style="warning" %}
If someone creates a **copy** of that **document** that **contained the App Script**, he will also be **copying the App Script**, therefore when he **opens** the copied **spreadsheet**, the **regular OAuth prompt** will appear **bypassing the unverified prompt**, because **the user is now the author of the App Script of the copied file**.
{% endhint %}
This method will be able to bypass also the Workspace admin restriction:
2022-04-22 10:32:18 +02:00
![](<../.gitbook/assets/image (662) (1) (1) (1).png>)
2022-02-17 17:34:34 +01:00
But can be prevented with:
2022-02-17 19:17:32 +01:00
![](<../.gitbook/assets/image (632).png>)
2022-02-17 17:34:34 +01:00
2022-05-01 14:41:36 +02:00
## Shared Document Unverified Prompt Bypass
2022-02-17 17:34:34 +01:00
Moreover, if someone **shared** with you a document with **editor access**, you can generate **App Scripts inside the document** and the **OWNER (creator) of the document will be the owner of the App Script**.
{% hint style="warning" %}
This means, that the **creator of the document will appear as creator of any App Script** anyone with editor access creates inside of it.
This also means that the **App Script will be trusted by the Workspace environment** of the creator of the document.
{% endhint %}
{% hint style="danger" %}
This also means that if an **App Script already existed** and people has **granted access**, anyone with **Editor** permission to the doc can **modify it and abuse that access.**\
2022-04-06 00:24:52 +02:00
To abuse this you also need people to trigger the App Script. And one neat trick if to **publish the script as a web app**. When the **people** that already granted **access** to the App Script access the web page, they will **trigger the App Script** (this also works using `<img>` tags.
2022-02-17 17:34:34 +01:00
{% endhint %}
2022-05-01 14:41:36 +02:00
# Post-Exploitation
2022-02-17 17:34:34 +01:00
2022-05-01 14:41:36 +02:00
## Google Groups Privesc
2022-02-18 14:19:49 +01:00
By default in workspace a **group** can be **freely accessed** by any member of the organization.\
Workspace also allow to **grant permission to groups** (even GCP permissions), so if groups can be joined and they have extra permissions, an attacker may **abuse that path to escalate privileges**.
You potentially need access to the console to join groups that allow to be joined by anyone in the org. Check groups information in [**https://groups.google.com/all-groups**](https://groups.google.com/all-groups).
2022-05-01 14:41:36 +02:00
## Privesc to GCP Summary
2022-02-17 19:17:32 +01:00
* Abusing the **google groups privesc** you might be able to escalate to a group with some kind of privileged access to GCP
* Abusing **OAuth applications** you might be able to impersonate users and access to GCP on their behalf
2022-05-01 14:41:36 +02:00
## Access Groups Mail info
2022-02-18 03:15:30 +01:00
2022-04-22 10:32:18 +02:00
If you managed to **compromise a google user session**, from [**https://groups.google.com/all-groups**](https://groups.google.com/all-groups) you can see the history of mails sent to the mail groups the user is member of, and you might find **credentials** or other **sensitive data**.
2022-02-18 03:15:30 +01:00
2022-05-01 14:41:36 +02:00
## Takeout - Download Everything Google Knows about an account
2022-02-18 03:15:30 +01:00
2022-04-06 00:24:52 +02:00
If you have a **session inside victims google account** you can download everything Google saves about that account from [**https://takeout.google.com**](https://takeout.google.com/u/1/?pageId=none)
2022-02-18 03:15:30 +01:00
2022-05-01 14:41:36 +02:00
## Vault - Download all the Workspace data of users
2022-02-18 03:15:30 +01:00
2022-04-22 10:32:18 +02:00
If an organization has **Google Vault enabled**, you might be able to access [**https://vault.google.com**](https://vault.google.com/u/1/) and **download** all the **information**.
2022-02-18 03:15:30 +01:00
2022-05-01 14:41:36 +02:00
## Contacts download
2022-02-18 03:15:30 +01:00
2022-02-18 14:19:49 +01:00
From [**https://contacts.google.com**](https://contacts.google.com/u/1/?hl=es\&tab=mC) you can download all the **contacts** of the user.
2022-02-18 03:15:30 +01:00
2022-05-01 14:41:36 +02:00
## Cloudsearch
2022-02-18 03:15:30 +01:00
2022-02-18 14:19:49 +01:00
In [**https://cloudsearch.google.com/**](https://cloudsearch.google.com) you can just search **through all the Workspace content** (email, drive, sites...) a user has access to. Ideal to **find quickly sensitive information**.
2022-02-18 03:15:30 +01:00
2022-05-01 14:41:36 +02:00
## Currents
2022-02-18 03:15:30 +01:00
2022-02-18 14:19:49 +01:00
In [**https://currents.google.com/**](https://currents.google.com) you can access a Google **Chat**, so you might find sensitive information in there.
2022-02-18 03:15:30 +01:00
2022-05-01 14:41:36 +02:00
## Google Drive Mining
2022-02-17 17:34:34 +01:00
When **sharing** a document yo can **specify** the **people** that can access it one by one, **share** it with your **entire company** (**or** with some specific **groups**) by **generating a link**.
When sharing a document, in the advance setting you can also **allow people to search** for this file (by **default** this is **disabled**). However, it's important to note that once users views a document, it's searchable by them.
For sake of simplicity, most of the people will generate and share a link instead of adding the people that can access the document one by one.
Some proposed ways to find all the documents:
* Search in internal chat, forums...
2022-04-06 00:24:52 +02:00
* **Spider** known **documents** searching for **references** to other documents. You can do this within an App Script with[ **PaperChaser**](https://github.com/mandatoryprogrammer/PaperChaser)
2022-02-17 17:34:34 +01:00
2022-05-01 14:41:36 +02:00
## **Keep Notes**
2022-02-18 14:19:49 +01:00
In [**https://keep.google.com/**](https://keep.google.com) you can access the notes of the user, **sensitive** **information** might be saved in here.
2022-05-01 14:41:36 +02:00
## Persistence inside a Google account
2022-02-18 14:19:49 +01:00
If you managed to **compromise a google user session** and the user had **2FA**, you can **generate** an [**app password**](https://support.google.com/accounts/answer/185833?hl=en) and **regenerate the 2FA backup codes** to know that even if the user change the password you **will be able to access his account**. Another option **instead** of **regenerating** the codes is to **enrol your own authenticator** app in the 2FA.
2022-05-01 14:41:36 +02:00
## Persistence via OAuth Apps
2022-02-18 14:19:49 +01:00
If you have **compromised the account of a user,** you can just **accept** to grant all the possible permissions to an **OAuth App**. The only problem is that Workspace can configure to **disallow external and/or internal OAuth apps** without being reviewed.\
It is pretty common to not trust by default external OAuth apps but trust internal ones, so if you have **enough permissions to generate a new OAuth application** inside the organization and external apps are disallowed, generate it and **use that new internal OAuth app to maintain persistence**.
2022-05-01 14:41:36 +02:00
## Persistence via delegation
2022-02-18 14:19:49 +01:00
You can just **delegate the account** to a different account controlled by the attacker.
2022-05-01 14:41:36 +02:00
## Persistence via Android App
2022-02-18 14:19:49 +01:00
If you have a **session inside victims google account** you can browse to the **Play Store** and **install** a **malware** you have already uploaded it directly **in the phone** to maintain persistence and access the victims phone.
2022-05-01 14:41:36 +02:00
## **Persistence via Gmail**
2022-02-17 17:34:34 +01:00
* You can create **filters to hide** security notifications from Google
* from: (no-reply@accounts.google.com) "Security Alert"
* Hide password reset emails
2022-02-18 14:19:49 +01:00
* Create **forwarding address to forward sensitive information** (or everything) - You need manual access.
2022-02-17 17:34:34 +01:00
* Create a forwarding address to send emails that contains the word "password" for example
2022-02-18 14:19:49 +01:00
* Add **recovery email/phone under attackers control**
2022-05-01 14:41:36 +02:00
## **Persistence via** App Scripts
2022-02-18 14:19:49 +01:00
You can create **time-based triggers** in App Scripts, so if the App Script is accepted by the user, it will be **triggered** even **without the user accessing it**.
The docs mention that to use `ScriptApp.newTrigger("funcion")` you need the **scope** `script.scriptapp`, but **apparently thats not necessary** as long as you have declare some other scope.
2022-05-01 14:41:36 +02:00
## **Administrate Workspace**
2022-02-17 17:34:34 +01:00
2022-02-18 14:19:49 +01:00
In [**https://admin.google.com**/](https://admin.google.com), if you have enough permissions you might be able to modify settings in the Workspace of the whole organization.
2022-02-17 17:34:34 +01:00
2022-04-06 00:24:52 +02:00
You can also search emails through all the users invoices in [**https://admin.google.com/ac/emaillogsearch**](https://admin.google.com/ac/emaillogsearch)
2022-02-17 17:34:34 +01:00
2022-05-01 14:41:36 +02:00
# Account Compromised Recovery
2022-02-18 03:15:30 +01:00
* Log out of all sessions
* Change user password
* Generate new 2FA backup codes
* Remove App passwords
* Remove OAuth apps
* Remove 2FA devices
* Remove email forwarders
* Remove emails filters
* Remove recovery email/phones
* Remove bad Android Apps
* Remove bad account delegations
2022-05-01 14:41:36 +02:00
# References
2022-02-17 17:34:34 +01:00
* [https://www.youtube-nocookie.com/embed/6AsVUS79gLw](https://www.youtube-nocookie.com/embed/6AsVUS79gLw) - Matthew Bryant - Hacking G Suite: The Power of Dark Apps Script Magic
2022-02-18 14:19:49 +01:00
* [https://www.youtube.com/watch?v=KTVHLolz6cE](https://www.youtube.com/watch?v=KTVHLolz6cE) - Mike Felch and Beau Bullock - OK Google, How do I Red Team GSuite?
2022-04-28 18:01:33 +02:00
<details>
<summary><strong>Support HackTricks and get benefits!</strong></summary>
Do you work in a **cybersecurity company**? Do you want to see your **company advertised in HackTricks**? or do you want to have access the **latest version of the PEASS or download HackTricks in PDF**? Check the [**SUBSCRIPTION PLANS**](https://github.com/sponsors/carlospolop)!
Discover [**The PEASS Family**](https://opensea.io/collection/the-peass-family), our collection of exclusive [**NFTs**](https://opensea.io/collection/the-peass-family)
Get the [**official PEASS & HackTricks swag**](https://peass.creator-spring.com)
**Join the** [**💬**](https://emojipedia.org/speech-balloon/) [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** me on **Twitter** [**🐦**](https://github.com/carlospolop/hacktricks/tree/7af18b62b3bdc423e11444677a6a73d4043511e9/\[https:/emojipedia.org/bird/README.md)[**@carlospolopm**](https://twitter.com/carlospolopm)**.**
**Share your hacking tricks submitting PRs to the** [**hacktricks github repo**](https://github.com/carlospolop/hacktricks)**.**
</details>