2019-05-25 20:40:06 +00:00
|
|
|
#--depends-on commands
|
|
|
|
|
2016-04-20 12:52:23 +00:00
|
|
|
import hashlib
|
2018-10-03 12:22:37 +00:00
|
|
|
from src import ModuleManager, utils
|
2016-04-20 12:52:23 +00:00
|
|
|
|
2018-09-26 17:27:17 +00:00
|
|
|
class Module(ModuleManager.BaseModule):
|
2019-06-23 11:14:06 +00:00
|
|
|
@utils.hook("received.command.hash", min_args=2, remove_empty=False)
|
2016-04-20 12:52:23 +00:00
|
|
|
def hash(self, event):
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2018-09-30 16:29:09 +00:00
|
|
|
:help: Hash a given string with a given algorithm
|
|
|
|
:usage: <algo> <string>
|
2018-09-26 17:27:17 +00:00
|
|
|
"""
|
2016-04-20 12:52:23 +00:00
|
|
|
algorithm = event["args_split"][0].lower()
|
|
|
|
if algorithm in hashlib.algorithms_available:
|
|
|
|
phrase = " ".join(event["args_split"][1:])
|
|
|
|
cipher_text = hashlib.new(algorithm, phrase.encode("utf8")
|
|
|
|
).hexdigest()
|
|
|
|
event["stdout"].write("%s -> %s" % (phrase, cipher_text))
|
|
|
|
else:
|
|
|
|
event["stderr"].write("Unknown algorithm provided")
|