Skip to content

Instantly share code, notes, and snippets.

@sunnyc7
sunnyc7 / ReverseIP in POSH
Created July 16, 2012 14:54
Reverse an IP in Powershell
## string reverse
## You can replace the IP with a variable which you get from a variable, or read from nslookup
$ip = "192.168.1.10"
$reverseIP = ($ip.split("."))[3..0]
$newIP = [string]::join(".",$reverseIP)
$newIP
@sunnyc7
sunnyc7 / Win32NativeWithoutPInvoke.ps1
Last active December 10, 2015 08:58
Access Win32 Native Api functions like DuplicateHandle, NTQuerySystemInformation (Part of Kernel32.dll), without using P/Invoke wizardry or Reflection.
# Author: @mattifestation.
# Link:http://www.exploit-monday.com/2012/12/list-all-win32native-functions.html
## Comment:
# My experience running on V3.0 has been slow so far. I will try on other workstations and test v3.0
# Matt's screenshot look impressive.
# To QCall or Not to QCall.
$PinvokeMethods = [AppDomain]::CurrentDomain.GetAssemblies().GetTypes().GetMethods('NonPublic, Public, Static, Instance') |
    ? { $_.Attributes.HasFlag([Reflection.MethodAttributes]::PinvokeImpl) } | % { $CurrentMethod = $_; $_.CustomAttributes } |
        ? { $_.AttributeType -eq [Runtime.InteropServices.DllImportAttribute] } | ? { $_.ConstructorArguments.Value -ne 'QCall' } |
@sunnyc7
sunnyc7 / get-2010sg.ps1
Last active December 10, 2015 18:58
Mod of doug finke's PDF downloader script to download
#Original Doug Finke's gist - https://gist.github.com/4467657
#download all scripting games code by Rohn Edwards
$url="http://2012sg.poshcode.org/Scripts/By/862"
(Invoke-WebRequest $url).links | where{$_.innerHTML -eq "Download"} | ForEach {
$outFile = "c:\temp\$($_.outerText)"
#"Downloading $($_.InnerHtml) -> $($outFile)"
$callstring = "http://2012sg.poshcode.org"+$_.href
$callstring
Invoke-WebRequest $callstring -OutFile $outFile
@sunnyc7
sunnyc7 / webconfig hash
Created April 4, 2013 14:07
Convert Web.Config to a hashtable. Use Keys to get the values.
<#
web.config.xml
<configuration>
<applicationSettings>
<add key="machineName" value="Prod" />
<add key="anotherMachineName" value="Test" />
<add key="EnvTypeDefault" value="Dev" />
<add key="RootURLProd" value="http://domain.com/app/" />
<add key="RootURLTest" value="http://test.domain.com/app/" />
#requires -version 3.0
[CmdletBinding()]
param (
[Parameter(Mandatory)]
[string]
$Path
)
function Sort-NodeArray {
param (
Configuration AspNet45WebServer {
WindowsFeature WebAspNet45 {
Name = 'Web-Asp-Net45'
Ensure = 'Present'
}
WindowsFeature WebWindowsAuth {
Name = 'Web-Windows-Auth'
Ensure = 'Present'
winrm.cmd g winrm/config/service/auth -r:$env:computername -a:kerberos
winrm.cmd s winrm/config/service/auth -r:$env:computername -a:kerberos @{CredSSP="true"}
[CmdletBinding()]
param (
[Parameter(Mandatory=$true)]
[string]
$ComputerName,
[int]
$Port = 443
)
#requires -version 3
[CmdletBinding()]
param ()
$DatabasePath = Get-CimInstance -ClassName Win32_NetworkAdapterConfiguration -Filter 'DatabasePath is not null' -Property DatabasePath |
Select-Object -ExpandProperty DatabasePath -First 1
$DatabasePath = [Environment]::ExpandEnvironmentVariables($DatabasePath)
$HostsFilePath = Join-Path -Path $DatabasePath -ChildPath HOSTS
function ConvertFrom-IISW3CLog {
[CmdletBinding()]
param (
[Parameter(Mandatory, ValueFromPipeline, ValueFromPipelineByPropertyName)]
[Alias('PSPath')]
[string[]]
$Path
)
process {