forked from p34709852/monkey
Ran format on PS1 script
This commit is contained in:
parent
3191b2d94e
commit
43adea0728
|
@ -1,77 +1,92 @@
|
||||||
function Deploy-Windows([String] $monkey_home = (Get-Item -Path ".\").FullName, [String] $branch = "develop"){
|
function Deploy-Windows([String] $monkey_home = (Get-Item -Path ".\").FullName, [String] $branch = "develop")
|
||||||
# Import the config variables
|
{
|
||||||
. ./config.ps1
|
|
||||||
"Config variables from config.ps1 imported"
|
|
||||||
|
|
||||||
# If we want monkey in current dir we need to create an empty folder for source files
|
|
||||||
if ( (Join-Path $monkey_home '') -eq (Join-Path (Get-Item -Path ".\").FullName '') ){
|
|
||||||
$monkey_home = Join-Path -Path $monkey_home -ChildPath $MONKEY_FOLDER_NAME
|
|
||||||
}
|
|
||||||
|
|
||||||
# Set variables for script execution
|
# Set variables for script execution
|
||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
|
||||||
$webClient = New-Object System.Net.WebClient
|
$webClient = New-Object System.Net.WebClient
|
||||||
|
|
||||||
|
|
||||||
|
# Import the config variables
|
||||||
|
. ./config.ps1
|
||||||
|
"Config variables from config.ps1 imported"
|
||||||
|
|
||||||
|
# If we want monkey in current dir we need to create an empty folder for source files
|
||||||
|
if ((Join-Path $monkey_home '') -eq (Join-Path (Get-Item -Path ".\").FullName ''))
|
||||||
|
{
|
||||||
|
$monkey_home = Join-Path -Path $monkey_home -ChildPath $MONKEY_FOLDER_NAME
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# We check if git is installed
|
# We check if git is installed
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
git | Out-Null -ErrorAction Stop
|
git | Out-Null -ErrorAction Stop
|
||||||
"Git requirement satisfied"
|
"Git requirement satisfied"
|
||||||
}
|
}
|
||||||
catch [System.Management.Automation.CommandNotFoundException]
|
catch [System.Management.Automation.CommandNotFoundException]
|
||||||
{
|
{
|
||||||
"Please install git before running this script or add it to path and restart cmd"
|
"Please install git before running this script or add it to path and restart cmd"
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download the monkey
|
# Download the monkey
|
||||||
$output = cmd.exe /c "git clone --single-branch -b $branch $MONKEY_GIT_URL $monkey_home 2>&1"
|
$output = cmd.exe /c "git clone --single-branch -b $branch $MONKEY_GIT_URL $monkey_home 2>&1"
|
||||||
$binDir = (Join-Path -Path $monkey_home -ChildPath $MONKEY_ISLAND_DIR | Join-Path -ChildPath "\bin")
|
$binDir = (Join-Path -Path $monkey_home -ChildPath $MONKEY_ISLAND_DIR | Join-Path -ChildPath "\bin")
|
||||||
if ( $output -like "*already exists and is not an empty directory.*"){
|
if ($output -like "*already exists and is not an empty directory.*")
|
||||||
"Assuming you already have the source directory. If not, make sure to set an empty directory as monkey's home directory."
|
{
|
||||||
} elseif ($output -like "fatal:*"){
|
"Assuming you already have the source directory. If not, make sure to set an empty directory as monkey's home directory."
|
||||||
"Error while cloning monkey from the repository:"
|
}
|
||||||
$output
|
elseif ($output -like "fatal:*")
|
||||||
return
|
{
|
||||||
} else {
|
"Error while cloning monkey from the repository:"
|
||||||
"Monkey cloned from the repository"
|
$output
|
||||||
# Create bin directory
|
return
|
||||||
New-Item -ItemType directory -path $binDir
|
}
|
||||||
"Bin directory added"
|
else
|
||||||
|
{
|
||||||
|
"Monkey cloned from the repository"
|
||||||
|
# Create bin directory
|
||||||
|
New-Item -ItemType directory -path $binDir
|
||||||
|
"Bin directory added"
|
||||||
}
|
}
|
||||||
|
|
||||||
# We check if python is installed
|
# We check if python is installed
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$version = cmd.exe /c '"python" --version 2>&1'
|
$version = cmd.exe /c '"python" --version 2>&1'
|
||||||
if ( $version -like 'Python 3.*' ) {
|
if ($version -like 'Python 3.*')
|
||||||
"Python 3.* was found, installing dependencies"
|
{
|
||||||
} else {
|
"Python 3.* was found, installing dependencies"
|
||||||
throw System.Management.Automation.CommandNotFoundException
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
throw System.Management.Automation.CommandNotFoundException
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch [System.Management.Automation.CommandNotFoundException]
|
catch [System.Management.Automation.CommandNotFoundException]
|
||||||
{
|
{
|
||||||
"Downloading python 3 ..."
|
"Downloading python 3 ..."
|
||||||
"Select 'add to PATH' when installing"
|
"Select 'add to PATH' when installing"
|
||||||
$webClient.DownloadFile($PYTHON_URL, $TEMP_PYTHON_INSTALLER)
|
$webClient.DownloadFile($PYTHON_URL, $TEMP_PYTHON_INSTALLER)
|
||||||
Start-Process -Wait $TEMP_PYTHON_INSTALLER -ErrorAction Stop
|
Start-Process -Wait $TEMP_PYTHON_INSTALLER -ErrorAction Stop
|
||||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path","User")
|
$env: Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine") + ";" + [System.Environment]::GetEnvironmentVariable("Path", "User")
|
||||||
Remove-Item $TEMP_PYTHON_INSTALLER
|
Remove-Item $TEMP_PYTHON_INSTALLER
|
||||||
# Check if installed correctly
|
# Check if installed correctly
|
||||||
$version = cmd.exe /c '"python" --version 2>&1'
|
$version = cmd.exe /c '"python" --version 2>&1'
|
||||||
if ( $version -like '* is not recognized*' ) {
|
if ($version -like '* is not recognized*')
|
||||||
"Python is not found in PATH. Add it to PATH and relaunch the script."
|
{
|
||||||
return
|
"Python is not found in PATH. Add it to PATH and relaunch the script."
|
||||||
}
|
return
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
"Upgrading pip..."
|
"Upgrading pip..."
|
||||||
$output = cmd.exe /c 'python -m pip install --user --upgrade pip 2>&1'
|
$output = cmd.exe /c 'python -m pip install --user --upgrade pip 2>&1'
|
||||||
$output
|
$output
|
||||||
if ( $output -like '*No module named pip*' ) {
|
if ($output -like '*No module named pip*')
|
||||||
"Make sure pip module is installed and re-run this script."
|
{
|
||||||
return
|
"Make sure pip module is installed and re-run this script."
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
"Installing python packages for island"
|
"Installing python packages for island"
|
||||||
|
@ -83,28 +98,32 @@ function Deploy-Windows([String] $monkey_home = (Get-Item -Path ".\").FullName,
|
||||||
|
|
||||||
$user_python_dir = cmd.exe /c 'py -m site --user-site'
|
$user_python_dir = cmd.exe /c 'py -m site --user-site'
|
||||||
$user_python_dir = Join-Path (Split-Path $user_python_dir) -ChildPath "\Scripts"
|
$user_python_dir = Join-Path (Split-Path $user_python_dir) -ChildPath "\Scripts"
|
||||||
if(!($ENV:PATH | Select-String -SimpleMatch $user_python_dir)){
|
if (!($ENV: PATH | Select-String -SimpleMatch $user_python_dir))
|
||||||
"Adding python scripts path to user's env"
|
{
|
||||||
$env:Path += ";"+$user_python_dir
|
"Adding python scripts path to user's env"
|
||||||
[Environment]::SetEnvironmentVariable("Path",$env:Path,"User")
|
$env: Path += ";" + $user_python_dir
|
||||||
|
[Environment]::SetEnvironmentVariable("Path", $env:Path, "User")
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download mongodb
|
# Download mongodb
|
||||||
if(!(Test-Path -Path (Join-Path -Path $binDir -ChildPath "mongodb") )){
|
if (!(Test-Path -Path (Join-Path -Path $binDir -ChildPath "mongodb")))
|
||||||
"Downloading mongodb ..."
|
{
|
||||||
$webClient.DownloadFile($MONGODB_URL, $TEMP_MONGODB_ZIP)
|
"Downloading mongodb ..."
|
||||||
"Unzipping mongodb"
|
$webClient.DownloadFile($MONGODB_URL, $TEMP_MONGODB_ZIP)
|
||||||
Expand-Archive $TEMP_MONGODB_ZIP -DestinationPath $binDir
|
"Unzipping mongodb"
|
||||||
# Get unzipped folder's name
|
Expand-Archive $TEMP_MONGODB_ZIP -DestinationPath $binDir
|
||||||
$mongodb_folder = Get-ChildItem -Path $binDir | Where-Object -FilterScript {($_.Name -like "mongodb*")} | Select-Object -ExpandProperty Name
|
# Get unzipped folder's name
|
||||||
# Move all files from extracted folder to mongodb folder
|
$mongodb_folder = Get-ChildItem -Path $binDir | Where-Object -FilterScript {
|
||||||
New-Item -ItemType directory -Path (Join-Path -Path $binDir -ChildPath "mongodb")
|
($_.Name -like "mongodb*")
|
||||||
New-Item -ItemType directory -Path (Join-Path -Path $monkey_home -ChildPath $MONKEY_ISLAND_DIR | Join-Path -ChildPath "db")
|
} | Select-Object -ExpandProperty Name
|
||||||
"Moving extracted files"
|
# Move all files from extracted folder to mongodb folder
|
||||||
Move-Item -Path (Join-Path -Path $binDir -ChildPath $mongodb_folder | Join-Path -ChildPath "\bin\*") -Destination (Join-Path -Path $binDir -ChildPath "mongodb\")
|
New-Item -ItemType directory -Path (Join-Path -Path $binDir -ChildPath "mongodb")
|
||||||
"Removing zip file"
|
New-Item -ItemType directory -Path (Join-Path -Path $monkey_home -ChildPath $MONKEY_ISLAND_DIR | Join-Path -ChildPath "db")
|
||||||
Remove-Item $TEMP_MONGODB_ZIP
|
"Moving extracted files"
|
||||||
Remove-Item (Join-Path -Path $binDir -ChildPath $mongodb_folder) -Recurse
|
Move-Item -Path (Join-Path -Path $binDir -ChildPath $mongodb_folder | Join-Path -ChildPath "\bin\*") -Destination (Join-Path -Path $binDir -ChildPath "mongodb\")
|
||||||
|
"Removing zip file"
|
||||||
|
Remove-Item $TEMP_MONGODB_ZIP
|
||||||
|
Remove-Item (Join-Path -Path $binDir -ChildPath $mongodb_folder) -Recurse
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download OpenSSL
|
# Download OpenSSL
|
||||||
|
@ -140,20 +159,23 @@ function Deploy-Windows([String] $monkey_home = (Get-Item -Path ".\").FullName,
|
||||||
"Installing npm"
|
"Installing npm"
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
$version = cmd.exe /c '"npm" --version 2>&1'
|
$version = cmd.exe /c '"npm" --version 2>&1'
|
||||||
if ( $version -like "*is not recognized*"){
|
if ($version -like "*is not recognized*")
|
||||||
throw System.Management.Automation.CommandNotFoundException
|
{
|
||||||
} else {
|
throw System.Management.Automation.CommandNotFoundException
|
||||||
"Npm already installed"
|
}
|
||||||
}
|
else
|
||||||
|
{
|
||||||
|
"Npm already installed"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch [System.Management.Automation.CommandNotFoundException]
|
catch [System.Management.Automation.CommandNotFoundException]
|
||||||
{
|
{
|
||||||
"Downloading npm ..."
|
"Downloading npm ..."
|
||||||
$webClient.DownloadFile($NPM_URL, $TEMP_NPM_INSTALLER)
|
$webClient.DownloadFile($NPM_URL, $TEMP_NPM_INSTALLER)
|
||||||
Start-Process -Wait $TEMP_NPM_INSTALLER
|
Start-Process -Wait $TEMP_NPM_INSTALLER
|
||||||
$env:Path = [System.Environment]::GetEnvironmentVariable("Path","Machine")
|
$env: Path = [System.Environment]::GetEnvironmentVariable("Path", "Machine")
|
||||||
Remove-Item $TEMP_NPM_INSTALLER
|
Remove-Item $TEMP_NPM_INSTALLER
|
||||||
}
|
}
|
||||||
|
|
||||||
"Updating npm"
|
"Updating npm"
|
||||||
|
@ -173,41 +195,46 @@ function Deploy-Windows([String] $monkey_home = (Get-Item -Path ".\").FullName,
|
||||||
New-Item -ItemType directory -path $binaries -ErrorAction SilentlyContinue
|
New-Item -ItemType directory -path $binaries -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# Download upx
|
# Download upx
|
||||||
if(!(Test-Path -Path (Join-Path -Path $binDir -ChildPath "upx.exe") )){
|
if (!(Test-Path -Path (Join-Path -Path $binDir -ChildPath "upx.exe")))
|
||||||
"Downloading upx ..."
|
{
|
||||||
$webClient.DownloadFile($UPX_URL, $TEMP_UPX_ZIP)
|
"Downloading upx ..."
|
||||||
"Unzipping upx"
|
$webClient.DownloadFile($UPX_URL, $TEMP_UPX_ZIP)
|
||||||
Expand-Archive $TEMP_UPX_ZIP -DestinationPath $binDir -ErrorAction SilentlyContinue
|
"Unzipping upx"
|
||||||
Move-Item -Path (Join-Path -Path $binDir -ChildPath $UPX_FOLDER | Join-Path -ChildPath "upx.exe") -Destination $binDir
|
Expand-Archive $TEMP_UPX_ZIP -DestinationPath $binDir -ErrorAction SilentlyContinue
|
||||||
# Remove unnecessary files
|
Move-Item -Path (Join-Path -Path $binDir -ChildPath $UPX_FOLDER | Join-Path -ChildPath "upx.exe") -Destination $binDir
|
||||||
Remove-Item -Recurse -Force (Join-Path -Path $binDir -ChildPath $UPX_FOLDER)
|
# Remove unnecessary files
|
||||||
"Removing zip file"
|
Remove-Item -Recurse -Force (Join-Path -Path $binDir -ChildPath $UPX_FOLDER)
|
||||||
Remove-Item $TEMP_UPX_ZIP
|
"Removing zip file"
|
||||||
|
Remove-Item $TEMP_UPX_ZIP
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download mimikatz binaries
|
# Download mimikatz binaries
|
||||||
$mk32_path = Join-Path -Path $binDir -ChildPath $MK32_DLL
|
$mk32_path = Join-Path -Path $binDir -ChildPath $MK32_DLL
|
||||||
if(!(Test-Path -Path $mk32_path )){
|
if (!(Test-Path -Path $mk32_path))
|
||||||
"Downloading mimikatz 32 binary"
|
{
|
||||||
$webClient.DownloadFile($MK32_DLL_URL, $mk32_path)
|
"Downloading mimikatz 32 binary"
|
||||||
|
$webClient.DownloadFile($MK32_DLL_URL, $mk32_path)
|
||||||
}
|
}
|
||||||
$mk64_path = Join-Path -Path $binDir -ChildPath $MK64_DLL
|
$mk64_path = Join-Path -Path $binDir -ChildPath $MK64_DLL
|
||||||
if(!(Test-Path -Path $mk64_path )){
|
if (!(Test-Path -Path $mk64_path))
|
||||||
"Downloading mimikatz 64 binary"
|
{
|
||||||
$webClient.DownloadFile($MK64_DLL_URL, $mk64_path)
|
"Downloading mimikatz 64 binary"
|
||||||
|
$webClient.DownloadFile($MK64_DLL_URL, $mk64_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
# Download sambacry binaries
|
# Download sambacry binaries
|
||||||
$samba_path = Join-Path -Path $monkey_home -ChildPath $SAMBA_BINARIES_DIR
|
$samba_path = Join-Path -Path $monkey_home -ChildPath $SAMBA_BINARIES_DIR
|
||||||
$samba32_path = Join-Path -Path $samba_path -ChildPath $SAMBA_32_BINARY_NAME
|
$samba32_path = Join-Path -Path $samba_path -ChildPath $SAMBA_32_BINARY_NAME
|
||||||
if(!(Test-Path -Path $samba32_path )){
|
if (!(Test-Path -Path $samba32_path))
|
||||||
"Downloading sambacry 32 binary"
|
{
|
||||||
$webClient.DownloadFile($SAMBA_32_BINARY_URL, $samba32_path)
|
"Downloading sambacry 32 binary"
|
||||||
|
$webClient.DownloadFile($SAMBA_32_BINARY_URL, $samba32_path)
|
||||||
}
|
}
|
||||||
$samba64_path = Join-Path -Path $samba_path -ChildPath $SAMBA_64_BINARY_NAME
|
$samba64_path = Join-Path -Path $samba_path -ChildPath $SAMBA_64_BINARY_NAME
|
||||||
if(!(Test-Path -Path $samba64_path )){
|
if (!(Test-Path -Path $samba64_path))
|
||||||
"Downloading sambacry 64 binary"
|
{
|
||||||
$webClient.DownloadFile($SAMBA_64_BINARY_URL, $samba64_path)
|
"Downloading sambacry 64 binary"
|
||||||
|
$webClient.DownloadFile($SAMBA_64_BINARY_URL, $samba64_path)
|
||||||
}
|
}
|
||||||
|
|
||||||
"Script finished"
|
"Script finished"
|
||||||
|
|
Loading…
Reference in New Issue