Jump to content

Powershell Guru needed please!


Whiskey
 Share

Recommended Posts

I'm working on a recon payload, something to grab a bunch of info about a machine that could be useful in future payloads.  One of the things I'm attempting to grab is network adapter info with MACs and IPs.  However I run in to two issues.  The first is I only want to return the IPv4 addresses, but all the workarounds to this known to me break my code.  Second, if I try to pass more info to my output table, the info in concatenated with ellipses (...) those things.

Here's the code snippet (minus extra outputs causing ellipses):

Get-WmiObject Win32_NetworkAdapterConfiguration | where { $_.MACAddress -notlike $null }  | select Index, Description, IPAddress, MACAddress | Format-Table Index, Description, IPAddress, MACAddress

Can anyone tell me how to only grab IPv4 from the output of Win32_NetworkAdapterConfiguration?  Thank you!

As for the ellipses, fixing that would be a bonus, but it's not crucial to what I'm working on.

I'll share my QuickRecon payload here as soon as it's working - even though it's nothing "new", just a combination of the best parts of existing recon payloads.

Link to comment
Share on other sites

Well maybe this will help, maybe it won't.  But if you type this into powershell: 

Get-WmiObject Win32_NetworkAdapterConfiguration | where { $_.MACAddress -notlike $null }  | Select-String -InputObject {$_.IPAddress} -Pattern '\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b'

It'll grab / display the IPv4 and IPv6 only.  I still can't figure out how to cut the IPv6 part and it's really bugging me.

Then if you type this:

Get-WmiObject Win32_NetworkAdapterConfiguration | where { $_.MACAddress -notlike $null }  | Select-String -InputObject {$_.IPAddress} -Pattern '\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b' | Out-File ./test.txt

It'll do the same thing but save it to a file.

Hope this helps a little.  I don't do much with powershell so this is a learning experience for me.  Would like to see the whole payload when you have it complete.

Link to comment
Share on other sites

This is why I scratch my head to powershell.  Again not sure if this helps or not but this:

Get-WmiObject Win32_NetworkAdapterConfiguration | where { $_.MACAddress -notlike $null }  | Select-String -InputObject {$_.IPAddress} -Pattern '\b\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}\b' -AllMatches |%{$_.Matches}|%{$_.Value}

Only displays IPv4 addresses.  Yay if nothing else I learned a lot.

Link to comment
Share on other sites

Thanks.  I've already tried a very similar string with no success.  I'll keep poking at this, but since you asked, I've dropped this payload on my github for anyone to take a look and help.

https://github.com/ciavolella/BashBunny/tree/main/QuickRecon

In the info.ps1 file is the line from my original post.  If you modify it to add say "DefaultIPGateway", then the output gets concatenated in the outputted table.

Also, in the payload.txt I'm using the loop function to detect when the script finishes to display the proper LED color, however this isn't working and I don't know why.  It's the exact same loop used in many other payloads, so I'm at a loss.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...