-
Notifications
You must be signed in to change notification settings - Fork 182
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
84 additions
and
0 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
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,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() |
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,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 |