Skip to content

Commit

Permalink
add ban_hash.py example script
Browse files Browse the repository at this point in the history
  • Loading branch information
jgarman committed Sep 1, 2017
1 parent 11e5fb9 commit a99c6ff
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 0 deletions.
1 change: 1 addition & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ Changes for Cb Protection:
Changes for Cb Response:

* Added ``.webui_link`` property to Cb Response Query objects.
* Added ``ban_hash.py`` example.

Bug Fixes:

Expand Down
37 changes: 37 additions & 0 deletions examples/response/ban_hash.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/usr/bin/env python

import sys
from cbapi.example_helpers import build_cli_parser, get_cb_response_object
from cbapi.response import BannedHash


def ban_hash(cb, args):
b = cb.create(BannedHash)
b.md5hash = args.hash
if args.description:
b.text = args.description
else:
b.text = "Banned via ban_hash.py example script"
b.enabled = True

try:
b.save()
except Exception as e:
print("Error banning hash {0}: {1}".format(args.hash, str(e)))
else:
print("Hash {0} successfully banned".format(args.hash))


def main():
parser = build_cli_parser("Add an MD5 hash to the banned hash list in Cb Response")
parser.add_argument("-H", "--hash", help="MD5 hash of the file to ban in Cb Response", required=True)
parser.add_argument("-d", "--description", help="Description of why the hash is banned")

args = parser.parse_args()
cb = get_cb_response_object(args)

return ban_hash(cb, args)


if __name__ == "__main__":
sys.exit(main())

0 comments on commit a99c6ff

Please sign in to comment.