Skip to content

Commit 13899eb

Browse files
authored
Merge pull request #87 from knownsec/dev
update():remove username and password authenticate method
2 parents 24bbfd0 + 437497d commit 13899eb

File tree

8 files changed

+53
-162
lines changed

8 files changed

+53
-162
lines changed

README.rst

Lines changed: 16 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -57,12 +57,7 @@ After successfully installing ``ZoomEye-python``, you can use the
5757

5858
Before using the ``ZoomEye-python cli``, the user ``token`` needs to be
5959
initialized. The credential is used to verify the user’s identity to
60-
query data from ``ZoomEye``; we provide two authentication methods:
61-
62-
::
63-
64-
1.username/password
65-
2.APIKEY (recommend)
60+
query data from ``ZoomEye``; only support API-KEY authentication methods.
6661

6762
You can view the help through ``zoomeye init -h``, and use ``APIKEY`` to
6863
demonstrate below:
@@ -79,10 +74,6 @@ information (https://www.zoomeye.org/profile); ``APIKEY`` will not
7974
expire, users can reset in personal information according to their
8075
needs.
8176

82-
in addition, we also provide the initialization method of
83-
``username/password``. After authentication in this way, the
84-
``JWT-token`` will be returned, which has certain timeliness and
85-
requires the user to login again after failure.
8677

8778
2.query quota
8879
^^^^^^^^^^^^^
@@ -623,18 +614,10 @@ The ``-dot`` parameter will generate a picture in ``png`` format and save the or
623614
1.initialize token
624615
^^^^^^^^^^^^^^^^^^
625616

626-
Similarly, the SDK also supports two authentication methods,
627-
``username/password`` and ``APIKEY``, as follows:
628-
629-
**1.user/pass**
630-
631-
.. code:: python
632-
633-
from zoomeye.sdk import ZoomEye
634-
635-
zm = ZoomEye(username="username", password="password")
617+
Similarly, the SDK also supports API-KEY authentication methods,
618+
``APIKEY``, as follows:
636619

637-
**2.APIKEY**
620+
**APIKEY**
638621

639622
.. code:: python
640623
@@ -649,27 +632,25 @@ The following are the interfaces and instructions provided by the SDK:
649632

650633
::
651634

652-
1.login()
653-
use username/password or APIKEY for authentication
654-
2.dork_search(dork, page=0, resource="host", facets=None)
635+
1.dork_search(dork, page=0, resource="host", facets=None)
655636
search the data of the specified page according to dork
656-
3.multi_page_search(dork, page=1, resource="host", facets=None)
637+
2.multi_page_search(dork, page=1, resource="host", facets=None)
657638
search multiple pages of data according to dork
658-
4.resources_info()
639+
3.resources_info()
659640
get current user information
660-
5.show_count()
641+
4.show_count()
661642
get the number of all matching results under the current dork
662-
6.dork_filter(keys)
643+
5.dork_filter(keys)
663644
extract the data of the specified field from the search results
664-
7.get_facet()
645+
6.get_facet()
665646
get statistical results of all data from search results
666-
8.history_ip(ip)
647+
7.history_ip(ip)
667648
query historical data information of an ip
668-
9.show_site_ip(data)
649+
8.show_site_ip(data)
669650
traverse the web-search result set, and output the domain name and ip address
670-
10.show_ip_port(data)
651+
9.show_ip_port(data)
671652
traverse the host-search result set and output the ip address and port
672-
11.generate_dot(self, q, source=0, page=1)
653+
10.generate_dot(self, q, source=0, page=1)
673654
Generate graphviz files and pictures written in the domain center
674655

675656
3.SDK example
@@ -684,12 +665,8 @@ The following are the interfaces and instructions provided by the SDK:
684665
'__file__', '__loader__', '__name__', '__package__', '__spec__',
685666
'fields_tables_host', 'fields_tables_web', 'getpass', 'requests',
686667
'show_ip_port', 'show_site_ip', 'zoomeye_api_test']
687-
>>> # Use username and password to login
688-
>>> zm = zoomeye.ZoomEye()
689-
>>> zm.username = 'username@zoomeye.org'
690-
>>> zm.password = 'password'
691-
>>> print(zm.login())
692-
....JIUzI1NiIsInR5cCI6IkpXVCJ9.....
668+
>>> # Use API-KEY search
669+
>>> zm = zoomeye.ZoomEye(api_key="01234567-acbd-00000-1111-22222222222")
693670
>>> data = zm.dork_search('apache country:cn')
694671
>>> zoomeye.show_site_ip(data)
695672
213.***.***.46.rev.vo***one.pt ['46.***.***.213']

docs/README_CN.md

Lines changed: 14 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,7 @@ optional arguments:
3939
```
4040

4141
#### 1.初始化token
42-
在使用 `ZoomEye-python cli` 前需要先初始化用户 `token`,该凭证用于验证用户身份以便从 `ZoomEye` 查询数据;我们提供了两种认证方式:
43-
44-
1.username/password
45-
2.APIKEY (推荐)
42+
在使用 `ZoomEye-python cli` 前需要先初始化用户 `token`,该凭证用于验证用户身份以便从 `ZoomEye` 查询数据;仅支持 API-KEY 认证。
4643

4744
可以通过 `zoomeye init -h` 查看帮助,下面通过 `APIKEY` 来进行演示:
4845

@@ -55,7 +52,6 @@ Quota: 10000
5552

5653
用户可以通过登陆 `ZoomEye` 在个人信息中(<https://www.zoomeye.org/profile>) 获取 `APIKEY``APIKEY` 不会过期,用户可根据需求在个人信息中进行重置。
5754

58-
除此之外,我们还提供了 `username/password` 的初始化方式,通过这种方式认证后会返回 `JWT-token`,具有一定的时效性,失效后需要用户重新登陆。
5955

6056
#### 2.查询配额
6157
用户可以通过 `info` 命令查询个人信息以及数据配额,如下:
@@ -495,17 +491,9 @@ total: 90/79882
495491

496492
### 0x04 使用SDK
497493
#### 1.初始化token
498-
同样,在 SDK 中也支持 `username/password``APIKEY` 两种认证方式,如下:
499-
500-
**1.user/pass**
501-
502-
```python
503-
from zoomeye.sdk import ZoomEye
504-
505-
zm = ZoomEye(username="username", password="password")
506-
```
494+
同样,在 SDK 中仅支持通过 `APIKEY` 认证,如下:
507495

508-
**2.APIKEY**
496+
**APIKEY**
509497

510498
```python
511499
from zoomeye.sdk import ZoomEye
@@ -516,27 +504,25 @@ zm = ZoomEye(api_key="01234567-acbd-00000-1111-22222222222")
516504
#### 2.SDK API
517505
以下是 SDK 提供的接口以及说明:
518506

519-
1.login()
520-
使用 username/password 或者 APIKEY 进行认证
521-
2.dork_search(dork, page=0, resource="host", facets=None)
507+
1.dork_search(dork, page=0, resource="host", facets=None)
522508
根据 dork 搜索指定页的数据
523-
3.multi_page_search(dork, page=1, resource="host", facets=None)
509+
2.multi_page_search(dork, page=1, resource="host", facets=None)
524510
根据 dork 搜索多页数据
525-
4.resources_info()
511+
3.resources_info()
526512
获取当前用户的信息
527-
5.show_count()
513+
4.show_count()
528514
获取当前 dork 下全部匹配结果的数量
529-
6.dork_filter(keys)
515+
5.dork_filter(keys)
530516
从搜索结果中提取指定字段的数据
531-
7.get_facet()
517+
6.get_facet()
532518
从搜索结果中获取全量数据的聚合结果
533-
8.history_ip(ip)
519+
7.history_ip(ip)
534520
查询某个 ip 的历史数据信息
535-
9.show_site_ip(data)
521+
8.show_site_ip(data)
536522
遍历 web-search 结果集,并输出域名和ip地址
537-
10.show_ip_port(data)
523+
9.show_ip_port(data)
538524
遍历 host-search 结果集,并输出ip地址和端口
539-
11.generate_dot(self, q, source=0, page=1)
525+
10.generate_dot(self, q, source=0, page=1)
540526
生成以域名中心写出graphviz文件和图片
541527

542528
#### 3.使用示例
@@ -549,12 +535,8 @@ $ python3
549535
'__file__', '__loader__', '__name__', '__package__', '__spec__',
550536
'fields_tables_host', 'fields_tables_web', 'getpass', 'requests',
551537
'show_ip_port', 'show_site_ip', 'zoomeye_api_test']
552-
>>> # Use username and password to login
538+
>>> # Use API-KEY search dork
553539
>>> zm = zoomeye.ZoomEye()
554-
>>> zm.username = 'username@zoomeye.org'
555-
>>> zm.password = 'password'
556-
>>> print(zm.login())
557-
....JIUzI1NiIsInR5cCI6IkpXVCJ9.....
558540
>>> data = zm.dork_search('apache country:cn')
559541
>>> zoomeye.show_site_ip(data)
560542
213.***.***.46.rev.vo***one.pt ['46.***.***.213']

zoomeye/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,5 @@
1111

1212
__name__ = 'zoomeye'
1313
__package__ = 'zoomeye'
14-
__version__ = 'v2.1.2'
14+
__version__ = 'v2.2.0'
1515
__site__ = "https://www.zoomeye.org/doc"

zoomeye/cli.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,6 @@ def main():
153153
# initial account configuration related commands
154154
parser_init = subparsers.add_parser("init", help="Initialize the token for ZoomEye-python")
155155
parser_init.add_argument("-apikey", help="ZoomEye API Key", default=None, metavar='[api key]')
156-
parser_init.add_argument("-username", help="ZoomEye account username", default=None, metavar='[username]')
157-
parser_init.add_argument("-password", help="ZoomEye account password", default=None, metavar='[password]')
158156
parser_init.set_defaults(func=core.init)
159157

160158
parser_ip_info = subparsers.add_parser("ip", help="Query IP information")

zoomeye/core.py

Lines changed: 3 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -43,52 +43,17 @@ def key_init(key):
4343
os.chmod(key_file, 0o600)
4444

4545

46-
def jwt_init(username, password):
47-
"""
48-
initialize through the user name and password, write jwt to the local configuration file,
49-
the expiration time is about 12 hours, so it is recommended to initialize through the api key.
50-
:param username: str, login zoomeye account
51-
:param password: str, login zoomeye account password
52-
:return:
53-
"""
54-
file.check_exist(zoomeye_dir)
55-
try:
56-
zoom = ZoomEye(username=username, password=password)
57-
access_token = zoom.login()
58-
except Exception:
59-
return
60-
jwt_file = zoomeye_dir + "/jwt"
61-
if access_token:
62-
# display the remaining resources of the current account
63-
user_data = zoom.resources_info()
64-
show.printf("Role: {}".format(user_data["plan"]))
65-
show.printf("Quota: {}".format(user_data["resources"].get("search")))
66-
with open(jwt_file, 'w') as f:
67-
f.write(access_token)
68-
show.printf("successfully initialized", color="green")
69-
# change the permission of the configuration file to read-only
70-
os.chmod(jwt_file, 0o600)
71-
else:
72-
show.printf("failed initialized!", color="red")
73-
74-
7546
def init(args):
7647
"""
7748
the initialization processing function will select the initialization method according to the user's input.
7849
:param args:
7950
:return:
8051
"""
8152
api_key = args.apikey
82-
username = args.username
83-
password = args.password
8453
# use api key init
85-
if api_key and username is None and password is None:
54+
if api_key:
8655
key_init(api_key)
8756
return
88-
# use username and password init
89-
if api_key is None and username and password:
90-
jwt_init(username, password)
91-
return
9257
# invalid parameter
9358
show.printf("input parameter error", color="red")
9459
show.printf("please run <zoomeye init -h> for help.", color="red")
@@ -134,8 +99,8 @@ def info(args):
13499
:param args:
135100
:return:
136101
"""
137-
api_key, access_token = file.get_auth_key()
138-
zm = ZoomEye(api_key=api_key, access_token=access_token)
102+
api_key = file.get_auth_key()
103+
zm = ZoomEye(api_key=api_key)
139104
# get user information
140105
user_data = zm.resources_info()
141106
if user_data:

zoomeye/data.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -346,8 +346,8 @@ def __init__(self, dork, num, resource, facet=None, force=False):
346346
self.facet_data = None
347347
self.total = 0
348348

349-
self.api_key, self.access_token = file.get_auth_key()
350-
self.zoomeye = ZoomEye(api_key=self.api_key, access_token=self.access_token)
349+
self.api_key = file.get_auth_key()
350+
self.zoomeye = ZoomEye(api_key=self.api_key)
351351

352352
def handle_page(self):
353353
try:
@@ -652,8 +652,8 @@ def get_data(self):
652652
get user level and IP historical data
653653
"""
654654
normal_user = ['user', 'developer']
655-
api_key, access_token = file.get_auth_key()
656-
zm = ZoomEye(api_key=api_key, access_token=access_token)
655+
api_key = file.get_auth_key()
656+
zm = ZoomEye(api_key=api_key)
657657
role = zm.resources_info()
658658
# permission restrictions
659659
if role["plan"] in normal_user:
@@ -716,8 +716,8 @@ def request_data(self):
716716
"""
717717
get api data
718718
"""
719-
api_key, access_token = file.get_auth_key()
720-
zm = ZoomEye(api_key=api_key, access_token=access_token)
719+
api_key = file.get_auth_key()
720+
zm = ZoomEye(api_key=api_key)
721721
data = zm.dork_search(self.dork)
722722
return data
723723

@@ -755,8 +755,8 @@ def __init__(self, q, source, page):
755755
self.q = q
756756
self.source = source
757757
self.page = page
758-
api_key, access_token = file.get_auth_key()
759-
self.zm = ZoomEye(api_key=api_key, access_token=access_token)
758+
api_key = file.get_auth_key()
759+
self.zm = ZoomEye(api_key=api_key)
760760

761761
def show_information(self):
762762
"""show domain search data"""

zoomeye/file.py

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,28 +63,19 @@ def get_auth_key():
6363
:return:
6464
"""
6565
api_key = None
66-
access_token = None
6766
try:
6867
# read the api key from the configuration file,
6968
# if not, it will throw an exception that the file is not found.
7069
api_key = get_api_key(zoomeye_dir + "/apikey")
71-
return api_key, access_token
70+
return api_key
7271
# catch file not found exception
7372
except FileNotFoundError:
74-
# try to get the json web token in the configuration file
75-
try:
76-
access_token = get_jwt_token(zoomeye_dir + "/jwt")
77-
return api_key, access_token
78-
except FileNotFoundError:
79-
print("please run 'zoomeye init -apikey <api key>' "
80-
"or 'zoomeye init -username <username> -password <password>before using this command")
81-
exit(0)
73+
print("please run 'zoomeye init -apikey <api key>' before using this command")
74+
exit(0)
8275
# catch other exceptions
8376
except Exception:
84-
# there is no past api key and json web token in the configuration file
85-
# tell users that they need to be initialized before use
86-
print("please run 'zoomeye init -apikey <api key>' "
87-
"or 'zoomeye init -username <username> -password <password>before using this command")
77+
# unknown error
78+
print("Unknown Error! Please submit issue.")
8879
exit(0)
8980

9081

0 commit comments

Comments
 (0)