-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathpentestbox-search-tools.py
112 lines (96 loc) · 3.19 KB
/
pentestbox-search-tools.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#coding=utf-8
'''
autor:c0ny1
date: 2018-1-27
'''
import os,sys
CASE = False # 是否区分大小写
MODLE = "string" # 搜索模式
# aliases文件路径
SCRIPT_PATH = sys.path[0]
aliases = "..\\..\\..\\config\\aliases"
customaliases = "..\\customaliases"
paths = {
"aliases":(SCRIPT_PATH + "\\" + aliases),
"customaliases":(SCRIPT_PATH + "\\" + customaliases)
}
# 全词搜索
def search_by_whole_word(keyword,string):
keyword = keyword.replace('\'','')
if keyword == string:
return True
else:
return False
# 模糊搜索
def search_by_string(keyword,string):
if keyword in string:
return True
else:
return False
# 通配符搜索
def search_by_wildcard(re_str,test_str):
# 如果两个字符串相等 就返回True
if re_str == test_str :
return True
# 标记第一个字母
r = re_str[0] if re_str != '' else ''
t = test_str[0] if test_str !='' else ''
# r 不是? 也 不是* 的情况
if r != '?' and r != '*' :
if r != t : # 如果不想相等就返回False
return False
else : # 相等 就 删掉第一个单词 递归
re_str,test_str = re_str[1:],test_str[1:]
return search_by_wildcard( re_str,test_str)
# 如果r是? 相当于匹配一个字符 都删掉一个字符 然后 递归
if r == '?' :
re_str, test_str = re_str[1:], test_str[1:]
return search_by_wildcard(re_str, test_str)
# 如果r是* re 是n个* 则返回True
if r == '*' and re_str.strip('*') == '' :
return True
# 否则 就是包含* ,*匹配0个字符或多个字符,所以我们返回 递归 0个匹配 与 1个匹配 的逻辑或
return search_by_wildcard(re_str[1:], test_str) or search_by_wildcard(re_str, test_str[1:])
def help_info():
print "Usage: s [keyword] [-h/-cs]"
print "Examples:"
print " 1.s Burp"
print " 2.s 'Burpsuite'"
print " 3.s Burp?u*"
print " 4.s Burp?u* -sc"
def search(paths,model,keyword,case_sensitive=False):
for path in paths:
f = open(paths[path])
is_find = False
for line in f.readlines():
tool_name = line.split('=')[0]
if not case_sensitive: #是否区分大小写
keyword = keyword.lower()
tool_name = tool_name.lower()
if model == "string":
is_find = search_by_string(keyword,tool_name)
elif model == "whole_word":
is_find = search_by_whole_word(keyword,tool_name)
elif model == "wildcard":
is_find = search_by_wildcard(keyword,tool_name)
else:
pass
if is_find:
print '[+] %s' % tool_name
f.close()
def main():
if len(sys.argv)<=1 or sys.argv[1] == "-h":
help_info()
exit()
keyword = sys.argv[1]
global CASE
if len(sys.argv)>=3 and sys.argv[2] == '-cs':
CASE = True
if '*' in keyword or '?' in keyword:
search(paths,"wildcard",keyword,CASE)
elif '\'' in keyword:
search(paths,"whole_word",keyword,CASE)
else:
search(paths,"string",keyword,CASE)
if __name__ == '__main__':
main()