Created
April 19, 2020 23:02
-
-
Save razlupercio/cb28439b5336e849598bc759bef3d675 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Imports System | |
Imports System.Text | |
Imports System.Security.Cryptography | |
' decrypt script used on Nest - HTB machine... | |
Public Class Utils | |
Public Shared Function DecryptString(EncryptedString As String) As String | |
If String.IsNullOrEmpty(EncryptedString) Then | |
Return String.Empty | |
Else | |
Return Decrypt(EncryptedString, "N3st22", "88552299", 2, "464R5DFA5DL6LE28", 256) | |
End If | |
End Function | |
Public Shared Function Decrypt(ByVal cipherText As String, _ | |
ByVal passPhrase As String, _ | |
ByVal saltValue As String, _ | |
ByVal passwordIterations As Integer, _ | |
ByVal initVector As String, _ | |
ByVal keySize As Integer) _ | |
As String | |
Dim initVectorBytes As Byte() | |
initVectorBytes = Encoding.ASCII.GetBytes(initVector) | |
Dim saltValueBytes As Byte() | |
saltValueBytes = Encoding.ASCII.GetBytes(saltValue) | |
Dim cipherTextBytes As Byte() | |
cipherTextBytes = Convert.FromBase64String(cipherText) | |
Dim password As New Rfc2898DeriveBytes(passPhrase, _ | |
saltValueBytes, _ | |
passwordIterations) | |
Dim keyBytes As Byte() | |
keyBytes = password.GetBytes(CInt(keySize / 8)) | |
Dim symmetricKey As New AesCryptoServiceProvider | |
symmetricKey.Mode = CipherMode.CBC | |
Dim decryptor As ICryptoTransform | |
decryptor = symmetricKey.CreateDecryptor(keyBytes, initVectorBytes) | |
Dim memoryStream As IO.MemoryStream | |
memoryStream = New IO.MemoryStream(cipherTextBytes) | |
Dim cryptoStream As CryptoStream | |
cryptoStream = New CryptoStream(memoryStream, _ | |
decryptor, _ | |
CryptoStreamMode.Read) | |
Dim plainTextBytes As Byte() | |
ReDim plainTextBytes(cipherTextBytes.Length) | |
Dim decryptedByteCount As Integer | |
decryptedByteCount = cryptoStream.Read(plainTextBytes, _ | |
0, _ | |
plainTextBytes.Length) | |
memoryStream.Close() | |
cryptoStream.Close() | |
Dim plainText As String | |
plainText = Encoding.ASCII.GetString(plainTextBytes, _ | |
0, _ | |
decryptedByteCount) | |
System.Console.WriteLine(plainText) | |
Return plainText | |
End Function | |
End Class | |
Public Class SsoIntegration | |
Public Property Username as String | |
Public Property Password as String | |
End Class | |
Module mainModule | |
Sub Main() | |
Dim test As New SsoIntegration With {.Username = "REDACTED", .Password = Utils.DecryptString("REDACTED")} | |
End Sub | |
End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment