Skip to content

Commit a99c6ff

Browse files
committed
add ban_hash.py example script
1 parent 11e5fb9 commit a99c6ff

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

docs/changelog.rst

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Changes for Cb Protection:
3838
Changes for Cb Response:
3939

4040
* Added ``.webui_link`` property to Cb Response Query objects.
41+
* Added ``ban_hash.py`` example.
4142

4243
Bug Fixes:
4344

examples/response/ban_hash.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
3+
import sys
4+
from cbapi.example_helpers import build_cli_parser, get_cb_response_object
5+
from cbapi.response import BannedHash
6+
7+
8+
def ban_hash(cb, args):
9+
b = cb.create(BannedHash)
10+
b.md5hash = args.hash
11+
if args.description:
12+
b.text = args.description
13+
else:
14+
b.text = "Banned via ban_hash.py example script"
15+
b.enabled = True
16+
17+
try:
18+
b.save()
19+
except Exception as e:
20+
print("Error banning hash {0}: {1}".format(args.hash, str(e)))
21+
else:
22+
print("Hash {0} successfully banned".format(args.hash))
23+
24+
25+
def main():
26+
parser = build_cli_parser("Add an MD5 hash to the banned hash list in Cb Response")
27+
parser.add_argument("-H", "--hash", help="MD5 hash of the file to ban in Cb Response", required=True)
28+
parser.add_argument("-d", "--description", help="Description of why the hash is banned")
29+
30+
args = parser.parse_args()
31+
cb = get_cb_response_object(args)
32+
33+
return ban_hash(cb, args)
34+
35+
36+
if __name__ == "__main__":
37+
sys.exit(main())

0 commit comments

Comments
 (0)