Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
300COM-10703337/vueScan.py
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
184 lines (160 sloc)
5.92 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# pylint:disable=anomalous-backslash-in-string | |
import re | |
import urllib.parse as up | |
from queue import Queue | |
import time | |
import sys | |
import copy | |
from config import cookie, headers | |
from selenium import webdriver | |
import json | |
def Scan(url, All = False, timeout = -1, cookie = None, localStorage = None): | |
option = webdriver.ChromeOptions() | |
option.add_argument('headless') | |
driver = webdriver.Chrome(options = option) | |
#driver.add_cookie(cookie) | |
if isinstance(url, str): | |
Urls = [url] | |
elif isinstance(url, list): | |
Urls = url | |
q = Queue() | |
for eachUrl in Urls: | |
q.put(eachUrl) | |
Accessable = [] | |
cnt = 0 | |
Parse = up.urlparse(url) | |
host = "%s://%s/" % (Parse[0], Parse[1]) | |
now = time.time() | |
while not q.empty(): | |
print("finish:%d/%d.\r" % (cnt, len(Urls)), end='', flush=True) | |
cnt += 1 | |
if timeout != -1 and time.time() - now > timeout: | |
break | |
thisUrl = q.get() | |
#print(thisUrl, end = ' ') | |
try: | |
driver.get(thisUrl) | |
if localStorage: | |
for eachKey in localStorage.keys(): | |
driver.execute_script("localStorage.setItem('%s', '%s')" % (eachKey, localStorage[eachKey])) | |
driver.refresh() | |
time.sleep(1) | |
html = driver.page_source | |
tags = ['href', 'value', 'action'] | |
pattern = '^((ht|f)tps?):\/\/[\w\-]+(\.[\w\-]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?$' | |
except KeyboardInterrupt: | |
break | |
except: | |
# print("failed") | |
continue | |
thisUrl = driver.current_url | |
ans = [] | |
for each in tags: | |
pattern = '%s=\'(.*?)\'' % each | |
ans += re.findall(pattern, html, re.S) | |
pattern = '%s="(.*?)"' % each | |
ans += re.findall(pattern, html, re.S) | |
ret = [] | |
ext_white_list = ['.php', '.htm', '.html', '.xhtml'] | |
for each in ans: | |
if "javascript:" in each: | |
continue | |
each = each.replace('\\', '/') | |
lastSection = each.split('/')[-1].lower() | |
access = False | |
if '.' in lastSection: | |
for eachWhite in ext_white_list: | |
if eachWhite in lastSection: | |
access = True | |
break | |
if not access: | |
continue | |
elif each.startswith("http"): | |
ret.append(each) | |
elif each.startswith('//'): | |
ret.append("%s:%s" % (Parse[0], each)) | |
elif each.startswith('/'): | |
ret.append(host + each[1:]) | |
elif each.startswith("../"): | |
urlCopy = copy.copy(thisUrl).split('/') | |
if len(urlCopy[-1]) == 0: | |
urlCopy = urlCopy[:-1] | |
each = each.split('/') | |
if len(each[0]) == 0: | |
each = each[1:] | |
cnt = 0 | |
for eachSection in each: | |
if eachSection == '..': | |
cnt += 1 | |
else: | |
break | |
if cnt + 3 >= len(urlCopy): | |
urlCopy = urlCopy[:3] | |
else: | |
urlCopy = urlCopy[:-cnt] | |
urlCopy = "/".join(urlCopy) | |
each = "/".join(each[cnt:]) | |
ret.append("%s/%s" % (urlCopy, each)) | |
else: | |
ret.append(thisUrl + each) | |
ans = [] | |
for each in ret: | |
this = up.urlparse(each) | |
if All or this[1] == Parse[1]: | |
tmp = up.urlunparse((this[0], this[1], this[2], '', '', '')) | |
if '.' in tmp.split('/')[-1]: | |
tmp = "/".join(tmp.split('/')[:-1]) | |
ans.append(tmp) | |
ret = ans.copy() | |
for each in ans: | |
if each[-1] == '/': | |
each = each[:-1] | |
tmp = each.split('/') | |
l = len(tmp) | |
for i in range(3, l - 1): | |
this = '/'.join(tmp[:i]) | |
if this not in ret: | |
ret.append(this) | |
for each in ret: | |
if not each.endswith('/'): | |
each = each + '/' | |
if each not in Urls: | |
Urls.append(each) | |
q.put(each) | |
if thisUrl not in Accessable: | |
Accessable.append(thisUrl) | |
# print("success") | |
driver.quit() | |
return (Urls, Accessable) | |
def main(url, All = False, timeout = -1, cookie = None, localStorage = None): | |
return Scan(url, All, timeout, cookie, localStorage) | |
if __name__ == "__main__": | |
if len(sys.argv) == 2: | |
host = sys.argv[1] | |
ans = main(host) | |
print("This Web Has Urls Below:") | |
for each in ans[0]: | |
print(each) | |
print("------------------------------") | |
print("These Url Below is Accessable:") | |
for each in ans[1]: | |
print(each) | |
print("------------------------------") | |
print("finished") | |
# print(urls) | |
exit(0) | |
else: | |
data = {'vuex': '{"user":{"userInfo":{"username":"test","IsAdmin":false,"uuid":"d3fdc539-a242-441a-91c0-e1b59bcd4e38","email":"a@a.wwa"},"token":"asdasdasd","expiresAt":"2020/10/16"}}'} | |
url = input() | |
ans = main(url, localStorage = data) | |
print("This Web Has Urls Below:") | |
for each in ans[0]: | |
print(each) | |
print("------------------------------") | |
print("These Url Below is Accessable:") | |
for each in ans[1]: | |
print(each) | |
print("------------------------------") | |
print("finished") | |
# print(urls) | |
exit(0) |