Commit aa542b5d authored by dmknght's avatar dmknght
Browse files

add user agent support

parent 36f8dc9e
......@@ -15,6 +15,7 @@ type
query: string
extension: string
path: string
agent: string
var
allDorkResults: seq[DorkFile]
......@@ -62,6 +63,7 @@ proc helpBanner() =
showHelpCmd(keyword = "-d", args = "Domain name", descr = "[Required] Target's name (ex: parrotsec.org)")
showHelpCmd(keyword = "-f", args = "File extension", descr = "[Required] Extension without \".\" (ex: \"xlsx\", \"xlsx,pdf\")")
showHelpCmd(keyword = "-q", args = "Query string", descr = "[Optional] Keywords to filter result (ex: members)")
showHelpCmd(keyword = "-a", args = "User-Agent", descr = "[Optional] Use custom User-Agent")
showHelpCmd(keyword = "-s", args = "Download folder", descr = "[Optional] Enable download files (ex: /tmp/)")
......@@ -78,7 +80,7 @@ proc printResult() =
echo "-".repeat(70)
proc downloadFiles(folder: string) =
proc downloadFiles(folder: string, agent: string) =
#[
Download file if users want to download all of them
If URL can't be used, try use webcache
......@@ -88,7 +90,7 @@ proc downloadFiles(folder: string) =
client = newHttpClient()
downloaded = 0
client.headers = newHttpHeaders({"User-Agent": "Mozilla/5.0 (Windows NT 10.0; ) Gecko/20100101 Firefox/68.0"})
client.headers = if agent == "": newHttpHeaders({"User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"}) else: newHttpHeaders({"User-Agent": agent})
for eachResult in allDorkResults:
let
......@@ -155,7 +157,7 @@ proc getResult(resp: Response, ext: string) =
allDorkResults.add(dorkResult)
proc basicSearch(domain, extension, query: string) =
proc basicSearch(domain, extension, query, agent: string) =
#[
Do the google dork by basic HTTP GET queries
Make the basic query like this:
......@@ -172,7 +174,7 @@ proc basicSearch(domain, extension, query: string) =
payload = encodeUrl(payload)
client.headers = newHttpHeaders({"User-Agent": "Mozilla/5.0 (Windows NT 10.0; ) Gecko/20100101 Firefox/68.0"})
client.headers = if agent == "": newHttpHeaders({"User-Agent": "Mozilla/5.0 (Windows NT 10.0; rv:78.0) Gecko/20100101 Firefox/78.0"}) else: newHttpHeaders({"User-Agent": agent})
let resp = client.get("https://google.com/search?num=500&q=" & payload)
getResult(resp, extension)
......@@ -189,7 +191,7 @@ proc handleOptions(options: Options) =
else:
if "," in options.extension:
options.extension = "(" & options.extension.replace(",", " | ") & ")"
basicSearch(options.domain, options.extension, options.query)
basicSearch(options.domain, options.extension, options.query, options.agent)
let szResults = len(allDorkResults)
if szResults > 0:
printResult()
......@@ -207,9 +209,9 @@ proc handleOptions(options: Options) =
except:
stderr.write("[x] Error while creating download folder\n")
return
downloadFiles(options.path)
downloadFiles(options.path, options.agent)
else:
downloadFiles(options.path)
downloadFiles(options.path, options.agent)
echo "Found " & intToStr(szResults) & " results"
......@@ -250,6 +252,7 @@ proc main =
query: "",
extension: "",
path: "",
agent: "",
)
while index < paramCount():
......@@ -265,6 +268,9 @@ proc main =
elif paramStr(index) == "-s":
options.path = paramStr(index + 1)
index += 1
elif paramStr(index) == "-a":
options.agent = paramStr(index + 1)
index += 1
else:
stderr.write("[x] Unknow options " & paramStr(index) & "\n")
helpBanner()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment