import os
import re
import sys
# 获取文件中的URL
def getUrls(file):
f = open(file, 'r', encoding="utf-8")
file_text = f.read()
urls = re.findall(r'[a-zA-z]+://[^\s]*', file_text)
if 'jsjiami.com' in file_text:
urls.append('Encrypted')
if urls:
return urls
def getExt(file):
scriptType = 'jstspy'
file_ext = os.path.splitext(file)[1]
file_ext = file_ext.split('.')[1]
if file_ext in scriptType:
return True
def getFile(file):
Files = []
if os.path.isdir(file) == True:
print('当前目录: %s' % os.path.abspath(child))
os.chdir(file)
files = os.listdir()
for i in files:
getFile(i)
os.chdir('../')
else:
Files.append(os.path.abspath(file))
return Files
def load_send():
global send
cur_path = os.path.abspath(os.path.dirname(file))
sys.path.append(cur_path)
if os.path.exists(cur_path + "/sendNotify.py"):
try:
from sendNotify import send
except:
send=False
print("加载通知服务失败~")
else:
send=False
print("加载通知服务失败~")
load_send()
if name == "main":
total_encrypted = 0
print('当前目录 %s ' % os.getcwd())
dir_childs = os.listdir()
for child in dir_childs:
# 判断是否目录
# if os.path.isdir(child) == True:
# print('当前目录: %s' % os.path.abspath(child))
# os.chdir(child)
# # 获取文件
# os.chdir('../')
total_files = getFile(child)
try:
for file in total_files:
if getExt(file) == True:
print('###### %s ######' % file)
urls = getUrls(file)
for url in urls:
if 'jd.com' not in url:
print(url+'\n')
if url == 'Encrypted':
total_encrypted += 1
except Exception as e:
print(e)
print('当前共查找到加密脚本 %d 个' % total_encrypted)
msg = '当前共查找到加密脚本 %d 个' % total_encrypted
send('加密脚本检测', msg)
记得按照上图手动选择一下那个文件再调试运行,否则可能会碰到下图显示的问题