Skip to content

Commit

Permalink
Merge pull request #10 from rly0nheart/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
rly0nheart committed Jun 26, 2023
2 parents cff95e6 + 13f5bd6 commit 5def068
Show file tree
Hide file tree
Showing 7 changed files with 166 additions and 85 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
![Screenshot_20210827-111909-removebg-preview](https://user-images.githubusercontent.com/74001397/131107876-db415339-0c1d-4876-8665-fe9b76c4518c.png)

![OS](https://img.shields.io/badge/OS-GNU%2FLinux-red?style=for-the-badge&logo=linux)
![OS](https://img.shields.io/badge/OS-Windows-blue?style=for-the-badge&logo=Windows)
![GitHub](https://img.shields.io/github/license/rly0nheart/oxdork?style=for-the-badge&logo=github)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/rly0nheart/oxdork?include_prereleases&style=for-the-badge&logo=github)
![GitHub repo size](https://img.shields.io/github/repo-size/rly0nheart/oxdork?style=for-the-badge&logo=github)
![OS](https://img.shields.io/badge/OS-GNU%2FLinux-red?style=flat&logo=linux)
![OS](https://img.shields.io/badge/OS-Windows-blue?style=flat&logo=Windows)
![GitHub](https://img.shields.io/github/license/rly0nheart/oxdork?style=flat&logo=github)
![GitHub release (latest by date including pre-releases)](https://img.shields.io/github/v/release/rly0nheart/oxdork?include_prereleases&style=flat&logo=github)
![GitHub repo size](https://img.shields.io/github/repo-size/rly0nheart/oxdork?style=flat&logo=github)



Expand Down
10 changes: 0 additions & 10 deletions oxdork/banner.py

This file was deleted.

58 changes: 48 additions & 10 deletions oxdork/config.py
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")
23 changes: 23 additions & 0 deletions oxdork/data/data.json
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"
}
}
}
14 changes: 10 additions & 4 deletions oxdork/main.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,21 @@
import time
from oxdork.oxdork import *
from datetime import datetime
from oxdork.config import data, create_parser

xprint(ascii_banner()[0])

parser = create_parser()
args = parser.parse_args()

def main():

def run():
start_time = datetime.now()
log.info(f"Started Oxdork {ascii_banner()[1]} at {time.asctime()}")
log.info(f"Starting {data()['program']['name']} v{version.full_version()} at {time.asctime()}")
try:
check_updates()
process_user_query(arguments.query)
queries = process_input(args.query)
for query in queries:
begin_search(query, count=args.count, output=args.output)
except KeyboardInterrupt as ctrlc:
log.warning(f"User interruption detected: {ctrlc}")
except Exception as error:
Expand Down
98 changes: 62 additions & 36 deletions oxdork/oxdork.py
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
38 changes: 18 additions & 20 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
[build-system]
requires = ["setuptools", "setuptools-scm"]
build-backend = "setuptools.build_meta"
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"

[tool.setuptools]
packages = ["oxdork"]
[tool.poetry]
include = [
{path = "oxdork/data/data.json"}
]

[project]
name = "oxdork"
version = "3.1.1"
description = "Google dorking tool"
version = "3.2.0"
description = "Google dorking tool."
readme = "README.md"
requires-python = ">=3.8"
license = {file = "LICENSE"}
license = "MIT License"
homepage = "https://github.com/rly0nheart/oxdork"
documentation = "https://github.com/rly0nheart/oxdork/wiki/"
repository = "https://github.com/rly0nheart/oxdork.git"
keywords = ["python", "osint", "google-dorking", "osint", "inurl", "intext", "intitle"]
authors = [{name = "Richard Mwewa", email = "rly0nheart@duck.com"}]
authors = ["Richard Mwewa <rly0nheart@duck.com>"]
classifiers = [
"Development Status :: 5 - Production/Stable",
"Programming Language :: Python :: 3",
Expand All @@ -24,16 +28,10 @@ classifiers = [
""
]

dependencies = [
"rich",
"google",
"requests"
]
[tool.poetry.dependencies]
rich = "*"
google = "*"

[project.urls]
homepage = "https://github.com/rly0nheart/oxdork"
documentation = "https://github.com/rly0nheart/oxdork/wiki/"
repository = "https://github.com/rly0nheart/oxdork.git"

[project.scripts]
oxdork = "oxdork.main:main"
[tool.poetry.scripts]
oxdork = "oxdork.main:run"

0 comments on commit 5def068

Please sign in to comment.