-
Notifications
You must be signed in to change notification settings - Fork 228
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/kevthehermit/PasteHunter
- Loading branch information
Showing
10 changed files
with
173 additions
and
35 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -106,3 +106,4 @@ ENV/ | |
/.idea | ||
/postprocess/tester.py | ||
.vscode/ | ||
logs/ |
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,27 @@ | ||
/* | ||
This rule will look for common encoded certificates and secrets | ||
*/ | ||
|
||
rule certificates | ||
{ | ||
meta: | ||
author = "@KevTheHermit" | ||
info = "Part of PasteHunter" | ||
reference = "https://github.com/kevthehermit/PasteHunter" | ||
|
||
strings: | ||
$enabled_sec = "enable secret" wide ascii nocase | ||
$enable_pass = "enable password" wide ascii nocase | ||
$ssh_priv = "BEGIN RSA PRIVATE KEY" wide ascii nocase | ||
$openssh_priv = "BEGIN OPENSSH PRIVATE KEY" wide ascii nocase | ||
$dsa_priv = "BEGIN DSA PRIVATE KEY" wide ascii nocase | ||
$ec_priv = "BEGIN EC PRIVATE KEY" wide ascii nocase | ||
$pgp_priv = "BEGIN PGP PRIVATE KEY" wide ascii nocase | ||
$pem_cert = "BEGIN CERTIFICATE" wide ascii nocase | ||
$pkcs7 = "BEGIN PKCS7" | ||
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
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,51 @@ | ||
import os | ||
import datetime | ||
import json | ||
import logging | ||
import requests | ||
from common import parse_config | ||
|
||
logger = logging.getLogger('pastehunter') | ||
|
||
config = parse_config() | ||
|
||
|
||
class SlackOutput(): | ||
def __init__(self): | ||
self.valid = True | ||
self.webhook_url = config['outputs']['slack_output']['webhook_url'] | ||
self.accepted_rules = config['outputs']['slack_output']['rule_list'] | ||
|
||
if self.webhook_url == '': | ||
logging.error("Slack Webhook not configured") | ||
self.valid = False | ||
if self.webhook_url == '': | ||
logging.error("No Rules configured to alert") | ||
|
||
def store_paste(self, paste_data): | ||
if self.valid: | ||
send = False | ||
|
||
for rule in self.accepted_rules: | ||
if rule in paste_data['YaraRule']: | ||
send = True | ||
|
||
if send: | ||
json_data = { | ||
"text": "Pastehunter alert!", | ||
"attachments": [ | ||
{ | ||
"fallback": "Plan a vacation", | ||
"author_name": "PasteHunter", | ||
"title": "Paste ID {0}".format(paste_data['pasteid']), | ||
"text": "Yara Rule {0} Found on {1}".format(paste_data['YaraRule'], paste_data['pastesite']) | ||
} | ||
] | ||
} | ||
|
||
req = requests.post(self.webhook_url, json=json_data) | ||
if req.status_code == 200 and req.text == 'ok': | ||
logger.debug("Paste sent to slack") | ||
else: | ||
logger.error( | ||
"Failed to post to slack Status Code {0}".format(req.status_code)) |
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,16 @@ | ||
import re | ||
import math | ||
from collections import Counter | ||
|
||
def shannon_entropy(s): | ||
# https://rosettacode.org/wiki/Entropy#Python | ||
s = str(s) | ||
p, lns = Counter(s), float(len(s)) | ||
return -sum(count / lns * math.log(count / lns, 2) for count in p.values()) | ||
|
||
|
||
def run(results, raw_paste_data, paste_object): | ||
# Calculate the Shannon Entropy for the raw paste | ||
paste_object["Shannon Entropy"] = shannon_entropy(raw_paste_data) | ||
# Send the updated json back | ||
return paste_object |
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