Skip to content

Commit

Permalink
Convert the base32 string to uppercase before decoding (#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkst-pieter authored Dec 9, 2024
1 parent 0435113 commit 7e83cf6
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
8 changes: 4 additions & 4 deletions canarytokens/tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,10 +272,10 @@ def correct_base32_padding(b32_data):
return b32_data

if file_name and file_name != "f":
b32_data = correct_base32_padding(file_name[0:])
b32_data = correct_base32_padding(file_name[0:].upper())
data["windows_fake_fs_file_name"] = base64.b32decode(b32_data).decode()
if process_name and process_name != "i":
b32_data = correct_base32_padding(process_name[0:])
b32_data = correct_base32_padding(process_name[0:].upper())
data["windows_fake_fs_process_name"] = base64.b32decode(b32_data).decode()

return {"src_data": data}
Expand Down Expand Up @@ -570,8 +570,8 @@ def _get_info_for_webdav(request: Request):
hit_time = datetime.utcnow().strftime("%s.%f")
hit_info = {
"additional_info": WebDavAdditionalInfo(
file_path=request.getHeader("X-Alert-Path"),
useragent=http_general_info["useragent"],
file_path=request.getHeader("X-Alert-Path"),
useragent=http_general_info["useragent"],
),
"geo_info": queries.get_geoinfo(ip=client_ip),
"input_channel": INPUT_CHANNEL_HTTP,
Expand Down
7 changes: 7 additions & 0 deletions tests/units/test_tokens.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,13 @@ def test_cmd_process_pattern(
"doc b.docx",
"explorer.exe",
),
(
# ensure lowercase also works
"u7595.fmrxwgidcfzsg6y3y.imv4ha3dpojsxeltfpbsq.someid.sometoken.com",
"7595",
"doc b.docx",
"explorer.exe",
),
(
"u7595.f.iMV4HA3DPOJSXELTFPBSQ.someid.sometoken.com",
"7595",
Expand Down

0 comments on commit 7e83cf6

Please sign in to comment.