Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Open sidebar
packages
tools
goofileN
Commits
557ebd0b
Verified
Commit
557ebd0b
authored
Jun 02, 2020
by
Nong Hoang Tu
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Release tool
parents
Pipeline
#525
failed with stages
in 11 minutes and 47 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
278 additions
and
0 deletions
+278
-0
goofileN.nimble
goofileN.nimble
+14
-0
src/goofileN.nim
src/goofileN.nim
+264
-0
No files found.
goofileN.nimble
0 → 100644
View file @
557ebd0b
# Package
version = "0.1.0"
author = "DmKnght"
description = "A folk version of goofile in Nim lang"
license = "MIT"
srcDir = "src"
bin = @["goofileN"]
# Dependencies
requires "nim >= 1.2.0"
src/goofileN.nim
0 → 100644
View file @
557ebd0b
import
httpClient
import
htmlparser
import
xmltree
from
strutils
import
intToStr
,
repeat
,
split
,
startsWith
,
replace
from
uri
import
encodeURL
,
decodeURL
from
os
import
paramCount
,
paramStr
,
getCurrentDir
,
existsDir
,
createDir
,
getHomeDir
type
DorkFile
=
ref
object
title
:
string
realURL
:
string
cacheURL
:
string
Options
=
ref
object
domain
:
string
query
:
string
extension
:
string
path
:
string
var
allDorkResults
:
seq
[
DorkFile
]
proc
showHelpCmd
(
keyword
=
"help"
,
args
=
""
,
descr
=
""
)
=
#[
Make
color
for
command
syntax
in
help
bannner
Print
them
in
help
Syntax
:
<
command
>
<
keyword
>
<
args
>
[<
description
>]
command
->
light
green
keyword
->
red
args
(
optional
)
->
yellow
description
(
optional
)
->
blue
]
#
var
cmdOutput
=
" "
cmdOutput
&=
"
\e
[31m"
&
keyword
&
"
\e
[0m "
# Red color for keyword
if
args
!=
""
:
cmdOutput
&=
"<
\e
[33m"
&
args
&
"
\e
[0m> "
if
descr
!=
""
:
cmdOutput
&=
"[
\e
[34m"
&
descr
&
"
\e
[0m]"
echo
cmdOutput
proc
banner
()
=
#[
Print
core
banner
of
program
]
#
echo
"goofileN: a folk of goofile tool that was written in Nim lang"
echo
" This tool searches for a specific file type in a given domain"
echo
"Developer: Nong Hoang
\"
DmKnght
\"
Tu"
echo
"License: MIT"
# TODO add URL and other info
proc
helpBanner
()
=
#[
Print
help
commands
with
colored
format
]
#
echo
"Usage:"
showHelpCmd
(
keyword
=
"-d"
,
args
=
"Domain name"
,
descr
=
"[Required] Target's domain name (ex: parrotsec.org)"
)
showHelpCmd
(
keyword
=
"-f"
,
args
=
"File type"
,
descr
=
"[Required] File extension. No need
\"
.
\"
for this args (ex: xlsx)"
)
showHelpCmd
(
keyword
=
"-q"
,
args
=
"Query"
,
descr
=
"[Optional] Keywords to filter result (ex: members)"
)
showHelpCmd
(
keyword
=
"-s"
,
args
=
"Path"
,
descr
=
"[Optional] Path to auto save all files. This will trigger download procedure (ex: /tmp/)"
)
proc
printResult
()
=
#[
Print
result
in
table
style
]
#
echo
"-"
.
repeat
(
70
)
for
eachResult
in
allDorkResults
:
echo
"| Title: "
&
eachResult
.
title
echo
"| URL: "
&
decodeURL
(
eachResult
.
realURL
)
echo
"| Cache: "
&
decodeURL
(
eachResult
.
cacheURL
)
echo
"-"
.
repeat
(
70
)
proc
downloadFiles
(
folder
:
string
)
=
#[
Download
file
if
users
want
to
download
all
of
them
If
URL
can
't be used, try use webcache
]#
var
client = newHttpClient()
downloaded = 0
client.headers = newHttpHeaders({"User-Agent": "Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/68.0"})
for eachResult in allDorkResults:
let
fileName = decodeUrl(eachResult.realURL).split("/")[^1]
finalPath = folder & fileName
try:
echo "[+] Downloading " & eachResult.realURL
client.downloadFile(eachResult.realURL, finalPath)
echo "[*] Saved at " & finalPath
downloaded += 1
except:
stderr.write("[x] Error while downloading " & eachResult.realURL & "
\n
")
if eachResult.cacheURL != "No web cache URL found":
echo "[-] Download from cache is not supported. Please try it manually: " & eachResult.cacheURL
echo "[*] Downloaded " & intToStr(downloaded) & " files"
proc getResult(resp: Response) =
#[
Check respose and create filter for the URL
Expect result:
1. Title
2. URL
3. Web cache URL
]#
if resp.status != "200 OK":
stderr.write("[x] Get status code " & resp.status & "
\n
")
else:
let allResults = parseHTML(resp.body)
for eachResult in allResults.findAll("div"):
# Filter all result thing
if eachResult.attr("class") == "r":
let
urlResults = eachResult.findAll("a")
titleResults = eachResult.findAll("h3")
var
tmpCacheURL = ""
dorkResult: DorkFile
try:
tmpCacheURL = urlResults[2].attr("href")
except IndexError:
tmpCacheURL = "No web cache URL found"
dorkResult = DorkFile(
title: titleResults[0].innerText,
realURL: urlResults[0].attr("href"),
cacheURL: tmpCacheURL,
)
allDorkResults.add(dorkResult)
proc basicSearch(domain, extension, query: string) =
#[
Do the google dork by basic HTTP GET queries
Make the basic query like this:
site:<domain name> ext:<file type> <Keyword>
Num=500 how many results in first page
Q= Our queries
TODO: multiple file types
]#
var
client = newHttpClient()
payload = "site:" & domain & " ext:" & extension
if query != "":
payload &= " " & query
payload = encodeUrl(payload)
client.headers = newHttpHeaders({"User-Agent": "Mozilla/5.0 (Windows NT 10.0; …) Gecko/20100101 Firefox/68.0"})
let resp = client.get("https://google.com/search?num=500&q=" & payload)
getResult(resp)
proc handleOptions(options: Options) =
#[
Handle all user'
s
options
and
throw
error
1.
Verify
required
options
and
run
the
basic
search
(
no
API
support
by
now
)
2.
If
result
>
0
print
as
table
3.
If
result
>
0
and
user
want
to
download
:
Download
all
file
]
#
if
options
.
domain
==
""
or
options
.
extension
==
""
:
stderr
.
write
(
"[x] Domain name and file extension is required
\n
"
)
else
:
basicSearch
(
options
.
domain
,
options
.
extension
,
options
.
query
)
let
szResults
=
len
(
allDorkResults
)
if
szResults
>
0
:
printResult
()
if
options
.
path
==
"."
:
options
.
path
=
getCurrentDir
()
elif
options
.
path
.
startsWith
(
"~"
):
options
.
path
=
options
.
path
.
replace
(
"~"
,
getHomeDir
())
if
options
.
path
!=
""
and
options
.
path
[
^
1
]
!=
"/"
[
0
]
:
options
.
path
&=
"/"
if
options
.
path
!=
""
:
if
not
existsDir
(
options
.
path
):
try
:
createDir
(
options
.
path
)
except
:
stderr
.
write
(
"[x] Error while creating download folder
\n
"
)
return
downloadFiles
(
options
.
path
)
else
:
downloadFiles
(
options
.
path
)
echo
"Found "
&
intToStr
(
szResults
)
&
" results"
proc
main
=
#[
Handle
arguments
to
pass
to
function
1.
Get
all
basic
arguments
for
query
2.
Handle
all
aguments
or
print
error
/
help
3.
Call
job
4
Print
result
5.
Handle
file
download
]
#
#[
All
needed
arguments
:
1.
Target
(
domain
)
2.
File
type
3.
Query
4.
Optional
:
save
folder
]
#
banner
()
if
paramCount
()
==
0
:
helpBanner
()
return
elif
paramCount
()
==
1
and
paramStr
(
1
)
==
"help"
or
paramStr
(
1
)
==
"-h"
or
paramStr
(
1
)
==
"--help"
or
paramStr
(
1
)
==
"-help"
:
helpBanner
()
return
else
:
var
index
=
1
options
:
Options
options
=
Options
(
domain
:
""
,
query
:
""
,
extension
:
""
,
path
:
""
,
)
while
index
<
paramCount
():
if
paramStr
(
index
)
==
"-d"
:
options
.
domain
=
paramStr
(
index
+
1
)
index
+=
1
elif
paramStr
(
index
)
==
"-f"
:
options
.
extension
=
paramStr
(
index
+
1
)
index
+=
1
elif
paramStr
(
index
)
==
"-q"
:
options
.
query
=
paramStr
(
index
+
1
)
index
+=
1
elif
paramStr
(
index
)
==
"-s"
:
options
.
path
=
paramStr
(
index
+
1
)
index
+=
1
else
:
stderr
.
write
(
"[x] Unknow options "
&
paramStr
(
index
)
&
"
\n
"
)
helpBanner
()
return
index
+=
1
handleOptions
(
options
)
echo
"[*] Completed"
main
()
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment