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

Added ability to monitor PasteBin Users #44

Open
wants to merge 70 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
8494b4f
Merge pull request #9 from recrudesce/master
kevthehermit Nov 8, 2017
1385fc6
Boolean values in config file.
kevthehermit Nov 12, 2017
9b0dfbd
Implement Blacklist
kevthehermit Nov 16, 2017
00fafa9
Major Revision
kevthehermit Nov 16, 2017
211b84f
Prep for Gists
kevthehermit Nov 17, 2017
821fac3
Sample Conf update
kevthehermit Nov 17, 2017
a4299dd
Sample code for gists
kevthehermit Nov 17, 2017
27c1d60
Support for gist.github.com
kevthehermit Nov 19, 2017
2227e02
Logging format
kevthehermit Nov 19, 2017
cac4b33
Dumpz.org text endpoint
kevthehermit Nov 19, 2017
8e4d0bd
Update The Readme
kevthehermit Nov 19, 2017
5c38b9a
Spelling Mistake
kevthehermit Nov 20, 2017
9d9c1dd
Gist Blacklisting
kevthehermit Nov 22, 2017
a37dc20
SMTP Support
kevthehermit Nov 22, 2017
07bb3da
Wrong Key in Gists
kevthehermit Nov 22, 2017
7bb652f
Change Debug level
kevthehermit Nov 22, 2017
bef28e3
Update sample config for SMTP
kevthehermit Nov 22, 2017
068f155
Change config file to JSON
kevthehermit Nov 28, 2017
66bbfab
Update .gitignore
kevthehermit Nov 28, 2017
e246e5b
DB Create User rules
kevthehermit Nov 29, 2017
1590f55
Merge remote-tracking branch 'origin/develop' into develop
kevthehermit Nov 30, 2017
ee2e0f5
Tweak Readme
kevthehermit Nov 30, 2017
80365c3
Update Requirements.txt
kevthehermit Nov 30, 2017
f5a6785
Post Process Modules
kevthehermit Nov 30, 2017
8709d8f
Base64_exe to cuckoo
kevthehermit Nov 30, 2017
a627293
issues with storing gzip decompressed streams that are not ascii text
kevthehermit Dec 1, 2017
405c30a
Improve B64 rule and post processor
kevthehermit Dec 1, 2017
3b03d11
revert b64 to at 0 until i can improve the post processor
kevthehermit Dec 1, 2017
dc773f4
Update Dox rule
kevthehermit Dec 3, 2017
2b82017
Add some base64 rules and tune DOX
kevthehermit Dec 3, 2017
8de4e1a
Fix extra b64
kevthehermit Dec 3, 2017
b3a05b7
Update Base64 post processor
kevthehermit Dec 3, 2017
7e3157f
Update Base64
kevthehermit Dec 3, 2017
4e79ecf
Merge remote-tracking branch 'origin/develop' into develop
kevthehermit Dec 4, 2017
d20c6d1
utf8 encode the uncompressed stream. Still needs work
kevthehermit Dec 4, 2017
a5ab8ca
Add test rules file
kevthehermit Dec 4, 2017
83b4ab2
Enable Test Rules
kevthehermit Dec 8, 2017
2b96c51
Add Weekly Index to Elastic Output
kevthehermit Dec 10, 2017
c6aa753
Merge remote-tracking branch 'origin/develop' into develop
kevthehermit Dec 10, 2017
871f413
Merge pull request #12 from kevthehermit/develop
kevthehermit Dec 10, 2017
c45df93
Update Readme for latest yara
kevthehermit Dec 10, 2017
d2065bd
Store All for pastebin
kevthehermit Dec 10, 2017
3e5e74a
Merge pull request #13 from kevthehermit/develop
kevthehermit Dec 10, 2017
8126847
Weekly Index for Elastic
kevthehermit Dec 10, 2017
30e4af4
Fix Weekly Index
kevthehermit Dec 10, 2017
a6bc827
Enable Test Rules in config
kevthehermit Dec 10, 2017
86b5b25
Add Year to weekly index in Elastic output
kevthehermit Dec 10, 2017
f45ff8c
Added setting to allow configuration of sleep duration between runs
Dec 11, 2017
84f6a73
Merge pull request #14 from MrAdz350/master
kevthehermit Dec 11, 2017
4d42642
Enrich rules
ntddk Dec 14, 2017
4f1aa41
Update Docker to 6.1.0
kevthehermit Dec 18, 2017
3f1aa2a
Merge pull request #15 from ntddk/rule
kevthehermit Dec 18, 2017
bf19945
Fix Slack API Key Rule
kevthehermit Dec 18, 2017
72396aa
Fix Config name in readme
kevthehermit Dec 23, 2017
e2d5f00
Update default config settings
kevthehermit Jan 5, 2018
c26dd9b
Add email body.
kevthehermit Jan 28, 2018
742b4ae
Update Email Subject line
kevthehermit Jan 28, 2018
23d477e
Fix path for csv logging
kevthehermit Feb 10, 2018
db6bbf9
[add] Output to multiple recipients over SMTP
Feb 21, 2018
efb617e
[fix] Logic flaw when testing rules for multiple receivers
Feb 26, 2018
65dfc9e
[fix] Maintain compatibility with older configuration format
Feb 26, 2018
40a2380
Updated pastebin scrape URL
daverstephens Apr 25, 2018
59bd5b9
Merge pull request #32 from daverstephens/patch-1
kevthehermit Apr 26, 2018
e543bd1
Merge pull request #25 from gquere/smtp_multiple_recipients
kevthehermit Apr 26, 2018
38a4322
Update gitignore for code editor
kevthehermit Apr 26, 2018
440283e
Match IP Addresses in Docker and compose
kevthehermit Apr 26, 2018
28d7623
Update logging and SMTP
kevthehermit Apr 26, 2018
f4a762f
remove config file
Apr 26, 2018
188572c
update settings to include log level
kevthehermit May 4, 2018
26d2a49
Added ability to monitor PasteBin Users
vampiricalmind Sep 14, 2018
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
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,8 @@ ENV/
.mypy_cache/
/settings.conf
/YaraRules/custom_keywords.yar
/paste_history.tmp
/settings.json
/.idea
/postprocess/tester.py
.vscode/
125 changes: 91 additions & 34 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,75 @@
# PasteHunter
Scan pastebin pastes with a collection of yara rules.

# PreReqs
PasteHunter is a python3 application that is designed to query a collection of sites that host publicliy pasted data.
For all the pasts it finds it scans the raw contents against a series of yara rules looking for information that can be used
by an org or a researcher.

## Supported Inputs
Pastehunter currently has support for the following sites:
- pastebin.com
- dumpz.org
- gist.github.com

Support for the following sites is listed as ToDo:
- paste.ee

## Supported Outputs
Pastehunter supports several output modules:
- dump to ElasticSearch DB (default)
- email sending over SMTP
- dump to JSON file
- dump to CSV file

### SMTP
Multiple recipients can be specified, with different rulesets each.
It's possible to combine these rules using simple OR or AND logic (respectively rule_list and mandatory_rule_list).
You need to set SMTP_SECURITY in the config file to one of the following options:
- 'tls'
- 'starttls'
- 'none'

Refer to your email provider to determine which you require.

## PostProcess Modules
Pastehunter comes with a couple of post process modules that extact useful data from pastes or pass them to other services
The following are default modules:
- Base64 Decoders
- Cuckoo
- Viper

## PreReqs

### Pastebin

You need a Pro account on pastebin that has access to the scraping API.
https://pastebin.com/api_scraping_faq

* Yara
* Python3
* Elastic Search Kibana optional
### GitHub
Github needs an oauth token to stop it hitting the free ratelimit.
Create one at https://github.com/settings/tokens

YOU DO NOT NEED TO GIVE IT ANY ACCESS PERMISSIONS

# Installation

## Local install

### Elastic Search
https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html

### Kibana
https://www.elastic.co/guide/en/kibana/current/deb.html

# Install.
### Yara
https://yara.readthedocs.io/en/latest/gettingstarted.html#compiling-and-installing-yara

If you have yara errors check the installed version numbers for yara and yara-python match the lastest versions.

### PasteHunter
git clone https://github.com/kevthehermit/pastehunter

### Python / Deps
Python 3
```pip3 install -r requirements.txt```

## Using Docker

Expand All @@ -36,47 +95,45 @@ Kibana is using the static IP address : 172.16.10.12 in the `esnet` network
Elasticsearch is running only on the localhost interface on default port 9200.
The mount point is `/usr/share/elasticsearch/data` by default

if elastic search fails to start and you see "max virtual memory areas vm.max_map_count [65530] likely too low"
in the logs then try

`sudo sysctl -w vm.max_map_count=262144`

https://elk-docker.readthedocs.io/#troubleshooting Paragraph starting As from version 5

#### Pastehunter

You can re-run the pastehunter script by doing `docker-compose up -d`
Docker-compose will use already running instances of Elasticsearch and Kibana

## Local install

### Elastic Search
https://www.elastic.co/guide/en/elasticsearch/reference/current/deb.html

### Kibana
https://www.elastic.co/guide/en/kibana/current/deb.html

### Yara
https://yara.readthedocs.io/en/v3.6.0/gettingstarted.html#compiling-and-installing-yara
# Configure

Don't forget the python bindings
```pip install yara-python```
copy settings.json.sample to settings.json
populate the details.
For the scraping API you need to whitelist your IP on pastebin. No API key is required. See the link above

If you have yara errors check the installed version numbers for yara and yara-python match the lastest versions.
The logging level can be set to one of the following values.


### This little app
git clone https://github.com/kevthehermit/pastehunter
| Level | Numerical |
|----------|-----------|
| CRITICAL | 50 |
| ERROR | 40 |
| WARNING | 30 |
| INFO | 20 |
| DEBUG | 10 |
| NOTSET | 0 |

# Configure
The default is INFO:20

copy settings.conf.sample to settings.conf
populate the details.
For the scraping API you need to whitelist your IP on pastebin. No API key is required. See the link above

# Running

This needs python 3 as per the prereqs.
You can run it on its own with ```python3 pastehunter.py```
Start the application with ```python3 pastehunter.py```

Or you can set a cronjob to run this script every two minutes with a pastelimit of 200
It may be useful to run in a screen to keep it running in the background.

```
localadmin@pastebin:~/pastehunter$ cat /etc/cron.d/pastehunter
# Run every 5 minutes
*/2 * * * * localadmin cd /home/localadmin/pastehunter && python3 pastehunter.py >> /home/localadmin/pastehunter/cronlog.txt
localadmin@pastebin:~/pastehunter$
```
## Service
Service config is coming
53 changes: 53 additions & 0 deletions YaraRules/api_keys.yar
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,56 @@ rule google_api
condition:
all of them
}

rule slack_api
{
meta:
author = "@ntddk"
info = "Part of PasteHunter"
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$a = /(xox(p|b|o|a)-[0-9]{9,12}-[0-9]{9,12}-[0-9]{9,12}-[a-z0-9]{32})/
condition:
all of them
}

rule github_api
{
meta:
author = "@ntddk"
info = "Part of PasteHunter"
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$a = /[g|G][i|I][t|T][h|H][u|U][b|B].*[[\'|"]0-9a-zA-Z]{35,40}[\'|"]/
condition:
all of them
}

rule aws_api
{
meta:
author = "@ntddk"
info = "Part of PasteHunter"
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$a = /AKIA[0-9A-Z]{16}/
condition:
all of them
}

rule heroku_api
{
meta:
author = "@ntddk"
info = "Part of PasteHunter"
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$a = /[h|H][e|E][r|R][o|O][k|K][u|U].*[0-9A-F]{8}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{4}-[0-9A-F]{12}/
condition:
all of them
}

70 changes: 68 additions & 2 deletions YaraRules/base64.yar
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,10 @@ rule b64_exe
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$b64_exe = /TV(oA|pB|pQ|qA|qQ|ro)/
$b64_exe = /\bTV(oA|pB|pQ|qA|qQ|ro)/
// Double b64 = VFZxUU
condition:
$b64_exe
$b64_exe at 0

}

Expand Down Expand Up @@ -88,4 +89,69 @@ rule b64_url
condition:
any of them

}

rule b64_doc
{
meta:
author = "@KevTheHermit"
info = "Part of PasteHunter"
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$b64_doc = "0M8R4" // d0cf11
condition:
$b64_doc at 0

}

rule b64_rtf
{
meta:
author = "@KevTheHermit"
info = "Part of PasteHunter"
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$b64_rtf = "e1xydGY" // {\rtf
condition:
$b64_rtf at 0

}

rule b64_docx
{
meta:
author = "@KevTheHermit"
info = "Part of PasteHunter"
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$b64_zip = "UEs"
$docx1 = "d29yZC9fcmVsc" // word/_rel
$docx2 = "Zm9udFRhYmxl" // fontTable
$docx3 = "ZG9jUHJvcHM" // docProps
$docx4 = "Q29udGVudF9UeXBlcw" // Content_Types
$docx5 = "c2V0dGluZ3M" //settings
condition:
$b64_zip at 0 and 3 of ($docx*)

}

rule b64_xml_doc
{
meta:
author = "@KevTheHermit"
info = "Part of PasteHunter"
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$b64_xml = "PD94bWwg"
$docx1 = "b3BlbmRvY3VtZW50" // opendocument
$docx2 = "InBhcmFncmFwaCI" // "paragraph"
$docx3 = "b2ZmaWNlL3dvcmQv" // office/word/
$docx4 = "RG9jdW1lbnRQcm9wZXJ0aWVz" // DocumentProperties
condition:
$b64_xml at 0 and 3 of ($docx*)

}
15 changes: 15 additions & 0 deletions YaraRules/blacklist.yar
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
rule blacklist
{
meta:
author = "@KevTheHermit"
info = "Part of PasteHunter"
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$a = "#EXTINF:" nocase // IPTV stream Lists.
$b = "--app-name=LeagueClient" nocase // League of Legends Debug Log
$c = "common.application_name: LeagueClient" // League of Legends Debug Log
condition:
any of them

}
25 changes: 23 additions & 2 deletions YaraRules/core_keywords.yar
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,32 @@ rule core_keywords
$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
$DOX = " DOX" wide ascii nocase
$hacked = "hacked by" wide ascii nocase
$onion_url = /.*.\.onion/
condition:
any of them

}
}

rule dox
{
meta:
author = "@KevTheHermit"
info = "Part of PasteHunter"
reference = "https://github.com/kevthehermit/PasteHunter"

strings:
$dox = "DOX" wide ascii nocase fullword
$keyword1 = "name" wide ascii nocase
$keyword2 = "dob" wide ascii nocase
$keyword3 = "age" wide ascii nocase
$keyword4 = "password" wide ascii nocase
$keyword5 = "email" wide ascii nocase
condition:
$dox and 3 of ($keyword*)

}
Loading