Skip to content

Commit

Permalink
B64decode (#16)
Browse files Browse the repository at this point in the history
* Added string padding function

* Strip '=' before padding strings to prevent errors

* Fixed infinite look error

* adding #nosec for assert lines

Skip bandit checking for use of assert in test files

* pyhton black formatting

* Reverting python black formtting
This reverts commit 126c3da.

* Added string padding function

* Strip '=' before padding strings to prevent errors

* Fixed infinite look error

* black formatted

* Fixes from testing with notebooks.

Added kql_sent_threatintel.yaml and kql_sent_net.yaml queries

* Using different notation to separate macros from replaceable parameters

* Black formatting and linting/mpy errors

* Added mypy.ini to get rid of import stub warnings

Additional mypy fixes

* Merging with master

* Incrementing version and fixing pylint warning.
  • Loading branch information
petebryan authored and ianhelle committed Aug 3, 2019
1 parent 468cd68 commit d84269e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion msticpy/_version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""Version file."""
VERSION = "0.2.2"
VERSION = "0.2.3"
14 changes: 13 additions & 1 deletion msticpy/sectools/base64unpack.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def unpack_items(
_debug_trace = trace

if input_string is not None:
input_string = _b64_string_pad(input_string)
return _decode_b64_string_recursive(input_string)
if data is not None:
if not column:
Expand All @@ -176,7 +177,8 @@ def unpack_items(
output_df = None
rows_with_b64_match = data[data[column].str.contains(_BASE64_REGEX)]
for input_row in rows_with_b64_match[[column]].itertuples():
(decoded_string, output_frame) = _decode_b64_string_recursive(input_row[1])
input_string = _b64_string_pad(input_row[1])
(decoded_string, output_frame) = _decode_b64_string_recursive(input_string)
output_frame["src_index"] = input_row.Index
output_frame["full_decoded_string"] = decoded_string
if output_df is None:
Expand Down Expand Up @@ -831,3 +833,13 @@ def _binary_to_bytesio(binary):
if isinstance(binary, io.BytesIO):
return binary.getbuffer()
return io.BytesIO(binary).getbuffer()


def _b64_string_pad(string):
if len(string) % 4 == 0:
return string

string = string.rstrip("=")
while len(string) % 4 != 0:
string = string + "A"
return string

0 comments on commit d84269e

Please sign in to comment.