-
Notifications
You must be signed in to change notification settings - Fork 262
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This new Canarytoken type gives users the ability to mount a WebDAV endpoint, with unique credentials. If the WebDAV mount is browsed and the file are access, we send a notification. It relies on a WebDAV server written separately that is hosted as a Cloudflare Worker. This feature will not run on self-hosted Canarytokens instances. Actual author: Jacob Torrey
- Loading branch information
1 parent
333e672
commit 1a1e68a
Showing
26 changed files
with
411 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import json | ||
import requests | ||
from typing import Optional | ||
from enum import Enum | ||
from hashlib import sha1 | ||
|
||
from canarytokens.settings import FrontendSettings | ||
|
||
settings = FrontendSettings() | ||
|
||
ACCOUNT_ID = settings.CLOUDFLARE_ACCOUNT_ID | ||
NAMESPACE_ID = settings.CLOUDFLARE_NAMESPACE | ||
|
||
|
||
# Matches the keys in the worker's fs.js | ||
class FsType(str, Enum): | ||
TESTING = "testing" | ||
SECURITY = "security" | ||
DEFENSE = "defense" | ||
MEDICAL = "medical" | ||
IT = "it" | ||
|
||
|
||
def generate_webdav_password( | ||
token_id: str, server_domain: str = settings.DOMAINS[0] | ||
) -> str: | ||
return sha1((server_domain + token_id).encode()).hexdigest() | ||
|
||
|
||
def insert_webdav_token( | ||
password: str, | ||
alert_url: str, | ||
webdav_fs_type: Optional[FsType] = None, | ||
custom_fs: Optional[str] = None, | ||
) -> bool: | ||
""" | ||
Inserts a token config into the Cloudflare KV store | ||
Returns: True if successful, False otherwise | ||
""" | ||
api_cred = settings.CLOUDFLARE_API_TOKEN | ||
value = {"token_url": alert_url} | ||
|
||
if webdav_fs_type is not None: | ||
value["fs_template"] = f"{webdav_fs_type}" | ||
if custom_fs is not None: | ||
value["custom_fs"] = custom_fs | ||
|
||
fd = {"value": json.dumps(value), "metadata": "{}"} | ||
put_url = f"https://api.cloudflare.com/client/v4/accounts/{ACCOUNT_ID}/storage/kv/namespaces/{NAMESPACE_ID}/values/{password}" | ||
res = requests.put( | ||
put_url, files=fd, headers={"Authorization": "Bearer " + api_cred} | ||
) | ||
if res.status_code == 200: | ||
return True | ||
else: | ||
print(res.text) | ||
return False |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.