fofa 0.3.9 → 0.3.10

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: 49f7d62fe77e1389d972aa534eeb8e820140edfd
4
- data.tar.gz: 7ccb4489b6c43316f1340595203616eb21f96d05
3
+ metadata.gz: ec762cac0cbe6e4e4ee3870f74c23bd428c57ceb
4
+ data.tar.gz: ea73a0e0ba7d6739966f10b4d67ab5a7a65a9017
5
5
  SHA512:
6
- metadata.gz: e2efc067981fde4bbeec5b1dcda5ca7148ebab4716c85e4bb017f8a26d3551c719ace01ca85221e1c2bd9e58b1f359de8a434b255721e39772ab82c87f6c6ea3
7
- data.tar.gz: e6730bcdf797391f4f6ffd1a4d36f0c8289d3b9167fafaf895183340980055545413251c2763d3fd8c1f77c362555dbe80a4c2bf9e47f3d4e31765eef4e0cde4
6
+ metadata.gz: 6f4dc47c12e9a2e667a72c7110199da7309174024c18fe794294527340205338e26f7bbf5a275c8a38387ff1af12ca10fb455b6e2518b89e700a8fa5f8232c80
7
+ data.tar.gz: 325524afc95a5713f61ace3cbd2b7f5d6837d82e36c39d538d7336a9e5a8797432deca8b4d9decf6a4c333ad3108f74ee8d790de4f6335fee1527887bca326f9
data/Gemfile CHANGED
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in fofa.gemspec
4
4
  gemspec
5
5
 
6
- gem 'colorize'
6
+ gem 'colorize'
7
+ gem 'concurrent-ruby'
@@ -1,12 +1,13 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- fofa (0.3.9)
4
+ fofa (0.3.10)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
8
8
  specs:
9
9
  colorize (0.8.1)
10
+ concurrent-ruby (1.0.5)
10
11
  diff-lcs (1.2.5)
11
12
  rake (10.5.0)
12
13
  rspec (3.5.0)
@@ -29,6 +30,7 @@ PLATFORMS
29
30
  DEPENDENCIES
30
31
  bundler (~> 1.12)
31
32
  colorize
33
+ concurrent-ruby
32
34
  fofa!
33
35
  rake (~> 10.0)
34
36
  rspec (~> 3.0)
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require "bundler/setup"
4
- require "fofa"
4
+ require_relative "../lib/fofa"
5
5
  require "optparse"
6
6
  require "colorize"
7
7
 
@@ -38,7 +38,7 @@ ARGV.options do |opts|
38
38
  options[:page] = val.to_i
39
39
  end
40
40
 
41
- opts.on('-m', '--mode=MODE', String, 'Mode, default to [search], -m should be specified when [import_service] ') do |val|
41
+ opts.on('-m', '--mode=MODE', String, 'Mode, default to [search], -m should be specified when [import_service, query_ip_list] ') do |val|
42
42
  options[:mode] = val.to_sym
43
43
  end
44
44
 
@@ -84,6 +84,7 @@ ARGV.options do |opts|
84
84
  opts.separator "\t fofacli -e aaa@bbb.com -a xxx domain=\"baidu.com\""
85
85
  opts.separator "\t fofacli -e aaa@bbb.com -a xxx -s 100 domain=\"baidu.com\""
86
86
  opts.separator "\t fofacli -e aaa@bbb.com -a xxx --query_file /tmp/fofaquery"
87
+ opts.separator "\t fofacli -e aaa@bbb.com -a xxx -d ip,domain,title,port,protocol -m query_ip_list -f ip.txt"
87
88
 
88
89
  begin
89
90
  opts.parse!
@@ -110,39 +111,91 @@ unless options[:apikey]
110
111
  end
111
112
 
112
113
  case options[:mode]
113
- when :search
114
- if ARGV.empty? && !options[:query]
115
- puts "Fofa query not specified.".red
116
- puts ARGV.options
117
- exit -1
118
- end
119
- query = options[:query] || ARGV.join(' ')
120
- puts "Query: '#{query}'"
121
- if options[:page] #search one page
122
- puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
123
- .search(query, {
124
- page:options[:page],
125
- size:options[:limit],
126
- fields:options[:fields],
127
- post:options[:post]
128
- })
129
- else
130
- puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
131
- .search_all(query, {
132
- size:options[:limit],
133
- page_size:options[:size_per_page],
134
- fields:options[:fields],
135
- post:options[:post]
136
- })
137
- end
138
-
139
- when :import_service
140
- unless options[:file]
141
- puts "File not specified.".red
142
- puts ARGV.options
143
- exit -1
144
- end
145
- puts "Import service from '#{options[:file]}'"
146
- puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]}).import_service(options[:file], {split_size:options[:split_size], fields:options[:fields]})
114
+ when :search
115
+ if ARGV.empty? && !options[:query]
116
+ puts "Fofa query not specified.".red
117
+ puts ARGV.options
118
+ exit -1
119
+ end
120
+ query = options[:query] || ARGV.join(' ')
121
+ puts "Query: '#{query}'"
122
+ if options[:page] #search one page
123
+ puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
124
+ .search(query, {
125
+ page:options[:page],
126
+ size:options[:limit],
127
+ fields:options[:fields],
128
+ post:options[:post]
129
+ })
130
+ else
131
+ puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
132
+ .search_all(query, {
133
+ size:options[:limit],
134
+ page_size:options[:size_per_page],
135
+ fields:options[:fields],
136
+ post:options[:post]
137
+ })
138
+ end
139
+
140
+ when :import_service
141
+ unless options[:file]
142
+ puts "File not specified.".red
143
+ puts ARGV.options
144
+ exit -1
145
+ end
146
+ puts "Import service from '#{options[:file]}'"
147
+ puts Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]}).import_service(options[:file], {split_size:options[:split_size], fields:options[:fields]})
148
+ when :query_ip_list
149
+ unless options[:file]
150
+ puts "File not specified.".red
151
+ puts ARGV.options
152
+ exit -1
153
+ end
154
+ puts "Query information from '#{options[:file]}'"
155
+ fofa = Fofa::API.new(options[:email], options[:apikey], {debug:options[:verbose]})
156
+ require 'concurrent'
157
+ semaphore = Concurrent::Semaphore.new(1)
158
+ pool = Concurrent::FixedThreadPool.new(10)
159
+ $stdout.sync = true
160
+ File.open(options[:file]){|f|
161
+ fields = options[:fields].split(',')
162
+ f.each_line{|line|
163
+ pool.post do
164
+ ip = line.strip
165
+ ip_hash = {'obj'=>ip, 'exists'=>false}
166
+ fields.each{|key|
167
+ ip_hash[key] = []
168
+ }
169
+ fofa.search_all(%Q|ip="#{ip}"|, {
170
+ size:options[:limit],
171
+ page_size:options[:size_per_page],
172
+ fields:options[:fields],
173
+ post:options[:post]
174
+ }).each{|a|
175
+ ip_hash['exists'] = true
176
+ a.each_with_index { |value, index|
177
+ if value && value.size>0
178
+ unless (fields[index] == 'domain' && value=~/\d*\.\d*\.\d*\.\d*/)
179
+ ip_hash[fields[index]] << value
180
+ ip_hash[fields[index]].uniq!
181
+ end
182
+
183
+ end
184
+ }
185
+ }
186
+ if ip_hash['exists']
187
+ ip_hash.delete('exists')
188
+ ip_hash.each{|k,v|
189
+ ip_hash.delete(k) if v.size==0
190
+ }
191
+ semaphore.acquire
192
+ puts ip_hash.to_json
193
+ semaphore.release
194
+ end
195
+ end
196
+ }
197
+ } #File
198
+ pool.shutdown
199
+ pool.wait_for_termination
147
200
  end
148
201
 
@@ -1,3 +1,6 @@
1
+ # 0.3.10
2
+ # add query_ip_list mode
3
+ #
1
4
  # 0.3.9
2
5
  # add post option to fix '414 Request-URI Too Large'
3
6
  #
@@ -10,5 +13,5 @@
10
13
  # 0.3.6
11
14
  # add fields
12
15
  module Fofa
13
- VERSION = "0.3.9"
16
+ VERSION = "0.3.10"
14
17
  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.9
4
+ version: 0.3.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - fofa
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-04-23 00:00:00.000000000 Z
11
+ date: 2017-05-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler