Skip to content

Commit 8e1715a

Browse files
committed
pwn_shodan_search - intial working commit
1 parent 38f3bd8 commit 8e1715a

File tree

3 files changed

+79
-3
lines changed

3 files changed

+79
-3
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ $ rvm use ruby-3.1.2@pwn
3737
$ rvm list gemsets
3838
$ gem install --verbose pwn
3939
$ pwn
40-
pwn[v0.4.470]:001 >>> PWN.help
40+
pwn[v0.4.471]:001 >>> PWN.help
4141
```
4242

4343
[![Installing the pwn Security Automation Framework](https://raw.githubusercontent.com/0dayInc/pwn/master/documentation/pwn_install.png)](https://youtu.be/G7iLUY4FzsI)
@@ -52,7 +52,7 @@ $ rvm use ruby-3.1.2@pwn
5252
$ gem uninstall --all --executables pwn
5353
$ gem install --verbose pwn
5454
$ pwn
55-
pwn[v0.4.470]:001 >>> PWN.help
55+
pwn[v0.4.471]:001 >>> PWN.help
5656
```
5757

5858

bin/pwn_shodan_search

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env ruby
2+
# frozen_string_literal: false
3+
4+
require 'pwn'
5+
require 'optparse'
6+
require 'yaml'
7+
require 'json'
8+
9+
opts = {}
10+
OptionParser.new do |options|
11+
options.banner = "USAGE:
12+
#{$PROGRAM_NAME} [opts]
13+
"
14+
15+
options.on('-c', '--config-yaml', '<Required - YAML config containing api_key from Shodan.io>') do |y|
16+
opts[:yaml] = y
17+
end
18+
19+
options.on('-qFILE', '--query-file=FILE', '<Required - File containing one Shodan.io query string per line>') do |q|
20+
opts[:query_file] = q
21+
end
22+
23+
options.on('-oFILE', '--output-results-file=FILE', '<Optional - Defaults to /tmp/shodan-results-Time.now.strftime("%y-%m-%d.%H:%M:%S")>') do |o|
24+
opts[:output_results_file] = o
25+
end
26+
end.parse!
27+
28+
if opts.empty?
29+
puts `#{$PROGRAM_NAME} --help`
30+
exit 1
31+
end
32+
33+
begin
34+
yaml_file = opts[:yaml]
35+
raise "ERROR: #{yaml_file} does not exist." unless File.exist?(yaml_file)
36+
37+
yaml = YAML.load_file(yaml_file, symbolize_names: true)
38+
39+
api_key = yaml[:api_key]
40+
41+
query_file = opts[:query_file]
42+
raise "ERROR: #{query_file} does not exist." unless File.exist?(query_file)
43+
44+
queries = File.readlines(query_file)
45+
46+
timestamp = Time.now.strftime('%Y-%m-%d.%H:%M:%S')
47+
query_results_file = opts[:output_results_file]
48+
query_results_file ||= "/tmp/shodan-results-#{timestamp}.txt"
49+
50+
raw_query_results_file = "/tmp/shodan-results-#{timestamp}-RAW.json"
51+
File.open(raw_query_results_file, 'w') do |r|
52+
File.open(query_results_file, 'w') do |f|
53+
queries.each do |query_line|
54+
query = query_line.chomp
55+
print "QUERY: '#{query}'"
56+
r.puts("QUERY: '#{query}'")
57+
f.puts("QUERY: '#{query}'")
58+
search_results = PWN::Plugins::Shodan.search(
59+
api_key: api_key,
60+
query: query
61+
)
62+
puts " >>> Matches: #{search_results[:total]}"
63+
r.puts search_results.to_json
64+
65+
search_results[:matches].select do |m|
66+
f.puts "ORG: #{m[:org]} | PUBIP: #{m[:ip_str]} #{'*' * 36}"
67+
f.puts "Product: #{m[:product]}"
68+
f.puts "TCP Port: #{m[:port]}"
69+
f.puts "Data: #{m[:data]}\n\n\n"
70+
end
71+
end
72+
end
73+
end
74+
rescue SystemExit, Interrupt
75+
puts "\nGoodbye."
76+
end

lib/pwn/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
module PWN
4-
VERSION = '0.4.470'
4+
VERSION = '0.4.471'
55
end

0 commit comments

Comments
 (0)