-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathwanna_scan.rb
137 lines (110 loc) · 3 KB
/
wanna_scan.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
require 'optparse'
require 'pathname'
require_relative 'lib/ms17_010_scan'
require_relative 'lib/double_pulsar_scan'
require_relative 'lib/host_scan.rb'
require_relative 'lib/port_scan.rb'
def usage
<<~USAGE
Usage: ruby wanna_scan.rb [options] {value}
Options:
-i [ip addr] scan ip
-I [interface] scan interface
-o [output directory] output in the directory
USAGE
end
def output(dir)
return if dir.nil?
date = Time.new.strftime('%Y%m%d-%H%M%S')
path = Pathname.new(dir).join('wanna_scan_' + date + '.txt')
File.open(path, 'w') do |f|
f.puts(date)
f.puts("[+] Vulnerability of MS17-010 list\n")
@ms17_010_scan.vulnerable_host.each { |s| f.puts(s) }
f.puts("\n[+] Infected with DoublePulsar list")
@double_pulsar_scan.vulnerable_host.each { |s| f.puts(s) }
end
end
params = ARGV.getopts('i:I:o:')
if params['i'] && params['I']
puts "You can not specify many options.\n\n"
puts usage
exit
elsif !params['i'] && !params['I']
puts usage
exit
end
# [TODO] check the input value?
ip = params['i']
unless ip.nil?
port_scan = PortScan.new
port_scan.start(ip)
if port_scan.open_445_list.empty?
puts("#{ip} is not opening 445 port.")
exit
end
puts('[*] MS17-010 Scan start')
@ms17_010_scan = Ms17010Scan.new
@ms17_010_scan.start(ip)
if @ms17_010_scan.vulnerable_host.empty?
puts '[-] The vulnerability is not found'
else
puts("[+] #{@ms17_010_scan.vulnerable_host[0]} has a vulnerability of MS17-010")
end
puts('[*] MS17-010 Scan finish')
puts("\n[*] DoublePulsar Scan start")
@double_pulsar_scan = DoublePulsarScan.new
@double_pulsar_scan.start(ip)
if @double_pulsar_scan.vulnerable_host.empty?
puts('[-] DoublePulsar is not found')
else
puts "[+] #{@double_pulsar_scan.vulnerable_host[0]} has been infected with DoublePulsar"
end
puts("[*] DoublePulsar Scan finish\n\n")
output(params['o'])
exit
end
# [TODO] check the input value?
host_scan = HostScan.new(params['I'])
port_scan = PortScan.new
threads = []
# Search host opend 445 port
host_scan.ip_list.each do |s|
threads << Thread.new do
port_scan.start(s)
end
end
threads.each(&:join)
# MS17-010 scan
puts('[*] MS17-010 Scan start')
@ms17_010_scan = Ms17010Scan.new
port_scan.open_445_list.each do |host|
threads << Thread.new do
@ms17_010_scan.start(host)
end
end
threads.each(&:join)
puts("[+] Vulnerability of MS17-010 list\n")
if @ms17_010_scan.vulnerable_host.empty?
puts('nothing')
else
puts @ms17_010_scan.vulnerable_host
end
puts('[*] MS17-010 Scan finish')
# DoublePulsar scan
puts("\n[*] DoublePulsar Scan start")
@double_pulsar_scan = DoublePulsarScan.new
port_scan.open_445_list.each do |host|
threads << Thread.new do
@double_pulsar_scan.start(host)
end
end
threads.each(&:join)
puts('[+] Infected with DoublePulsar list')
if @double_pulsar_scan.vulnerable_host.empty?
puts('nothing')
else
puts @double_pulsar_scan.vulnerable_host
end
puts("[*] DoublePulsar Scan finish\n\n")
output(params['o'])