|
| 1 | +/** |
| 2 | + * @name Insecure SMB settings |
| 3 | + * @description Use of insecure SMB configurations allow attackers to access connections |
| 4 | + * @kind problem |
| 5 | + * @problem.severity error |
| 6 | + * @security-severity 8.8 |
| 7 | + * @precision high |
| 8 | + * @id powershell/microsoft/public/insecure-smb-setting |
| 9 | + * @tags correctness |
| 10 | + * security |
| 11 | + * external/cwe/cwe-315 |
| 12 | + */ |
| 13 | + |
| 14 | +import powershell |
| 15 | + |
| 16 | +abstract class SMBConfiguration extends CmdCall { |
| 17 | + abstract Expr getAMisconfiguredSetting(); |
| 18 | + |
| 19 | + /** Gets the minimum version of the SMB protocol to be used */ |
| 20 | + Expr getMisconfiguredSmb2DialectMin() { |
| 21 | + exists(Expr dialectMin | |
| 22 | + dialectMin = this.getNamedArgument("smb2dialectmin") and |
| 23 | + dialectMin.getValue().stringMatches(["none", "smb202", "smb210"]) and |
| 24 | + result = dialectMin |
| 25 | + ) |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +/** A call to `Set-SmbServerConfiguration`. */ |
| 30 | +class SetSMBClientConfiguration extends SMBConfiguration { |
| 31 | + SetSMBClientConfiguration() { this.getAName() = "Set-SmbClientConfiguration" } |
| 32 | + |
| 33 | + /** holds if the argument `requireencryption` is supplied with a `$false` value. */ |
| 34 | + Expr getMisconfiguredRequireEncryption() { |
| 35 | + exists(Expr requireEncryption | |
| 36 | + requireEncryption = this.getNamedArgument("requireencryption") and |
| 37 | + requireEncryption.getValue().asBoolean() = false and |
| 38 | + result = requireEncryption |
| 39 | + ) |
| 40 | + } |
| 41 | + |
| 42 | + /** Holds if the argument `blockntlm` is supplied with a `$false` value. */ |
| 43 | + Expr getMisconfiguredBlocksNTLM() { |
| 44 | + exists(Expr blocksNTLM | |
| 45 | + blocksNTLM = this.getNamedArgument("blockntlm") and |
| 46 | + blocksNTLM.getValue().asBoolean() = false and |
| 47 | + result = blocksNTLM |
| 48 | + ) |
| 49 | + } |
| 50 | + |
| 51 | + override Expr getAMisconfiguredSetting() { |
| 52 | + result = this.getMisconfiguredRequireEncryption() or |
| 53 | + result = this.getMisconfiguredBlocksNTLM() or |
| 54 | + result = this.getMisconfiguredSmb2DialectMin() |
| 55 | + } |
| 56 | +} |
| 57 | + |
| 58 | +/** A call to `Set-SmbServerConfiguration`. */ |
| 59 | +class SetSMBServerConfiguration extends SMBConfiguration { |
| 60 | + SetSMBServerConfiguration() { this.getAName() = "Set-SmbServerConfiguration" } |
| 61 | + |
| 62 | + /** holds if the argument `encryptdata` is supplied with a `$false` value. */ |
| 63 | + Expr getMisconfiguredEncryptData() { |
| 64 | + exists(Expr encryptData | |
| 65 | + encryptData = this.getNamedArgument("encryptdata") and |
| 66 | + encryptData.getValue().asBoolean() = false and |
| 67 | + result = encryptData |
| 68 | + ) |
| 69 | + } |
| 70 | + |
| 71 | + /** holds if the argument `encryptdata` is supplied with a `$false` value. */ |
| 72 | + Expr getMisconfiguredRejectUnencryptedAccess() { |
| 73 | + exists(Expr rejectUnencryptedAccess | |
| 74 | + rejectUnencryptedAccess = this.getNamedArgument("rejectunencryptedaccess") and |
| 75 | + rejectUnencryptedAccess.getValue().asBoolean() = false and |
| 76 | + result = rejectUnencryptedAccess |
| 77 | + ) |
| 78 | + } |
| 79 | + |
| 80 | + override Expr getAMisconfiguredSetting() { |
| 81 | + result = this.getMisconfiguredEncryptData() or |
| 82 | + result = this.getMisconfiguredRejectUnencryptedAccess() or |
| 83 | + result = this.getMisconfiguredSmb2DialectMin() |
| 84 | + } |
| 85 | +} |
| 86 | + |
| 87 | +from SMBConfiguration config |
| 88 | +select config.getAMisconfiguredSetting(), "Unsafe SMB setting" |
0 commit comments