-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path01_setup.ps1
43 lines (37 loc) · 2.13 KB
/
01_setup.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
##
## SETUP CNTLM ... THIS IS THE ENTRY POINT AFTER SETTING UP THE CNTLM TEMPLATE - WELCOME TO YOU.
##
## the credentials of the user are NOT stored on the HDD as file, except as env variable in memory / on process time.
## with the help of the credentials, the user on the VM will be created with the provided user:password.
# all files need to be read and written with no windows line feeds (aka -raw when reading, aka -NoNewline when writing)
# otherwise cntlm will fail to generate the correct password
Param(
[Parameter(Mandatory=$true)] $user_name,
[Parameter(Mandatory=$true)][SecureString] $user_password
)
$user_pw_decrypted = [Runtime.InteropServices.Marshal]::PtrToStringAuto([Runtime.InteropServices.Marshal]::SecureStringToBSTR($user_password))
(get-content .\cntlm.conf.template -raw) | %{$_ -replace "USER_NAME",$user_name} | Set-Content -NoNewline cntlm.conf
$ntlmv2_hash = echo $user_pw_decrypted | .\cntlm-win\cntlm.exe -c ".\cntlm.conf" -H -v | Select-String -Pattern "PassNTLMv2\s+(\S+)"
(get-content .\cntlm.conf -raw) | %{$_ -replace "USER_PASS",$ntlmv2_hash.Matches[0].Groups[1].Value} | Set-Content -NoNewline cntlm.conf
##
## SETUP ENV FOR WINDOWS VAGRANT
##
## otherwise vagrant can not connect to the internet...
## these env vars are also going to be exported in the Vagrantfile to the VM
## all env vars are erased after this process
$env:HTTPS_PROXY = "http://localhost:3128"
$env:HTTP_PROXY = $env:HTTPS_PROXY
$env:HTTP_PROXY = $env:HTTPS_PROXY
$env:HTTP_PROXY = $env:HTTPS_PROXY
$env:VM_USER = $user_name.toLower() # needed for linux, because uppercase names are not allowed
$env:VM_PASS = $user_pw_decrypted
##
## START CNTLM WITH PROVIDED OR NEWLY CREATED CONFIG
##
$arguments_cntlm = "-c "".\cntlm.conf"" -v"
Start-Process -FilePath ".\cntlm-win\cntlm.exe" -ArgumentList $arguments_cntlm
##
## START VAGRANT - THE MAGIC HAPPENS IN THE VAGRANTFILE AFTER THIS STEP
## output of the vagrant process will be logged to a textfile, because the window closes after the process.
##
Start-Process -FilePath "vagrant" -ArgumentList "up" -LoadUserProfile -RedirectStandardOutput "vagrant_output.txt"