本文整理匯總了Python中ssdeep.hash方法的典型用法代碼示例。如果您正苦於以下問題:Python ssdeep.hash方法的具體用法?Python ssdeep.hash怎麽用?Python ssdeep.hash使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類ssdeep
的用法示例。
在下文中一共展示了ssdeep.hash方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: load_data_from_results_file
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def load_data_from_results_file(path):
c2_bases = {}
with open(path, "r") as f:
for line in f:
line = line.strip()
data = json.loads(line)
data['content'] = data['content'].decode('hex')
data['content_ssdeep'] = ssdeep.hash(data['content'])
if data['base_url'] not in c2_bases:
c2_bases[data['base_url']] = {}
data["offset"] = data["url"][len(data["base_url"]):]
print "{0} - {1} - {2}".format(data['code'], data['base_url'], data['offset'])
c2_bases[data['base_url']][data['offset']] = data
return c2_bases
示例2: Calculate
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def Calculate(self, string):
if self.name == "md5":
hash = hashlib.md5(string).hexdigest()
elif self.name == "sha1":
hash = hashlib.sha1(string).hexdigest()
elif self.name == "crc":
crc32 = crcmod.Crc(0x104c11db7, initCrc=0, xorOut=0xFFFFFFFF)
crc32.update(string)
hash = crc32.hexdigest()
elif self.name == "murmur":
hash = mmh3.hash(string)
elif self.name == "ssdeep":
hash = ssdeep.hash(string)
elif self.name == "tlsh":
hash = tlsh.hash(string)
return hash
示例3: get_spam_level
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def get_spam_level(player, message_content):
"""
Get's a spam level for a message using a
fuzzy hash > 50% means it's probably spam
"""
message_hash = ssdeep.hash(message_content)
spam_level = 0
spam_levels = [ssdeep.compare(message_hash, prior_hash) for prior_hash in player.last_message_hashes if
prior_hash is not None]
if len(spam_levels) > 0:
spam_level = max(spam_levels)
player.last_message_hashes.append(message_hash)
if spam_level > SPAM_TOLERANCE:
player.spam_detections += 1
return spam_level
示例4: main
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def main():
""" Determines the file type then outputs the binary md5 hash
and the function fuzzy hashes
Usage:
python malget.py [FILE] """
args = argparse_setup()
output_file = "malgetOutput.txt"
if args.output:
output_file = args.output
binary_tuple, sizes = malget(args.PATH, args.unpack)
with open(output_file, "w") as f:
f.write(binary_tuple[0]+"\n")
for item in binary_tuple[1]:
f.write(item + "\n")
print("Output to file {0}".format(output_file))
示例5: should_parse
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def should_parse(repo, state, is_gist=False):
owner_login = repo.owner.login if is_gist else repo.repository.owner.login
if owner_login in state.bad_users:
print(bcolors.FAIL + "Failed check: Ignore User" + bcolors.ENDC)
return False
if not is_gist and repo.repository.name in state.bad_repos:
print(bcolors.FAIL + "Failed check: Ignore Repo" + bcolors.ENDC)
return False
if not is_gist and repo.name in state.bad_files:
print(bcolors.FAIL + "Failed check: Ignore File" + bcolors.ENDC)
return False
# Fuzzy Hash Comparison
try:
if not is_gist:
# Temporary fix for PyGithub until fixed upstream (PyGithub#1178)
repo._url.value = repo._url.value.replace(
repo._path.value,
urllib.parse.quote(repo._path.value))
candidate_sig = ssdeep.hash(repo.decoded_content)
for sig in state.bad_signatures:
similarity = ssdeep.compare(candidate_sig, sig)
if similarity > SIMILARITY_THRESHOLD:
print(
bcolors.FAIL +
"Failed check: Ignore Fuzzy Signature on Contents "
"({}% Similarity)".format(similarity) +
bcolors.ENDC)
return False
except github.UnknownObjectException:
print(
bcolors.FAIL +
"API Error: File no longer exists on github.com" +
bcolors.ENDC)
return False
return True
示例6: ui_loop
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def ui_loop(repo, log_buf, state, is_gist=False):
choice = input_handler(state, is_gist)
if choice == "c":
state.bad_signatures.append(ssdeep.hash(repo.decoded_content))
elif choice == "u":
state.bad_users.append(repo.owner.login if is_gist
else repo.repository.owner.login)
elif choice == "r" and not is_gist:
state.bad_repos.append(repo.repository.name)
elif choice == "f" and not is_gist:
state.bad_files.append(repo.name)
elif choice == "p":
print_handler(repo.decoded_content)
ui_loop(repo, log_buf, state, is_gist)
elif choice == "s":
save_state(state.query, state)
ui_loop(repo, log_buf, state, is_gist)
elif choice == "a":
with open(state.logfile, "a") as fd:
fd.write(log_buf)
elif choice.startswith("/"):
log_buf += regex_handler(choice, repo)
ui_loop(repo, log_buf, state, is_gist)
elif choice == "b":
if state.index - 1 < state.lastInitIndex:
print(
bcolors.FAIL +
"Can't go backwards past restore point "
"because of rate-limiting/API limitations" +
bcolors.ENDC)
ui_loop(repo, log_buf, state, is_gist)
else:
state.index -= 2
elif choice == "q":
sys.exit(0)
示例7: make_request
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def make_request(url, quiet=False, raw_results=False):
if not quiet:
print "Requesting {0}".format(url)
r = requests.get(url, allow_redirects=False, timeout=90)
content = r.content
return r.status_code, ssdeep.hash(content) if not raw_results else content.encode('hex')
示例8: scan
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def scan(self, payload: Payload, request: Request) -> WorkerResponse:
return WorkerResponse(results={'ssdeep': ssdeep.hash(payload.content)})
示例9: ssdeepcompare
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def ssdeepcompare(target, IP):
try:
ss_target = requests.get('http://{}/'.format(target))
ssdeep_target_fuzz = ssdeep.hash(ss_target.text)
print target, ssdeep_target_fuzz
content = requests.get('https://{}'.format(IP), verify=False, timeout = 5, headers = {'Host': target})
ssdeep_fuzz = ssdeep.hash(content.text)
print IP, ssdeep_fuzz
print "ssdeep score for", IP, "is", ssdeep.compare(ssdeep_target_fuzz, ssdeep_fuzz)
except(requests.exceptions.ConnectionError):
print "cant connect to", IP
示例10: getSsdeep
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def getSsdeep(data):
try:
res = ssdeep.hash(data)
return res
except Exception, e:
logging.exception(str(e))
return ''
# ****************TEST_CODE******************
示例11: get_digest_size
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def get_digest_size(file_handle: IO[bytes]) -> int:
""" The size of the resulting hash in bytes."""
pass
示例12: get_hash_digest
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def get_hash_digest(file_handle: IO[bytes]) -> bytes:
return bytes(str.encode(ssdeep.hash(file_handle)))
示例13: get_hash_hexdigest
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def get_hash_hexdigest(file_handle: IO[bytes]) -> str:
return ssdeep.hash(file_handle)
示例14: META_BASIC_INFO
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def META_BASIC_INFO(s, buff):
BASIC_INFO = OrderedDict([('MD5', hashlib.md5(buff).hexdigest()),
('SHA1', hashlib.sha1(buff).hexdigest()),
('SHA256', hashlib.sha256(buff).hexdigest()),
('SHA512', hashlib.sha512(buff).hexdigest()),
('ssdeep' , ssdeep.hash(buff)),
('Size', '%s bytes' % len(buff))])
return BASIC_INFO
示例15: get_binary_hash
# 需要導入模塊: import ssdeep [as 別名]
# 或者: from ssdeep import hash [as 別名]
def get_binary_hash(filename):
""" Get the md5 hash of the file to put at the top of the document """
blocksize = 65536
hasher = hashlib.md5()
with open(filename, "rb") as afile:
buf = afile.read(blocksize)
while len(buf) > 0:
hasher.update(buf)
buf = afile.read(blocksize)
return hasher.hexdigest()