Skip to content

Commit 66d6ac4

Browse files
committed
Land rapid7#8978, Add smb1 scanner
2 parents 0d31c1c + c584592 commit 66d6ac4

File tree

2 files changed

+131
-0
lines changed
  • documentation/modules/auxiliary/scanner/smb
  • modules/auxiliary/scanner/smb

2 files changed

+131
-0
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# Description
2+
This module scans for hosts that support the SMBv1 protocol. It works by sending an SMB_COM_NEGOTATE request to each host specified in RHOSTS and claims that it only supports the following SMB dialects:
3+
```PC NETWORK PROGRAM 1.0
4+
LANMAN1.0
5+
Windows for Workgroups 3.1a
6+
LM1.2X002
7+
LANMAN2.1
8+
NT LM 0.12
9+
```
10+
If the SMB server has SMBv1 enabled it will respond to the request with a dialect selected.
11+
If the SMB server does not support SMBv1 a RST will be sent.
12+
13+
___
14+
# Usage
15+
16+
The following is an example of its usage, where x.x.x.x allows SMBv1 and y.y.y.y does not.
17+
18+
#### A host that does support SMBv1.
19+
20+
```
21+
msf auxiliary(smb1) > use auxiliary/scanner/smb/smb1
22+
msf auxiliary(smb1) > set RHOSTS x.x.x.x
23+
RHOSTS => x.x.x.x
24+
msf auxiliary(smb1) > run
25+
26+
[+] x.x.x.x:445 - x.x.x.x supports SMBv1 dialect.
27+
[*] Scanned 1 of 1 hosts (100% complete)
28+
[*] Auxiliary module execution completed
29+
msf auxiliary(smb1) > services -S x.x.x.x
30+
31+
Services
32+
========
33+
34+
host port proto name state info
35+
---- ---- ----- ---- ----- ----
36+
x.x.x.x 445 tcp smb1 open
37+
```
38+
39+
#### A host that does not support SMBv1
40+
41+
```
42+
msf auxiliary(smb1) > use auxiliary/scanner/smb/smb1
43+
msf auxiliary(smb1) > set RHOSTS y.y.y.y
44+
RHOSTS => y.y.y.y
45+
msf auxiliary(smb1) > run
46+
47+
[*] Scanned 1 of 1 hosts (100% complete)
48+
[*] Auxiliary module execution completed
49+
```
50+
___
51+
52+
53+
## Options
54+
55+
The only option is RHOSTS, which can be specified as a single IP, hostname, or an IP range in CIDR notation or range notation. It can also be set using hosts from the database using ```hosts -R```.

modules/auxiliary/scanner/smb/smb1.rb

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
##
2+
# This module requires Metasploit: https://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
class MetasploitModule < Msf::Auxiliary
7+
# Exploit mixins should go first
8+
include Msf::Exploit::Remote::Tcp
9+
10+
# Scanner mixin should be near last
11+
include Msf::Auxiliary::Scanner
12+
include Msf::Auxiliary::Report
13+
14+
# Aliases for common classes
15+
SIMPLE = Rex::Proto::SMB::SimpleClient
16+
XCEPT = Rex::Proto::SMB::Exceptions
17+
CONST = Rex::Proto::SMB::Constants
18+
19+
def initialize
20+
super(
21+
'Name' => 'SMBv1 Protocol Detection',
22+
'Description' => 'Detect systems that support the SMBv1 protocol',
23+
'Author' => 'Chance Johnson @loftwing',
24+
'License' => MSF_LICENSE
25+
)
26+
27+
register_options([ Opt::RPORT(445) ])
28+
end
29+
30+
# Modified from smb2 module by @hdm
31+
# Fingerprint a single host
32+
def run_host(ip)
33+
begin
34+
connect
35+
36+
# Only accept NT LM 0.12 dialect and WfW3.0
37+
dialects = ['PC NETWORK PROGRAM 1.0',
38+
'LANMAN1.0',
39+
'Windows for Workgroups 3.1a',
40+
'LM1.2X002',
41+
'LANMAN2.1',
42+
'NT LM 0.12']
43+
data = dialects.collect { |dialect| "\x02" + dialect + "\x00" }.join('')
44+
45+
pkt = Rex::Proto::SMB::Constants::SMB_NEG_PKT.make_struct
46+
pkt['Payload']['SMB'].v['Command'] = Rex::Proto::SMB::Constants::SMB_COM_NEGOTIATE
47+
pkt['Payload']['SMB'].v['Flags1'] = 0x08
48+
pkt['Payload']['SMB'].v['Flags2'] = 0xc801
49+
pkt['Payload'].v['Payload'] = data
50+
51+
pkt['Payload']['SMB'].v['ProcessID'] = rand(0x10000)
52+
pkt['Payload']['SMB'].v['MultiplexID'] = rand(0x10000)
53+
54+
sock.put(pkt.to_s)
55+
res = sock.get_once
56+
# expecting \xff instead of \xfe
57+
if res && res.index("\xffSMB")
58+
print_good("#{ip} supports SMBv1 dialect.")
59+
report_note(
60+
host: ip,
61+
proto: 'tcp',
62+
sname: 'smb1',
63+
port: rport,
64+
type: "supports SMB 1"
65+
)
66+
end
67+
rescue ::Rex::ConnectionError
68+
rescue EOFError
69+
rescue Errno::ECONNRESET
70+
rescue ::Exception => e
71+
print_error("#{rhost}: #{e.class} #{e} #{e.backtrace}")
72+
ensure
73+
disconnect
74+
end
75+
end
76+
end

0 commit comments

Comments
 (0)