Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How about add a telegram output channel? #56

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,6 @@ Pastehunter supports several output modules:
- Dump to JSON file.
- Dump to CSV file.
- Send to syslog.
- Send to telegram channel.

For examples of data discovered using pastehunter check out my posts https://techanarchy.net/blog/hunting-pastebin-with-pastehunter and https://techanarchy.net/blog/pastehunter-the-results
25 changes: 25 additions & 0 deletions outputs/telegram_output.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from telegram.ext import Updater

from common import parse_config
import logging

logger = logging.getLogger('pastehunter')
config = parse_config()


class TelegramOutput():
def __init__(self):
self.token = config['outputs']['telegram_output']['token']
self.chat_id = config['outputs']['telegram_output']['chat_id']
self.updater = Updater(token=self.token,
request_kwargs={"proxy_url": config['outputs']['telegram_output']['proxy_url']})

def store_paste(self, paste_data):
if paste_data['pastesite']=='pastebin.com':
url = paste_data['full_url']
else:
url = paste_data['scrape_url']
send_data = "From {0}: Matched Rule: {1}, See : {2}".format(paste_data['pastesite'], str(paste_data['YaraRule']), url)

self.updater.bot.send_message(chat_id=self.chat_id, text=send_data)
logger.debug("send a message %s"%send_data)
13 changes: 12 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,15 @@
requests>=2.20.0
asn1crypto==0.24.0
certifi==2018.11.29
cffi==1.11.5
chardet==3.0.4
cryptography==2.4.2
elasticsearch>=5.0.0,<6.0.0
future==0.17.1
idna==2.6
pycparser==2.19
python-telegram-bot==11.1.0
six==1.12.0
splunk-sdk
yara-python
urllib3==1.22
yara-python
8 changes: 8 additions & 0 deletions settings.json.sample
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,14 @@
}
},
"outputs": {
"telegram_output": {
"enabled": true,
"token": "xxx",
"chat_id": "",
"proxy_url": "",
"module": "outputs.telegram_output",
"classname": "TelegramOutput"
},
"elastic_output": {
"enabled": true,
"module": "outputs.elastic_output",
Expand Down