Korean :
정답은 무엇인가
이번 문제는 C#으로 컴파일되어 있어서 조금 검색해보니 자체 어셈블리어를 사용하고 있고, 기존 PE 파일 구조와 달라서 OllyDbg로는 리버싱이 불가능 하다고 한다.
그래서 .NET Reflector로 디컴파일하여 AES 암호 알고리즘으로 키워드를 만들어 내는 것을 알 수 있었고,
패스워드나 IV, Iteration, 해쉬알고리즘 등은 이미 작성되어 있어서 따로 코딩해서 알아낼 수 있었다.
답 : Leteminman
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Security.Cryptography; //추가
using System.IO; // 추가
namespace ConsoleApplication7
{
public class RijndaelSimple
{
// Methods
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[] rgbSalt = Encoding.ASCII.GetBytes(saltValue);
byte[] buffer = Convert.FromBase64String(cipherText);
byte[] rgbKey = new PasswordDeriveBytes(passPhrase, rgbSalt, hashAlgorithm, passwordIterations).GetBytes(keySize / 8);
ICryptoTransform transform = new RijndaelManaged { Mode = CipherMode.CBC }.CreateDecryptor(rgbKey, bytes);
MemoryStream stream = new MemoryStream(buffer);
CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Read);
byte[] buffer5 = new byte[buffer.Length];
int count = stream2.Read(buffer5, 0, buffer5.Length);
stream.Close();
stream2.Close();
return Encoding.UTF8.GetString(buffer5, 0, count);
}
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[] rgbSalt = Encoding.ASCII.GetBytes(saltValue);
byte[] buffer = Encoding.UTF8.GetBytes(plainText);
byte[] rgbKey = new PasswordDeriveBytes(passPhrase, rgbSalt, hashAlgorithm, passwordIterations).GetBytes(keySize / 8);
ICryptoTransform transform = new RijndaelManaged { Mode = CipherMode.CBC }.CreateEncryptor(rgbKey, bytes);
MemoryStream stream = new MemoryStream();
CryptoStream stream2 = new CryptoStream(stream, transform, CryptoStreamMode.Write);
stream2.Write(buffer, 0, buffer.Length);
stream2.FlushFinalBlock();
byte[] inArray = stream.ToArray();
stream.Close();
stream2.Close();
return Convert.ToBase64String(inArray);
}
}
class Program
{
static void Main(string[] args)
{
string plainText = "";
string cipherText = "BnCxGiN4aJDE+qUe2yIm8Q==";
string passPhrase = "^F79ejk56$\x00a3";
string saltValue = "DHj47&*)$h";
string hashAlgorithm = "MD5";
int passwordIterations = 0x400;
string initVector = "&!\x00a3$%^&*()CvHgE!";
int keySize = 0x100;
RijndaelSimple.Encrypt(plainText, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
plainText = RijndaelSimple.Decrypt(cipherText, passPhrase, saltValue, hashAlgorithm, passwordIterations, initVector, keySize);
Console.WriteLine(plainText);
}
}
}
'WARGAME > codeengn' 카테고리의 다른 글
코드엔진 베이직 15 (0) | 2014.12.14 |
---|---|
코드엔진 베이직 14 (0) | 2014.12.14 |
코드엔진 베이직 12 (0) | 2014.12.13 |
코드엔진 베이직 11 (0) | 2014.12.13 |
코드엔진 베이직 10 (0) | 2014.12.13 |