Skip to content

Commit

Permalink
breachedcompilation fix & ticket #16 suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
ktx committed May 10, 2019
1 parent bcbf69b commit 5c22001
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 35 deletions.
48 changes: 14 additions & 34 deletions h8mail.py
Original file line number Diff line number Diff line change
@@ -1,41 +1,20 @@
import argparse
import re
import os
import configparser
from utils.colors import colors as c
import os
import re

from utils.classes import target
from utils.colors import colors as c
from utils.helpers import (
print_banner,
fetch_emails,
find_files,
get_config_from_file,
get_emails_from_file,
print_banner,
save_results_csv,
find_files,
)
from utils.localsearch import local_search, local_search_single, local_to_targets


def breachcomp_check(targets, breachcomp_path):
# https://gist.github.com/scottlinux/9a3b11257ac575e4f71de811322ce6b3
try:
import subprocess

query_bin = os.path.join(breachcomp_path, "query.sh")
subprocess.call(["chmod", "+x", query_bin])
for t in targets:
procfd = subprocess.run([query_bin, t.email], stdout=subprocess.PIPE)
output = procfd.stdout.decode("utf-8")
if len(output) != 0:
t.pwnd = True
split_output = output.split("\n")
for line in split_output:
if line:
t.breachcomp_passw.append(line.split(":")[1])
return targets
except Exception as ex:
c.bad_news(c, "Breach compilation")
print(ex)

from utils.breachcompilation import breachcomp_check

def print_results(results):
for t in results:
Expand All @@ -59,6 +38,8 @@ def print_results(results):
c.print_result(c, t.email, t.data[i][1], t.data[i][0])
if "LOCAL" in t.data[i][0]:
c.print_result(c, t.email, t.data[i][1], t.data[i][0])
if "BREACHEDCOMP" in t.data[i][0]:
c.print_result(c, t.email, t.data[i][1], t.data[i][0])


def target_factory(targets, api_keys, user_args):
Expand Down Expand Up @@ -100,8 +81,8 @@ def h8mail(user_args):
breached_targets = target_factory(targets, api_keys, user_args)

# These are not done inside the factory as the factory iterates over each target individually
# if user_args.bc_path:
# breached_targets = breachcomp_check(breached_targets, user_args.bc_path)
if user_args.bc_path:
breached_targets = breachcomp_check(breached_targets, user_args.bc_path)
if user_args.local_breach_src:
res = find_files(user_args.local_breach_src)
if user_args.single_file:
Expand Down Expand Up @@ -160,7 +141,7 @@ def main(user_args):
"-sk",
"--skip-defaults",
dest="skip_defaults",
help="Skip HaveIBeenPwned and HunterIO check",
help="Skips HaveIBeenPwned and HunterIO check. Ideal for local scans.",
action="store_true",
default=False,
)
Expand All @@ -174,13 +155,13 @@ def main(user_args):
"-lb",
"--local-breach",
dest="local_breach_src",
help="Local breaches to scan for targets",
help="Local breaches to scan for targets. Uses multiprocesses, one separate process per file. Supports file or folder as input",
)
parser.add_argument(
"-sf",
"--single-file",
dest="single_file",
help="If breach contains big files, set this flag to view the progress bar. Disables concurrent file searching for stability",
help="If breach contains big files, set this flag to view the progress bar. Disables concurrent file searching for stability.",
action="store_true",
default=False,
)
Expand All @@ -190,4 +171,3 @@ def main(user_args):
print_banner()
main(args)
c.good_news(c, "Done")

22 changes: 22 additions & 0 deletions utils/breachcompilation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
from utils.colors import colors as c
import os

def breachcomp_check(targets, breachcomp_path):
# https://gist.github.com/scottlinux/9a3b11257ac575e4f71de811322ce6b3
try:
import subprocess

query_bin = os.path.join(breachcomp_path, "query.sh")
subprocess.call(["chmod", "+x", query_bin])
for t in targets:
procfd = subprocess.run([query_bin, t.email], stdout=subprocess.PIPE)
output = procfd.stdout.decode("utf-8")
if len(output) != 0:
split_output = output.split("\n")
for line in split_output:
if ":" in line:
t.data.append(("BREACHEDCOMP", line.split(":")[1]))
return targets
except Exception as ex:
c.bad_news(c, "Breach compilation")
print(ex)
2 changes: 1 addition & 1 deletion utils/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ def get_hunterio_public(self):
response = req.json()
if response["data"]["total"] != 0:
self.data.append(("HUNTER_PUB", response["data"]["total"]))
c.good_news(c, "Found {num} related emails for {target} using hunter.io".format(num=response["data"]["total"], target=self.email))
c.good_news(c, "Found {num} related emails for {target} using Hunter.IO".format(num=response["data"]["total"], target=self.email))
except Exception as ex:
c.bad_news(c, "HunterIO (pubic API) error: " + self.email)
print(ex)
Expand Down
17 changes: 17 additions & 0 deletions utils/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,22 @@ def print_result(self, target, data, source):
self.reset,
)
)
if "BREACHEDCOMP" in source:
print(
"{}{}{:15}{}|{}{:>25.25}{} > {}{}{}{}".format(
self.fg.lightblue,
self.bold,
source,
self.fg.lightgrey,
self.fg.pink,
target,
self.fg.lightgrey,
self.bold,
self.fg.green,
data,
self.reset,
)
)
elif "LOCALSEARCH" in source:
print(
"{}{}{:15}{}|{}{:>25.25}{} > {}{}{}{}".format(
Expand Down Expand Up @@ -139,6 +155,7 @@ def print_result(self, target, data, source):
self.reset,
)
)

else:
print(
"{}{:15}{}|{}{:>25.25}{} > {}{}{}".format(
Expand Down

0 comments on commit 5c22001

Please sign in to comment.