• XSS.stack #1 – первый литературный журнал от юзеров форума

compile time exemple

user

HDD-drive
Пользователь
Регистрация
26.08.2019
Сообщения
36
Реакции
9
C++:
#include <stdio.h>
#include <stdint.h>

__declspec(noinline) void exampleRandom1();
__declspec(noinline) void exampleRandom2();
__declspec(noinline) void exampleHashing();
__declspec(noinline) void exampleEncryption();

#define vxCPLSEED ((__TIME__[7] - '0') * 1  + (__TIME__[6] - '0') * 10  + (__TIME__[4] - '0') * 60   + (__TIME__[3] - '0') * 600 + (__TIME__[1] - '0') * 3600 + (__TIME__[0] - '0') * 36000)

template <uint32_t Const> struct vxCplConstantify { enum { Value = Const }; };

constexpr uint32_t vxCplRandom(uint32_t Id)
{
    return (1013904223 + 1664525 * ((Id > 0) ? (vxCplRandom(Id - 1)) : (vxCPLSEED))) & 0xFFFFFFFF;
}

#define vxRANDOM(Min, Max) (Min + (vxRAND() % (Max - Min + 1)))
#define vxRAND()           (vxCplConstantify<vxCplRandom(__COUNTER__ + 1)>::Value)

constexpr char   vxCplTolower(char Ch) { return (Ch >= 'A' && Ch <= 'Z') ? (Ch - 'A' + 'a') : (Ch); }
constexpr uint32_t vxCplHashPart3(char Ch, uint32_t Hash) { return ((Hash << 4) + vxCplTolower(Ch)); }
constexpr uint32_t vxCplHashPart2(char Ch, uint32_t Hash) { return (vxCplHashPart3(Ch, Hash) ^ ((vxCplHashPart3(Ch, Hash) & 0xF0000000) >> 23)); }
constexpr uint32_t vxCplHashPart1(char Ch, uint32_t Hash) { return (vxCplHashPart2(Ch, Hash) & 0x0FFFFFFF); }
constexpr uint32_t vxCplHash(const char* Str) { return (*Str) ? (vxCplHashPart1(*Str, vxCplHash(Str + 1))) : (0); }

#define vxHASH(Str) (uint32_t)(vxCplConstantify<vxCplHash(Str)>::Value ^ vxCplConstantify<vxCplRandom(1)>::Value)

template <uint32_t...> struct vxCplIndexList {};
template <typename   IndexList, uint32_t Right> struct vxCplAppend;
template <uint32_t... Left, uint32_t Right> struct vxCplAppend<vxCplIndexList<Left...>, Right> { typedef vxCplIndexList<Left..., Right> Result; };
template <uint32_t N> struct vxCplIndexes { typedef typename vxCplAppend<typename vxCplIndexes<N - 1>::Result, N - 1>::Result Result; };
template <> struct vxCplIndexes<0> { typedef vxCplIndexList<> Result; };

const char vxCplEncryptCharKey = vxRANDOM(0, 0xFF);
constexpr char vxCplEncryptChar(const char Ch, uint32_t Idx) { return Ch ^ (vxCplEncryptCharKey + Idx); }

template <typename IndexList> struct vxCplEncryptedString;
template <uint32_t... Idx>    struct vxCplEncryptedString<vxCplIndexList<Idx...> >
{
    char Value[sizeof...(Idx) + 1];

    constexpr inline vxCplEncryptedString(const char* const Str): Value { vxCplEncryptChar(Str[Idx], Idx)... }
    {
    }

    char* decrypt()
    {
        for (uint32_t t = 0; t < sizeof...(Idx); t++)
        {
            this->Value[t] = this->Value[t] ^ (vxCplEncryptCharKey + t);
        }
        this->Value[sizeof...(Idx)] = '\0'; return this->Value;
    }
};

#define vxENCRYPT(Str) (vxCplEncryptedString<vxCplIndexes<sizeof(Str) - 1>::Result>(Str).decrypt())

void exampleRandom1()
{
    switch (vxRANDOM(1, 4))
    {
    case 1: { printf("exampleRandom1: Code path 1!\n"); break; }
    case 2: { printf("exampleRandom1: Code path 2!\n"); break; }
    case 3: { printf("exampleRandom1: Code path 3!\n"); break; }
    case 4: { printf("exampleRandom1: Code path 4!\n"); break; }
    default: { printf("Fucking poltergeist!\n"); }
    }
}

void exampleRandom2()
{
    volatile uint32_t RndVal = vxRANDOM(0, 100);
    if (vxRAND() % 2) { RndVal += vxRANDOM(0, 100); }
    else { RndVal -= vxRANDOM(0, 200); }
    printf("exampleRandom2: %d\n", RndVal);
}

void exampleHashing()
{
    printf("exampleHashing: 0x%08X\n", vxHASH("hello world!"));
    printf("exampleHashing: 0x%08X\n", vxHASH("HELLO WORLD!"));
}

void exampleEncryption()
{
    printf("exampleEncryption: %s\n", vxENCRYPT("Hello world!"));
}

int main()
{
    exampleRandom1();
    exampleRandom2();
    exampleHashing();
    exampleEncryption();

}

Код:
exampleRandom1: Code path 2!
exampleRandom2: 145
exampleHashing: 0x2D13947A
exampleHashing: 0x2D13947A
exampleEncryption: Hello world!

Код:
exampleRandom1 proc near
    var_18= dword ptr -18h
   push ebp
   mov   ebp, esp
   sub   esp, 18h
   mov   [esp+18h+var_18], offset aExamplerandom1 ; "exampleRandom1: Code path 2!"
   call puts
   leave
   retn
exampleRandom1 endp
 
exampleRandom2 proc near
   var_28= dword ptr -28h
   var_24= dword ptr -24h
   var_C= dword ptr -0Ch
   push ebp
   mov   ebp, esp
   sub   esp, 28h
   mov   [ebp+var_C], 78
   mov   eax, [ebp+var_C]
   mov   [esp+28h+var_28], offset aExamplerandom2 ; "exampleRandom2: %d\n"
   add   eax, 67
   mov   [ebp+var_C], eax
   mov   eax, [ebp+var_C]
   mov   [esp+28h+var_24], eax
   call printf
   leave
   retn
exampleRandom2 endp
 
exampleHashing proc near
   var_18= dword ptr -18h
   var_14= dword ptr -14h
   push ebp
   mov   ebp, esp
   sub   esp, 18h
   mov   [esp+18h+var_14], 2D13947Ah
   mov   [esp+18h+var_18], offset aExamplehashing ; "exampleHashing: 0x%08X\n"
   call printf
   mov   [esp+18h+var_14], 2D13947Ah
   mov   [esp+18h+var_18], offset aExamplehashing ; "exampleHashing: 0x%08X\n"
   call printf
   leave
   retn
exampleHashing endp
 
exampleEncryption proc near
   var_28= dword ptr -28h
   var_24= dword ptr -24h
   var_15= byte ptr -15h
   var_14= byte ptr -14h
   var_13= byte ptr -13h
   var_12= byte ptr -12h
   var_11= byte ptr -11h
   var_10= byte ptr -10h
   var_F= byte ptr -0Fh
   var_E= byte ptr -0Eh
   var_D= byte ptr -0Dh
   var_C= byte ptr -0Ch
   var_B= byte ptr -0Bh
   var_A= byte ptr -0Ah
   var_9= byte ptr -9
   push ebp
   xor   eax, eax
   mov   ebp, esp
   mov   ecx, 0Dh
   push edi
   lea   edi, [ebp+var_15]
   sub   esp, 24h
   rep stosb
   xor   eax, eax
   mov   [ebp+var_15], 4Ah
   mov   [ebp+var_14], 66h
   mov   [ebp+var_13], 68h
   mov   [ebp+var_12], 69h
   mov   [ebp+var_11], 69h
   mov   [ebp+var_10], 27h
   mov   [ebp+var_F], 7Fh
   mov   [ebp+var_E], 66h
   mov   [ebp+var_D], 78h
   mov   [ebp+var_C], 67h
   mov   [ebp+var_B], 68h
   mov   [ebp+var_A], 2Ch
   loc_401045:
   lea   ecx, [eax+2]
   xor   [ebp+eax+var_15], cl
   inc   eax
   cmp   eax, 0Ch
   lea   edx, [ebp+var_15]
   jnz   short loc_401045
   mov   [esp+28h+var_24], edx
   mov   [esp+28h+var_28], offset aExampleencrypt ; "exampleEncryption: %s\n"
   mov   [ebp+var_9], 0
   call printf
   add   esp, 24h
   pop   edi
   pop   ebp
   retn
exampleEncryption endp

в аттаче проЖект под vs2022
 

Вложения

  • compile time.zip
    4.6 КБ · Просмотры: 6
Пожалуйста, обратите внимание, что пользователь заблокирован
Интересно, кто бы мог быть автором этого говнокода лет 9 назад, ума не приложу: http://www.rohitab.com/discuss/topic/39611-malware-related-compile-time-hacks-with-c11/ но тут у нас уже была более современная статья по этой теме. И то, что комменты с шапки пропали - это тоже печально.
 
Интересно, кто бы мог быть автором этого говнокода лет 9 назад, ума не приложу: http://www.rohitab.com/discuss/topic/39611-malware-related-compile-time-hacks-with-c11/ но тут у нас уже была более современная статья по этой теме. И то, что комменты с шапки пропали - это тоже печально.
хз кто автор валяется на диске давно, коментарии присутствуют в проекте
 
Пожалуйста, обратите внимание, что пользователь заблокирован
хз кто автор валяется на диске давно
Автор выше ответил
 


Напишите ответ...
  • Вставить:
Прикрепить файлы
Верх