-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from rly0nheart/dev
Dev
- Loading branch information
Showing
7 changed files
with
166 additions
and
85 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 was deleted.
Oops, something went wrong.
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 |
---|---|---|
@@ -1,26 +1,64 @@ | ||
import os | ||
import json | ||
import logging | ||
import argparse | ||
from rich.logging import RichHandler | ||
from oxdork.banner import ascii_banner | ||
|
||
|
||
class Version: | ||
def __init__(self): | ||
""" | ||
Initialize the Version class. | ||
Retrieves version components from the data() function and assigns them to instance variables. | ||
""" | ||
self.major = data()["program"]["version"]["major"] | ||
self.minor = data()["program"]["version"]["minor"] | ||
self.patch = data()["program"]["version"]["patch"] | ||
self.suffix = data()["program"]["version"]["suffix"] | ||
|
||
def full_version(self) -> str: | ||
""" | ||
Return the full version string composed of the version components. | ||
:return: The complete version string in the format "major.minor.patchsuffix". | ||
""" | ||
return f"{self.major}.{self.minor}.{self.patch}{self.suffix}" | ||
|
||
|
||
def data() -> dict: | ||
""" | ||
Loads the program's data from data/data.json | ||
:return: Dictionary (JSON) containing program data | ||
""" | ||
# Get the absolute path of the current file | ||
current_dir = os.path.dirname(os.path.abspath(__file__)) | ||
|
||
# Construct the path to the data.json file | ||
settings_path = os.path.join(current_dir, "data", "data.json") | ||
|
||
# Load the settings from the file | ||
with open(settings_path) as file: | ||
program_data = json.load(file) | ||
|
||
return program_data | ||
|
||
|
||
# Create parser | ||
def create_parser(): | ||
parser = argparse.ArgumentParser(description="Google dorking tool — by Richard Mwewa (https://about.me/rly0nheart)", | ||
epilog="oxDork uses Google dorking techniques and Google dorks to find security holes and misconfigurations in web servers.") | ||
parser = argparse.ArgumentParser(description=f"{data()['program']['name']} v{Version().full_version()} — by" | ||
f" {data()['program']['developer']['name']}" | ||
f" ({data()['program']['developer']['about']})", | ||
epilog=data()['program']['about']) | ||
parser.add_argument("query", help="query string or text file containing queries") | ||
parser.add_argument("-c", "--count", help="number of results to show (default %(default)s).", default=10) | ||
parser.add_argument("-o", "--output", help="write output to specified file.") | ||
parser.add_argument("-v", "--version", action="version", | ||
version=ascii_banner()[1]) | ||
version=Version().full_version()) | ||
return parser | ||
|
||
|
||
# Parse command line arguments | ||
parser = create_parser() | ||
arguments = parser.parse_args() | ||
|
||
# Configure logging | ||
logging.basicConfig(level="NOTSET", format="%(message)s", | ||
handlers=[RichHandler(markup=True, log_time_format='[%I:%M:%S%p]', show_level=False)]) | ||
handlers=[RichHandler(markup=True, log_time_format='%I:%M:%S%p', show_level=False)]) | ||
log = logging.getLogger("rich") |
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,23 @@ | ||
{ | ||
"program": | ||
{ | ||
"name": "OxDork", | ||
"about": "Google dorking tool", | ||
"version": | ||
{ | ||
"major": "3", | ||
"minor": "2", | ||
"patch": "0", | ||
"suffix": "" | ||
}, | ||
"license": "MIT License", | ||
"developer": | ||
{ | ||
"name": "Richard Mwewa", | ||
"alias": "rly0nheart", | ||
"about": "https://about.me/rly0nheart", | ||
"twitter": "https://twitter.com/rly0nheart", | ||
"github": "https://github.com/rly0nheart" | ||
} | ||
} | ||
} |
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 |
---|---|---|
@@ -1,61 +1,87 @@ | ||
import os | ||
import time | ||
import requests | ||
from datetime import datetime | ||
from rich.prompt import Prompt | ||
import json | ||
from googlesearch import search | ||
from rich import print as xprint | ||
from oxdork.banner import ascii_banner | ||
from oxdork.config import log, arguments | ||
from urllib.request import urlopen | ||
from oxdork.config import log, Version | ||
|
||
version = Version() | ||
|
||
# Process user input | ||
# If input is a file, open it and loop through each line and use it as a query. | ||
# in the start_search_with_query function | ||
# If input is a string, call start_search_with_query | ||
def process_user_query(query): | ||
if os.path.isfile(query): | ||
with open(query, 'r') as file: | ||
|
||
def process_input(user_input) -> list: | ||
""" | ||
Processes user input. If input is a file, opens the file and reads the contents, line by line. | ||
If not, use the input as it is | ||
:param user_input: user input | ||
:return: A list of the processed queries/query | ||
""" | ||
if os.path.isfile(user_input): | ||
with open(user_input, 'r') as file: | ||
log.info(f"Loaded queries from file: {file.name}") | ||
for count, line in enumerate(file, start=1): | ||
log.info(f"Current query: {count}. {line}") | ||
start_search_with_query(query=line, count=arguments.count, output=arguments.output) | ||
queries = file.readlines() | ||
queries = [query.strip() for query in queries] | ||
return queries | ||
else: | ||
start_search_with_query(query=query, count=arguments.count, output=arguments.output) | ||
return [user_input] | ||
|
||
|
||
def begin_search(query, count, output) -> None: | ||
""" | ||
Start search with the processed input | ||
# Start search with the query from the process_query function | ||
def start_search_with_query(query, count, output): | ||
:param query: Search query | ||
:param count: Number of results to return (defaults to 10) | ||
:param output: String representing a file to which results will be written | ||
:return: None | ||
""" | ||
number = 0 | ||
log.info(f"Fetching {count} results for {query}...") | ||
for counter, result in enumerate(search(query, num=int(count), start=0, stop=None, lang="en", tld="com", pause=2.5), start=1): | ||
log.info(f"Fetching {count} results for `{query}`...") | ||
for counter, result in enumerate(search(query, num=int(count), start=0, stop=None, | ||
lang="en", tld="com", pause=2.5), start=1): | ||
number += 1 | ||
log.info(f"{counter}. {result}") | ||
|
||
# Start writting results to a file | ||
# Start writing results to a file | ||
# if user passes the filename to -o/--output | ||
if output: | ||
write_output(result, counter, output) | ||
__write_output(result, counter, output) | ||
|
||
# If result number is greate than or equal to | ||
# the user specified count limit. Break the search loop. | ||
if number >= int(count): | ||
break | ||
|
||
|
||
# Write results to a file | ||
def write_output(result, counter, output): | ||
with open(f"{output}.txt", "a") as file: | ||
def __write_output(result: str, counter: int, filename: str) -> None: | ||
""" | ||
Write a result to a file. | ||
:param result: The result to write. | ||
:type result: str | ||
:param counter: The index of the result. | ||
:type counter: int | ||
:param filename: The name of the output file (without extension). | ||
:type filename: str | ||
:return: None | ||
""" | ||
with open(f"{filename}.txt", "a") as file: | ||
file.write(f"{counter}. {result}\n") | ||
file.close() | ||
|
||
|
||
# Check program updates | ||
def check_updates(): | ||
response = requests.get("https://api.github.com/repos/rly0nheart/oxdork/releases/latest").json() | ||
if response['tag_name'] == ascii_banner()[1]: | ||
pass | ||
else: | ||
log.info(f"A new release is available: oxDork {response['tag_name']}") | ||
xprint(f"\n{response['body']}\n") | ||
log.info("Run 'pip install --upgrade oxdork' to get the updates.\n") | ||
def check_updates() -> None: | ||
""" | ||
Checks for latest updates by retrieving the release tag from the releases page of the program from GitHub | ||
Then compares the remote version tag with the tag in the program. | ||
If they match, program assumes it's up-to-date. | ||
If not, print a message notifying the user about the remote version (which is treated as the official new release) | ||
, and lastly prints the release notes of the presumed new release. | ||
:return: None | ||
""" | ||
with urlopen("https://api.github.com/repos/rly0nheart/oxdork/releases/latest") as response: | ||
release_data = json.loads(response.read().decode()) | ||
if release_data['tag_name'] != version.full_version(): | ||
xprint(f"* A new release of `OxDork` is available ({release_data['tag_name']}).\n") | ||
else: | ||
pass |
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