aboutsummaryrefslogtreecommitdiff
path: root/Recon
diff options
context:
space:
mode:
authorMatt Graeber <mattgraeber@gmail.com>2014-01-30 14:38:50 -0800
committerMatt Graeber <mattgraeber@gmail.com>2014-01-30 14:38:50 -0800
commitd9ca5357e4603222268b1c619da10cc7858153d4 (patch)
tree11acd5887b575ec27b5f6b46655d3111624698ac /Recon
parent7c51e9331b084d6fe6d05b9711b5ab66fb396040 (diff)
parent14780a567874934c49af5f097462ed4953d5a738 (diff)
downloadPowerSploit-d9ca5357e4603222268b1c619da10cc7858153d4.tar.gz
PowerSploit-d9ca5357e4603222268b1c619da10cc7858153d4.zip
Merge pull request #26 from obscuresec/master
Update Invoke-ReverseDnsLookup.ps1
Diffstat (limited to 'Recon')
-rw-r--r--Recon/Invoke-ReverseDnsLookup.ps1235
1 files changed, 130 insertions, 105 deletions
diff --git a/Recon/Invoke-ReverseDnsLookup.ps1 b/Recon/Invoke-ReverseDnsLookup.ps1
index 1346ae6..5e811ee 100644
--- a/Recon/Invoke-ReverseDnsLookup.ps1
+++ b/Recon/Invoke-ReverseDnsLookup.ps1
@@ -50,146 +50,171 @@ IP HostName
Description
-----------
Returns the hostnames of the IP addresses specified by the IP range specified.
+
+.EXAMPLE
+
+PS C:\> Write-Output "74.125.228.1,74.125.228.0/29" | Invoke-ReverseDnsLookup
+
+IP HostName
+-- --------
+74.125.228.1 iad23s05-in-f1.1e100.net
+74.125.228.1 iad23s05-in-f1.1e100.net
+74.125.228.2 iad23s05-in-f2.1e100.net
+74.125.228.3 iad23s05-in-f3.1e100.net
+74.125.228.4 iad23s05-in-f4.1e100.net
+74.125.228.5 iad23s05-in-f5.1e100.net
+74.125.228.6 iad23s05-in-f6.1e100.net
+
+Description
+-----------
+Returns the hostnames of the IP addresses piped from another source.
+
.LINK
http://www.exploit-monday.com
+https://github.com/mattifestation/PowerSploit
#>
Param (
- [Parameter(Position = 0, Mandatory = $True)]
+ [Parameter(Position = 0, Mandatory = $True,ValueFromPipeline=$True)]
[String]
$IpRange
)
- function Parse-IPList ([String] $IpRange)
- {
-
- function IPtoInt
+ BEGIN {
+
+ function Parse-IPList ([String] $IpRange)
{
- Param([String] $IpString)
+
+ function IPtoInt
+ {
+ Param([String] $IpString)
- $Hexstr = ""
- $Octets = $IpString.Split(".")
- foreach ($Octet in $Octets) {
- $Hexstr += "{0:X2}" -f [Int] $Octet
+ $Hexstr = ""
+ $Octets = $IpString.Split(".")
+ foreach ($Octet in $Octets) {
+ $Hexstr += "{0:X2}" -f [Int] $Octet
+ }
+ return [Convert]::ToInt64($Hexstr, 16)
}
- return [Convert]::ToInt64($Hexstr, 16)
- }
- function InttoIP
- {
- Param([Int64] $IpInt)
- $Hexstr = $IpInt.ToString("X8")
- $IpStr = ""
- for ($i=0; $i -lt 8; $i += 2) {
- $IpStr += [Convert]::ToInt64($Hexstr.SubString($i,2), 16)
- $IpStr += '.'
+ function InttoIP
+ {
+ Param([Int64] $IpInt)
+ $Hexstr = $IpInt.ToString("X8")
+ $IpStr = ""
+ for ($i=0; $i -lt 8; $i += 2) {
+ $IpStr += [Convert]::ToInt64($Hexstr.SubString($i,2), 16)
+ $IpStr += '.'
+ }
+ return $IpStr.TrimEnd('.')
}
- return $IpStr.TrimEnd('.')
- }
- $Ip = [System.Net.IPAddress]::Parse("127.0.0.1")
+ $Ip = [System.Net.IPAddress]::Parse("127.0.0.1")
- foreach ($Str in $IpRange.Split(","))
- {
- $Item = $Str.Trim()
- $Result = ""
- $IpRegex = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
-
- # First, validate the input
- switch -regex ($Item)
+ foreach ($Str in $IpRange.Split(","))
{
- "^$IpRegex/\d{1,2}$"
- {
- $Result = "cidrRange"
- break
- }
- "^$IpRegex-$IpRegex$"
- {
- $Result = "range"
- break
- }
- "^$IpRegex$"
- {
- $Result = "single"
- break
- }
- default
+ $Item = $Str.Trim()
+ $Result = ""
+ $IpRegex = "\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}"
+
+ # First, validate the input
+ switch -regex ($Item)
{
- Write-Warning "Inproper input"
- return
+ "^$IpRegex/\d{1,2}$"
+ {
+ $Result = "cidrRange"
+ break
+ }
+ "^$IpRegex-$IpRegex$"
+ {
+ $Result = "range"
+ break
+ }
+ "^$IpRegex$"
+ {
+ $Result = "single"
+ break
+ }
+ default
+ {
+ Write-Warning "Inproper input"
+ return
+ }
}
- }
- #Now, start processing the IP addresses
- switch ($Result)
- {
- "cidrRange"
+ #Now, start processing the IP addresses
+ switch ($Result)
{
- $CidrRange = $Item.Split("/")
- $Network = $CidrRange[0]
- $Mask = $CidrRange[1]
+ "cidrRange"
+ {
+ $CidrRange = $Item.Split("/")
+ $Network = $CidrRange[0]
+ $Mask = $CidrRange[1]
- if (!([System.Net.IPAddress]::TryParse($Network, [ref] $Ip))) { Write-Warning "Invalid IP address supplied!"; return}
- if (($Mask -lt 0) -or ($Mask -gt 30)) { Write-Warning "Invalid network mask! Acceptable values are 0-30"; return}
+ if (!([System.Net.IPAddress]::TryParse($Network, [ref] $Ip))) { Write-Warning "Invalid IP address supplied!"; return}
+ if (($Mask -lt 0) -or ($Mask -gt 30)) { Write-Warning "Invalid network mask! Acceptable values are 0-30"; return}
- $BinaryIP = [Convert]::ToString((IPtoInt $Network),2).PadLeft(32,'0')
- #Generate lower limit (Excluding network address)
- $Lower = $BinaryIP.Substring(0, $Mask) + "0" * ((32-$Mask)-1) + "1"
- #Generate upperr limit (Excluding broadcast address)
- $Upper = $BinaryIP.Substring(0, $Mask) + "1" * ((32-$Mask)-1) + "0"
- $LowerInt = [Convert]::ToInt64($Lower, 2)
- $UpperInt = [Convert]::ToInt64($Upper, 2)
- for ($i = $LowerInt; $i -le $UpperInt; $i++) { InttoIP $i }
- }
- "range"
- {
- $Range = $item.Split("-")
+ $BinaryIP = [Convert]::ToString((IPtoInt $Network),2).PadLeft(32,'0')
+ #Generate lower limit (Excluding network address)
+ $Lower = $BinaryIP.Substring(0, $Mask) + "0" * ((32-$Mask)-1) + "1"
+ #Generate upperr limit (Excluding broadcast address)
+ $Upper = $BinaryIP.Substring(0, $Mask) + "1" * ((32-$Mask)-1) + "0"
+ $LowerInt = [Convert]::ToInt64($Lower, 2)
+ $UpperInt = [Convert]::ToInt64($Upper, 2)
+ for ($i = $LowerInt; $i -le $UpperInt; $i++) { InttoIP $i }
+ }
+ "range"
+ {
+ $Range = $item.Split("-")
- if ([System.Net.IPAddress]::TryParse($Range[0],[ref]$Ip)) { $Temp1 = $Ip }
- else { Write-Warning "Invalid IP address supplied!"; return }
+ if ([System.Net.IPAddress]::TryParse($Range[0],[ref]$Ip)) { $Temp1 = $Ip }
+ else { Write-Warning "Invalid IP address supplied!"; return }
- if ([System.Net.IPAddress]::TryParse($Range[1],[ref]$Ip)) { $Temp2 = $Ip }
- else { Write-Warning "Invalid IP address supplied!"; return }
+ if ([System.Net.IPAddress]::TryParse($Range[1],[ref]$Ip)) { $Temp2 = $Ip }
+ else { Write-Warning "Invalid IP address supplied!"; return }
- $Left = (IPtoInt $Temp1.ToString())
- $Right = (IPtoInt $Temp2.ToString())
+ $Left = (IPtoInt $Temp1.ToString())
+ $Right = (IPtoInt $Temp2.ToString())
- if ($Right -gt $Left) {
- for ($i = $Left; $i -le $Right; $i++) { InttoIP $i }
- }
- else { Write-Warning "Invalid IP range. The right portion must be greater than the left portion."; return}
+ if ($Right -gt $Left) {
+ for ($i = $Left; $i -le $Right; $i++) { InttoIP $i }
+ }
+ else { Write-Warning "Invalid IP range. The right portion must be greater than the left portion."; return}
- break
- }
- "single"
- {
- if ([System.Net.IPAddress]::TryParse($Item,[ref]$Ip)) { $Ip.IPAddressToString }
- else { Write-Warning "Invalid IP address supplied!"; return }
- break
- }
- default
- {
- Write-Warning "An error occured."
- return
+ break
+ }
+ "single"
+ {
+ if ([System.Net.IPAddress]::TryParse($Item,[ref]$Ip)) { $Ip.IPAddressToString }
+ else { Write-Warning "Invalid IP address supplied!"; return }
+ break
+ }
+ default
+ {
+ Write-Warning "An error occured."
+ return
+ }
}
}
- }
+ }
}
-
- Parse-IPList $IpRange | ForEach-Object {
- try {
- $Temp = [System.Net.Dns]::GetHostEntry($_)
+
+ PROCESS {
+ Parse-IPList $IpRange | ForEach-Object {
+ try {
+ Write-Verbose "Resolving $_"
+ $Temp = [System.Net.Dns]::GetHostEntry($_)
- $Result = @{
- IP = $_
- HostName = $Temp.HostName
- }
+ $Result = @{
+ IP = $_
+ HostName = $Temp.HostName
+ }
- New-Object PSObject -Property $Result
- } catch [System.Net.Sockets.SocketException] {}
+ New-Object PSObject -Property $Result
+ } catch [System.Net.Sockets.SocketException] {}
+ }
}
-
}