ajout du vieux main comme bait
This commit is contained in:
parent
fcba3b1a6f
commit
5378e7ad26
3 changed files with 218 additions and 134 deletions
|
|
@ -1,160 +1,240 @@
|
|||
#include "stdafx.h"
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#pragma clang diagnostic ignored "-Wwritable-strings"
|
||||
#include "stdafx.h" // IWYU pragma: keep
|
||||
#include "functions.h"
|
||||
#include "lonesha256.h"
|
||||
#include "tables_poly.h"
|
||||
#include "tables_poly.h"
|
||||
#include "encryption.h"
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#ifdef _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
/* ==============================================================================
|
||||
* MATHÉMATIQUES SUR LE CORPS DE GALOIS GF(2^8)
|
||||
* Polynôme irréductible standard (AES) : x^8 + x^4 + x^3 + x + 1 (0x1B)
|
||||
* ============================================================================== */
|
||||
* ==============================================================================
|
||||
*/
|
||||
|
||||
// Multiplication dans GF(256) : a * b mod 0x1B
|
||||
uint8_t gf_mul(uint8_t a, uint8_t b) {
|
||||
uint8_t p = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (b & 1) p ^= a;
|
||||
uint8_t hi_bit = a & 0x80;
|
||||
a <<= 1;
|
||||
if (hi_bit) a ^= 0x1B;
|
||||
b >>= 1;
|
||||
}
|
||||
return p;
|
||||
uint8_t p = 0;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (b & 1)
|
||||
p ^= a;
|
||||
uint8_t hi_bit = a & 0x80;
|
||||
a <<= 1;
|
||||
if (hi_bit)
|
||||
a ^= 0x1B;
|
||||
b >>= 1;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
// Évaluation d'un polynôme de degré 7 sur GF(256)
|
||||
uint8_t evaluate_polynomial(uint8_t x, const uint8_t coeffs[8]) {
|
||||
uint8_t result = 0;
|
||||
uint8_t x_pow = 1;
|
||||
for (int j = 0; j < 8; j++) {
|
||||
result ^= gf_mul(coeffs[j], x_pow);
|
||||
x_pow = gf_mul(x_pow, x);
|
||||
uint8_t result = 0;
|
||||
uint8_t x_pow = 1;
|
||||
for (int j = 0; j < 8; j++) {
|
||||
result ^= gf_mul(coeffs[j], x_pow);
|
||||
x_pow = gf_mul(x_pow, x);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
char *(*p1)();
|
||||
int (*p2)(char *decoded);
|
||||
} FuncList;
|
||||
|
||||
char *this_is_useful_fr_dont_miss_it() { // it's not, pure red herring
|
||||
char *useful = (char *)malloc(sizeof(char) * 100);
|
||||
for (int i = 0; i < 99; i++) {
|
||||
useful[i] ^= useful[i + 1] + 'c';
|
||||
}
|
||||
return useful;
|
||||
}
|
||||
|
||||
int cmp_hash(char *decoded) {
|
||||
unsigned char hash[32] = {0xf4, 0xed, 0x2a, 0x38, 0xd2, 0xff, 0xcc, 0x38,
|
||||
0xbc, 0x63, 0x28, 0x46, 0xaf, 0xe2, 0x4f, 0x34,
|
||||
0x2d, 0xd8, 0xb8, 0x5e, 0x74, 0xbd, 0x73, 0x99,
|
||||
0x2d, 0x91, 0x56, 0x24, 0xb4, 0x73, 0x5d, 0xee};
|
||||
unsigned char hash_computed[32];
|
||||
lonesha256(hash_computed, (unsigned char *)decoded, sizeof(char) * 57);
|
||||
for (int i = 0; i < 32; i++) {
|
||||
if (hash[i] != hash_computed[i]) {
|
||||
return hash[i] - hash_computed[i];
|
||||
}
|
||||
return result;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Fake main
|
||||
int fakemain(int argc, wchar_t *argv[]) {
|
||||
Obfuscated_stdFunclist *stdfunclist = new Obfuscated_stdFunclist();
|
||||
|
||||
FuncList list = {this_is_useful_fr_dont_miss_it, cmp_hash};
|
||||
// char* encoded = "Salut a tous les amis, gg pour avoir dechiffre ce string";
|
||||
char *encoded = "\x64\x55\x56\x41\x43\x14\x56\x13\x46\x5b\x47\x40\x14\x5e\x52"
|
||||
"\x47\x13\x56\x5e\x5d\x40\x1f\x13\x53\x54\x14\x42\x5b\x41\x40"
|
||||
"\x13\x53\x47\x58\x5d\x46\x14\x53\x51\x54\x5b\x5b\x52\x54\x41"
|
||||
"\x51\x12\x54\x51\x13\x44\x47\x46\x5a\x5d\x54";
|
||||
char *key = (char *)malloc(sizeof(char) * 9);
|
||||
for (int i = 0; argv[1][i] != '\0'; ++i) {
|
||||
key[i] = (char)argv[1][i] ^ this_is_useful_fr_dont_miss_it()[i] ^
|
||||
list.p1()[i]; // xors to argv[1][i]
|
||||
}
|
||||
key[8] = '\0';
|
||||
// printf("Key: %s\n", key);
|
||||
encrypt_decrypt(key, encoded);
|
||||
#ifdef _WIN32
|
||||
DWORD old;
|
||||
VirtualProtect(&list.p1, 0x100, PAGE_EXECUTE_READWRITE, &old);
|
||||
#endif
|
||||
if (!list.p2(encoded)) { // cmp_hash
|
||||
stdfunclist->obfusc_printf("%s", encoded);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* ==============================================================================
|
||||
* MOTEUR D'OBFUSCATION BRANCHLESS (POINT-FUNCTION OBFUSCATION)
|
||||
* ============================================================================== */
|
||||
int main(int argc, char* argv[]) {
|
||||
if (argc < 2 || strlen(argv[1]) < 8) {
|
||||
printf("Arguments invalides.\n");
|
||||
return 1;
|
||||
}
|
||||
* ==============================================================================
|
||||
*/
|
||||
int main(int argc, char *argv[]) {
|
||||
if (argc < 2 || strlen(argv[1]) > 8) {
|
||||
printf("Arguments invalides.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
uint8_t input[8];
|
||||
memcpy(input, argv[1], 8);
|
||||
fakemain(argc, (wchar_t**) argv);
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 1. EXPANSION SPATIALE (FORWARD-COMPUTATION)
|
||||
* Objectif : Projeter l'entrée (8 octets) sur un espace pseudo-aléatoire de
|
||||
* 64 octets (512 bits) pour remplir parfaitement un bloc de compression
|
||||
* SHA-256 sans ajout de bits de padding prévisibles.
|
||||
*
|
||||
* Équation de récurrence non-linéaire :
|
||||
* S_{c, i+1} = P_{c, i}(S_{c, i} \oplus x_i)
|
||||
* où:
|
||||
* - c : Index de la chaîne d'évaluation parallèle (de 0 à 7).
|
||||
* - i : Index du caractère de l'entrée en cours de traitement (de 0 à 7).
|
||||
* - S_{c, i} : État interne de la chaîne 'c' à l'étape 'i'.
|
||||
* - x_i : i-ème octet (caractère) de l'entrée fournie.
|
||||
* - P_{c, i} : Polynôme de transition aléatoire sur GF(2^8) spécifique à cette étape.
|
||||
* -------------------------------------------------------------------------- */
|
||||
uint8_t input[8];
|
||||
memcpy(input, argv[1], 8);
|
||||
|
||||
uint8_t super_bloc[64];
|
||||
for (int c = 0; c < 8; c++) {
|
||||
uint8_t state = INITIAL_STATES[c];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// Mélange non-linéaire du caractère d'entrée avec l'état courant
|
||||
state = evaluate_polynomial(state ^ input[i], POLY_COEFFS[c][i]);
|
||||
// Capture de la trace pour former le bloc final
|
||||
super_bloc[c * 8 + i] = state;
|
||||
}
|
||||
}
|
||||
/* --------------------------------------------------------------------------
|
||||
* 1. EXPANSION SPATIALE (FORWARD-COMPUTATION)
|
||||
* Objectif : Projeter l'entrée (8 octets) sur un espace pseudo-aléatoire de
|
||||
* 64 octets (512 bits) pour remplir parfaitement un bloc de compression
|
||||
* SHA-256 sans ajout de bits de padding prévisibles.
|
||||
*
|
||||
* Équation de récurrence non-linéaire :
|
||||
* S_{c, i+1} = P_{c, i}(S_{c, i} \oplus x_i)
|
||||
* où:
|
||||
* - c : Index de la chaîne d'évaluation parallèle (de 0 à 7).
|
||||
* - i : Index du caractère de l'entrée en cours de traitement (de 0 à
|
||||
* 7).
|
||||
* - S_{c, i} : État interne de la chaîne 'c' à l'étape 'i'.
|
||||
* - x_i : i-ème octet (caractère) de l'entrée fournie.
|
||||
* - P_{c, i} : Polynôme de transition aléatoire sur GF(2^8) spécifique à
|
||||
* cette étape.
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 2. VÉRIFICATION D'INTÉGRITÉ (ORACLE ALÉATOIRE)
|
||||
* Calcul de l'empreinte H1 = SHA256(super_bloc)
|
||||
* -------------------------------------------------------------------------- */
|
||||
unsigned char h1[32];
|
||||
lonesha256(h1, super_bloc, 64);
|
||||
|
||||
// Accumulation des erreurs bit-à-bit par rapport à la cible cryptographique
|
||||
// Diff = \bigvee_{k=0}^{31} (H_1[k] ^ H_{cible}[k])
|
||||
uint32_t diff = 0;
|
||||
for (int i = 0; i < 32; i++) {
|
||||
diff |= (h1[i] ^ h_cible[i]);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 3. FILTRE MATHÉMATIQUE "BRANCHLESS" (ZÉRO CONDITION)
|
||||
* Transforme l'erreur accumulée en un masque binaire absolu.
|
||||
* Formule : Mask = ( (Diff | (~Diff + 1)) >> 63 ) - 1
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
uint64_t diff64 = diff;
|
||||
|
||||
// Si diff > 0 (mot de passe faux) -> is_wrong = 1
|
||||
// Si diff == 0 (mot de passe bon) -> is_wrong = 0
|
||||
uint64_t is_wrong = (diff64 | (~diff64 + 1)) >> 63;
|
||||
|
||||
// Si is_wrong == 1 -> Mask = 0x0000000000000000 (Ferme la porte au payload)
|
||||
// Si is_wrong == 0 -> Mask = 0xFFFFFFFFFFFFFFFF (Ouvre la porte au payload)
|
||||
uint64_t mask = is_wrong - 1;
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 4. DÉRIVATION DE LA CLÉ DE LEURRE (COMPORTEMENT GOODWARE)
|
||||
* K_G = SHA256(L)_{[0..7]} où L est une chaîne d'apparence inoffensive.
|
||||
* Permet une indistinguabilité totale lors d'une analyse statique (strings).
|
||||
* -------------------------------------------------------------------------- */
|
||||
unsigned char leurre[] = "Microsoft_CRT_Initialization";
|
||||
unsigned char h_leurre[32];
|
||||
lonesha256(h_leurre, leurre, 28); // K_G correspond aux 8 premiers octets
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 5. SÉPARATION DES DOMAINES (DOMAIN SEPARATION)
|
||||
* Calcul de l'empreinte de dérivation H2.
|
||||
* H_2 = SHA256(super_bloc \parallel \text{"DERIVATION"})
|
||||
* Garantit l'indépendance mathématique entre la vérification (H1) et le déchiffrement (H2).
|
||||
* -------------------------------------------------------------------------- */
|
||||
|
||||
unsigned char buffer_h2[74]; // 64 octets (SB) + 10 octets (Sel)
|
||||
memcpy(buffer_h2, super_bloc, 64);
|
||||
memcpy(buffer_h2 + 64, "DERIVATION", 10);
|
||||
|
||||
unsigned char h2[32];
|
||||
lonesha256(h2, buffer_h2, 74);
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 6. RÉSOLUTION ALGÉBRIQUE ET DÉCHIFFREMENT
|
||||
* Formule maîtresse : K_{finale} = K_G ^ ( (E_\Delta ^ H_2) \ \& \ Mask )
|
||||
* - Si Mask == 0x00 : K_{finale} = K_G ^ 0 = K_G (Goodware)
|
||||
* - Si Mask == 0xFF : K_{finale} = K_G ^ \Delta = K_G ^ (K_M ^ K_G) = K_M (Malware)
|
||||
* -------------------------------------------------------------------------- */
|
||||
unsigned char derived_key[8];
|
||||
uint8_t super_bloc[64];
|
||||
for (int c = 0; c < 8; c++) {
|
||||
uint8_t state = INITIAL_STATES[c];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// Tentative de déchiffrement du secret (\Delta)
|
||||
uint8_t computed_delta = enc_delta[i] ^ h2[i];
|
||||
|
||||
// Application du masque d'annihilation (filtre AND)
|
||||
uint8_t applied_delta = computed_delta & (mask & 0xFF);
|
||||
|
||||
// Recombinaison finale de la clé
|
||||
derived_key[i] = h_leurre[i] ^ applied_delta;
|
||||
|
||||
// Déchiffrement immédiat in-place du payload
|
||||
payload[i] ^= derived_key[i];
|
||||
// Mélange non-linéaire du caractère d'entrée avec l'état courant
|
||||
state = evaluate_polynomial(state ^ input[i], POLY_COEFFS[c][i]);
|
||||
// Capture de la trace pour former le bloc final
|
||||
super_bloc[c * 8 + i] = state;
|
||||
}
|
||||
payload[7] = '\0'; // Protection d'affichage C-String
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 7. EXÉCUTION DU PAYLOAD DÉCHIFFRÉ
|
||||
* -------------------------------------------------------------------------- */
|
||||
printf((char*)payload, argv[1]);
|
||||
/* --------------------------------------------------------------------------
|
||||
* 2. VÉRIFICATION D'INTÉGRITÉ (ORACLE ALÉATOIRE)
|
||||
* Calcul de l'empreinte H1 = SHA256(super_bloc)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
unsigned char h1[32];
|
||||
lonesha256(h1, super_bloc, 64);
|
||||
|
||||
// Boucle infinie demandée pour suspendre le processus
|
||||
while(1){}
|
||||
|
||||
return 0;
|
||||
// Accumulation des erreurs bit-à-bit par rapport à la cible cryptographique
|
||||
// Diff = \bigvee_{k=0}^{31} (H_1[k] ^ H_{cible}[k])
|
||||
uint32_t diff = 0;
|
||||
for (int i = 0; i < 32; i++) {
|
||||
diff |= (h1[i] ^ h_cible[i]);
|
||||
}
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 3. FILTRE MATHÉMATIQUE "BRANCHLESS" (ZÉRO CONDITION)
|
||||
* Transforme l'erreur accumulée en un masque binaire absolu.
|
||||
* Formule : Mask = ( (Diff | (~Diff + 1)) >> 63 ) - 1
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
uint64_t diff64 = diff;
|
||||
|
||||
// Si diff > 0 (mot de passe faux) -> is_wrong = 1
|
||||
// Si diff == 0 (mot de passe bon) -> is_wrong = 0
|
||||
uint64_t is_wrong = (diff64 | (~diff64 + 1)) >> 63;
|
||||
|
||||
// Si is_wrong == 1 -> Mask = 0x0000000000000000 (Ferme la porte au payload)
|
||||
// Si is_wrong == 0 -> Mask = 0xFFFFFFFFFFFFFFFF (Ouvre la porte au payload)
|
||||
uint64_t mask = is_wrong - 1;
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 4. DÉRIVATION DE LA CLÉ DE LEURRE (COMPORTEMENT GOODWARE)
|
||||
* K_G = SHA256(L)_{[0..7]} où L est une chaîne d'apparence inoffensive.
|
||||
* Permet une indistinguabilité totale lors d'une analyse statique (strings).
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
unsigned char leurre[] = "Microsoft_CRT_Initialization";
|
||||
unsigned char h_leurre[32];
|
||||
lonesha256(h_leurre, leurre, 28); // K_G correspond aux 8 premiers octets
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 5. SÉPARATION DES DOMAINES (DOMAIN SEPARATION)
|
||||
* Calcul de l'empreinte de dérivation H2.
|
||||
* H_2 = SHA256(super_bloc \parallel \text{"DERIVATION"})
|
||||
* Garantit l'indépendance mathématique entre la vérification (H1) et le
|
||||
* déchiffrement (H2).
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
unsigned char buffer_h2[74]; // 64 octets (SB) + 10 octets (Sel)
|
||||
memcpy(buffer_h2, super_bloc, 64);
|
||||
memcpy(buffer_h2 + 64, "DERIVATION", 10);
|
||||
|
||||
unsigned char h2[32];
|
||||
lonesha256(h2, buffer_h2, 74);
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 6. RÉSOLUTION ALGÉBRIQUE ET DÉCHIFFREMENT
|
||||
* Formule maîtresse : K_{finale} = K_G ^ ( (E_\Delta ^ H_2) \ \& \ Mask )
|
||||
* - Si Mask == 0x00 : K_{finale} = K_G ^ 0 = K_G (Goodware)
|
||||
* - Si Mask == 0xFF : K_{finale} = K_G ^ \Delta = K_G ^ (K_M ^ K_G) = K_M
|
||||
* (Malware)
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
unsigned char derived_key[8];
|
||||
for (int i = 0; i < 8; i++) {
|
||||
// Tentative de déchiffrement du secret (\Delta)
|
||||
uint8_t computed_delta = enc_delta[i] ^ h2[i];
|
||||
|
||||
// Application du masque d'annihilation (filtre AND)
|
||||
uint8_t applied_delta = computed_delta & (mask & 0xFF);
|
||||
|
||||
// Recombinaison finale de la clé
|
||||
derived_key[i] = h_leurre[i] ^ applied_delta;
|
||||
|
||||
// Déchiffrement immédiat in-place du payload
|
||||
payload[i] ^= derived_key[i];
|
||||
}
|
||||
payload[7] = '\0'; // Protection d'affichage C-String
|
||||
|
||||
/* --------------------------------------------------------------------------
|
||||
* 7. EXÉCUTION DU PAYLOAD DÉCHIFFRÉ
|
||||
* --------------------------------------------------------------------------
|
||||
*/
|
||||
printf((char *)payload, argv[1]);
|
||||
|
||||
// Boucle infinie demandée pour suspendre le processus
|
||||
while (1) {
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -133,6 +133,7 @@
|
|||
<ClInclude Include="functions.h" />
|
||||
<ClInclude Include="lonesha256.h" />
|
||||
<ClInclude Include="stdafx.h" />
|
||||
<ClInclude Include="tables_poly.h" />
|
||||
<ClInclude Include="targetver.h" />
|
||||
<ClInclude Include="tree.h" />
|
||||
</ItemGroup>
|
||||
|
|
|
|||
|
|
@ -36,6 +36,9 @@
|
|||
<ClInclude Include="functions.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="tables_poly.h">
|
||||
<Filter>Fichiers d%27en-tête</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClCompile Include="stdafx.cpp">
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue