test ike crypto works, new protos from pb

This commit is contained in:
raphaeIl
2025-01-11 10:23:59 -05:00
parent 0b12a29289
commit 01ebb3239d
661 changed files with 322271 additions and 220654 deletions

View File

@@ -9,6 +9,7 @@ using Novaria.Common.Utils;
using System.IO;
using System.Numerics;
using System.Security.Cryptography;
using Microsoft.AspNetCore.Http;
namespace Novaria.SDKServer.Controllers.Api
{
@@ -53,26 +54,35 @@ namespace Novaria.SDKServer.Controllers.Api
[HttpOptions] // Ike
public IActionResult OptionsRequest()
{
Log.Information("Received Gateway Ike Options Request, Payload: ");
// store key which is used in AeadTool
using var memoryStream = new MemoryStream();
Request.Body.CopyTo(memoryStream); // Copy request body to MemoryStream
byte[] rawBytes = memoryStream.ToArray(); // Get raw bytes from MemoryStream
// Set response headers
Response.Headers.Add("Date", DateTime.UtcNow.ToString("R"));
Response.Headers.Add("Content-Length", "251");
Response.Headers.Add("Connection", "keep-alive");
Utils.PrintByteArray(rawBytes);
//byte[] msgId = BitConverter.GetBytes(msg.msgId);
// Set cookies
Response.Headers.Append("Set-Cookie", "acw_tc=cb6df452e3196d1ec00d2fcdf7726b25ed2accbaa45e1066701a61d2da90b384;path=/;HttpOnly;Max-Age=1800");
Response.Headers.Append("Set-Cookie", "SERVERID=eef797ff9d3671d413582d7dc2f39f29|1736422941|1736422941;Path=/");
Response.Headers.Append("Set-Cookie", "SERVERCORSID=eef797ff9d3671d413582d7dc2f39f29|1736422941|1736422941;Path=/;SameSite=None;Secure");
// Set binary content as the response body
string filePath = "E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\options_response"; // Replace with the actual file path
byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
//// Set response headers
//Response.Headers.Add("Date", DateTime.UtcNow.ToString("R"));
//Response.Headers.Add("Content-Length", "251");
//Response.Headers.Add("Connection", "keep-alive");
// Write bytes directly to response body
Response.Body.WriteAsync(fileBytes, 0, fileBytes.Length);
//// Set cookies
//Response.Headers.Append("Set-Cookie", "acw_tc=cb6df452e3196d1ec00d2fcdf7726b25ed2accbaa45e1066701a61d2da90b384;path=/;HttpOnly;Max-Age=1800");
//Response.Headers.Append("Set-Cookie", "SERVERID=eef797ff9d3671d413582d7dc2f39f29|1736422941|1736422941;Path=/");
//Response.Headers.Append("Set-Cookie", "SERVERCORSID=eef797ff9d3671d413582d7dc2f39f29|1736422941|1736422941;Path=/;SameSite=None;Secure");
// Return no content since the body is written manually
//// Set binary content as the response body
//string filePath = "E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\options_response"; // Replace with the actual file path
//byte[] fileBytes = System.IO.File.ReadAllBytes(filePath);
//// Write bytes directly to response body
//Response.Body.WriteAsync(fileBytes, 0, fileBytes.Length);
//// Return no content since the body is written manually
return new EmptyResult();
}

View File

@@ -3,118 +3,147 @@ using System.Reflection;
using Google.Protobuf;
using Google.Protobuf.Reflection;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Newtonsoft.Json;
using Novaria.Common.Crypto;
using Novaria.Common.Utils;
using Pb;
using Novaria.Common.Core;
using Proto;
using Serilog;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using Microsoft.AspNetCore.Http;
using System.IO;
using NSec.Cryptography;
using static System.Runtime.InteropServices.JavaScript.JSType;
namespace Novaria.SDKServer
{
public class SDKServer
{
//public Packet ParseIkeMessage(byte[] encryptedRawPayload)
//{
//}
public static void Main(string[] args)
{
var protos = FileDescriptorSet.Parser.ParseFrom(PB.ProtoPB);
var tables = FileDescriptorSet.Parser.ParseFrom(PB.TablePB);
var tempDatas = FileDescriptorSet.Parser.ParseFrom(PB.RogueLikeTempDataPB);
//byte[] result = new byte[] { 72, 115, 142, 228, 125, 80, 99, 136, 69, 104, 100, 1, 40, 52, 96, 130, 76, 79, 164, 172, 151, 94, 234, 141, 235, 198, 110, 211, 218, 213, 155, 111, 64, 170, 181, 53, 117, 77, 234, 162, 247, 154, 219, 157, 50, 59, 84, 148, 165, 122, 236, 76, 15, 134, 140, 229, 224, 105, 90, 2, 226, 240, 240, 16, 6, 209, 29, 11, 52, 224, 26, 174, 113, 114, 54, 169, 108, 63, 53, 170, 94, 142, 153, 65, 192, 116, 145, 127, 107, 137, 193, 141, 203, 149, 9, 188, 91, 78, 191, 117, 145, 14, 105, 108, 203, 106, 161, 97, 133, 123, 132, 205, 151, 184, 240, 165 };
//byte[] key = new byte[] { 51, 76, 83, 57, 38, 111, 89, 100, 115, 112, 94, 53, 119, 105, 56, 38, 90, 120, 67, 35, 99, 55, 77, 90, 103, 55, 51, 104, 98, 69, 68, 119 };
//byte[] nonce = new byte[] { 50, 103, 122, 81, 54, 57, 80, 109, 55, 49, 86, 55 };
//byte[] data = new byte[] { 0, 1, 10, 96, 30, 72, 185, 252, 24, 18, 102, 148, 64, 6, 58, 221, 16, 109, 243, 95, 183, 216, 77, 49, 124, 134, 97, 3, 136, 61, 184, 215, 41, 126, 194, 60, 133, 13, 82, 220, 41, 147, 27, 174, 137, 10, 6, 222, 251, 18, 201, 192, 53, 249, 223, 27, 67, 209, 125, 129, 139, 32, 32, 225, 233, 158, 23, 191, 187, 238, 129, 226, 180, 85, 152, 50, 137, 33, 65, 129, 225, 180, 154, 172, 39, 177, 136, 36, 141, 168, 43, 144, 155, 99, 85, 21, 213, 194, 139, 112 };
foreach (var fileDescriptorProto in protos.File)
{
Console.WriteLine(fileDescriptorProto.ToString());
//Utils.SaveFileDescriptorProtoToFile(fileDescriptorProto, "protos");
}
//byte[] real_result = new byte[result.Length];
//byte[] decrypted_result = new byte[data.Length];
foreach (var fileDescriptorProto in tables.File)
{
//Utils.SaveFileDescriptorProtoToFile(fileDescriptorProto, "tables");
}
//AeadTool.Encrypt_ChaCha20(real_result, key.AsSpan(), nonce.AsSpan(), data.AsSpan(), true);
//Console.WriteLine();
//Console.WriteLine();
foreach (var fileDescriptorProto in tempDatas.File)
{
//Utils.SaveFileDescriptorProtoToFile(fileDescriptorProto, "temp_datas");
}
//Utils.PrintByteArray(result);
//Console.WriteLine();
//Console.WriteLine();
//Utils.PrintByteArray(real_result);
//byte[] associateData = new byte[13];
Span<byte> ss = new byte[]
{
0, 5, 10, 134, 1, 68, 109, 47, 77, 102, 110, 116, 78, 49, 107, 78,
97, 83, 47, 49, 79, 110, 121, 51, 86, 82, 76, 100, 90, 67, 69, 113,
47, 71, 47, 70, 81, 112, 83, 86, 65, 114, 48, 81, 112, 101, 107, 104,
104, 106, 83, 69, 48, 51, 73, 121, 107, 108, 65, 102, 65, 84, 112, 83,
56, 85, 80, 76, 107, 76, 103, 48, 80, 119, 116, 80, 48, 67, 78, 86,
43, 76, 85, 103, 98, 51, 75, 97, 79, 111, 56, 89, 115, 106, 68, 66,
86, 77, 51, 47, 65, 83, 108, 80, 77, 109, 56, 68, 50, 111, 119, 108,
71, 119, 106, 81, 83, 71, 105, 54, 106, 79, 97, 102, 99, 49, 122, 84,
98, 107, 89, 81, 121, 76, 43, 56, 121, 90, 103
};
//nonce.CopyTo(associateData, 0);
//associateData[associateData.Length - 1] = 1;
Span<byte> result = new byte[ss.Length];
//bool succ = AeadTool.Dencrypt_ChaCha20(decrypted_result.AsSpan(), key.AsSpan(), nonce.AsSpan(), result.AsSpan(), associateData.AsSpan());
ReadOnlySpan<byte> key = new byte[]
{
21, 218, 151, 4, 236, 175, 191, 183, 193, 244, 248, 163, 11, 144, 99, 164,
138, 121, 155, 96, 50, 149, 206, 111, 180, 143, 229, 65, 219, 192, 118, 47
};
ReadOnlySpan<byte> nonce = new byte[]
{
231, 71, 160, 150, 98, 120, 185, 234, 18, 80, 239, 227
};
ReadOnlySpan<byte> data = new byte[]
{
18, 191, 220, 69, 194, 61, 223, 106, 190, 177, 23, 221, 204, 255, 80, 97,
197, 131, 41, 185, 42, 139, 225, 133, 223, 140, 11, 43, 152, 78, 4, 163,
87, 50, 33, 61, 168, 219, 213, 188, 78, 115, 60, 143, 185, 165, 3, 62,
154, 34, 156, 61, 175, 105, 25, 129, 254, 143, 225, 107, 211, 9, 201, 7,
10, 85, 115, 115, 131, 209, 20, 48, 124, 149, 33, 52, 204, 166, 154, 207,
206, 28, 76, 249, 48, 191, 249, 11, 236, 193, 49, 216, 226, 101, 52, 234,
73, 79, 154, 226, 141, 9, 70, 194, 252, 202, 65, 168, 247, 161, 228, 84,
246, 133, 84, 64, 64, 252, 55, 44, 5, 164, 143, 110, 140, 232, 125, 91,
244, 62, 170, 18, 0, 212, 72, 235, 250, 85, 143, 89, 26, 162, 186, 243,
4, 222, 193, 249, 215, 243, 155, 204, 88, 131, 145
};
AeadTool.Dencrypt_ChaCha20(result, key, nonce, data);
Utils.PrintByteArray(result.ToArray());
return;
//byte[] bytes = File.ReadAllBytes("E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\req1");
// byte[] data = new byte[] {
// 88, 2, 120, 1, 106, 8, 79, 102, 102, 105, 99, 105, 97, 108,
// 98, 5, 122, 104, 95, 67, 78, 114, 16, 100, 99, 49, 56, 101,
// 49, 50, 98, 57, 54, 50, 57, 101, 57, 52, 101, 26, 48, 18,
// 40, 50, 50, 97, 99, 56, 56, 54, 101, 53, 102, 98, 101, 101,
// 102, 52, 100, 98, 98, 56, 100, 56, 51, 54, 100, 56, 98, 99,
// 98, 49, 54, 54, 54, 56, 100, 98, 55, 99, 97, 55, 100, 8,
// 240, 186, 151, 225, 3
//};
//var a = UserRequest.Parser.ParseFrom(data);
//Console.WriteLine(JsonConvert.SerializeObject(a));
//ServerListMeta message;
//using (var input = File.OpenRead("E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\test_protos.pb"))
//{
// message = ServerListMeta.Parser.ParseFrom(input);
//}
//Console.WriteLine(message.Announcement);
//Console.WriteLine(succ);
//Utils.PrintByteArray(decrypted_result);
//return;
//byte[] ike_req_bytes = new byte[] { 10, 96, 108, 183, 187, 238, 19, 29, 80, 121, 193, 82, 107, 114, 202, 58, 16, 52, 131, 72, 179, 174, 18, 170, 8, 124, 161, 231, 241, 121, 27, 190, 176, 218, 90, 9, 9, 88, 190, 59, 190, 128, 9, 247, 199, 212, 136, 3, 198, 175, 89, 222, 172, 222, 157, 99, 247, 254, 237, 66, 68, 238, 188, 125, 169, 248, 17, 130, 150, 12, 213, 10, 197, 36, 122, 134, 139, 88, 52, 177, 53, 38, 114, 145, 99, 40, 111, 82, 237, 245, 178, 106, 108, 170, 57, 235, 136, 25 };
//byte[] player_login_req_bytes = new byte[] { 106, 8, 79, 102, 102, 105, 99, 105, 97, 108, 26, 48, 8, 240, 186, 151, 225, 3, 18, 40, 50, 50, 97, 99, 56, 56, 54, 101, 53, 102, 98, 101, 101, 102, 52, 100, 98, 98, 56, 100, 56, 51, 54, 100, 56, 98, 99, 98, 49, 54, 54, 54, 56, 100, 98, 55, 99, 97, 55, 100, 98, 5, 122, 104, 95, 67, 78, 120, 1, 114, 16, 100, 99, 49, 56, 101, 49, 50, 98, 57, 54, 50, 57, 101, 57, 52, 101, 88, 2 };
//byte[] bytes = File.ReadAllBytes("E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\req1");
byte[] ike_req_raw_bytes = new byte[] { 50, 103, 122, 81, 54, 57, 80, 109, 55, 49, 86, 55, 1, 72, 115, 142, 228, 125, 80, 99, 136, 69, 104, 100, 1, 40, 52, 96, 130, 76, 79, 164, 172, 151, 94, 234, 141, 235, 198, 110, 211, 218, 213, 155, 111, 64, 170, 181, 53, 117, 77, 234, 162, 247, 154, 219, 157, 50, 59, 84, 148, 165, 122, 236, 76, 15, 134, 140, 229, 224, 105, 90, 2, 226, 240, 240, 16, 6, 209, 29, 11, 52, 224, 26, 174, 113, 114, 54, 169, 108, 63, 53, 170, 94, 142, 153, 65, 192, 116, 145, 127, 107, 137, 193, 141, 203, 149, 9, 188, 91, 78, 191, 117, 145, 14, 105, 108, 203, 106, 161, 97, 133, 123, 132, 205, 151, 184, 240, 165 };
ike_req_raw_bytes = new byte[] { 238, 229, 238, 9, 37, 193, 132, 180, 61, 153, 199, 186, 4, 244, 254, 140, 91, 117, 71, 80, 159, 135, 140, 203, 228, 77, 27, 179, 254, 183, 72, 176, 185, 189, 30, 193, 34, 117, 133, 225, 239, 52, 174, 149, 44, 203, 37, 116, 83, 34, 75, 49, 105, 102, 145, 145, 115, 125, 172, 100, 65, 173, 57, 198, 79, 9, 134, 169, 31, 138, 51, 247, 255, 85, 206, 195, 234, 144, 11, 167, 183, 159, 116, 21, 251, 193, 223, 68, 116, 202, 26, 223, 20, 101, 176, 136, 156, 88, 127, 113, 169, 34, 76, 180, 3, 157, 201, 127, 241, 46, 61, 56, 25, 18, 187, 103, 34, 64, 7, 115, 227, 135, 159, 149, 199, 166, 11, 119, 122, 225, 23, 134, 5, 63, 21, 182, 106, 94, 200, 13, 63, 231, 212, 51, 255, 81, 237, 238, 4, 156, 94, 149, 215, 120, 81, 14, 191, 209, 237, 139, 209, 238, 130, 202, 51, 63, 238, 214, 68, 109, 114, 108, 191, 208, 255, 32, 171, 246, 208, 139, 6, 223, 0, 120, 1, 104, 44, 82, 72, 129, 181, 237, 8, 213, 196, 193, 87, 114, 247, 12, 12, 218, 159, 182, 248, 63, 22, 207, 124, 217, 93, 121, 0, 49, 49, 237, 167, 215, 85, 173, 89, 152, 81, 151, 134, 240, 142, 208, 89, 9, 103, 243, 130, 221, 142, 44, 141, 64, 254, 215, 116, 155, 127, 32, 108, 178, 226 };
//ike_req_raw_bytes = File.ReadAllBytes("E:\\documents\\Decompiling\\Extracted\\NOVA\\Novaria\\Novaria.SDKServer\\options_req");
Console.WriteLine(ike_req_raw_bytes.Length);
bool flag = false;
//byte[] result = AeadTool.DecryptAesCBCInfo(AeadTool.DEFAULT_SERVERLIST_KEY, bytes[..16], bytes[16..(((int)(bytes.Length / 16)) * 16)]);
Utils.PrintByteArray(ike_req_raw_bytes);
BinaryReader reader = new BinaryReader(new MemoryStream(ike_req_raw_bytes));
byte[] nonceBytes = new byte[12];
reader.Read(nonceBytes);
byte[] aheadmarkBytes = new byte[1];
int payloadSize = ike_req_raw_bytes.Length - nonceBytes.Length;
if (flag)
{
reader.Read(aheadmarkBytes);
payloadSize--;
}
byte[] packetBytes = new byte[payloadSize];
reader.Read(packetBytes);
if (reader.BaseStream.Position != ike_req_raw_bytes.Length)
{
Console.WriteLine("something went wrong, not all the bytes were read");
Console.WriteLine("reader pos: " + reader.BaseStream.Position);
Console.WriteLine("original len:" + ike_req_raw_bytes.Length);
}
Span<byte> decrypt_result = new Span<byte>(new byte[payloadSize - 16]);
Span<byte> nonce = nonceBytes.AsSpan();
Span<byte> packet_data = packetBytes.AsSpan();
Console.WriteLine($"Nonce[{nonce.Length}]");
Utils.PrintByteArray(nonce.ToArray());
Console.WriteLine($"packet_data[{packet_data.Length}]: ");
Utils.PrintByteArray(packet_data.ToArray());
Console.WriteLine($"key[{AeadTool.FIRST_IKE_KEY.Length}]: ");
Utils.PrintByteArray(AeadTool.FIRST_IKE_KEY.ToArray());
Console.WriteLine($"Decrypted bytes[{decrypt_result.Length}]: ");
byte[] associateData = new byte[13];
nonceBytes.CopyTo(associateData, 0);
associateData[associateData.Length - 1] = 1;
bool success = AeadTool.Dencrypt_ChaCha20(decrypt_result, AeadTool.FIRST_IKE_KEY, nonce, packet_data, null);
Console.WriteLine("sucess: " + success);
Utils.PrintByteArray(decrypt_result.ToArray());
byte[] decrypted_bytes = decrypt_result.ToArray();
Utils.PrintByteArray(decrypted_bytes);
byte[] msgid_bytes = decrypted_bytes[..2];
Array.Reverse<byte>(msgid_bytes);
short msgId = BitConverter.ToInt16(msgid_bytes);
Packet packet = new Packet()
{
msgId = msgId,
msgBody = decrypted_bytes[2..],
};
Console.WriteLine("msgid: " + msgId);
Console.WriteLine("msgBody length: " + packet.msgBody.Length);
var packetObj = IKEResp.Parser.ParseFrom(packet.msgBody);
//var ikereq = IKEReq.Parser.ParseFrom(ike_req_bytes);
//var loginreq = LoginReq.Parser.ParseFrom(player_login_req_bytes);
Console.WriteLine(JsonSerializer.Serialize(packetObj));
////Utils.PrintByteArray(result);
//string resstr = System.Text.Encoding.UTF8.GetString(result);
//Console.WriteLine(resstr); // Output: "Hello"
Log.Information("Starting SDK Server...");
try
{

View File

@@ -0,0 +1,3 @@
<EFBFBD><EFBFBD>d<EFBFBD>
'<27><1A>!<21>15L<35>M<EFBFBD>m<EFBFBD>P<EFBFBD><50><0F>}n1<6E><31>b
<EFBFBD>&<26><08><><EFBFBD><EFBFBD>u<g<>Ui<55>OP1C<31><43><EFBFBD><EFBFBD>#<23><1D> Ht<48><0E> <20><>EZ<15>j<EFBFBD>MlZ<6C>B<EFBFBD>{<13>m<EFBFBD>tKY'V<>d<EFBFBD><64>?<3F><>ߨ<EFBFBD><DFA8>Lf<4C><66>:`W<>