fofa 0.3.18 → 0.3.19

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: d1266f6e972edc71cf6f3c36c8dca778832d9340
4
- data.tar.gz: 9e4c2976d711e4e43dfcd18878e6518434d5a7be
2
+ SHA256:
3
+ metadata.gz: bfc764bb2b5c3d56f6dfd68ac14a74478a7d19c4e14c72bec35b1d3f547fb7aa
4
+ data.tar.gz: 8c52a5488290a45f3c074fcdccca99bef75685e91d42fe554268eb886cad36f3
5
5
  SHA512:
6
- metadata.gz: 077e078e08a70d059fed83f8f92cd425096172c160ab0eab71702eb9026a1328bb812a7b7cb7cbf03f1eb9e239a94258b138513bcb275f26351c088b32d8b36e
7
- data.tar.gz: 892e27388b7cb3a1be9de0ec36d8b20c5c0223b1d481432218a61a6beeb86ebfcf9ddd6d464e4fb4e47fcc5994bed1ce9467981031d030ea23ce0874ec408fa9
6
+ metadata.gz: 67ba297c2bba208e41d01700549cb396de980fb3937e932e01699ee90ce0185d2e9f6daac48fd9366ac919adbc883cd3377686ec5b5fff15e5b44c2ff594e381
7
+ data.tar.gz: c998095f14e85ceeb262b4f6b3b02c102d3a75dd0d2c0088c6b0402b7e8b968e0311a950261c91c45719d80fb02d3e5910da3106d1c8470dd1ab04eba3eaf03a
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fofa (0.3.17)
4
+ fofa (0.3.19)
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.15.1
41
+ 1.16.4
@@ -21,7 +21,8 @@ options = {
21
21
  format: 'csv',
22
22
  check_app_category: nil,
23
23
  check_app_application: nil,
24
- check_app_all: false
24
+ check_app_all: false,
25
+ task_id: nil
25
26
  }
26
27
 
27
28
  ARGV.options do |opts|
@@ -42,12 +43,16 @@ ARGV.options do |opts|
42
43
  options[:page] = val.to_i
43
44
  end
44
45
 
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|
46
+ opts.on('-m', '--mode=MODE', String, 'Mode, default to [search], -m should be specified when [import_service, query_ip_list, check_app, ip_tags] ') do |val|
46
47
  options[:mode] = val.to_sym
47
48
  end
48
49
 
49
- opts.on('-f', '--file=FILE', String, 'Used at [import_service, check_app] mode') do |val|
50
+ opts.on('-f', '--file=FILE', String, 'Used at [import_service, check_app, ip_tags] mode') do |val|
50
51
  options[:file] = val
52
+ end
53
+
54
+ opts.on('-t', '--task_id=ID', Integer, 'Used at [ip_tags] mode') do |val|
55
+ options[:task_id] = val.to_i
51
56
  end
52
57
 
53
58
  opts.on('-s', '--limit=SIZE', Integer, "Limit size to fetch, default to #{options[:limit]}") do |val|
@@ -80,7 +85,7 @@ ARGV.options do |opts|
80
85
  opts.on('-g', "--category=CATEGORY", String, "Category to check, only used in check_app mode." ) do |val|
81
86
  options[:check_app_category] = val
82
87
  options[:mode] = :check_app
83
- end
88
+ end
84
89
 
85
90
  opts.separator "Common Options:"
86
91
 
@@ -99,7 +104,7 @@ ARGV.options do |opts|
99
104
 
100
105
  opts.on( nil, "--check_app_all", "Check all applications, only used in check_app mode." ) do
101
106
  options[:check_app_all] = true
102
- end
107
+ end
103
108
 
104
109
 
105
110
 
@@ -111,6 +116,8 @@ ARGV.options do |opts|
111
116
  opts.separator "\t fofacli -e aaa@bbb.com -a xxx -d ip,domain,title,port,protocol -m query_ip_list -f ip.txt"
112
117
  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"' -- {}@
113
118
  opts.separator "\t fofacli -m check_app --app \"Coremail\" mail.tsinghua.edu.cn"
119
+ opts.separator "\t fofacli -e aaa@bbb.com -a xxx -m ip_tags -f ./ip.txt"
120
+ opts.separator "\t fofacli -e aaa@bbb.com -a xxx -m ip_tags -t 1"
114
121
 
115
122
  begin
116
123
  opts.parse!
@@ -285,8 +292,48 @@ case options[:mode]
285
292
  $stderr.puts "[WARNING] No result!"
286
293
  end
287
294
 
295
+ end
296
+ when :ip_tags
297
+ fofa = Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
298
+ if options[:task_id]
299
+ task_id = options[:task_id]
300
+ else
301
+ unless options[:file]
302
+ puts "File not specified.".red
303
+ puts ARGV.options
304
+ exit -1
305
+ end
306
+ puts "Import ip and get tags from '#{options[:file]}'"
307
+ result = fofa.ip_tags(options[:file])
308
+ if result['error']
309
+ puts result
310
+ exit -1
311
+ end
312
+ puts result
313
+ task_id = result['task_id']
288
314
  end
289
315
 
316
+ if task_id
317
+ get_info = -> (fofa, id) { fofa.tag_info(id) }
318
+ puts "Checking progress!"
319
+ sleep(2)
320
+
321
+ loop do
322
+ info = get_info.call(fofa, task_id)
323
+ if info['error']
324
+ puts info
325
+ break
326
+ elsif info['progress'].to_i == 100
327
+ puts "state: #{info['state']}; progress: #{info['progress']}."
328
+ puts info['download_url']
329
+ break
330
+ else
331
+ puts "state: #{info['state']}; progress: #{info['progress']}."
332
+ sleep(10)
333
+ end
334
+ end
335
+
336
+ end
290
337
 
291
338
  end
292
339
 
@@ -157,6 +157,66 @@ module Fofa
157
157
  {"error"=>"Error: #{e.to_s}"}
158
158
  end
159
159
 
160
+ # Import ip and get tags
161
+ #
162
+ # Example:
163
+ # >> Fofa::API.new(email,apikey).ip_tags('./ips.txt')
164
+ # => {"task_id"=>1}
165
+ #
166
+ # Arguments:
167
+ # file: (String) ip file
168
+ def ip_tags(file)
169
+ url = "#{@api_server}/api/v1/ip_tags?key=#{@apikey}&email=#{@email}"
170
+ puts url if @options[:debug]
171
+
172
+ # Token used to terminate the file in the post body. Make sure it is not
173
+ # present in the file you're uploading.
174
+ # You might want to use `SecureRandom` class to generate this random strings
175
+ boundary = "AaB03x"
176
+ uri = URI.parse(url)
177
+
178
+ post_body = []
179
+ post_body << "--#{boundary}\r\n"
180
+ post_body << "Content-Disposition: form-data; name=\"file\"; filename=\"#{File.basename(file)}\"\r\n"
181
+ post_body << "Content-Type: text/plain\r\n"
182
+ post_body << "\r\n"
183
+ post_body << File.read(file)
184
+ post_body << "\r\n--#{boundary}--\r\n"
185
+
186
+ http = http_new(uri)
187
+ req = Net::HTTP::Post.new(uri.request_uri)
188
+ req.body = post_body.join
189
+ req["Content-Type"] = "multipart/form-data, boundary=#{boundary}"
190
+
191
+ resp = http.request(req)
192
+ puts resp if @options[:debug]
193
+ JSON.parse(resp.body)
194
+ rescue => e
195
+ {"error"=>"Error: #{e.to_s}"}
196
+ end
197
+
198
+ # Check ip_tags's task state, progress, and download_url
199
+ #
200
+ # Example:
201
+ # >> Fofa::API.new(email,apikey).tag_info(1)
202
+ # => {"state"=>"success", "progress"=>100, "download_url"=>"https://host/xxx/56af409c1c55762a7b9e9a39a801f80d.json"}
203
+ #
204
+ # Arguments:
205
+ # task_id: (Integer) task id
206
+ def tag_info(task_id)
207
+ url = "#{@api_server}/api/v1/ip_tags/info?key=#{@apikey}&email=#{@email}&task_id=#{task_id}"
208
+ puts url if @options[:debug]
209
+ uri = URI.parse(url)
210
+ http = http_new(uri)
211
+ req = Net::HTTP::Get.new(uri.request_uri)
212
+
213
+ resp = http.request(req)
214
+ JSON.parse(resp.body)
215
+ rescue => e
216
+ $stderr.puts "[WARNING]: #{e.to_s}"
217
+ {"error"=>"Error: #{e.to_s}"}
218
+ end
219
+
160
220
  private
161
221
  def http_new(uri)
162
222
  http = Net::HTTP.new(uri.host, uri.port)
@@ -1,3 +1,6 @@
1
+ # 0.3.19
2
+ # add feature: ip_tags, tag_info
3
+ #
1
4
  # 0.3.18
2
5
  # add feature: check applications from file
3
6
  #
@@ -31,5 +34,5 @@
31
34
  # 0.3.6
32
35
  # add fields
33
36
  module Fofa
34
- VERSION = "0.3.18"
37
+ VERSION = "0.3.19"
35
38
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fofa
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.18
4
+ version: 0.3.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - fofa
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-09-09 00:00:00.000000000 Z
11
+ date: 2020-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -106,7 +106,7 @@ homepage: https://fofa.so
106
106
  licenses:
107
107
  - MIT
108
108
  metadata: {}
109
- post_install_message:
109
+ post_install_message:
110
110
  rdoc_options: []
111
111
  require_paths:
112
112
  - lib
@@ -121,9 +121,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
121
121
  - !ruby/object:Gem::Version
122
122
  version: '0'
123
123
  requirements: []
124
- rubyforge_project:
125
- rubygems_version: 2.6.12
126
- signing_key:
124
+ rubygems_version: 3.0.6
125
+ signing_key:
127
126
  specification_version: 4
128
127
  summary: A Ruby library to interact with the FOFA API. https://fofa.so
129
128
  test_files: []