ABOUT ME

-

Today
-
Yesterday
-
Total
-
  • CodeEngn Basic RCE 13
    $ 리버싱 $/CodeEngn Basic RCE 2019. 5. 6. 14:06

     

    파일을 실행해 보면 다음과 같이 console에서 실행 됩니다.

     

    올리디버거로 파일을 열어서 분석을 하려고 했지만..

    열리지 않습니다. 그래서 파일이 어떻게 이루어져 있는지 확인을 해봤습니다.

     

     

    Microsoft Visual C#으로 되어 있습니다.

    그래서 열리지 않았던 같네요..

     

    C# 디컴파일 할수 있는 툴을 생각해 봤는데

    ILSpy 툴이 떠올랐습니다.

    ILSpy 다운로드 주소 : https://sourceforge.net/projects/ilspyportable/

     

    13.exe 열면 다음과 같이 파일이 열리고 디컴파일 소스코드를 찾습니다.

    해당 13.exe 파일에는 2개의 class 있는것 같습니다.

     

     

    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

    44

    45

    46

    47

    48

    using System;

    using System.IO;

    using System.Security.Cryptography;

    using System.Text;

     

    public class RijndaelSimple

    {

        public static string Encrypt(string plainText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)

        {

            byte[] bytes = Encoding.ASCII.GetBytes(initVector);

            byte[] bytes2 = Encoding.ASCII.GetBytes(saltValue);

            byte[] bytes3 = Encoding.UTF8.GetBytes(plainText);

            PasswordDeriveBytes passwordDeriveBytes = new PasswordDeriveBytes(passPhrase, bytes2, hashAlgorithm, passwordIterations);

            byte[] bytes4 = passwordDeriveBytes.GetBytes(keySize / 8);

            ICryptoTransform transform = new RijndaelManaged

            {

                Mode = CipherMode.CBC

            }.CreateEncryptor(bytes4, bytes);

            MemoryStream memoryStream = new MemoryStream();

            CryptoStream cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Write);

            cryptoStream.Write(bytes3, 0, bytes3.Length);

            cryptoStream.FlushFinalBlock();

            byte[] inArray = memoryStream.ToArray();

            memoryStream.Close();

            cryptoStream.Close();

            return Convert.ToBase64String(inArray);

        }

     

        public static string Decrypt(string cipherText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)

        {

            byte[] bytes = Encoding.ASCII.GetBytes(initVector);

            byte[] bytes2 = Encoding.ASCII.GetBytes(saltValue);

            byte[] array = Convert.FromBase64String(cipherText);

            PasswordDeriveBytes passwordDeriveBytes = new PasswordDeriveBytes(passPhrase, bytes2, hashAlgorithm, passwordIterations);

            byte[] bytes3 = passwordDeriveBytes.GetBytes(keySize / 8);

            ICryptoTransform transform = new RijndaelManaged

            {

                Mode = CipherMode.CBC

            }.CreateDecryptor(bytes3, bytes);

            MemoryStream memoryStream = new MemoryStream(array);

            CryptoStream cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Read);

            byte[] array2 = new byte[array.Length];

            int count = cryptoStream.Read(array2, 0, array2.Length);

            memoryStream.Close();

            cryptoStream.Close();

            return Encoding.UTF8.GetString(array2, 0, count);

        }

    }

    RijndaelSimple class

     

    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

    using System;

     

    public class RijndaelSimpleTest

    {

        [STAThread]

        private static void Main(string[] args)

        {

            string text = "";

            string cipherText = "BnCxGiN4aJDE+qUe2yIm8Q==";

            string passPhrase = "^F79ejk56$£";

            string saltValue = "DHj47&*)$h";

            string hashAlgorithm = "MD5";

            int passwordIterations = 1024;

            string initVector = "&!£$%^&*()CvHgE!";

            int keySize = 256;

            RijndaelSimple.Encrypt(text, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);

            text = RijndaelSimple.Decrypt(cipherText, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);

            while (true)

            {

                Console.WriteLine("Please enter the password: ");

                string a = Console.ReadLine();

                if (a == text)

                {

                    break;

                }

                Console.WriteLine("Bad Luck! Try again!");

            }

            Console.WriteLine("Well Done! You cracked it!");

            Console.ReadLine();

        }

    }

    RijndaelSimpleTest class

     

    C# 파일을 디컴파일한 소스코드를 저장 해보겠습니다

     

    13(1.0.0.0) 클릭 -> 오른쪽 위의 File -> Save Code 하시면 .cs 확장자로 저장이 가능 합니다.

     

    Visual studio 2017 이용해서 프로젝트를 만들어 보겠습니다.

     

    콘솔 (.NET Framework) 프로젝트를 하나 만들어 줍니다.

     

    그리고 저장한 파일을 실행후 소스코드를 복사합니다.

    그리고 Program.cs 소스코드를 붙여 넣기 합니다.

     

    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

    44

    45

    46

    47

    48

    49

    50

    51

    52

    53

    54

    55

    56

    57

    58

    59

    60

    61

    62

    63

    64

    65

    66

    67

    68

    69

    70

    71

    72

    73

    74

    75

    76

    77

    78

    79

    80

    81

    using System;

    using System.Diagnostics;

    using System.IO;

    using System.Reflection;

    using System.Runtime.CompilerServices;

    using System.Runtime.InteropServices;

    using System.Security.Cryptography;

    using System.Text;

     

    public class RijndaelSimple

    {

        public static string Encrypt(string plainText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)

        {

            byte[] bytes = Encoding.ASCII.GetBytes(initVector);

            byte[] bytes2 = Encoding.ASCII.GetBytes(saltValue);

            byte[] bytes3 = Encoding.UTF8.GetBytes(plainText);

            PasswordDeriveBytes passwordDeriveBytes = new PasswordDeriveBytes(passPhrase, bytes2, hashAlgorithm, passwordIterations);

            byte[] bytes4 = passwordDeriveBytes.GetBytes(keySize / 8);

            ICryptoTransform transform = new RijndaelManaged

            {

                Mode = CipherMode.CBC

            }.CreateEncryptor(bytes4, bytes);

            MemoryStream memoryStream = new MemoryStream();

            CryptoStream cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Write);

            cryptoStream.Write(bytes3, 0, bytes3.Length);

            cryptoStream.FlushFinalBlock();

            byte[] inArray = memoryStream.ToArray();

            memoryStream.Close();

            cryptoStream.Close();

            return Convert.ToBase64String(inArray);

        }

     

        public static string Decrypt(string cipherText, string passPhrase, string saltValue, string hashAlgorithm, int passwordIterations, string initVector, int keySize)

        {

            byte[] bytes = Encoding.ASCII.GetBytes(initVector);

            byte[] bytes2 = Encoding.ASCII.GetBytes(saltValue);

            byte[] array = Convert.FromBase64String(cipherText);

            PasswordDeriveBytes passwordDeriveBytes = new PasswordDeriveBytes(passPhrase, bytes2, hashAlgorithm, passwordIterations);

            byte[] bytes3 = passwordDeriveBytes.GetBytes(keySize / 8);

            ICryptoTransform transform = new RijndaelManaged

            {

                Mode = CipherMode.CBC

            }.CreateDecryptor(bytes3, bytes);

            MemoryStream memoryStream = new MemoryStream(array);

            CryptoStream cryptoStream = new CryptoStream(memoryStream, transform, CryptoStreamMode.Read);

            byte[] array2 = new byte[array.Length];

            int count = cryptoStream.Read(array2, 0, array2.Length);

            memoryStream.Close();

            cryptoStream.Close();

            return Encoding.UTF8.GetString(array2, 0, count);

        }

    }

    public class RijndaelSimpleTest

    {

        [STAThread]

        private static void Main(string[] args)

        {

            string text = "";

            string cipherText = "BnCxGiN4aJDE+qUe2yIm8Q==";

            string passPhrase = "^F79ejk56$£";

            string saltValue = "DHj47&*)$h";

            string hashAlgorithm = "MD5";

            int passwordIterations = 1024;

            string initVector = "&!£$%^&*()CvHgE!";

            int keySize = 256;

            RijndaelSimple.Encrypt(text, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);

            text = RijndaelSimple.Decrypt(cipherText, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);

            while (true)

            {

                Console.WriteLine("Please enter the password: ");

                string a = Console.ReadLine();

                if (a == text)

                {

                    break;

                }

                Console.WriteLine("Bad Luck! Try again!");

            }

            Console.WriteLine("Well Done! You cracked it!");

            Console.ReadLine();

        }

    }

    ↑복사한 소스코드

     

    72번줄의 if문을 들어가기 전에 text 출력하는 코드를 71번줄 아래에 입력해 줍니다.

    Console.WriteLine(text);

     

    그리고 실행을 하면 다음과 같이 출력됩니다.

     

     

    password : Leteminman

     

    '$ 리버싱 $ > CodeEngn Basic RCE' 카테고리의 다른 글

    CodeEngn Basic RCE 15  (0) 2019.05.07
    CodeEngn Basic RCE 14  (0) 2019.05.07
    CodeEngn Basic RCE 12  (0) 2019.05.06
    CodeEngn Basic RCE 11  (0) 2019.05.06
    CodeEngn Basic RCE 10  (0) 2019.05.06

    댓글

Designed by Tistory.