Skip to content

Commit 72b2ba2

Browse files
committed
replace [Net::HTTP] with [rex/proto/http]
1 parent a77f415 commit 72b2ba2

File tree

1 file changed

+43
-17
lines changed

1 file changed

+43
-17
lines changed

modules/auxiliary/gather/zoomeye_search.rb

Lines changed: 43 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@
55

66

77
require 'msf/core'
8-
require 'rex'
9-
require 'net/https'
10-
require 'uri'
8+
require 'rex/proto/http'
119

1210

1311
class MetasploitModule < Msf::Auxiliary
1412

15-
include Msf::Exploit::Remote::HttpClient
1613
include Msf::Auxiliary::Report
1714

1815
def initialize(info={})
@@ -45,6 +42,17 @@ def initialize(info={})
4542
], self.class)
4643
end
4744

45+
# Check to see if api.zoomeye.org resolves properly
46+
def zoomeye_resolvable?
47+
begin
48+
Rex::Socket.resolv_to_dotted("api.zoomeye.org")
49+
rescue RuntimeError, SocketError
50+
return false
51+
end
52+
53+
true
54+
end
55+
4856
def dork_search(dork, resource, page, facet=['ip'])
4957
# param: dork
5058
# ex: country:cn
@@ -57,19 +65,30 @@ def dork_search(dork, resource, page, facet=['ip'])
5765
# ex: [app, device]
5866
# A comma-separated list of properties to get summary information
5967

60-
zoomeye_dork_api = "https://api.zoomeye.org/#{resource}/search"
61-
zoomeye_dork_api << "?query=" + Rex::Text.uri_encode(dork)
62-
zoomeye_dork_api << "&page=#{page}"
63-
zoomeye_dork_api << "&facet=facet"
64-
65-
uri = URI.parse(zoomeye_dork_api)
66-
http = Net::HTTP.new(uri.host, uri.port)
67-
http.use_ssl = true
68-
request = Net::HTTP::Get.new(uri.request_uri)
69-
request['Authorization'] = "JWT #{datastore['ZOOMEYE_APIKEY']}"
68+
cli = Rex::Proto::Http::Client.new('api.zoomeye.org', 443, {}, true)
69+
cli.connect
70+
71+
begin
72+
req = cli.request_cgi({
73+
'uri' => "/#{resource}/search",
74+
'method' => 'GET',
75+
'headers' => { 'Authorization' => "JWT #{datastore['ZOOMEYE_APIKEY']}" },
76+
'vars_get' => {
77+
'query' => Rex::Text.uri_encode(dork),
78+
'page' => page,
79+
'facet' => facet
80+
}
81+
})
82+
83+
res = cli.send_recv(req)
84+
rescue ::Rex::ConnectionError, Errno::ECONNREFUSED, Errno::ETIMEDOUT
85+
print_error("HTTP Connection Failed")
86+
end
7087

71-
res = http.request(request)
72-
return 'server_response_error' unless res
88+
unless res
89+
print_error('server_response_error')
90+
return
91+
end
7392

7493
# Invalid Token, Not enough segments
7594
# Invalid Token, Signature has expired
@@ -78,7 +97,6 @@ def dork_search(dork, resource, page, facet=['ip'])
7897
end
7998

8099
ActiveSupport::JSON.decode(res.body)
81-
82100
end
83101

84102
def match_records?(records)
@@ -106,11 +124,19 @@ def parse_web_records(records)
106124
end
107125

108126
def run
127+
# check to ensure api.zoomeye.org is resolvable
128+
unless zoomeye_resolvable?
129+
print_error("Unable to resolve api.zoomeye.org")
130+
return
131+
end
132+
133+
# create ZoomEye request parameters
109134
dork = datastore['ZOOMEYE_DORK']
110135
resource = datastore['RESOURCE']
111136
page = 1
112137
maxpage = datastore['MAXPAGE']
113138

139+
# scroll max pages from ZoomEye
114140
while page <= maxpage
115141
print_status("ZoomEye #{resource} Search: #{dork} - page: #{page}")
116142
results = dork_search(dork, resource, page) if dork

0 commit comments

Comments
 (0)