-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathRandom.c
82 lines (68 loc) · 1.36 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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*!
*
* MINBEACON
*
* GuidePoint Security LLC
*
* Threat and Attack Simulation Team
*
!*/
#include "Common.h"
NTSTATUS
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:
*
* Creates a random UINT32 integer
*
!*/
D_SEC( B ) UINT32 RandomInt32( VOID )
{
API Api;
UINT32 Val = 0;
/* Zero out stack structures */
RtlSecureZeroMemory( &Api, sizeof( Api ) );
/* Build Stack API Table */
Api.RtlRandomEx = PeGetFuncEat( PebGetModule( H_LIB_NTDLL ), H_API_RTLRANDOMEX );
/* Get Random Value */
Val = NtGetTickCount();
Val = Api.RtlRandomEx( &Val );
Val = Api.RtlRandomEx( &Val );
/* Zero out stack structures */
RtlSecureZeroMemory( &Api, sizeof( Api ) );
/* Return Integer */
return Val;
};
/*!
*
* Purpose:
*
* Fills a buffer with a random string of the
* specified size.
*
!*/
D_SEC( B ) VOID RandomString( _In_ PVOID Buffer, _In_ UINT32 Length )
{
PCHAR Chr = C_PTR( G_PTR( "ABCDEFGHIJKLMNOPQRSTUVWXYZ" ) );
PCHAR Buf = C_PTR( Buffer );
UINT32 Val = 0;
/* Go through each individual character */
for ( INT Idx = 0 ; Idx < Length ; ++Idx ) {
/* Get a random value */
Val = RandomInt32( ) % 26;
/* Set character */
Buf[ Idx ] = Chr[ Val ];
};
};