Skip to content

Commit bbbb794

Browse files
kelvin_benYour Name
kelvin_ben
authored and
Your Name
committed
- 新增AI智能分析快速过滤第三方URL地址
- 新增Domain\Title\CDN识别功能 - 优化Excel文件内容输出格式 - 优化URL和IP筛选规则 - 优化全局日志输出 - 修复APK下多DEX文件搜索结果不准确的问题
1 parent cd7bb3a commit bbbb794

File tree

8 files changed

+72
-108
lines changed

8 files changed

+72
-108
lines changed

app.py

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ def cli():
1717
@cli.command(help="Get the key information of Android system.")
1818
@click.option("-i", "--inputs", required=True, type=str, help="Input APK file or DEX directory.")
1919
@click.option("-r", "--rules", required=False, type=str, default="", help="Add regular search rule.")
20-
@click.option("-s", "--net-sniffer", is_flag=True, default=False, help="Whether to enable network sniffing.")
20+
@click.option("-s", "--net-sniffer", is_flag=True, default=True, help="Whether to enable network sniffing.")
2121
@click.option("-n", '--no-resource', is_flag=True, default=False,help="Ignore resource files.")
2222
@click.option("-p", '--package',required=False,type=str,default="",help="Specifies the retrieval package name.")
2323
@click.option("-a", '--all-str',is_flag=True, default=False,help="Output all strings.")
@@ -36,7 +36,7 @@ def android(inputs: str, rules: str, net_sniffer: bool,no_resource:bool,package:
3636
@cli.command(help="Get the key information of iOS system.")
3737
@click.option("-i", "--inputs", required=True, type=str, help="Input IPA file or ELF file.")
3838
@click.option("-r", "--rules", required=False, type=str, default="", help="Add regular search rule.")
39-
@click.option("-s", "--net-sniffer", is_flag=True, default=False, help="Whether to enable network sniffing.")
39+
@click.option("-s", "--net-sniffer", is_flag=True, default=True, help="Whether to enable network sniffing.")
4040
@click.option("-n", '--no-resource', is_flag=True, default=False,help="Ignore resource files.")
4141
@click.option("-a", '--all-str',is_flag=True, default=False,help="Output all strings.")
4242
@click.option("-t", '--threads',required=False, type=int,default=10,help="Set the number of threads to 10 by default")
@@ -57,17 +57,15 @@ def ios(inputs: str, rules: str, net_sniffer: bool,no_resource:bool,all_str:bool
5757
@click.option("-r", "--rules", required=False, type=str, default="", help="Add regular search rule.")
5858
@click.option("-a", '--all-str',is_flag=True, default=False,help="Output all strings.")
5959
@click.option("-t", '--threads',required=False, type=int,default=10,help="Set the number of threads to 10 by default")
60-
def web(inputs: str, rules: str, all_str:bool,threads:int) -> None:
60+
@click.option("-s", "--net-sniffer", is_flag=True, default=True, help="Whether to enable network sniffing.")
61+
def web(inputs: str, rules: str, all_str:bool,threads:int,net_sniffer) -> None:
6162
try:
6263
# 初始化全局对象
6364
bootstrapper = Bootstrapper(__file__)
6465
bootstrapper.init()
6566

66-
BaseTask("Web", inputs, rules,all_str, threads).start()
67-
68-
# task = WebTask(input, rules,all,threads)
69-
# task.start()
70-
67+
BaseTask("Web", inputs, rules,all_str, net_sniffer,threads).start()
68+
7169
except Exception as e:
7270
raise e
7371

config.py

Lines changed: 15 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -29,35 +29,26 @@
2929
# 3. URI地址,URI不能很好的拼接所以此处忽略
3030
filter_strs =[
3131
r'https://.*|http://.*',
32-
r'.*://([[0-9]{1,3}\.]{3}[0-9]{1,3}).*',
32+
# r'.*://([[0-9]{1,3}\.]{3}[0-9]{1,3}).*',
33+
r'.*://([\d{1,3}\.]{3}\d{1,3}).*'
3334
# r'/[a-z0-9A-Z]+/.*'
3435
]
3536

3637
# 此处忽略常见的域名等信息
3738
filter_no = [
38-
# r'.*127.0.0.1',
39-
# r'.*0.0.0.0',
40-
# r'.*localhost',
41-
# r'.*w3.org',
42-
# r'.*apache.org',
43-
# r'.*android.com',
44-
# r'.*weixin.qq.com',
45-
# r'.*jpush.cn',
46-
# r'.*umengcloud.com',
47-
# r'.*umeng.com',
48-
# r'.*baidu.com',
49-
# r'.*apple.com',
50-
# r'.*alibaba.com',
51-
# r'.*qq.com',
52-
# r'.*sohu.com',
53-
# r'.*openssl.org',
54-
# r'.*weibo.com',
55-
# r'.*wechat.com',
56-
# r'.*.amap.com',
57-
# r'.*openxmlformats.org',
58-
# r'.*github.com',
59-
# r'.*w3school.com.cn',
60-
# r'.*google.com'
39+
r'.*127.0.0.1',
40+
r'.*0.0.0.0',
41+
r'.*localhost',
42+
r'.*w3.org',
43+
r'.*apache.org',
44+
r'.*android.com',
45+
r'.*jpush.cn',
46+
r'.*umengcloud.com',
47+
r'.*umeng.com',
48+
r'.*github.com',
49+
r'.*w3school.com.cn',
50+
r'.*apple.com',
51+
r'.*.amap.com',
6152
]
6253

6354
# 此处配置壳信息

libs/core/net.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,14 @@ def __init__(self,threadID,name,domain_queue,worksheet):
1616

1717
def __get_Http_info__(self,threadLock):
1818
while True:
19+
if self.domain_queue.empty():
20+
break
1921
domains = self.domain_queue.get(timeout=5)
2022
domain = domains["domain"]
2123
url_ip = domains["url_ip"]
2224
time.sleep(2)
2325
result = self.__get_request_result__(url_ip)
26+
print("[+] Processing URL address:"+url_ip)
2427
if result != "error":
2528
if self.lock.acquire(True):
2629
cores.excel_row = cores.excel_row + 1
@@ -33,17 +36,15 @@ def __get_Http_info__(self,threadLock):
3336
self.worksheet.write(cores.excel_row, 5, label = result["server"])
3437
self.worksheet.write(cores.excel_row, 6, label = result["title"])
3538
self.worksheet.write(cores.excel_row, 7, label = result["cdn"])
36-
self.worksheet.write(cores.excel_row, 8, label = "")
39+
# self.worksheet.write(cores.excel_row, 8, label = "")
3740
self.lock.release()
38-
if self.domain_queue.empty():
39-
break
41+
42+
4043

4144
def __get_request_result__(self,url):
4245
result={"status":"","server":"","cookie":"","cdn":"","des_ip":"","sou_ip":"","title":""}
4346
cdn = ""
4447
try:
45-
# python3 app.py ios -i C:\Users\Administrator\Desktop\frida-ipa-dump\三晋通\Payload\三晋通.app\三晋通
46-
#
4748
with requests.get(url, timeout=5,stream=True) as rsp:
4849
status_code = rsp.status_code
4950
result["status"] = status_code
@@ -80,7 +81,6 @@ def __get_request_result__(self,url):
8081
except requests.exceptions.ReadTimeout as e2:
8182
return "timeout"
8283

83-
8484
def run(self):
8585
threadLock = threading.Lock()
8686
self.__get_Http_info__(threadLock)

libs/core/parses.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def __regular_parse__(self):
2626
break
2727

2828
file_path = self.file_queue.get(timeout = 5)
29-
scan_str = ("Scan file : %s" % file_path)
29+
scan_str = ("[+] Scan file : %s" % file_path)
3030
print(scan_str)
3131

3232
if self.types == "iOS":
@@ -65,7 +65,7 @@ def __parse_string__(self,result):
6565
for filter_str in config.filter_strs:
6666
filter_str_pat = re.compile(filter_str)
6767
filter_resl = filter_str_pat.findall(result)
68-
# print(result,filter_resl)
68+
6969
# 过滤掉未搜索到的内容
7070
if len(filter_resl)!=0:
7171
# 提取第一个结果
@@ -75,27 +75,18 @@ def __parse_string__(self,result):
7575
continue
7676

7777
self.threadLock.acquire()
78+
print("[+] The string searched for matching rule is: %s" % (resl_str))
7879
self.result_list.append(resl_str)
7980
self.threadLock.release()
8081
continue
8182

8283
def __filter__(self,resl_str):
8384
return_flag = 1
84-
print(resl_str)
8585
resl_str = resl_str.replace("\r","").replace("\n","").replace(" ","")
86+
8687
if len(resl_str) == 0:
8788
return 0
88-
89-
# 目前流通的域名中加上协议头最短长度为11位
90-
if len(resl_str) <= 10:
91-
return 0
92-
93-
# 单独处理https或者http开头的字符串
94-
# http_list =["https","https://","https:","http","http://","https:",]
95-
# for filte in http_list:
96-
# if filte == resl_str:
97-
# return 0
98-
89+
9990
for filte in config.filter_no:
10091
resl_str = resl_str.replace(filte,"")
10192
if len(resl_str) == 0:

libs/task/base_task.py

Lines changed: 11 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class BaseTask(object):
1919
app_history_list=[]
2020

2121
# 统一初始化入口
22-
def __init__(self, types="Android", inputs="", rules="", net_sniffer=False, no_resource=False, package="", all_str=False, threads=10):
22+
def __init__(self, types="Android", inputs="", rules="", net_sniffer=True, no_resource=False, package="", all_str=False, threads=10):
2323
self.types = types
2424
self.net_sniffer = net_sniffer
2525
self.path = inputs
@@ -35,12 +35,12 @@ def __init__(self, types="Android", inputs="", rules="", net_sniffer=False, no_r
3535
# 统一调度平台
3636
def start(self):
3737

38-
print("[*] AI决策系统正在分析规则中...")
38+
print("[*] AI is analyzing filtering rules......")
3939

4040
# 获取历史记录
4141
self.__history_handle__()
4242

43-
print("[*] 本次的过滤规则为:" , config.filter_no)
43+
print("[*] The filtering rules obtained by AI are as follows: %s" % (config.filter_no) )
4444

4545
# 任务控制中心
4646
task_info = self.__tast_control__()
@@ -55,6 +55,7 @@ def start(self):
5555
return
5656

5757
# 线程控制中心
58+
print("[*] ========= Searching for strings that match the rules ===============")
5859
self.__threads_control__(file_queue)
5960

6061
# 等待线程结束
@@ -92,44 +93,19 @@ def __print_control__(self,packagename,comp_list,file_identifier):
9293
# 此处需要hash值或者应用名称, apk文件获取pachage, dex文件获取hash, macho-o获取文件名
9394

9495
if packagename:
95-
print("========= The package name of this APP is: ===============")
96+
print("[*] ========= The package name of this APP is: ===============")
9697
print(packagename)
9798

9899
if len(comp_list) != 0:
99-
print("========= Component information is as follows :===============")
100+
print("[*] ========= Component information is as follows :===============")
100101
for json in comp_list:
101102
print(json)
102-
print("=========The result set for the static scan is shown below:===============")
103-
104-
NetTask(self.result_dict,self.app_history_list,file_identifier,self.threads).start()
105103

106-
# with open(txt_result_path,"a+",encoding='utf-8',errors='ignore') as f:
107-
# row = 1
108-
# for key,value in self.result_dict.items():
109-
# f.write(key+"\r")
110-
111-
# for result in value:
112-
# if result in self.value_list:
113-
# continue
114-
# if not(file_identifier in self.app_history_list) and ("http://" in result or "https://" in result):
115-
# domain = result.replace("https://","").replace("http://","")
116-
# if "/" in domain:
117-
# domain = domain[:domain.index("/")]
118-
119-
# if not(domain in self.domain_list):
120-
# self.domain_list.append(domain)
121-
# self.__write_content_in_file__(cores.domain_history_path,domain)
122-
# if append_file_flag:
123-
# for identifier in file_identifier:
124-
# self.__write_content_in_file__(cores.app_history_path,identifier)
125-
# append_file_flag = False
126-
127-
# self.value_list.append(result)
128-
# worksheet.write(row,0, label = result)
129-
# row = row + 1
130-
# f.write("\t"+result+"\r")
131-
print("For more information about the search, see TXT file result: %s" %(cores.txt_result_path))
132-
print("For more information about the search, see XLS file result: %s" %(cores.xls_result_path))
104+
if self.net_sniffer:
105+
print("[*] ========= Sniffing the URL address of the search ===============")
106+
NetTask(self.result_dict,self.app_history_list,file_identifier,self.threads).start()
107+
print("[*] For more information about the search, see XLS file result: %s" %(cores.xls_result_path))
108+
print("[*] For more information about the search, see TXT file result: %s" %(cores.txt_result_path))
133109

134110
def __history_handle__(self):
135111
domain_history_path = cores.domain_history_path

libs/task/net_task.py

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,14 @@ def start(self):
2626
xls_result_path = cores.xls_result_path
2727
workbook = xlwt.Workbook(encoding = 'utf-8')
2828
worksheet = self.__creating_excel_header__(workbook)
29-
self.__start_threads__(worksheet)
29+
3030
self.__write_result_to_txt__()
3131

32+
self.__start_threads__(worksheet)
33+
3234
for thread in self.thread_list:
3335
thread.join()
3436

35-
3637
workbook.save(xls_result_path)
3738

3839
def __creating_excel_header__(self,workbook):
@@ -45,7 +46,7 @@ def __creating_excel_header__(self,workbook):
4546
worksheet.write(0,5, label = "Server")
4647
worksheet.write(0,6, label = "Title")
4748
worksheet.write(0,7, label = "CDN")
48-
worksheet.write(0,8, label = "Finger")
49+
# worksheet.write(0,8, label = "Finger")
4950
return worksheet
5051

5152
def __write_result_to_txt__(self):
@@ -58,29 +59,33 @@ def __write_result_to_txt__(self):
5859
for result in value:
5960
if result in self.value_list:
6061
continue
61-
62-
# 100个文件标识
63-
for file in self.file_identifier:
64-
if not(file in self.app_history_list) and ("http://" in result or "https://" in result):
6562

66-
# print(self.file_identifier,self.app_history_list,not(self.file_identifier[0] in self.app_history_list))
67-
# if not(self.file_identifier in self.app_history_list) and ("http://" in result or "https://" in result):
68-
domain = result.replace("https://","").replace("http://","")
69-
if "/" in domain:
70-
domain = domain[:domain.index("/")]
71-
72-
self.domain_queue.put({"domain":domain,"url_ip":result})
63+
if (("http://" in result) or ("https://" in result)) and ("." in result):
64+
domain = result.replace("https://","").replace("http://","")
65+
if "/" in domain:
66+
domain = domain[:domain.index("/")]
67+
68+
if "|" in result:
69+
result = result[:result.index("|")]
70+
# 目前流通的域名中加上协议头最短长度为11位
71+
if len(result) <= 10:
72+
continue
73+
self.domain_queue.put({"domain":domain,"url_ip":result})
74+
75+
for identifier in self.file_identifier:
76+
if identifier in self.app_history_list:
77+
if not(domain in self.domain_list):
78+
self.domain_list.append(domain)
79+
self.__write_content_in_file__(cores.domain_history_path,domain)
80+
continue
7381

74-
print(domain,self.domain_list,not(domain in self.domain_list))
7582
if not(domain in self.domain_list):
7683
self.domain_list.append(domain)
7784
self.__write_content_in_file__(cores.domain_history_path,domain)
85+
7886
if append_file_flag:
79-
for identifier in self.file_identifier:
80-
if self.file_identifier in self.app_history_list:
81-
continue
82-
self.__write_content_in_file__(cores.app_history_path,identifier)
83-
append_file_flag = False
87+
self.__write_content_in_file__(cores.app_history_path,identifier)
88+
append_file_flag = False
8489
self.value_list.append(result)
8590
f.write("\t"+result+"\r")
8691
f.close()

libs/task/web_task.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,7 @@ def __get_scanner_file__(self,scanner_dir,file_suffix):
3737
else:
3838
if len(dir_file.split("."))>1:
3939
if dir_file.split(".")[-1] in file_suffix:
40+
with open(file_path,'rb') as f:
41+
dex_md5 = str(hashlib.md5().update(f.read()).hexdigest()).upper()
42+
self.file_identifier.append(dex_md5)
4043
self.file_queue.put(dir_file_path)

update.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
### V1.0.6
22
- 新增AI智能分析快速过滤第三方URL地址
3-
- 新增Domain\Title\CDN\Finger识别功能
3+
- 新增Domain\Title\CDN识别功能
44
- 优化Excel文件内容输出格式
55
- 优化URL和IP筛选规则
66
- 优化全局日志输出

0 commit comments

Comments
 (0)