-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathdumpdork.py
More file actions
275 lines (232 loc) · 10.6 KB
/
dumpdork.py
File metadata and controls
275 lines (232 loc) · 10.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
#!/usr/bin/python3
# Author: Mateo Fumis (hackermater) - linkedin.com/in/mateo-gabriel-fumis
import os
import sys
import requests
import urllib.parse
import json
import argparse
import yaml
from colorama import init, Fore, Style
init(autoreset=True)
# Configuration Directory and File
CONFIG_DIR = os.path.expanduser("~/.config/dumpdork")
CONFIG_FILE = os.path.join(CONFIG_DIR, "config.yaml")
# Providers Configuration
PROVIDERS = {
"google": {
"host": "google-search74.p.rapidapi.com",
"url_pattern": "https://google-search74.p.rapidapi.com/"
},
"brave": {
"host": "brave-web-search.p.rapidapi.com",
"url_pattern": "https://brave-web-search.p.rapidapi.com/search"
},
"github": {
"is_official": True,
"repo_search": "https://api.github.com/search/repositories",
"code_search": "https://api.github.com/search/code"
}
}
def print_banner():
banner = rf"""
{Fore.CYAN} ____ ____ _
{Fore.CYAN} | _ \ _ _ _ __ ___ _ __ | _ \ ___ _ __| | __
{Fore.CYAN} | | | | | | | '_ ` _ \| '_ \| | | |/ _ \| '__| |/ /
{Fore.CYAN} | |_| | |_| | | | | | | |_) | |_| | (_) | | | <
{Fore.CYAN} |____/ \__,_|_| |_| |_| .__/|____/ \___/|_| |_|\_\
{Fore.CYAN} |_|
{Fore.YELLOW} Advanced Dorking Tool v1.2
{Fore.WHITE} Created by: Mateo Fumis (hackermater)
"""
print(banner)
def load_config(config_file):
try:
with open(config_file, 'r') as file:
return yaml.safe_load(file)
except FileNotFoundError:
print(f"{Fore.RED}Error: Configuration file '{config_file}' not found.")
print(f"{Fore.YELLOW}Tip: Run with -w to set up your API keys.")
sys.exit(1)
except yaml.YAMLError as e:
print(f"{Fore.RED}Error: Failed to parse configuration file. {e}")
sys.exit(1)
def save_config(config_file, keys_dict):
os.makedirs(CONFIG_DIR, exist_ok=True)
config = {
'rapidapi': {
'host': PROVIDERS["google"]["host"],
'keys': keys_dict
}
}
with open(config_file, 'w') as file:
yaml.dump(config, file, default_flow_style=False)
print(f"{Fore.GREEN}Configuration saved to '{config_file}'")
def get_github_commits(repo_full_name, key, limit=3):
"""Fetch recent commits for a specific GitHub repository."""
url = f"https://api.github.com/repos/{repo_full_name}/commits"
headers = {
'Accept': "application/vnd.github.v3+json",
'User-Agent': 'DumpDork-Tool'
}
if key and key.strip() != "" and key != "Not configured":
headers['Authorization'] = f"token {key}"
try:
response = requests.get(url, headers=headers, params={'per_page': limit})
if response.status_code == 200:
return response.json()
except:
pass
return []
def perform_search(source, query, limit, key):
if source not in PROVIDERS:
return None
provider = PROVIDERS[source]
headers = {}
params = {}
if source == "github":
is_code_search = any(x in query for x in ["filename:", "extension:", "path:", "content:"])
url = provider["code_search"] if is_code_search else provider["repo_search"]
params = {'q': query, 'per_page': limit}
if key and key.strip() != "" and key != "Not configured":
headers['Authorization'] = f"token {key}"
headers['Accept'] = "application/vnd.github.v3+json"
headers['User-Agent'] = 'DumpDork-Tool'
elif source == "google":
url = provider["url_pattern"]
params = {'query': query, 'limit': limit}
headers = {
'x-rapidapi-host': provider["host"],
'x-rapidapi-key': key
}
elif source == "brave":
url = provider["url_pattern"]
params = {'q': query, 'count': limit}
headers = {
'x-rapidapi-host': provider["host"],
'x-rapidapi-key': key
}
try:
response = requests.get(url, headers=headers, params=params)
if response.status_code == 200:
data = response.json()
if source == "github" and not data.get('items') and url == provider["code_search"]:
response = requests.get(provider["repo_search"], headers=headers, params=params)
if response.status_code == 200:
return response.json()
return data
elif response.status_code == 401:
print(f"{Fore.RED}Error 401: Unauthorized. Your {source} token/key is invalid.")
elif response.status_code == 403:
print(f"{Fore.RED}Error 403: Forbidden for {source}. Code search may require an API Token.")
else:
print(f"{Fore.RED}Error {response.status_code} from {source}")
except Exception as e:
print(f"{Fore.RED}Connection Error: {e}")
return None
def wizard_setup():
print(f"{Fore.YELLOW}{Style.BRIGHT}Welcome to the DumpDork API Setup Wizard!")
keys_dict = {}
if os.path.exists(CONFIG_FILE):
try:
existing_config = load_config(CONFIG_FILE)
keys_dict = existing_config.get('rapidapi', {}).get('keys', {})
except:
pass
for source in PROVIDERS.keys():
print(f"\n{Fore.CYAN}--- {source.upper()} ---")
if source == "github":
print("Using official GitHub API (api.github.com)")
else:
print(f"RapidAPI Host: {PROVIDERS[source]['host']}")
current_key = keys_dict.get(source, "Not configured")
print(f"Current Key: {current_key}")
prompt = f"Enter API key/token for {source} (leave blank to skip): "
new_key = input(prompt).strip()
if new_key.lower() == 'clear':
keys_dict[source] = ""
elif new_key:
keys_dict[source] = new_key
save_config(CONFIG_FILE, keys_dict)
def main():
try:
parser = argparse.ArgumentParser(description='Perform a search using Dorks across multiple platforms', prog='dumpdork.py')
parser.add_argument('query', nargs='?', type=str, help='Search query or dork')
parser.add_argument('-s', '--source', type=str, default='google', choices=['google', 'github', 'brave'], help='Search engine source')
parser.add_argument('-l', '--limit', type=int, default=50, help='Maximum number of results')
parser.add_argument('-o', '--output', type=str, help='Save results to a JSON file')
parser.add_argument('-w', '--wizard', action='store_true', help='Run API configuration wizard')
print_banner()
if len(sys.argv) == 1:
parser.print_usage()
print(f"\nUse {Fore.YELLOW}-h{Fore.RESET} or {Fore.YELLOW}--help{Fore.RESET} for full details.\n")
sys.exit(0)
args = parser.parse_args()
if args.wizard:
wizard_setup()
sys.exit(0)
if args.query is None:
parser.print_usage()
print(f"{Fore.RED}Error: A search query is required unless using -w.")
sys.exit(1)
config = load_config(CONFIG_FILE)
keys_dict = config.get('rapidapi', {}).get('keys', {})
api_key = keys_dict.get(args.source)
if not api_key and args.source != "github":
print(f"{Fore.RED}Error: No API key found for {args.source}. Run with -w to setup.")
sys.exit(1)
print(f"{Fore.YELLOW}Searching {args.source} for: {args.query}...\n")
results = perform_search(args.source, args.query, args.limit, api_key)
if results:
items = []
if args.source == "github":
items = results.get('items', [])
elif args.source == "brave":
items = results.get('results', []) or results.get('web', {}).get('results', [])
else: # Google
items = results.get('results', [])
for item in items:
if args.source == "github":
repository = item.get('repository', {}) if 'repository' in item else item
full_name = repository.get('full_name') or item.get('full_name') or 'No Name'
url = item.get('html_url') or repository.get('html_url') or 'No URL'
desc = item.get('description') or repository.get('description') or 'No Description'
owner = repository.get('owner', {}).get('login') or item.get('owner', {}).get('login', 'Unknown')
if desc and len(desc) > 150:
desc = desc[:147] + "..."
if 'path' in item:
print(f"{Fore.CYAN}File: {Style.BRIGHT}{item.get('path')} {Fore.WHITE}in {full_name}")
else:
print(f"{Fore.CYAN}Repo: {Style.BRIGHT}{full_name} ({Fore.WHITE}by @{owner}{Fore.CYAN})")
print(f"{Fore.GREEN}URL: {Style.BRIGHT}{urllib.parse.unquote(url)}")
print(f"{Fore.MAGENTA}Description: {Style.BRIGHT}{desc}")
commits = get_github_commits(full_name, api_key)
if commits:
print(f"{Fore.YELLOW}Recent Commits:")
for c in commits:
msg = c.get('commit', {}).get('message', '').split('\n')[0]
date = c.get('commit', {}).get('author', {}).get('date', '')[:10]
print(f" {Fore.WHITE}- [{date}] {msg[:80]}")
print("")
else:
title = item.get('title') or 'No Title'
url = item.get('url') or item.get('link') or 'No URL'
desc = item.get('description') or item.get('snippet') or 'No Description'
if desc and len(desc) > 150:
desc = desc[:147] + "..."
print(f"{Fore.CYAN}Title: {Style.BRIGHT}{title}")
print(f"{Fore.GREEN}URL: {Style.BRIGHT}{urllib.parse.unquote(url)}")
print(f"{Fore.MAGENTA}Description: {Style.BRIGHT}{desc}\n")
print(f"{Fore.YELLOW}{Style.BRIGHT}Execution finished. Total results found: {len(items)}")
if args.output:
with open(args.output, 'w', encoding='utf-8') as json_file:
json.dump(results, json_file, ensure_ascii=False, indent=4)
print(f"{Fore.YELLOW}Results saved to '{args.output}'")
else:
print(f"{Fore.RED}No results found.")
print(f"{Fore.YELLOW}{Style.BRIGHT}Execution finished. Total results found: 0")
except KeyboardInterrupt:
print(f"\n{Fore.RED}[!] Process interrupted by user. Exiting...")
sys.exit(0)
if __name__ == "__main__":
main()