-
Notifications
You must be signed in to change notification settings - Fork 34
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
Improve Python detection based on the PyPI malregistry #584
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
52cd00c
more pypi rules
tstromberg 0f1a411
Add more PyPI rules
tstromberg 301e55e
Merge branch 'main' into pypi
tstromberg 53e357b
More PyPI fun
tstromberg 095d688
better Python file handling
tstromberg 740286d
refresh testdata
tstromberg b44ce22
add new testdata
tstromberg e81542c
Merge branch 'main' into pypi
egibs 4a0f243
Merge branch 'main' into pypi
tstromberg 2a430eb
Refresh test data
egibs File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
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
2 changes: 1 addition & 1 deletion
2
rules/anti-static/obfuscation/php/hex.yara → ...i-static/obfuscation/php/hex_decimal.yara
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,34 @@ | ||
rule python_eval_hex: high { | ||
meta: | ||
description = "evaluates code from an obfuscated data stream" | ||
|
||
strings: | ||
$hex = /eval\(\"\\x\d{1,3}.{0,32}/ | ||
$chars = /eval\(\"\\\d{1,3}.{0,32}/ | ||
|
||
condition: | ||
any of them | ||
} | ||
|
||
rule python_eval_marshal: high { | ||
meta: | ||
description = "evaluates code from marshalled data" | ||
|
||
strings: | ||
$marshal = "eval(marshal.loads" | ||
$json = "eval(json.loads" | ||
|
||
condition: | ||
any of them | ||
} | ||
|
||
rule python_eval_gzip: high { | ||
meta: | ||
description = "evaluates code from gzip content" | ||
|
||
strings: | ||
$ref = /eval\(.{0,32}\(gzip\.decompress\(b.{0,32}/ | ||
|
||
condition: | ||
any of them | ||
} |
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,34 @@ | ||
rule python_exec_hex: high { | ||
meta: | ||
description = "executs code from an obfuscated data stream" | ||
|
||
strings: | ||
$hex = /exec\(\"\\x\d{1,3}.{0,32}/ | ||
$chars = /exec\(\"\\\d{1,3}.{0,32}/ | ||
|
||
condition: | ||
any of them | ||
} | ||
|
||
rule python_exec_marshal: high { | ||
meta: | ||
description = "evaluates code from marshalled data" | ||
|
||
strings: | ||
$marshal = "exec(marshal.loads" | ||
$json = "exec(json.loads" | ||
|
||
condition: | ||
any of them | ||
} | ||
|
||
rule python_exec_gzip: high { | ||
meta: | ||
description = "executes code from gzip content" | ||
|
||
strings: | ||
$ref = /exec\(.{0,32}\(gzip\.decompress\(b.{0,32}/ | ||
|
||
condition: | ||
any of them | ||
} |
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,20 @@ | ||
rule fernet_base64: high { | ||
meta: | ||
description = "Decodes base64, uses Fernet" | ||
filetypes = "py" | ||
|
||
strings: | ||
$fernet = "Fernet" fullword | ||
$fernet2 = "fernet" fullword | ||
$bdecode_64 = "b64decode" fullword | ||
$bdecode_32 = "b32decode" fullword | ||
$o1 = "decode()" | ||
$o2 = "decompress(" | ||
$o4 = "bytes.fromhex" | ||
$o5 = "decrypt(" | ||
$o6 = "exec(" | ||
$o7 = "eval(" | ||
|
||
condition: | ||
filesize < 2MB and any of ($fernet*) and any of ($bdecode*) and any of ($o*) | ||
} |
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,23 @@ | ||
rule python_long_hex: medium { | ||
meta: | ||
description = "contains a large hexadecimal string variable" | ||
filetypes = "py" | ||
|
||
strings: | ||
$assign = /\w{0,16}=["'][a-z0-9]{1024}/ | ||
|
||
condition: | ||
filesize < 1MB and $assign | ||
} | ||
|
||
rule python_long_hex_multiple: high { | ||
meta: | ||
description = "contains multiple large hexadecimal string variables" | ||
filetypes = "py" | ||
|
||
strings: | ||
$assign = /\w{0,16}=["'][a-z0-9]{1024}/ | ||
|
||
condition: | ||
filesize < 1MB and #assign > 3 | ||
} |
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,16 @@ | ||
rule python_hex_decimal: high { | ||
meta: | ||
description = "contains a large amount of escaped hex/decimal content" | ||
filetypes = "py" | ||
|
||
strings: | ||
$f_return = "return" | ||
$f_decode = "decode(" | ||
$f_eval = "eval(" | ||
$f_exec = "exec(" | ||
|
||
$trash = /\\x{0,1}\d{1,3}\\/ | ||
|
||
condition: | ||
filesize < 1MB and any of ($f*) and #trash in (filesize - 1024..filesize) > 100 | ||
} |
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,12 @@ | ||
rule dumb_int_compares: high { | ||
meta: | ||
description = "compares arbitrary integers, likely encoding something" | ||
filetypes = "py" | ||
|
||
strings: | ||
$import = "import" fullword | ||
$decode_or_b64decode = /if \d{2,16} == \d{2,16}/ | ||
|
||
condition: | ||
filesize < 1MB and all of them | ||
} |
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,26 @@ | ||
rule multi_decode_3: high { | ||
meta: | ||
description = "multiple (3+) levels of decoding" | ||
filetypes = "py" | ||
|
||
strings: | ||
$return = "return" | ||
$decode_or_b64decode = /\.[b64]{0,3}decode\(.{0,256}\.[b64]{0,3}decode\(.{0,256}\.[b64]{0,3}decode/ | ||
|
||
condition: | ||
filesize < 1MB and all of them | ||
} | ||
|
||
rule multi_decode: medium { | ||
meta: | ||
description = "multiple (2) levels of decoding" | ||
filetypes = "py" | ||
|
||
strings: | ||
$return = "return" | ||
$decode_or_b64decode = /\.[b64]{0,3}decode\(.{0,32}\.[b64]{0,3}decode\(/ | ||
|
||
condition: | ||
filesize < 1MB and all of them | ||
} | ||
|
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,12 @@ | ||
rule Vare_Obfuscator: high { | ||
meta: | ||
description = "obfuscated with https://github.com/saintdaddy/Vare-Obfuscator" | ||
filetype = "py" | ||
|
||
strings: | ||
$var = "__VareObfuscator__" | ||
$var2 = "Vare Obfuscator" | ||
|
||
condition: | ||
any of them | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the closing escape correct?