r/PowerShell • u/JustinGrote • Mar 19 '19
PoshNmap: A Powershell Wrapper around the Nmap Network Discovery Tool (made by me)
https://github.com/justingrote/poshnmap18
Mar 19 '19 edited Jun 26 '23
Goodbye, Reddit :(
23
u/PorreKaj Mar 19 '19
Or PoshSnap, a tool for deleting half your user accounts.
4
u/JacksRagingIT Mar 19 '19
Perfectly balanced.
8
u/boli99 Mar 19 '19 edited Mar 25 '19
Balance -Perfectly -AsAllThingsShouldBe3
u/boundbylife Mar 20 '19
Can only be terminated by
Get-AdUser Avengers\Captain.Marvel | Set-ACL -Path \\Titan2\ThanosHut\Gauntlet.inf
6
2
u/SpacezCowboy Mar 19 '19
Fantastic idea! I'll be putting this to good use.
5
u/SpacezCowboy Mar 19 '19 edited Mar 19 '19
Get an exception trying to run it right now.
PS C:\WINDOWS\system32> invoke-nmap www.google.com Unable to find type [JsonConvert]. At C:\Program Files\WindowsPowerShell\Modules\PoshNmap\0.4.1\Public\ConvertFrom-NmapXML.ps1:43 char:30 + $convertedJson = [JsonConvert]::SerializeXmlNode($nmapRun ... + ~~~~~~~~~~~~~ + CategoryInfo : InvalidOperation: (JsonConvert:TypeName) [], RuntimeException + FullyQualifiedErrorId : TypeNotFound FormatNmapXml : This is not a valid Hashtable output from Convert-NmapXML At C:\Program Files\WindowsPowerShell\Modules\PoshNmap\0.4.1\Public\ConvertFrom-NmapXML.ps1:64 char:86 + ... esult | ConvertFrom-Json | ConvertPSObjectToHashtable | FormatNmapXml + ~~~~~~~~~~~~~ + CategoryInfo : OperationStopped: (This is not a v...Convert-NmapXML:String) [FormatNmapXml], RuntimeExc eption + FullyQualifiedErrorId : This is not a valid Hashtable output from Convert-NmapXML,FormatNmapXml4
u/JustinGrote Mar 19 '19
Fixed in 0.4.2, run update-module to get it! Apparently some versions of Windows 10 don't bundle the newtonsoft json library natively, I included it explicitly
1
2
u/cyberd0g Mar 19 '19 edited Mar 19 '19
same. works in powershell 6, but no-go on 5.1.17763.316
3
1
u/JustinGrote Mar 19 '19 edited Mar 19 '19
I'll put it as an issue! Works fine on my 5.1 and it built on a windows host with 5.1 just fine.
EDIT: Fixed! :) https://www.reddit.com/r/PowerShell/comments/b314wh/poshnmap_a_powershell_wrapper_around_the_nmap/eix201s
1
u/AnayaBit Mar 19 '19
I have the same problem here :(
1
2
u/dastylinrastan Mar 19 '19
I found the problem, should be fixed by today, in the meantime it works on PSCore. Sorry about that!
1
Mar 19 '19
Getting the same error. I'm running 5.1.17134.590
2
2
u/dastylinrastan Mar 19 '19
I found the problem, should be fixed by today, in the meantime it works on PSCore. Sorry about that!
3
2
u/michael_erana Mar 20 '19
Looks great!
I tried installing it but I'm getting some odd behavior.
PS C:\WIP> invoke-nmap targetServer -preset QuickPlus | fl -prop *
invoke-nmap : The term 'invoke-nmap' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:1
+ invoke-nmap targetServer -preset QuickPlus | fl -prop *
+ ~~~~~~~~~~~
+ CategoryInfo : ObjectNotFound: (invoke-nmap:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundExceptionI made sure that the command was registered with:
PS C:\WIP> find-command invoke-nmap
Name Version ModuleName Repository
---- ------- ---------- ----------
Invoke-Nmap 0.4.2 PoshNmap PSGallery
PS C:\WIP> get-installedmodule poshnmap
Version Name Repository Description
------- ---- ---------- -----------
0.4.2 PoshNmap PSGallery A wrapper for NMAP Network DiscoveryLooks good right?
I tried reloading PS but still the same behavior.
I'm running:
PS C:\WIP> $PSVersionTable.PSVersion
Major Minor Build Revision
----- ----- ----- --------
5 0 10240 17443Any hints on where to look next?
3
u/kdf2883 Mar 20 '19
Run Get-Module and see if PoshNmap is in the list. If it doesn't exist then the module isn't loaded into the session
2
u/michael_erana Mar 20 '19
Ah ha!
PS C:\WIP> get-module poshnmap## bupkus ##
PS C:\WIP> import-module poshnmap import-module : The version of Windows PowerShell on this computer is '5.0.10240.17443'. The module 'C:\Users\merana.VERTEXINC\Documents\WindowsPowerShell\Modules\poshnmap\0.4.2\poshnmap.psd1' requires a minimum Windows PowerShell version of '5.1' to run. Verify that you have the minimum required version of Windows PowerShell installed, and then try again. At line:1 char:1 + import-module poshnmap + ~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : ResourceUnavailable: (C:\Users\merana...2\poshnmap.psd1:String) [Import-Module], InvalidOperationException + FullyQualifiedErrorId : Modules_InsufficientPowerShellVersion,Microsoft.PowerShell.Commands.ImportModuleCommandHmmm... I wonder if it will run if I downgrade the required version.... or.. I should just bite the bullet and update PS.
1
u/Luxtaposition Mar 20 '19
Thank you!!
1
u/Accomplished-Sort564 Mar 30 '23
I get an error trying to use Import-Module poshNmap
PS C:\Users\ID10> import-module poshnmap -verbose -force
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\poshnmap\0.6.1\poshnmap.psd1'.
VERBOSE: Removing the imported "ConvertFrom-NmapXml" function.
VERBOSE: Removing the imported "Get-NmapPresetArguments" function.
VERBOSE: Removing the imported "Invoke-Nmap" function.
VERBOSE: Populating RepositorySourceLocation property for module poshnmap.
VERBOSE: Loading module from path 'C:\Program Files\WindowsPowerShell\Modules\poshnmap\0.6.1\PoshNmap.psm1'.
Add-Type : Cannot bind parameter 'Path' to the target. Exception setting "Path": "Cannot find path 'C:\Program
Files\WindowsPowerShell\Modules\poshnmap\0.6.1\PoshNmap\lib\Newtonsoft.Json-net40-client.dll' because it does not
exist."
At C:\Program Files\WindowsPowerShell\Modules\poshnmap\0.6.1\PoshNmap.psm1:20 char:24
+ ... -Type -Path $PSSCriptRoot\PoshNmap\lib\Newtonsoft.Json-net40-client.d ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : WriteError: (:) [Add-Type], ParameterBindingException
+ FullyQualifiedErrorId : ParameterBindingFailed,Microsoft.PowerShell.Commands.AddTypeCommand
VERBOSE: Importing function 'ConvertFrom-NmapXml'.
VERBOSE: Importing function 'Get-NmapPresetArguments'.
VERBOSE: Importing function 'Invoke-Nmap'.
3
u/andyinv Mar 19 '19
Why aren't you wrapping all the command-line options?
One of your examples is passing the nmap commands straight through - as opposed to you using like a "-Ports" style powershell parameter?