fofa 0.3.15 → 0.3.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3702c8e5ab5d5135d9fbb5a704d664a5e1204ae3
4
- data.tar.gz: 84e1115974c19064259ee09203955b018721098c
3
+ metadata.gz: c547727d9ed816e3d644f0416cc146bf6e856914
4
+ data.tar.gz: 4b972ee2dc95eefadfe1233d4ab01cd912c790d1
5
5
  SHA512:
6
- metadata.gz: 5d311b9c353802d07313c945b7a1d89e06dac4cc794d2a34b486b42ae9f90a69c3eb66bb6df79ade84c13c71ae1efbdac711ff09118daefb9d1ec8ebd8f27890
7
- data.tar.gz: 05dafa6ddca51d34bc9a9723e83762b4a2e7aaca0bd31f012220d8ec5171394f7b12dc93f18bc8a683cde3061d8bba64ef337dd99453a4d9c563f58957963a60
6
+ metadata.gz: e3650e6c08280779282fd7865c912d9e2ec152ca3b8aea318e43f7a6e70014ca32308b7a38de9a45edb2b9e27434dc74fba6c9d2811f05648aea9ba7acff7863
7
+ data.tar.gz: 2e919a75409e0c1a6fc7ee1eba8f9c094f630c061eaabbfa2d84e56519efe98c9583040177503eb48a701f9bf18c913c0419c5d77908c4249a28a05cba5a79b3
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fofa (0.3.14)
4
+ fofa (0.3.16)
5
5
  colorize
6
6
  concurrent-ruby
7
7
 
@@ -38,4 +38,4 @@ DEPENDENCIES
38
38
  rspec (~> 3.0)
39
39
 
40
40
  BUNDLED WITH
41
- 1.14.6
41
+ 1.15.1
@@ -18,7 +18,10 @@ options = {
18
18
  fields: 'host',
19
19
  post: false,
20
20
  query: nil,
21
- format: 'csv'
21
+ format: 'csv',
22
+ check_app_category: nil,
23
+ check_app_application: nil,
24
+ check_app_all: false
22
25
  }
23
26
 
24
27
  ARGV.options do |opts|
@@ -39,7 +42,7 @@ ARGV.options do |opts|
39
42
  options[:page] = val.to_i
40
43
  end
41
44
 
42
- opts.on('-m', '--mode=MODE', String, 'Mode, default to [search], -m should be specified when [import_service, query_ip_list] ') do |val|
45
+ opts.on('-m', '--mode=MODE', String, 'Mode, default to [search], -m should be specified when [import_service, query_ip_list, check_app] ') do |val|
43
46
  options[:mode] = val.to_sym
44
47
  end
45
48
 
@@ -67,6 +70,16 @@ ARGV.options do |opts|
67
70
  raise "File not exist of #{val}" unless File.exists? val
68
71
  options[:query] = File.read(val).strip
69
72
  options[:post] = true
73
+ end
74
+
75
+ opts.on('-l', "--application=APPLICATION", String, "Application to check, only used in check_app mode." ) do |val|
76
+ options[:check_app_application] = val
77
+ options[:mode] = :check_app
78
+ end
79
+
80
+ opts.on('-g', "--category=CATEGORY", String, "Category to check, only used in check_app mode." ) do |val|
81
+ options[:check_app_category] = val
82
+ options[:mode] = :check_app
70
83
  end
71
84
 
72
85
  opts.separator "Common Options:"
@@ -84,6 +97,12 @@ ARGV.options do |opts|
84
97
  options[:verbose] = true
85
98
  end
86
99
 
100
+ opts.on( nil, "--check_app_all", "Check all applications, only used in check_app mode." ) do
101
+ options[:check_app_all] = true
102
+ end
103
+
104
+
105
+
87
106
  opts.separator ""
88
107
  opts.separator "For example:"
89
108
  opts.separator "\t fofacli -e aaa@bbb.com -a xxx domain=\"baidu.com\""
@@ -91,7 +110,7 @@ ARGV.options do |opts|
91
110
  opts.separator "\t fofacli -e aaa@bbb.com -a xxx --query_file /tmp/fofaquery"
92
111
  opts.separator "\t fofacli -e aaa@bbb.com -a xxx -d ip,domain,title,port,protocol -m query_ip_list -f ip.txt"
93
112
  opts.separator %Q@\t cat vapps.txt | xargs -I{} -n 1 sh -c 'fofacli "app=$1" -d host,ip,port,country,province,city -s 1000 -o json -v > "$1.txt"' -- {}@
94
-
113
+
95
114
  begin
96
115
  opts.parse!
97
116
  rescue OptionParser::InvalidOption => e
@@ -227,5 +246,18 @@ case options[:mode]
227
246
  } #File
228
247
  pool.shutdown
229
248
  pool.wait_for_termination
249
+ when :check_app
250
+ query = options[:query] || ARGV.join(' ')
251
+ res = Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
252
+ .check_app(query, {
253
+ category:options[:check_app_category],
254
+ application:options[:check_app_application],
255
+ all:options[:all],
256
+ })
257
+
258
+ res.each{|r|
259
+ log_record(options, r)
260
+ }
261
+
230
262
  end
231
263
 
@@ -33,10 +33,7 @@ module Fofa
33
33
  url += "&qbase64=#{Base64.encode64(query)}" unless options[:post]
34
34
  puts url if @options[:debug]
35
35
  uri = URI.parse(url)
36
- http = Net::HTTP.new(uri.host, uri.port)
37
- if uri.scheme == 'https'
38
- http.use_ssl = true
39
- end
36
+ http = http_new(uri)
40
37
 
41
38
  if options[:post]
42
39
  req = Net::HTTP::Post.new(uri.request_uri)
@@ -106,11 +103,7 @@ module Fofa
106
103
  url = "#{@api_server}/api/v1/import/services?key=#{@apikey}&email=#{@email}&port=#{options[:port]}"
107
104
  puts url if @options[:debug]
108
105
  uri = URI.parse(url)
109
- http = Net::HTTP.new(uri.host, uri.port)
110
- if uri.scheme == 'https'
111
- http.use_ssl = true
112
- end
113
- http.set_debug_output $stderr if @options[:debug]
106
+ http = http_new(uri)
114
107
 
115
108
  File.open(file) do |f|
116
109
  results = []
@@ -139,5 +132,63 @@ module Fofa
139
132
  {"error"=>"Error: #{e.to_s}"}
140
133
  end
141
134
 
135
+ # Check applications of asset
136
+ #
137
+ # Example:
138
+ # >> Fofa::API.new(email,apikey).checkapp("mail.tsinghua.edu.cn", category:"邮件系统")
139
+ # => ["Coremail"]
140
+ #
141
+ # Arguments:
142
+ # host: (String) Category name
143
+ # options: (Hash) category: Category name, application: Application name, all: return all applications or break when match first
144
+ def check_app(host, options={})
145
+ options = {all:false}.merge(options)
146
+ url = "#{@api_server}/api/v1/search/checkapp?key=#{@apikey}&email=#{@email}&host=#{host}"
147
+ url += "&all=#{options[:all]}" if options[:all]
148
+ url += "&application=#{URI.escape(options[:application])}" if options[:application]
149
+ url += "&category=#{URI.escape(options[:category])}" if options[:category]
150
+ puts url if @options[:debug]
151
+ uri = URI.parse(url)
152
+ http = http_new(uri)
153
+ req = Net::HTTP::Get.new(uri.request_uri)
154
+ resp = http.request(req)
155
+ JSON.parse(resp.body)
156
+
157
+ # File.open(file) do |f|
158
+ # results = []
159
+ # f.each_line.lazy.each_with_index do |line, i|
160
+ #
161
+ # line = line.strip
162
+ # if m = /Discovered open port (?<port>.*?)\/tcp on (?<host>.*?)$/.match(line)
163
+ # hostinfo = "#{m[:host]}:#{m[:port]}"
164
+ # elsif line.include?(':')
165
+ # hostinfo = line
166
+ # else
167
+ # hostinfo = "#{line}:#{options[:port]}"
168
+ # end
169
+ #
170
+ # results << line
171
+ # if i % split_size == 0
172
+ # req = Net::HTTP::Post.new(uri.request_uri)
173
+ # req.body = results.join("\n")
174
+ # resp = http.request(req)
175
+ # puts resp if @options[:debug]
176
+ # results = []
177
+ # end
178
+ # end
179
+ # end
180
+ rescue => e
181
+ {"error"=>"Error: #{e.to_s}"}
182
+ end
183
+
184
+ private
185
+ def http_new(uri)
186
+ http = Net::HTTP.new(uri.host, uri.port)
187
+ if uri.scheme == 'https'
188
+ http.use_ssl = true
189
+ end
190
+ http.set_debug_output $stderr if @options[:debug]
191
+ http
192
+ end
142
193
  end
143
194
  end
@@ -1,3 +1,6 @@
1
+ # 0.3.17
2
+ # add checkapp api call
3
+ #
1
4
  # 0.3.15
2
5
  # fixed query encode bug of '&&'
3
6
  #
@@ -25,5 +28,5 @@
25
28
  # 0.3.6
26
29
  # add fields
27
30
  module Fofa
28
- VERSION = "0.3.15"
31
+ VERSION = "0.3.17"
29
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.15
4
+ version: 0.3.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - fofa