@@ -35,7 +35,8 @@ def initialize(info={})
35
35
36
36
register_options (
37
37
[
38
- OptString . new ( 'ZOOMEYE_APIKEY' , [ true , 'The ZoomEye API Key' ] ) ,
38
+ OptString . new ( 'USERNAME' , [ true , 'The ZoomEye username' ] ) ,
39
+ OptString . new ( 'PASSWORD' , [ true , 'The ZoomEye password' ] ) ,
39
40
OptString . new ( 'ZOOMEYE_DORK' , [ true , 'The ZoomEye Dock' ] ) ,
40
41
OptEnum . new ( 'RESOURCE' , [ true , 'ZoomEye Resource Type' , 'host' , [ 'host' , 'web' ] ] ) ,
41
42
OptInt . new ( 'MAXPAGE' , [ true , 'Max amount of pages to collect' , 1 ] )
@@ -53,6 +54,32 @@ def zoomeye_resolvable?
53
54
true
54
55
end
55
56
57
+ def login ( username , password )
58
+ # See more: https://www.zoomeye.org/api/doc#login
59
+
60
+ access_token = ''
61
+ @cli = Rex ::Proto ::Http ::Client . new ( 'api.zoomeye.org' , 443 , { } , true )
62
+ @cli . connect
63
+
64
+ data = { 'username' => username , 'password' => password }
65
+ req = @cli . request_cgi ( {
66
+ 'uri' => '/user/login' ,
67
+ 'method' => 'POST' ,
68
+ 'data' => data . to_json
69
+ } )
70
+
71
+ res = @cli . send_recv ( req )
72
+
73
+ unless res
74
+ print_error ( 'server_response_error' )
75
+ return
76
+ end
77
+
78
+ records = ActiveSupport ::JSON . decode ( res . body )
79
+ access_token = records [ 'access_token' ] if records && records . key? ( 'access_token' )
80
+ access_token
81
+ end
82
+
56
83
def dork_search ( dork , resource , page )
57
84
# param: dork
58
85
# ex: country:cn
@@ -65,22 +92,19 @@ def dork_search(dork, resource, page)
65
92
# ex: [app, device]
66
93
# A comma-separated list of properties to get summary information
67
94
68
- cli = Rex ::Proto ::Http ::Client . new ( 'api.zoomeye.org' , 443 , { } , true )
69
- cli . connect
70
-
71
95
begin
72
- req = cli . request_cgi ( {
73
- 'uri' => "/#{ resource } /search" ,
74
- 'method' => 'GET' ,
75
- 'headers' => { 'Authorization' => "JWT #{ datastore [ 'ZOOMEYE_APIKEY' ] } " } ,
96
+ req = @ cli. request_cgi ( {
97
+ 'uri' => "/#{ resource } /search" ,
98
+ 'method' => 'GET' ,
99
+ 'headers' => { 'Authorization' => "JWT #{ @zoomeye_token } " } ,
76
100
'vars_get' => {
77
- 'query' => dork ,
78
- 'page' => page ,
79
- 'facet' => 'ip'
101
+ 'query' => dork ,
102
+ 'page' => page ,
103
+ 'facet' => 'ip'
80
104
}
81
105
} )
82
106
83
- res = cli . send_recv ( req )
107
+ res = @ cli. send_recv ( req )
84
108
85
109
rescue ::Rex ::ConnectionError , Errno ::ECONNREFUSED , Errno ::ETIMEDOUT
86
110
print_error ( "HTTP Connection Failed" )
@@ -131,6 +155,12 @@ def run
131
155
return
132
156
end
133
157
158
+ @zoomeye_token = login ( datastore [ 'USERNAME' ] , datastore [ 'PASSWORD' ] )
159
+ unless @zoomeye_token
160
+ print_error ( "Unable to login api.zoomeye.org" )
161
+ return
162
+ end
163
+
134
164
# create ZoomEye request parameters
135
165
dork = datastore [ 'ZOOMEYE_DORK' ]
136
166
resource = datastore [ 'RESOURCE' ]
0 commit comments