Network complexity is rapidly increasing with the addition of non-traditional devices gaining access to organizational networks. Singular purpose devices made available through the Internet of Things (IoT) offering has increased network complexity even further with the ease of adding said devices to the network and sometimes without the knowledge of a system administrator. Hence the following received question:
"How do I ensure all the appropriate ports are closed with all these devices being added to my network?"
In scenarios like these, tools such as Azure Security Center do a great job on reporting probability of attacks that can occur in one's network and steps are needed to address this. However sometimes the challenge itself is convincing the organizational decision makers of the needed investment.
To help with this, the following PowerShell script will provide a rudimentary analysis report on what ports of what IPs are currently open. This report can be used as a great starting point to highlight probable attack vectors that could occur and the beginning to a conversation on additional security tool adoption. Lets begin.
$port = (80)
$network = (192.168.0)
$range = (1..254)
$ErrorActionPreference= ‘silentlycontinue’
$(Foreach ($add in $range)
{ $ip = “{0}.{1}” –F $network,$add
Write-Progress “Scanning Network” $ip -PercentComplete (($add/$range.Count)*100)
If(Test-Connection –BufferSize 32 –Count 1 –quiet –ComputerName $ip)
{ $socket = new-object System.Net.Sockets.TcpClient($ip, $port)
If($socket.Connected) { “$ip port $port open”
$socket.Close() }
else { “$ip port $port not open ” }
}
}) | Out-File C:\reports\portscan.csv
The following is the above script in its entirety:
$port = (enter port value)
$network = “enter network value”
$range = 1..254
$ErrorActionPreference= ‘silentlycontinue’
$(Foreach ($add in $range)
{ $ip = “{0}.{1}” –F $network,$add
Write-Progress “Scanning Network” $ip -PercentComplete (($add/$range.Count)*100)
If(Test-Connection –BufferSize 32 –Count 1 –quiet –ComputerName $ip)
{ $socket = new-object System.Net.Sockets.TcpClient($ip, $port)
If($socket.Connected) { “$ip port $port open”
$socket.Close() }
else { “$ip port $port not open ” }
}
}) | Out-File C:\reports\portscan.csv
Again this is a rudimentary report output that can be utilized to begin the conversation with organizational decision makers regarding needed investments. Do comment below on additional tips or script edits.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.