New Text Document
New Text Document
/usr/bin/python3
# -*- coding: utf-8 -*-
__version__ = "6.1.0"
user_agent = [
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:65.0) Gecko/20100101
Firefox/65.0",
"Mozilla/5.0 (MSIE 10.0; Windows NT 6.1; Trident/5.0)",
"Opera/9.80 (Windows NT 6.0) Presto/2.12.388 Version/12.14",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_9_3) AppleWebKit/537.75.14 (KHTML,
like Gecko) Version/7.0.3 Safari/7046A194A"
]
_ROOT = os.path.abspath(os.path.dirname(__file__))
_local_wordlist = _ROOT + "{sep}local{sep}wordlist.txt".format(sep=os.sep)
_remote_plugin_folder = _ROOT + '{sep}remote'.format(sep=os.sep)
_user_agent = random.choice(user_agent)
# default params
_params = {
"no_local": False, # [bool] local wordlist ignore --no-
local
"no_remote": False, # [bool] remote wordlist ignore --no-
remote
"no_scan": False, # [bool] scanning ignore, show wordlist
--no-scan
"no_http": False, # [bool] http requests ignore --no-http
"no_http_code": [], # [list] http code list to ignore --no-
http-code 404
"no_ip": [], # [list] ip address to ignore --no-ip
127.0.0.1
"dns": "", # [str] use custom DNS ex. 8.8.8.8 --
dns 8.8.8.8
"timeout": 3, # [int] timeout in seconds -t 5
"threads": 30, # [int] threads num -th 50
"useragent": _user_agent, # [str] use a custom user agent --user-
agent Mozilla
"wordlist": _local_wordlist, # [str] path to custom wordlist -w
file.txt
"silent_mode": False, # [bool] silent mode --silent (--silent
csv)
"output_folder": "knockpy_report", # [str] report folder -o /folder/
"save_output": True, # [bool] save report -o false to
disable it
"plugin_test": False, # [bool] test plugin --plugin-test
"plugin_folder": _remote_plugin_folder # [str] plugin folder (no via arg)
}
# check for valid domain
def is_valid_domain(domain):
if not isinstance(domain, str) or not re.match("[a-z0-9\.-]", domain) or
domain.startswith(("http", "www.")):
return False
return True
"""
# module to import in python script:
# get wordlist
if params["plugin_test"]:
return wordlists.get(domain, params)
# get wordlists
local, remote, wordlist = Start.wordlist(domain, params)
# start scan
return Start.threads(domain, max_len, wordlist, params)
class Start():
# print random message
def msg_rnd():
return ["happy hacking ;)", "good luck!", "never give up!",
"hacking is not a crime",
"https://en.wikipedia.org/wiki/Bug_bounty_program"]
def arguments():
# check for extra arguments
extraargs.parse_and_exit(sys.argv)
description = "-"*80+"\n"
description += "* SCAN\n"
description += "full scan:\tknockpy domain.com\n"
description += "quick scan:\tknockpy domain.com --no-local\n"
description += "faster scan:\tknockpy domain.com --no-local --no-http\n"
description += "ignore code:\tknockpy domain.com --no-http-code 404 500
530\n"
description += "silent mode:\tknockpy domain.com --silent\n\n"
description += "* SUBDOMAINS\n"
description += "show recon:\tknockpy domain.com --no-local --no-scan\n\n"
description += "* REPORT\n"
description += "show report:\tknockpy --report
knockpy_report/domain.com_yyyy_mm_dd_hh_mm_ss.json\n"
description += "plot report:\tknockpy --plot
knockpy_report/domain.com_yyyy_mm_dd_hh_mm_ss.json\n"
description += "csv report:\tknockpy --csv
knockpy_report/domain.com_yyyy_mm_dd_hh_mm_ss.json\n"
description += "-"*80
epilog = "once you get knockpy results, don't forget to use 'nmap' and
'dirsearch'\n\n"
epilog += random.choice(Start.msg_rnd())
# args
parser.add_argument("domain", nargs='?', help="target to scan",
default=sys.stdin, type=str)
parser.add_argument("-v", "--version", action="version", version="%(prog)s
" + __version__)
parser.add_argument("--no-local", help="local wordlist ignore",
action="store_true", required=False)
parser.add_argument("--no-remote", help="remote wordlist ignore",
action="store_true", required=False)
parser.add_argument("--no-scan", help="scanning ignore, show wordlist and
exit", action="store_true", required=False)
parser.add_argument("--no-http", help="http requests ignore\n\n",
action="store_true", required=False)
parser.add_argument("--no-http-code", help="http code list to ignore\n\n",
nargs="+", dest="code", type=int, required=False)
parser.add_argument("--no-ip", help="ip address to ignore\n\n", nargs="+",
type=str, required=False)
parser.add_argument("--dns", help="use custom DNS ex. 8.8.8.8\n\n",
dest="dns", required=False)
parser.add_argument("--user-agent", help="use a custom user agent\n\n",
dest="useragent", required=False)
parser.add_argument("--plugin-test", help="test plugins and exit\n\n",
action="store_true", required=False)
parser.add_argument("--silent",
default=False,
nargs="?",
choices=[False, "json", "json-pretty", "csv"],
help="silent or quiet mode, default output: False\n\n",
)
args = parser.parse_args()
# choice wordlist
if _params["no_local"] and _params["no_remote"]: sys.exit("no wordlist")
# --user-agent
if args.useragent:
_params["useragent"] = args.useragent
# --plugin-test
if args.plugin_test:
_params["plugin_test"] = args.plugin_test
if not params["silent_mode"]:
for item in concurrent.futures.as_completed(results_executor):
if item.result() != None:
print (item.result())
# return a dict
return results
local = wordlists.purge(local)
remote = wordlists.purge(remote)
def main():
domain, params = Start.arguments()
# action: scan
if not params["silent_mode"]:
print (logo.show(__version__))
output.progressPrint("getting wordlist ...")
# get wordlist
if params["plugin_test"]:
print (wordlists.get(domain, params))
sys.exit()
# get wordlists
local, remote, wordlist = Start.wordlist(domain, params)
# print header
if not params["silent_mode"]:
print (output.headerPrint(local, remote, domain))
# Start threads
results = Start.threads(domain, max_len, wordlist, params)
# elapsed time
time_end = time.time()
# show output
# when silent_mode is None (--silent without args) -> "no-output" -> quiet
if not params["silent_mode"]:
# when silent_mode is False
print (output.footerPrint(time_end, time_start, results))
elif params["silent_mode"] == "json":
# json without indent
print (json.dumps(results))
elif params["silent_mode"] == "json-pretty":
# json with indent
print (json.dumps(results, indent=4))
elif params["silent_mode"] == "csv":
print (report.csv(results))
# save report
if params["save_output"]:
report.save(results, domain, time_start, time_end, len(wordlist),
__version__, params["output_folder"])
if __name__ == "__main__":
try:
main()
except KeyboardInterrupt:
print("\nInterrupted")
try:
sys.exit(0)
except SystemExit:
os._exit(0)