@ -17,68 +17,95 @@ from libs.task.android_task import AndroidTask
from libs . task . download_task import DownloadTask
class BaseTask ( object ) :
thread_list = [ ]
result_dict = { }
app_history_list = [ ]
domain_history_list = [ ]
# 统一初始化入口
def __init__ ( self , types = " Android " , inputs = " " , rules = " " , sniffer = True , threads = 10 , package = " " ) :
self . types = types
self . path = inputs
if rules :
config . filter_strs . append ( r ' .* ' + str ( rules ) + ' .* ' )
self . sniffer = not sniffer
self . threads = threads
self . package = package
def __init__ ( self ) :
if cores . user_add_rules :
config . filter_strs . append ( r ' .* ' + str ( cores . user_add_rules ) + ' .* ' )
self . file_queue = Queue ( )
self . file_path_list = [ ]
self . thread_list = [ ]
self . app_history_list = [ ]
self . domain_history_list = [ ]
self . result_dict = { }
# 统一启动
def start ( self , types = " Android " , user_input_path = " " , package = " " ) :
# 如果输入路径为目录,则自动检索DEX、IPA、APK等文件
if not ( types == " Web " ) and os . path . isdir ( user_input_path ) :
self . __scanner_specified_file__ ( self . file_path_list , user_input_path )
# 如果输入的路径为txt, 则加载txt中的内容
elif user_input_path . endswith ( " txt " ) :
with open ( user_input_path ) as f :
lines = f . readlines ( )
for line in lines :
if line . startswith ( " http:// " ) or line . startswith ( " https:// " ) or line . endswith ( " apk " ) or line . endswith ( " .dex " ) or line . endswith ( " ipa " ) :
self . file_path_list . append ( line )
f . close ( )
else :
# 如果是文件则追加到文件列表中
self . file_path_list . append ( user_input_path )
# 长度小于1需重新选择目录
if len ( self . file_path_list ) < 1 :
raise Exception ( ' [x] The specified DEX, IPA and APK files are not found. Please re-enter the directory to be scanned! ' )
# 统一调度平台
def start ( self ) :
# 遍历目录
for file_path in self . file_path_list :
self . __control_center__ ( file_path , types )
# 控制中心
def __control_center__ ( self , file_path , types ) :
logging . info ( " [*] Processing {} " . format ( file_path ) )
logging . info ( " [*] AI is analyzing filtering rules...... " )
# 获取历史记录
# 处理 历史记录
self . __history_handle__ ( )
logging . info ( " [*] The filtering rules obtained by AI are as follows: {} " . format ( set ( config . filter_no ) ) )
logging . info ( " [*] The filtering rules obtained by AI are as follows: %s " % ( set ( config . filter_no ) ) )
# AI 修正扫描类型
cache_info = DownloadTask ( ) . start ( file_path , types )
cacar_path = cache_info [ " path " ]
types = cache_info [ " type " ]
# 任务控制中心
task_info = self . __tast_control__ ( )
task_info = self . __tast_control__ ( file_path )
if len ( task_info ) < 1 :
return
file_queue = task_info [ " file_queue " ]
shell_flag = task_info [ " shell_flag " ]
comp_list = task_info [ " comp_list " ]
packagename = task_info [ " packagename " ]
file_identifier = task_info [ " file_identifier " ]
# 文件队列
file_queue = task_info [ " file_queue " ]
# 是否存在壳
shell_flag = task_info [ " shell_flag " ]
# 组件列表(仅适用于Android)
comp_list = task_info [ " comp_list " ]
# 报名信息(仅适用于Android)
packagename = task_info [ " packagename " ]
# 文件标识符
file_identifier = task_info [ " file_identifier " ]
if shell_flag :
logging . info ( ' [-] \033 [3;31m Error: This application has shell, the retrieval results may not be accurate, Please remove the shell and try again! ' )
return
if shell_flag :
logging . error ( ' [x] This application has shell, the retrieval results may not be accurate, Please remove the shell and try again! ' )
continue
# 线程控制中心
logging . info ( " [*] ========= Searching for strings that match the rules =============== " )
self . __threads_control__ ( file_queue )
# 线程控制中心
logging . info ( " [*] ========= Searching for strings that match the rules =============== " )
self . __threads_control__ ( file_queue )
# 等待线程结束
for thread in self . thread_list :
thread . join ( )
# 等待线程结束
for thread in self . thread_list :
thread . join ( )
# 结果输出中心
self . __print_control__ ( packagename , comp_list , file_identifier )
# 结果输出中心
self . __print_control__ ( packagename , comp_list , file_identifier )
def __tast_control__ ( self ) :
# 任务控制中心
def __tast_control__ ( self , user_input_path ) :
task_info = { }
# 自动根据文件后缀名称进行修正
cache_info = DownloadTask ( ) . start ( self . path , self . types )
cacar_path = cache_info [ " path " ]
types = cache_info [ " type " ]
if ( not os . path . exists ( cacar_path ) and cores . download_flag ) :
logging . info ( " [- ] File download failed! Please download the file manually and try again. " )
logging . error ( " [x] File download failed! Please download the file manually and try again. " )
return task_info
# 调用Android 相关处理逻辑
@ -92,21 +119,19 @@ class BaseTask(object):
task_info = WebTask ( cacar_path ) . start ( )
return task_info
# 线程控制中心
def __threads_control__ ( self , file_queue ) :
for threadID in range ( 1 , self . threads ) :
for threadID in range ( 1 , cores . threads_num ) :
name = " Thread - " + str ( int ( threadID ) )
thread = ParsesThreads ( threadID , name , file_queue , self . result_dict , self . types )
thread . start ( )
self . thread_list . append ( thread )
# 信息输出中心
def __print_control__ ( self , packagename , comp_list , file_identifier ) :
txt_result_path = cores . txt_result_path
xls_result_path = cores . xls_result_path
all_flag = cores . all_flag
if self . sniffer :
if cores . net_sniffer_flag :
logging . info ( " [*] ========= Sniffing the URL address of the search =============== " )
NetTask ( self . result_dict , self . app_history_list , self . domain_history_list , file_identifier , self . threads ) . start ( )
NetTask ( self . result_dict , self . app_history_list , self . domain_history_list , file_identifier ) . start ( )
if packagename :
logging . info ( " [*] ========= The package name of this APP is: =============== " )
@ -117,7 +142,7 @@ class BaseTask(object):
for json in comp_list :
logging . info ( json )
if all_flag :
if cores . all_flag :
value_list = [ ]
with open ( txt_result_path , " a+ " , encoding = ' utf-8 ' , errors = ' ignore ' ) as f :
for key , value in self . result_dict . items ( ) :
@ -128,11 +153,12 @@ class BaseTask(object):
value_list . append ( result )
f . write ( " \t " + result + " \r " )
f . close ( )
logging . info ( " [*] For more information about the search, see TXT file result: %s " % ( txt_result_path ) )
logging . info ( " [>] For more information about the search, see TXT file result: {} " . format ( cores . txt_result_path ) )
if self . sniffer :
logging . info ( " [*] For more information about the search, see XLS file result: %s " % ( xls_result_path ) )
if cores . net_sniffer_flag :
logging . info ( " [>] For more information about the search, see XLS file result: {} " . format ( cores . xls_result_path ) )
# 获取历史记录
def __history_handle__ ( self ) :
domain_history_path = cores . domain_history_path
app_history_path = cores . app_history_path
@ -160,4 +186,13 @@ class BaseTask(object):
config . filter_no . append ( " .* " + domain )
f . close ( )
# 扫描指定后缀文件
def __scanner_specified_file__ ( self , file_list , root_dir , file_suffix = [ ' dex ' , ' ipa ' , ' apk ' ] ) :
dir_or_files = os . listdir ( root_dir )
for dir_or_file in dir_or_files :
dir_or_file_path = os . path . join ( root_dir , dir_or_file )
if os . path . isdir ( dir_or_file_path ) :
self . __scanner_specified_file__ ( file_list , dir_or_file_path , file_suffix )
else :
if dir_or_file_path . split ( " . " ) [ - 1 ] in file_suffix :
file_list . append ( dir_or_file_path )