Skip to content

Commit

Permalink
Feat: implement code formatter and GitHub action (sundowndev#171)
Browse files Browse the repository at this point in the history
* feat: create black config file

* feat: create build CI action

* chore: delete old travis CI config

* chore: fix lint errors

* Feat: init unit tests (sundowndev#172)

* refactor: add config package to the requirements (sundowndev#131)

* test(lib): banner

First unit test

* refactor(ci): add test step

* test(lib): banner

* refactor(ci): lint test files
  • Loading branch information
sundowndev authored Dec 20, 2019
1 parent d9b0100 commit d43309a
Show file tree
Hide file tree
Showing 17 changed files with 425 additions and 269 deletions.
29 changes: 29 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Build

on: [push]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
pip install black
pip install green
cp config.example.py config.py
- name: Lint with Black
run: |
python -m black --config black.config.toml lib scanners tests --check
- name: Test
run: |
python -m green tests/**/*.py --run-coverage
- name: Generate examples
run: |
bash ./examples/generate.sh
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

4 changes: 4 additions & 0 deletions black.config.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[tool.black]
line-length = 85
target-version = ['py37']
include = '\.pyi?$'
76 changes: 50 additions & 26 deletions lib/args.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# -*- coding:utf-8 -*-
#
# @name : PhoneInfoga - Phone numbers OSINT tool
# @url : https://github.com/sundowndev
Expand All @@ -8,28 +8,52 @@
import argparse
from lib.banner import __version__

parser = argparse.ArgumentParser(description="Advanced information gathering tool for phone numbers (https://github.com/sundowndev/PhoneInfoga) version {}".format(__version__),
usage='%(prog)s -n <number> [options]')

parser.add_argument('-n', '--number', metavar='number', type=str,
help='The phone number to scan (E164 or international format)')

parser.add_argument('-i', '--input', metavar="input_file", type=argparse.FileType('r'),
help='Phone number list to scan (one per line)')

parser.add_argument('-o', '--output', metavar="output_file", type=argparse.FileType('w'),
help='Output to save scan results')

parser.add_argument('-s', '--scanner', metavar="scanner", default="all", type=str,
help='The scanner to use')

parser.add_argument('--recon', action='store_true',
help='Launch custom format reconnaissance')

parser.add_argument('--no-ansi', action='store_true',
help='Disable colored output')

parser.add_argument('-v', '--version', action='store_true',
help='Show tool version')

args = parser.parse_args()
parser = argparse.ArgumentParser(
description="Advanced information gathering tool for phone numbers (https://github.com/sundowndev/PhoneInfoga) version {}".format(
__version__
),
usage="%(prog)s -n <number> [options]",
)

parser.add_argument(
"-n",
"--number",
metavar="number",
type=str,
help="The phone number to scan (E164 or international format)",
)

parser.add_argument(
"-i",
"--input",
metavar="input_file",
type=argparse.FileType("r"),
help="Phone number list to scan (one per line)",
)

parser.add_argument(
"-o",
"--output",
metavar="output_file",
type=argparse.FileType("w"),
help="Output to save scan results",
)

parser.add_argument(
"-s",
"--scanner",
metavar="scanner",
default="all",
type=str,
help="The scanner to use",
)

parser.add_argument(
"--recon", action="store_true", help="Launch custom format reconnaissance"
)

parser.add_argument("--no-ansi", action="store_true", help="Disable colored output")

parser.add_argument("-v", "--version", action="store_true", help="Show tool version")

args = parser.parse_args()
7 changes: 4 additions & 3 deletions lib/banner.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
#!/usr/bin/env python3
# -*- coding:utf-8 -*-
# -*- coding:utf-8 -*-
#
# @name : PhoneInfoga - Phone numbers OSINT tool
# @url : https://github.com/sundowndev
# @author : Raphael Cerveaux (sundowndev)

__version__ = 'v1.10.9'
__version__ = "v1.10.10"


def banner():
print(" ___ _ _____ __ ")
Expand All @@ -16,4 +17,4 @@ def banner():
print(" |___/ ")
print(" PhoneInfoga Ver. {}".format(__version__))
print(" Coded by Sundowndev")
print("\n")
print("\n")
2 changes: 1 addition & 1 deletion lib/colors.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import sys
import colorama

if sys.platform == 'win32':
if sys.platform == "win32":
colorama.init()

R = "\033[%s;31m"
Expand Down
9 changes: 5 additions & 4 deletions lib/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ def formatNumber(InputNumber):


def replaceVariables(string, number):
string = string.replace('$n', number['default'])
string = string.replace('$i', number['international'])
string = string.replace('$l', number['international'].replace(
'%s ' % (number['countryCode']), ''))
string = string.replace("$n", number["default"])
string = string.replace("$i", number["international"])
string = string.replace(
"$l", number["international"].replace("%s " % (number["countryCode"]), "")
)

return string
72 changes: 45 additions & 27 deletions lib/googlesearch.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,81 +18,99 @@

browser = None


def closeBrowser():
if browser is not None:
browser.quit()


def search(req, stop):
global browser

if google_api_key and google_cx_id:
return searchApi(req, stop)

if browser is None:
if os.environ.get('webdriverRemote'):
browser = webdriver.Remote(os.environ.get('webdriverRemote'), webdriver.DesiredCapabilities.FIREFOX.copy())
if os.environ.get("webdriverRemote"):
browser = webdriver.Remote(
os.environ.get("webdriverRemote"),
webdriver.DesiredCapabilities.FIREFOX.copy(),
)
else:
browser = webdriver.Firefox()

try:
REQ = urlencode({ 'q': req, 'num': stop, 'hl': 'en' })
URL = 'https://www.google.com/search?tbs=li:1&{}&amp;gws_rd=ssl&amp;gl=us'.format(
REQ)
REQ = urlencode({"q": req, "num": stop, "hl": "en"})
URL = "https://www.google.com/search?tbs=li:1&{}&amp;gws_rd=ssl&amp;gl=us".format(
REQ
)
browser.get(URL)
htmlBody = browser.find_element_by_css_selector("body").get_attribute('innerHTML')
htmlBody = browser.find_element_by_css_selector("body").get_attribute(
"innerHTML"
)

soup = BeautifulSoup(htmlBody, 'html5lib')
soup = BeautifulSoup(htmlBody, "html5lib")

while soup.find("div", id="recaptcha") is not None:
warn('You are temporary blacklisted from Google search. Complete the captcha then press ENTER.')
token = ask('>')
htmlBody = browser.find_element_by_css_selector("body").get_attribute('innerHTML')
soup = BeautifulSoup(htmlBody, 'html5lib')
warn(
"You are temporary blacklisted from Google search. Complete the captcha then press ENTER."
)
token = ask(">")
htmlBody = browser.find_element_by_css_selector("body").get_attribute(
"innerHTML"
)
soup = BeautifulSoup(htmlBody, "html5lib")

results = soup.find("div", id="search").find_all("div", class_="g")

links = []

for result in results:
url = result.find("a").get('href')
url = re.sub(r'(?:\/url\?q\=)', '', url)
url = re.sub(r'(?:\/url\?url\=)', '', url)
url = re.sub(r'(?:\&sa\=)(?:.*)', '', url)
url = re.sub(r'(?:\&rct\=)(?:.*)', '', url)
url = result.find("a").get("href")
url = re.sub(r"(?:\/url\?q\=)", "", url)
url = re.sub(r"(?:\/url\?url\=)", "", url)
url = re.sub(r"(?:\&sa\=)(?:.*)", "", url)
url = re.sub(r"(?:\&rct\=)(?:.*)", "", url)

if re.match(r"^(?:\/search\?q\=)", url) is not None:
url = 'https://google.com' + url
url = "https://google.com" + url

if url is not None:
links.append(url)

return links
except Exception as e:
error('Request failed. Please retry or open an issue on https://github.com/sundowndev/PhoneInfoga.')
error(
"Request failed. Please retry or open an issue on https://github.com/sundowndev/PhoneInfoga."
)
print(e)
return []


def searchApi(req, stop):
options = urlencode({ 'q': req, 'key': google_api_key, 'cx': google_cx_id, 'num': stop })
r = send('GET', 'https://www.googleapis.com/customsearch/v1?%s' % (options))
options = urlencode(
{"q": req, "key": google_api_key, "cx": google_cx_id, "num": stop}
)
r = send("GET", "https://www.googleapis.com/customsearch/v1?%s" % (options))
response = r.json()

if 'error' in response:
error('Error while fetching Google search API. Maybe usage limit ? Please verify your keys.')
print(response['error'])
if "error" in response:
error(
"Error while fetching Google search API. Maybe usage limit ? Please verify your keys."
)
print(response["error"])
askForExit()
return []

if 'items' not in response:
if "items" not in response:
return []

results = response['items']
results = response["items"]

links = []

for result in results:
if result['link'] is not None:
links.append(result['link'])
if result["link"] is not None:
links.append(result["link"])

return links
1 change: 1 addition & 0 deletions lib/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import sys
from lib.args import args


class Logger(object):
def __init__(self):
self.terminal = sys.stdout
Expand Down
7 changes: 4 additions & 3 deletions lib/output.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,15 @@ def throw(string):

def askForExit():
if not args.output:
user_input = ask('Continue scanning ? (y/N) ')
user_input = ask("Continue scanning ? (y/N) ")

if user_input.lower() == 'y' or user_input.lower() == 'yes':
if user_input.lower() == "y" or user_input.lower() == "yes":
return -1
else:
info("Good bye!")
sys.exit()


def ask(text):
if args.output:
sys.stdout = sys.__stdout__
Expand All @@ -84,4 +85,4 @@ def ask(text):

return res
else:
return input(text)
return input(text)
32 changes: 20 additions & 12 deletions lib/request.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,29 +10,37 @@
import random

uagent = []
uagent.append("Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0) Opera 12.14")
uagent.append(
"Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.0) Opera 12.14")
"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0"
)
uagent.append(
"Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:26.0) Gecko/20100101 Firefox/26.0")
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 Firefox/3.5.3"
)
uagent.append(
"Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.3) Gecko/20090913 Firefox/3.5.3")
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)"
)
uagent.append(
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)")
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.7 (KHTML, like Gecko) Comodo_Dragon/16.1.1.0 Chrome/16.0.912.63 Safari/535.7"
)
uagent.append(
"Mozilla/5.0 (Windows NT 6.2) AppleWebKit/535.7 (KHTML, like Gecko) Comodo_Dragon/16.1.1.0 Chrome/16.0.912.63 Safari/535.7")
"Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)"
)
uagent.append(
"Mozilla/5.0 (Windows; U; Windows NT 5.2; en-US; rv:1.9.1.3) Gecko/20090824 Firefox/3.5.3 (.NET CLR 3.5.30729)")
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) Gecko/20090718 Firefox/3.5.1"
)
uagent.append(
"Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.1) Gecko/20090718 Firefox/3.5.1")
uagent.append(
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0")
"Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:63.0) Gecko/20100101 Firefox/63.0"
)

# Request SSL DH key error workaround
# See https://github.com/sundowndev/PhoneInfoga/issues/16
requests.packages.urllib3.disable_warnings()
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += 'HIGH:!DH:!aNULL'
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS += "HIGH:!DH:!aNULL"
try:
requests.packages.urllib3.contrib.pyopenssl.DEFAULT_SSL_CIPHER_LIST += 'HIGH:!DH:!aNULL'
requests.packages.urllib3.contrib.pyopenssl.DEFAULT_SSL_CIPHER_LIST += (
"HIGH:!DH:!aNULL"
)
except AttributeError:
# no pyopenssl support used / needed / available
pass
Expand All @@ -41,6 +49,6 @@
def send(method, url, headers={}):
if not headers:
headers = {}
headers['User-Agent'] = random.choice(uagent)
headers["User-Agent"] = random.choice(uagent)

return requests.request(method, url, data="", headers=headers)
Loading

0 comments on commit d43309a

Please sign in to comment.