forked from SolomonSklash/netntlm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pipe.c
85 lines (76 loc) · 1.73 KB
/
pipe.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
83
84
85
/**
*
* Captures incoming Net-NTLMv1/v2 hashes
* for incoming authentication attempts
* via NTLM.
*
* GuidePoint Security LLC
* Threat and Attack Simulation
*
**/
#include "common.h"
/**
*
* @brief: Create a named pipe server.
*
* @param: API table.
* @param: PIpe name.
*
**/
D_SEC( E ) HANDLE PipeInit( _In_ PAPI Api, _In_ PCHAR Name )
{
return Api->CreateNamedPipeA( Name,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
1,
1024 * 1024, /* Extend to 1MB? */
1024 * 1024, /* Extend to 1MB? */
0,
NULL );
};
/**
*
* @brief: Waits for a connection from a client.
*
* @param: Pointer to API structure.
* @param: Pointer to a pipe handle.
*
**/
D_SEC( E ) BOOL PipeWait( _In_ PAPI Api, _In_ HANDLE Pipe )
{
if ( ! Api->ConnectNamedPipe( Pipe, NULL ) ) {
if ( NtCurrentTeb()->LastErrorValue != STATUS_PIPE_CONNECTED ) {
return FALSE;
};
};
return TRUE;
};
/**
*
* @brief: Creates a printf formatted message over a pipe.
*
* @param: Pointer to API structure.
* @param: Pointer to a pipe handle.
* @param: Format string.
* @param: Arguments.
*
**/
D_SEC( E ) BOOL PipePrint( _In_ PAPI Api, _In_ HANDLE Pipe, _In_ PCHAR Format, ... )
{
INT Len = 0;
ULONG Wrt = 0;
BOOL Ret = FALSE;
PVOID Str = NULL;
va_list Lst = NULL;
va_start( Lst, Format );
Len = Api->vsnprintf( NULL, 0, Format, Lst );
va_end( Lst );
if ( ( Str = Api->VirtualAlloc( NULL, Len + 1, MEM_COMMIT | MEM_RESERVE, PAGE_READWRITE ) ) != NULL ) {
va_start( Lst, Format );
Api->vsnprintf( Str, Len, Format, Lst );
va_end( Lst );
Ret = Api->WriteFile( Pipe, Str, Len + 1, &Wrt, NULL );
Api->VirtualFree( Str, 0, MEM_RELEASE );
};
return Ret;
};