The key challenge of security is the fact that protective measures suffice at best only to close the door on known exploits and breach techniques. Never assume that because you have followed these few measures that the Samba server is now an impenetrable fortress! Given the history of information systems so far, it is only a matter of time before someone will find yet another vulnerability.
14.3.1 Using Host-Based Protection
In many installations of Samba, the greatest threat comes from outside your immediate network. By default, Samba will accept connections from any host, which means that if you run an insecure version of Samba on a host that is directly connected to the Internet you can be especially vulnerable.
One of the simplest fixes in this case is to use the hosts allow and hosts deny options in the Samba smb.conf configuration file to only allow access to your server from a specific range of hosts. An example might be:
hosts allow = 127.0.0.1 192.168.2.0/24 192.168.3.0/24 hosts deny = 0.0.0.0/0
The above will only allow SMB connections from localhost (your own computer) and from the two private networks 192.168.2 and 192.168.3. All other connections will be refused as soon as the client sends its first packet. The refusal will be marked as not listening on called name error.
14.3.2 User -Based Protection
If you want to restrict access to your server to valid users only, then the following method may be of use. In the smb.conf [global] section put:
valid users = @ smbusers , jacko
This restricts all server access to either the user jacko or to members of the system group smbusers .
14.3.3 Using Interface Protection
By default, Samba will accept connections on any network interface that it finds on your system. That means if you have a ISDN line or a PPP connection to the Internet then Samba will accept connections on those links. This may not be what you want.
You can change this behavior using options like this:
interfaces = eth* lo bind interfaces only = yes
This tells Samba to only listen for connections on interfaces with a name starting with eth such as eth0 , eth1 plus on the loopback interface called lo . The name you will need to use depends on what OS you are using. In the above, I used the common name for Ethernet adapters on Linux.
If you use the above and someone tries to make an SMB connection to your host over a PPP interface called ppp0 , then they will get a TCP connection refused reply. In that case, no Samba code is run at all as the operating system has been told not to pass connections from that interface to any Samba process.
14.3.4 Using a Firewall
Many people use a firewall to deny access to services they do not want exposed outside their network. This can be a good idea, although I recommend using it in conjunction with the above methods so you are protected even if your firewall is not active for some reason.
If you are setting up a firewall, you need to know what TCP and UDP ports to allow and block. Samba uses the following:
The last one is important as many older firewall setups may not be aware of it, given that this port was only added to the protocol in recent years .
14.3.5 Using IPC$ Share-Based Denials
If the above methods are not suitable, then you could also place a more specific deny on the IPC$ share that is used in the recently discovered security hole. This allows you to offer access to other shares while denying access to IPC$ from potentially untrustworthy hosts.
To do this you could use:
hosts allow = 192.168.115.0/24 127.0.0.1 hosts deny = 0.0.0.0/0
This instructs Samba that IPC$ connections are not allowed from anywhere except from the two listed network addresses (localhost and the 192.168.115 subnet). Connections to other shares are still allowed. As the IPC$ share is the only share that is always accessible anonymously, this provides some level of protection against attackers that do not know a valid username/password for your host.
If you use this method, then clients will be given an 'access denied ' reply when they try to access the IPC$ share. Those clients will not be able to browse shares, and may also be unable to access some other resources. This is not recommended unless you cannot use one of the other methods listed above for some reason.
14.3.6 NTLMv2 Security
To configure NTLMv2 authentication, the following registry keys are worth knowing about:
The value 0x00000003 means send NTLMv2 response only. Clients will use NTLMv2 authentication, use NTLMv2 session security if the server supports it. Domain Controllers accept LM, NTLM and NTLMv2 authentication.
The value 0x00080000 means permit only NTLMv2 session security. If either NtlmMinClientSec or NtlmMinServerSec is set to 0x00080000, the connection will fail if NTLMv2 session security is not negotiated.