Skip to content

Commit

Permalink
Add pgp plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
Te-k committed Dec 29, 2017
1 parent 46b74b6 commit 6a87833
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ bitly Request bit.ly information through the API
screenshot Takes a screenshot of a webpage
greynoise Request Grey Noise API
telegram Request information from Telegram through the API
pgp Search for information in PGP key servers
```

To configure harpoon, run `harpoon config` and fil needed API keys. Then run `harpoon config -u` to download needed files. Check what plugins are configured with `harpoon config -c`.
Expand Down
52 changes: 52 additions & 0 deletions harpoon/commands/pgp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#! /usr/bin/env python
import sys
from harpoon.commands.base import Command
from harpoon.lib.pgp import Pgp


class CommandPgp(Command):
name = "pgp"
description = "Search for information in PGP key servers"
config = {}

def add_arguments(self, parser):
subparsers = parser.add_subparsers(help='Subcommands')
parser_a = subparsers.add_parser('search', help='Search in PGP server')
parser_a.add_argument('SEARCH', help='Query')
parser_a.add_argument('--only-emails', '-o', action='store_true',
help='Print only email addresses')
parser_a.set_defaults(subcommand='search')
self.parser = parser

def run(self, conf, args, plugins):
if hasattr(args, 'subcommand'):
if args.subcommand == "search":
res = Pgp.search(args.SEARCH)
if len(res):
if args.only_emails:
emails = set()
for r in res:
for e in r['emails']:
if args.SEARCH.lower() in e[1].lower():
emails.add(e[1])
for e in emails:
print(e)
else:
for r in res:
print("[+] %s\t%s\t%s %s" % (
r['id'],
r['date'].strftime("%Y-%m-%d"),
r['emails'][0][0],
r['emails'][0][1]
)
)
if len(r['emails']) > 1:
for e in r['emails'][1:]:
print("\t\t\t\t\t%s %s" % (e[0], e[1]))
else:
print("No results (could be too many results)")
print("Double check at http://pgp.mit.edu/pks/lookup?search=%s" % args.SEARCH)
else:
self.parser.print_help()
else:
self.parser.print_help()
31 changes: 31 additions & 0 deletions harpoon/lib/pgp.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import requests
import re
from bs4 import BeautifulSoup
from dateutil.parser import parse


class Pgp(object):
@staticmethod
def search(search):
url = "http://pgp.mit.edu/pks/lookup?search=" + search
r = requests.get(url)
if "No results found" in r.text:
# Nothing found
return []
res = []
soup = BeautifulSoup(r.text, 'lxml')
emailsearch = re.compile("([\w\(\) ]+) <([\w@\.]+)>")
for pre in soup.find_all('pre')[1:]:
key = {}
t = str(pre)
key['revoked'] = "*** KEY REVOKED ***" in t
key['id'] = pre.a['href'][26:]
a = t.find('</a>')
key['date'] = parse(t[a+5:a+15])
key['emails'] = []
# get ready for regex
for i in emailsearch.findall(t):
key['emails'].append([i[0].strip(), i[1].strip()])

res.append(key)
return res

0 comments on commit 6a87833

Please sign in to comment.