diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/nu_defines.h | 5 | ||||
-rwxr-xr-x | src/nu_server.c | 41 | ||||
-rwxr-xr-x | src/nu_server.h | 47 |
3 files changed, 78 insertions, 15 deletions
diff --git a/src/nu_defines.h b/src/nu_defines.h index a3d6f29..75c3f2b 100755 --- a/src/nu_defines.h +++ b/src/nu_defines.h | |||
@@ -1,3 +1,6 @@ | |||
1 | #ifndef _NU_DEFINES_H_ | ||
2 | #define _NU_DEFINES_H_ | ||
3 | |||
1 | #define SMB_HEADER_PROTOCOL_MAGIC 0x424d53ff | 4 | #define SMB_HEADER_PROTOCOL_MAGIC 0x424d53ff |
2 | 5 | ||
3 | typedef enum { | 6 | typedef enum { |
@@ -716,3 +719,5 @@ typedef enum { | |||
716 | STATUS_WX86_FLOAT_STACK_CHECK = 0xC0000270, | 719 | STATUS_WX86_FLOAT_STACK_CHECK = 0xC0000270, |
717 | STATUS_WOW_ASSERTION = 0xC0009898 | 720 | STATUS_WOW_ASSERTION = 0xC0009898 |
718 | } SMB_STATUS; | 721 | } SMB_STATUS; |
722 | |||
723 | #endif | ||
diff --git a/src/nu_server.c b/src/nu_server.c index d1bb46a..186c2d7 100755 --- a/src/nu_server.c +++ b/src/nu_server.c | |||
@@ -1,13 +1,5 @@ | |||
1 | #include <time.h> | ||
2 | #include <fcntl.h> | ||
3 | #include <signal.h> | ||
4 | #include <sys/types.h> | ||
5 | #include <sys/socket.h> | ||
6 | #include <netinet/in.h> | ||
7 | #include <stdio.h> | ||
8 | #include <sys/ioctl.h> | ||
9 | |||
10 | #include "nu_server.h" | 1 | #include "nu_server.h" |
2 | #include "nu_lanman.h" | ||
11 | 3 | ||
12 | static void bailout( char *reason ); | 4 | static void bailout( char *reason ); |
13 | static void sigint( int reason ) { bailout( "User interrupt." ); } | 5 | static void sigint( int reason ) { bailout( "User interrupt." ); } |
@@ -89,7 +81,7 @@ static SMB_STATUS handle_SMB_COM_SESSION_SETUP_ANDX( SMB_HEADER *header, SMB_DAT | |||
89 | return STATUS_SUCCESS; | 81 | return STATUS_SUCCESS; |
90 | } | 82 | } |
91 | 83 | ||
92 | static const BYTE SMB_COM_TREE_CONNECT_ANDX_bytes[] = { 8, 0, 'I', 'P', 'C', 0, 'I', 'P', 'C', 0 }; | 84 | static const BYTE SMB_COM_TREE_CONNECT_ANDX_bytes[] = { 9, 0, 'A', ':', 0, 'F', 'A', 'T', '3', '2', 0 }; |
93 | static BYTE SMB_COM_TREE_CONNECT_ANDX_params[] = { 3, 255, 0, 0, 0, 0, 0 }; | 85 | static BYTE SMB_COM_TREE_CONNECT_ANDX_params[] = { 3, 255, 0, 0, 0, 0, 0 }; |
94 | 86 | ||
95 | static SMB_STATUS handle_SMB_COM_TREE_CONNECT_ANDX( SMB_HEADER *header, SMB_DATA *data ){ | 87 | static SMB_STATUS handle_SMB_COM_TREE_CONNECT_ANDX( SMB_HEADER *header, SMB_DATA *data ){ |
@@ -99,11 +91,30 @@ static SMB_STATUS handle_SMB_COM_TREE_CONNECT_ANDX( SMB_HEADER *header, SMB_DATA | |||
99 | return STATUS_SUCCESS; | 91 | return STATUS_SUCCESS; |
100 | } | 92 | } |
101 | 93 | ||
94 | static SMB_STATUS handle_SMB_COM_TRANSACTION( SMB_HEADER *header, SMB_DATA *data ) { | ||
95 | if( !strcmp( (char*)&data->bytes[1], "\\PIPE\\LANMAN")) | ||
96 | { | ||
97 | /* TODO: Sanity Check on DataCount vs. ByteCount */ | ||
98 | SMB_PARAMS_TRANSACTION *params = (SMB_PARAMS_TRANSACTION *)data->params; | ||
99 | SMB_TRANSACTION_BYTES bytes; | ||
100 | |||
101 | bytes.params = ((BYTE*)&header->Protocol) + GETNWORD( params->ParameterOffset ); | ||
102 | bytes.paramc = GETNWORD( params->ParameterCount ); | ||
103 | bytes.data = ((BYTE*)&header->Protocol) + GETNWORD( params->DataOffset ); | ||
104 | bytes.datac = GETNWORD( params->DataCount ); | ||
105 | |||
106 | return handle_LANMAN( header, data, &bytes ); | ||
107 | } | ||
108 | else | ||
109 | return 0x00400002; | ||
110 | } | ||
111 | |||
102 | static int command_handler_match(const void *a, const void *b ) { return *(BYTE*)a - *(BYTE*)b; } | 112 | static int command_handler_match(const void *a, const void *b ) { return *(BYTE*)a - *(BYTE*)b; } |
103 | 113 | ||
104 | /* If you add command handlers, please insert them in the right position, | 114 | /* If you add command handlers, please insert them in the right position, |
105 | this list is sorted by command, for later bsearch*/ | 115 | this list is sorted by command, for later bsearch*/ |
106 | static SMB_COMMAND_HANDLER command_handler[] = { | 116 | static SMB_COMMAND_HANDLER command_handler[] = { |
117 | { SMB_COM_TRANSACTION, 0x00, handle_SMB_COM_TRANSACTION }, | ||
107 | { SMB_COM_NEGOTIATE, 0x00, handle_SMB_COM_NEGOTIATE }, | 118 | { SMB_COM_NEGOTIATE, 0x00, handle_SMB_COM_NEGOTIATE }, |
108 | { SMB_COM_SESSION_SETUP_ANDX, 0x01, handle_SMB_COM_SESSION_SETUP_ANDX }, | 119 | { SMB_COM_SESSION_SETUP_ANDX, 0x01, handle_SMB_COM_SESSION_SETUP_ANDX }, |
109 | { SMB_COM_TREE_CONNECT_ANDX, 0x01, handle_SMB_COM_TREE_CONNECT_ANDX } | 120 | { SMB_COM_TREE_CONNECT_ANDX, 0x01, handle_SMB_COM_TREE_CONNECT_ANDX } |
@@ -126,6 +137,7 @@ static void child( ) { | |||
126 | SMB_COMMAND cmd; | 137 | SMB_COMMAND cmd; |
127 | SMB_DATA requests[ 1 + SMB_MAXREQUESTS ]; | 138 | SMB_DATA requests[ 1 + SMB_MAXREQUESTS ]; |
128 | SMB_STATUS status = STATUS_SUCCESS; | 139 | SMB_STATUS status = STATUS_SUCCESS; |
140 | DWORD null = 0; | ||
129 | WORD sizeout = sizeof( SMB_HEADER ) - 4; | 141 | WORD sizeout = sizeof( SMB_HEADER ) - 4; |
130 | int num_requests = 0; | 142 | int num_requests = 0; |
131 | 143 | ||
@@ -144,7 +156,7 @@ static void child( ) { | |||
144 | sizeof(command_handler)/sizeof(*command_handler), sizeof(*command_handler), command_handler_match); | 156 | sizeof(command_handler)/sizeof(*command_handler), sizeof(*command_handler), command_handler_match); |
145 | 157 | ||
146 | requests[ num_requests ].bytes = | 158 | requests[ num_requests ].bytes = |
147 | (SMB_BYTES*)(((BYTE*)requests[ num_requests ].params) + *((BYTE*)(requests[ num_requests ].params)) + 2); | 159 | (SMB_BYTES*)(((BYTE*)requests[ num_requests ].params) + 2 * *((BYTE*)(requests[ num_requests ].params)) + 1); |
148 | 160 | ||
149 | if( handler ) { | 161 | if( handler ) { |
150 | if( handler->flags & SMB_COMMAND_FLAG_ANDX ) { | 162 | if( handler->flags & SMB_COMMAND_FLAG_ANDX ) { |
@@ -163,13 +175,14 @@ static void child( ) { | |||
163 | ((BYTE*)requests[ num_requests ].params)[4] = sizeout >> 8; | 175 | ((BYTE*)requests[ num_requests ].params)[4] = sizeout >> 8; |
164 | } else | 176 | } else |
165 | cmd = 0xff; | 177 | cmd = 0xff; |
166 | 178 | } else { /* no handler - return STATUS_UKCOMMAND*/ | |
167 | num_requests++; | ||
168 | } else { | ||
169 | if( num_requests ) | 179 | if( num_requests ) |
170 | ((BYTE*)requests[ num_requests-1 ].params)[1] = 0xff; | 180 | ((BYTE*)requests[ num_requests-1 ].params)[1] = 0xff; |
181 | requests[ num_requests ].params = (SMB_PARAMS*)&null; | ||
182 | requests[ num_requests ].bytes = (SMB_BYTES*) &null; | ||
171 | status = 0x00400002; | 183 | status = 0x00400002; |
172 | } | 184 | } |
185 | num_requests++; | ||
173 | } | 186 | } |
174 | 187 | ||
175 | memcpy( inpacket->Status, &status, 4 ); /* not aligned, maybe we might do a store DWORD on x86 */ | 188 | memcpy( inpacket->Status, &status, 4 ); /* not aligned, maybe we might do a store DWORD on x86 */ |
diff --git a/src/nu_server.h b/src/nu_server.h index 4d6abaa..89fe2e9 100755 --- a/src/nu_server.h +++ b/src/nu_server.h | |||
@@ -1,8 +1,23 @@ | |||
1 | #ifndef _NU_SERVER_H_ | ||
2 | #define _NU_SERVER_H_ | ||
3 | |||
4 | #include <time.h> | ||
5 | #include <fcntl.h> | ||
6 | #include <signal.h> | ||
7 | #include <sys/types.h> | ||
8 | #include <sys/socket.h> | ||
9 | #include <netinet/in.h> | ||
10 | #include <stdio.h> | ||
11 | #include <sys/ioctl.h> | ||
12 | |||
1 | typedef unsigned char BYTE; | 13 | typedef unsigned char BYTE; |
2 | typedef unsigned short WORD; | 14 | typedef unsigned short WORD; |
3 | typedef unsigned long DWORD; | 15 | typedef unsigned long DWORD; |
4 | typedef int64_t QWORD; | 16 | typedef int64_t QWORD; |
5 | 17 | ||
18 | #define SKIPSTRING( str ) ((BYTE*)(str)) + 1 + strlen( (str) ) | ||
19 | #define GETNWORD(addr) (*((BYTE*)(addr)) | 256 * ((BYTE*)(addr))[1] ) | ||
20 | |||
6 | #include "nu_defines.h" | 21 | #include "nu_defines.h" |
7 | #define SMB_MAXREQUESTS 16 | 22 | #define SMB_MAXREQUESTS 16 |
8 | 23 | ||
@@ -34,11 +49,41 @@ typedef struct { | |||
34 | 49 | ||
35 | typedef struct { | 50 | typedef struct { |
36 | SMB_PARAMS *params; | 51 | SMB_PARAMS *params; |
37 | SMB_BYTES *bytes; | 52 | SMB_BYTES *bytes; |
38 | } SMB_DATA; | 53 | } SMB_DATA; |
39 | 54 | ||
40 | typedef struct { | 55 | typedef struct { |
56 | BYTE WordCount; /* 19 + SetupCount */ | ||
57 | BYTE TotalParameterCount [2]; | ||
58 | BYTE TotalDataCount [2]; | ||
59 | BYTE MaxParameterCount [2]; /* For now we only support packets */ | ||
60 | BYTE MaxDataCount [2]; /* with TotalXXCount == MaxXXCount */ | ||
61 | BYTE MaxSetupCount; | ||
62 | BYTE Reserved; | ||
63 | BYTE Flags [2]; | ||
64 | BYTE Timeout [4]; | ||
65 | BYTE Reserved2 [2]; | ||
66 | |||
67 | BYTE ParameterCount [2]; | ||
68 | BYTE ParameterOffset [2]; | ||
69 | BYTE DataCount [2]; | ||
70 | BYTE DataOffset [2]; | ||
71 | BYTE SetupCount; | ||
72 | BYTE Reserved3; | ||
73 | BYTE Setup[0]; | ||
74 | } SMB_PARAMS_TRANSACTION; | ||
75 | |||
76 | typedef struct { | ||
77 | BYTE *params; | ||
78 | DWORD paramc; | ||
79 | BYTE *data; | ||
80 | DWORD datac; | ||
81 | } SMB_TRANSACTION_BYTES; | ||
82 | |||
83 | typedef struct { | ||
41 | BYTE cmd; | 84 | BYTE cmd; |
42 | SMB_COMMAND_FLAG flags; | 85 | SMB_COMMAND_FLAG flags; |
43 | SMB_STATUS (*handler)(SMB_HEADER *header, SMB_DATA *data); | 86 | SMB_STATUS (*handler)(SMB_HEADER *header, SMB_DATA *data); |
44 | } SMB_COMMAND_HANDLER; | 87 | } SMB_COMMAND_HANDLER; |
88 | |||
89 | #endif | ||