Utils
isProtocol
isProtocol: function(protocol: string,
FirewallRule: OutputInstanceNetworkInterfaceFirewallFirewallRule): boolean
Return true if the given FirewallRule accept the given protocol
protocol:string, value is either"tcp"or"udp"FirewallRule: OutputInstanceNetworkInterfaceFirewallFirewallRule e.g.Generic.Firewalls[0].IngressFirewallRules[0]
isContainPort
isContainPort: function(port: number,
FirewallRule:OutputInstanceNetworkInterfaceFirewallFirewallRule): boolean
Return true if the given FirewallRule accept the given port
port:number, 0 - 65535FirewallRule: OutputInstanceNetworkInterfaceFirewallFirewallRule e.g.Generic.Firewalls[0].IngressFirewallRules[0]
isCIDROpenToAll
isCIDROpenToAll: function(CIDR: string) : boolean
Return true if given CIDR is zero
CIDR:stringan ip address in CIDR format (e.g. 0.0.0.0/0)
isPortOpen
isPortOpen: function(obj: Output,
protocol: string,
port: number,
callback: (firewall: OutputInstanceNetworkInterfaceFirewall,
ingressFirewallRule: OutputInstanceNetworkInterfaceFirewallFirewallRule,
ipRange : number ) => void): boolean
Call the callback function if given port is open
obj: Output ,AWS,AzureorGenericconstantprotocol:string, eithertcporudpport:number, 0 - 65535callback: a function that accept OutputInstanceNetworkInterfaceFirewall object, OutputInstanceNetworkInterfaceFirewallFirewallRule object and OutputInstanceNetworkInterfaceFirewallFirewallRuleIPRange number
isPortOpenToPublic
isPortOpenToPublic: function(obj: Output,
protocol: string,
port: number,
callback: (firewall: OutputInstanceNetworkInterfaceFirewall,
ingressFirewallRule: OutputInstanceNetworkInterfaceFirewallFirewallRule,
ipRange : number ) => void): boolean
Call the callback function if given port is open to public
obj: Output ,AWS,AzureorGenericconstantprotocol:string, eithertcporudpport:number, 0 - 65535callback: a function that accept OutputInstanceNetworkInterfaceFirewall object, OutputInstanceNetworkInterfaceFirewallFirewallRule object and OutputInstanceNetworkInterfaceFirewallFirewallRuleIPRange number
formatPort
formatPort : function(fromPort: number, toPort: number): string
Convert port to print out format
- if
fromPort === toPort, then simply returntoPort - otherwise, return
"fromPort-toPort" fromPort:numbertoPort:number
printFirewallRules
printFirewallRules: function(type: string,
FirewallRule: OutputInstanceNetworkInterfaceFirewallFirewallRule,
CIDR: string)
Convert given FirewallRule to print out format
-
output is in format
return ${type} ${Protocol}/${Port} ${CIDR}, whereProtocol = FirewallRule.Protocol, andPortis formatted fromFirewallRule.fromPortandFirewallRule.toPortusing the formatPort function -
type:string, either"Ingress"or"Egress" -
FirewallRule: OutputInstanceNetworkInterfaceFirewallFirewallRule e.g.Generic.Firewalls[0].IngressFirewallRules[0] -
CIDR:string, an ip address in CIDR format (e.g. 0.0.0.0/0)
getElements
getElements: function(obj: any, key: string): any
Return object with key if found; Otherwise, return a empty array.
This function is usually used in legacy js utils code, or when obj is the raw attribute of cloud resource.
obj:any, any kind of cloud resource objectkey:string, attribute to get
getIAMListAdditionalRaw
getIAMListAdditionalRaw: function(obj: Output, name: string): any
Get AdditionalRaw in IAMList and return it as an array
obj: Output ,AWS,AzureorGenericconstantname:string, eitherPasswordPolicyorAccountSummary. The result will only return list ofrawthat belongs to OutputIamListIamAdditionalRaw instance withNameproperty equal to parametername
toAWSIamListAffectedResouceFormat
toAWSIamListAffectedResouceFormat: function(type: string,
account_id: number, resource: any, key: string): any
Convert affected resource to audit report understanble format. Usually the output is placed into the result function
type:string, the type you want to classify about the resource (e.g.PasswordPolicy)account_id:number, i-th affected resource (count from 0)resource:any, the affected resource, usually is part of Output instancekey:string, which field you want to highlight
For example:
// AWS_CIS_ 1.6: Ensure IAM password policy require at least one lowercase letter (Scored)
var PasswordPolicy = Utils.getIAMListAdditionalRaw(AWS, "PasswordPolicy");
PasswordPolicy.forEach((pp, i) => {
var affectedResouce = Utils.toAWSIamListAffectedResouceFormat("AWSPasswordPolicy", i, pp, "RequireLowercaseCharacters");
var action = "The password policy should require at least one lowercase letter";
if (pp == null) {
var remark = "Password policy has not been set";
result("High", [affectedResouce], action, remark);
}
else if (!pp.RequireLowercaseCharacters) {
result("High", [affectedResouce], action);
}
});