Option Explicit Function Defuscator(vbs) Dim t t = InStr(1, vbs, "Execute", 1) t = Mid(vbs, t + Len("Execute")) t = Eval(t) Defuscator = t End Function Dim fso, i Const ForReading = 1 Set fso = CreateObject("Scripting.FileSystemObject") For i = 0 To WScript.Arguments.Count - 1 Dim FileName FileName = WScript.Arguments(i) Dim MyFile Set MyFile = fso.OpenTextFile(FileName, ForReading) Dim vbs vbs = MyFile.ReadAll WScript.Echo Defuscator(vbs) MyFile.Close Next Set fso = Nothing
eAqi = "59fc6b263c3d0fcbc331ade699e62d3473bbf85522d588e3423e6c751ca091528a3c0186e460483917192c14" ANtg = "baacc7ffa8232d28f814bb14c428798b" Function Base64Decode(base64EncodedString) Dim xml, elem Set xml = CreateObject("MSXML2.DOMDocument") Set elem = xml.createElement("tmp") elem.dataType = "bin.base64" elem.text = base64EncodedString Dim stream Set stream = CreateObject("ADODB.Stream") stream.Type = 1 'Binary stream.Open stream.Write elem.nodeTypedValue stream.Position = 0 stream.Type = 2 'Text stream.Charset = "utf-8" Base64Decode = stream.ReadText stream.Close End Function
Function Initialize(strPwd) Dim box(256) Dim tempSwap Dim a Dim b
For i = 0 To 255 box(i) = i Next
a = 0 b = 0
For i = 0 To 255 a = (a + box(i) + Asc(Mid(strPwd, (i Mod Len(strPwd)) + 1, 1))) Mod 256 tempSwap = box(i) box(i) = box(a) box(a) = tempSwap Next
Initialize = box End Function Function Myfunc(strToHash) Dim tmpFile, strCommand, objFSO, objWshShell, out Set objFSO = CreateObject("Scripting.FileSystemObject") Set objWshShell = CreateObject("WScript.Shell") tmpFile = objFSO.GetSpecialFolder(2).Path & "\" & objFSO.GetTempName objFSO.CreateTextFile(tmpFile).Write(strToHash) strCommand = "certutil -hashfile " & tmpFile & " MD5" out = objWshShell.Exec(strCommand).StdOut.ReadAll objFSO.DeleteFile tmpFile Myfunc = Replace(Split(Trim(out), vbCrLf)(1), " ", "") End Function Function EnCrypt(box, strData) Dim tempSwap Dim a Dim b Dim x Dim y Dim encryptedData encryptedData = "" For x = 1 To Len(strData) a = (a + 1) Mod 256 b = (b + box(a)) Mod 256 tempSwap = box(a) box(a) = box(b) box(b) = tempSwap y = Asc(Mid(strData, x, 1)) Xor box((box(a) + box(b)) Mod 256) encryptedData = encryptedData & LCase(Right("0" & Hex(y), 2)) Next EnCrypt = encryptedData End Function msgbox "Do you know VBScript?" msgbox "VBScript (""Microsoft Visual Basic Scripting Edition"") is a deprecated Active Scripting language developed by Microsoft that is modeled on Visual Basic." msgbox "It allows Microsoft Windows system administrators to generate powerful tools for managing computers without error handling and with subroutines and other advanced programming constructs. It can give the user complete control over many aspects of their computing environment." msgbox "Interestingly, although VBScript has long since been deprecated, you can still run VBScript scripts on the latest versions of Windows 11 systems." msgbox "A VBScript script must be executed within a host environment, of which there are several provided with Microsoft Windows, including: Windows Script Host (WSH), Internet Explorer (IE), and Internet Information Services (IIS)." msgbox "For .vbs files, the host is Windows Script Host (WSH), aka wscript.exe/cscript.exe program in your system." msgbox "If you can not stop a VBScript from running (e.g. a dead loop), go to the task manager and kill wscript.exe/cscript.exe." msgbox "cscript and wscript are executables for the scripting host that are used to run the scripts. cscript and wscript are both interpreters to run VBScript (and other scripting languages like JScript) on the Windows platform." msgbox "cscript is for console applications and wscript is for Windows applications. It has something to do with STDIN, STDOUT and STDERR." msgbox "OK! Now, let us begin our journey."
key = InputBox("Enter the key:", "CTF Challenge") if (key = False) then wscript.quit if (len(key)<>6) then wscript.echo "wrong key length!" wscript.quit end if If (Myfunc(key) = ANtg) Then wscript.echo "You get the key!Move to next challenge." Else wscript.echo "Wrong key!Try again!" wscript.quit End If
userInput = InputBox("Enter the flag:", "CTF Challenge") if (userInput = False) then wscript.quit if (len(userInput)<>44) then wscript.echo "wrong!" wscript.quit end if box = Initialize(key) encryptedInput = EnCrypt(box, userInput)
If (encryptedInput = eAqi) Then MsgBox "Congratulations! You have learned VBS!" Else MsgBox "Wrong flag. Try again." End If