Skip to content

Commit f557ef2

Browse files
authored
Merge branch 'master' into master
2 parents 3c19c37 + 7ddd479 commit f557ef2

File tree

11 files changed

+103
-89
lines changed

11 files changed

+103
-89
lines changed

README.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,7 @@ The following are the interfaces and instructions provided by the SDK:
634634

635635
1.dork_search(dork, page=0, resource="host", facets=None)
636636
search the data of the specified page according to dork
637-
2.multi_page_search(dork, page=1, resource="host", facets=None)
637+
2.multi_page_search(dork, page=1, start_page=1, resource="host", facets=None)
638638
search multiple pages of data according to dork
639639
3.resources_info()
640640
get current user information

docs/README_CN.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -506,8 +506,8 @@ zm = ZoomEye(api_key="01234567-acbd-00000-1111-22222222222")
506506

507507
1.dork_search(dork, page=0, resource="host", facets=None)
508508
根据 dork 搜索指定页的数据
509-
2.multi_page_search(dork, page=1, resource="host", facets=None)
510-
根据 dork 搜索多页数据
509+
2.multi_page_search(dork, page=1, start_page=1, resource="host", facets=None)
510+
根据 dork 搜索多页数据,支持从指定的页数开始下载
511511
3.resources_info()
512512
获取当前用户的信息
513513
4.show_count()
@@ -557,7 +557,7 @@ soft********11180040.b***c.net ['126.***.***.40']
557557
{'product': [{'name': '', 'count': 28323128}, {'name': 'BusyBox telnetd', 'count': 10180912}, {'name': 'Linux telnetd', ......
558558
```
559559

560-
>`multi_page_search()` 同样也可以进行搜索,当需要获取大量数据时使用该函数,其中 `page` 字段表示获取多少页的数据;而 `dork_search()` 仅获取指定页的数据。
560+
>`multi_page_search()` 同样也可以进行搜索,当需要获取大量数据时使用该函数,其中 `page` 字段表示获取多少页的数据, `start_page`字段表示从第几页开始获取;而 `dork_search()` 仅获取指定页的数据。
561561

562562
#### 5.数据筛选
563563
SDK 中提供了 `dork_filter()` 函数,我们可以更加方便对数据进行筛选,提取指定的数据字段,如下:

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
long_description=README,
2525
long_description_content_type='text/x-rst',
2626
author='404 Team@Knownsec',
27-
url='https://github.com/knownsec/zoomeye-python',
27+
url='https://github.com/knownsec/zoomeye-python', #
2828
packages=['zoomeye'],
2929
entry_points={'console_scripts': ['zoomeye=zoomeye.cli:main']},
3030
install_requires=DEPENDENCIES,

zoomeye/cli.py

+18-16
Original file line numberDiff line numberDiff line change
@@ -51,23 +51,23 @@ def main():
5151
parser_info.set_defaults(func=core.info)
5252

5353
# query zoomeye data
54-
parser_search = subparsers.add_parser(
54+
P_search = subparsers.add_parser(
5555
"search",
5656
help="Search the ZoomEye database"
5757
)
5858

59-
parser_search.add_argument(
59+
P_search.add_argument(
6060
"dork",
6161
help="The ZoomEye search keyword or ZoomEye exported file"
6262
)
63-
parser_search.add_argument(
63+
P_search.add_argument(
6464
"-num",
6565
default=20,
6666
help="The number of search results that should be returned, support 'all'",
6767
type=str,
6868
metavar='value'
6969
)
70-
parser_search.add_argument(
70+
P_search.add_argument(
7171
"-facet",
7272
default=None,
7373
nargs='?',
@@ -80,7 +80,7 @@ def main():
8080
'''),
8181
metavar='field'
8282
)
83-
parser_search.add_argument(
83+
P_search.add_argument(
8484
"-filter",
8585
default=None,
8686
metavar='field=regexp',
@@ -93,7 +93,7 @@ def main():
9393
web field: [app,headers,keywords,title,site,city,country,webapp,component,framework,server,waf,os,timestamp,*]
9494
''')
9595
)
96-
parser_search.add_argument(
96+
P_search.add_argument(
9797
'-stat',
9898
default=None,
9999
metavar='field',
@@ -106,7 +106,7 @@ def main():
106106
web field: [webapp,component,framework,server,waf,os,country]
107107
''')
108108
)
109-
parser_search.add_argument(
109+
P_search.add_argument(
110110
"-save",
111111
default=None,
112112
metavar='field=regexp',
@@ -118,18 +118,18 @@ def main():
118118
type=str,
119119
const='all'
120120
)
121-
parser_search.add_argument(
121+
P_search.add_argument(
122122
"-count",
123123
help="The total number of results in ZoomEye database for a search",
124124
action="store_true"
125125
)
126-
parser_search.add_argument(
126+
P_search.add_argument(
127127
"-figure",
128128
help="Pie chart or bar chart showing data,can only be used under facet and stat",
129129
choices=('pie', 'hist'),
130130
default=None
131131
)
132-
parser_search.add_argument(
132+
P_search.add_argument(
133133
"-type",
134134
help=(
135135
"""
@@ -139,7 +139,7 @@ def main():
139139
choices={'web', 'host'},
140140
default="host"
141141
)
142-
parser_search.add_argument(
142+
P_search.add_argument(
143143
"-force",
144144
help=(
145145
"""
@@ -148,12 +148,13 @@ def main():
148148
),
149149
action="store_true"
150150
)
151-
parser_search.set_defaults(func=core.search)
151+
P_search.set_defaults(func=core.search)
152152

153153
# initial account configuration related commands
154-
parser_init = subparsers.add_parser("init", help="Initialize the token for ZoomEye-python")
155-
parser_init.add_argument("-apikey", help="ZoomEye API Key", default=None, metavar='[api key]')
156-
parser_init.set_defaults(func=core.init)
154+
155+
P_init = subparsers.add_parser("init", help="Initialize the token for ZoomEye-python.")
156+
P_init.add_argument("-apikey", help="ZoomEye API Key", default=None, metavar='[api key]')
157+
P_init.set_defaults(func=core.init)
157158

158159
parser_ip_info = subparsers.add_parser("ip", help="Query IP information")
159160
parser_ip_info.add_argument("ip", help="search device IP", metavar='ip', type=str)
@@ -219,8 +220,9 @@ def main():
219220
parser_domain.set_defaults(func=core.associated_domain_query)
220221

221222
args = parser.parse_args()
223+
ver=args.version
222224

223-
if args.version:
225+
if ver:
224226
get_version()
225227
exit(0)
226228

zoomeye/config.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
"""
1212
from zoomeye import __version__, __site__
1313

14+
seconds_of_fiveday = 60 * 60 * 24 * 5
1415

1516
# save api key file and json web token file path 保存API密钥文件和json web令牌文件路径
1617
ZOOMEYE_CONFIG_PATH = "~/.config/zoomeye/setting"
@@ -19,7 +20,7 @@
1920
ZOOMEYE_CACHE_PATH = "~/.config/zoomeye/cache"
2021

2122
# cache expired time, five day 缓存过期时间,5天
22-
EXPIRED_TIME = 60 * 60 * 24 * 5
23+
EXPIRED_TIME = seconds_of_fiveday
2324

2425
# print data max length 打印数据
2526
STRING_MAX_LENGTH = 23

zoomeye/core.py

+10-9
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616
zoomeye_dir = os.path.expanduser(config.ZOOMEYE_CONFIG_PATH)
1717

1818

19-
def init_key(key):
19+
def init_key(key): #初始化API密钥并将其保存在本地配置文件中
20+
2021
"""
2122
initialize through the api key, write the api key to the local configuration file,
2223
theoretically it will never expire unless you remake the api key
@@ -43,7 +44,7 @@ def init_key(key):
4344
os.chmod(key_file, 0o600)
4445

4546

46-
def init(args):
47+
def init(args):#根据用户输入的参数来选择初始化方法,可以通过API密钥来进行初始化
4748
"""
4849
the initialization processing function will select the initialization method according to the user's input.
4950
:param args:
@@ -55,11 +56,11 @@ def init(args):
5556
init_key(api_key)
5657
return
5758
# invalid parameter
58-
show.printf("input parameter error", color="red")
59+
show.printf("input parameter error!", color="red")
5960
show.printf("please run <zoomeye init -h> for help.", color="red")
6061

6162

62-
def search(args):
63+
def search(args):#进行搜索操作,根据用户输入的搜索条件进行搜索
6364
dork = args.dork
6465
num = int(args.num)
6566
facet = args.facet
@@ -93,7 +94,7 @@ def search(args):
9394
show.printf("please run <zoomeye search -h> for help.")
9495

9596

96-
def info(args):
97+
def info(args):#打印当前用户的身份和本月剩余的数据配额
9798
"""
9899
used to print the current identity of the user and the remaining data quota for the month
99100
:param args:
@@ -111,7 +112,7 @@ def info(args):
111112
show.printf("quota_info: {}".format(user_data["quota_info"]))
112113

113114

114-
def ip_history(args):
115+
def ip_history(args):#查询设备的历史信息
115116
"""
116117
query device history
117118
please see: https://www.zoomeye.org/doc#history-ip-search
@@ -141,7 +142,7 @@ def ip_history(args):
141142
zm.show_fields()
142143

143144

144-
def clear_file(args):
145+
def clear_file(args):#清除用户设置和ZoomEye缓存数据
145146
"""
146147
clear user setting and zoomeye cache data
147148
"""
@@ -165,7 +166,7 @@ def clear_file(args):
165166
show.printf("clear complete!", color='green')
166167

167168

168-
def information_ip(args):
169+
def information_ip(args):#获取特定IP的信息
169170
ip = args.ip
170171
filters = args.filter
171172
# determine whether the input is an IP address by regular
@@ -185,7 +186,7 @@ def information_ip(args):
185186
infor.show_information()
186187

187188

188-
def associated_domain_query(args):
189+
def associated_domain_query(args):#关联域名查询
189190
q = args.q
190191
resource = args.type
191192
page = args.page

zoomeye/data.py

+11-11
Original file line numberDiff line numberDiff line change
@@ -162,10 +162,10 @@ def regexp(keys, field_table, data_list):
162162
return result
163163

164164

165-
def filter_search_data(keys, field_table, data):
165+
def filter_search_data(datakeys, field_table, data):
166166
"""
167167
get the data of the corresponding field
168-
:param keys: list, user input field
168+
:param datakeys: list, user input field
169169
:param field_table: dict, fileds
170170
:param data: list, zoomeye api data
171171
:return: list, ex: [[1,2,3...],[1,2,3...],[1,2,3...]...]
@@ -174,7 +174,7 @@ def filter_search_data(keys, field_table, data):
174174
for d in data:
175175
item = []
176176
zmdict = ZoomEyeDict(d)
177-
for key in keys:
177+
for key in datakeys:
178178
if field_table.get(key.strip()) is None:
179179
support_fields = ','.join(list(field_table.keys()))
180180
show.printf("filter command has unsupport fields [{}], support fields has [{}]"
@@ -259,7 +259,7 @@ def process_filter(fields, data, tables):
259259
return result_data, has_equal, not_equal
260260

261261

262-
class Cache:
262+
class Cache:#用于缓存从API获取的数据或从本地文件中读取数据
263263
"""
264264
used to cache the data obtained from the api to the local,
265265
or directly clip the file from the local.
@@ -333,7 +333,7 @@ def update(self):
333333
pass
334334

335335

336-
class CliZoomEye:
336+
class CliZoomEye:#处理与ZoomEye搜索相关的功能,如默认显示、过滤、统计等
337337

338338
def __init__(self, dork, num, resource, facet=None, force=False):
339339
self.dork = dork
@@ -586,7 +586,7 @@ def count(self):
586586
show.printf(self.total)
587587

588588

589-
class HistoryDevice:
589+
class HistoryDevice:#处理获取主机历史数据的功能
590590
"""
591591
obtain the user's identity information and determine whether to use the IP history search function
592592
"""
@@ -704,7 +704,7 @@ def filter_fields(self, fields):
704704
show.print_filter_history(not_equal, result_data[:self.num], has_equal)
705705

706706

707-
class IPInformation:
707+
class IPInformation:#用于查询特定IP地址的信息
708708
"""
709709
query IP information
710710
"""
@@ -736,17 +736,17 @@ def filter_information(self, filters):
736736
result_data, has_equal, not_equal = process_filter(filters, info_data, fields_ip)
737737
if len(result_data) == 0:
738738
return
739-
for item in not_equal:
740-
if fields_ip.get(item.strip()) is None:
739+
for items in not_equal:
740+
if fields_ip.get(items.strip()) is None:
741741
support_fields = ','.join(list(fields_ip.keys()))
742742
show.printf(
743-
"filter command has unsupport fields [{}], support fields has [{}]".format(item, support_fields),
743+
"filter command has unsupport fields [{}], support fields has [{}]".format(items, support_fields),
744744
color='red')
745745
exit(0)
746746
show.print_info_filter(not_equal, result_data, has_equal)
747747

748748

749-
class DomainSearch:
749+
class DomainSearch:#用于查询相关域名或子域名
750750
"""
751751
query relation domain or sub domain
752752
"""

zoomeye/file.py

+10-10
Original file line numberDiff line numberDiff line change
@@ -24,17 +24,17 @@ def get_api_key(path) -> str:
2424
:param path:
2525
:return:
2626
"""
27-
key_file = zoomeye_dir + "/apikey"
27+
key_fl = zoomeye_dir + "/apikey"
2828
# api key config does not exits
2929
# raise FileNotFoundError
30-
if not os.path.exists(key_file):
30+
if not os.path.exists(key_fl):
3131
raise FileNotFoundError("not found api key config")
3232
# determine whether the permission of the configuration file is read-only,
3333
# if not, set it to read-only
34-
if not oct(os.stat(key_file).st_mode).endswith("600"):
35-
os.chmod(key_file, 0o600)
34+
if not oct(os.stat(key_fl).st_mode).endswith("600"):
35+
os.chmod(key_fl, 0o600)
3636
# return read file content
37-
with open(key_file, 'r') as f:
37+
with open(key_fl, 'r') as f:
3838
return f.read().strip()
3939

4040

@@ -44,19 +44,19 @@ def get_jwt_token(path) -> str:
4444
:param path:
4545
:return:
4646
"""
47-
key_file = zoomeye_dir + "/jwt"
47+
key_fl = zoomeye_dir + "/jwt"
4848
# json web token does not exits
4949
# raise FileNotFoundError
50-
if not os.path.exists(key_file):
50+
if not os.path.exists(key_fl):
5151
raise FileNotFoundError("not found access token config")
5252

5353

5454
# determine whether the permission of the configuration file is read-only,
5555
# if not, set it to read-only
56-
if not oct(os.stat(key_file).st_mode).endswith("600"):
57-
os.chmod(key_file, 0o600)
56+
if not oct(os.stat(key_fl).st_mode).endswith("600"):
57+
os.chmod(key_fl, 0o600)
5858
# return read config content
59-
with open(key_file, 'r') as f:
59+
with open(key_fl, 'r') as f:
6060
return f.read().strip()
6161

6262

0 commit comments

Comments
 (0)