forked from klezVirus/titanldr-ng
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRandom.c
66 lines (54 loc) · 1.15 KB
/
Random.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
*
* Reflective Loader
*
* GuidePoint Security LLC
*
* Threat and Attack Simulation
*
**/
#include "Common.h"
/* Definition */
ULONG
NTAPI
RtlRandomEx(
_In_ PUINT32 Seed
);
typedef struct
{
D_API( RtlRandomEx );
} API ;
/* API Hashes */
#define H_API_RTLRANDOMEX 0x7f1224f5 /* RtlRandomEx */
/* LIB Hashes */
#define H_LIB_NTDLL 0x1edab0ed /* ntdll.dll */
/*!
*
* Purpose:
*
* Returns a random string of the specified
* length.
*
!*/
D_SEC( E ) VOID RandomString( _In_ PCHAR Buffer, _In_ UINT32 Length )
{
API Api;
PCHAR Alp = C_PTR( G_SYM( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) );
UINT32 Val = 0;
/* Zero out stack structures */
RtlSecureZeroMemory( &Api, sizeof( Api ) );
/* Init API */
Api.RtlRandomEx = PeGetFuncEat( PebGetModule( H_LIB_NTDLL ), H_API_RTLRANDOMEX );
/* Create buffer to hold the random string */
for ( INT Idx = 0 ; Idx < Length ; ++Idx ) {
/* Generate random index */
Val = NtGetTickCount();
Val = Api.RtlRandomEx( &Val );
Val = Api.RtlRandomEx( &Val );
Val = Val % 26;
/* Set character */
Buffer[ Idx ] = Alp[ Val ];
};
/* Zero out stack structures */
RtlSecureZeroMemory( &Api, sizeof( Api ) );
};