MCPcopy
hub / github.com/ph4ntonn/Stowaway / SoReusePassive

Function SoReusePassive

agent/initial/method.go:274–373  ·  view source on GitHub ↗

soreuse port functions

(userOptions *Options)

Source from the content-addressed store, hash-verified

272
273// soreuse port functions
274func SoReusePassive(userOptions *Options) (net.Conn, string) {
275 listenAddr := fmt.Sprintf("%s:%s", userOptions.ReuseHost, userOptions.ReusePort)
276
277 listener, err := reuseport.Listen("tcp", listenAddr)
278 if err != nil {
279 log.Fatalf("[*] Error occurred: %s", err.Error())
280 }
281
282 defer func() {
283 listener.Close()
284 }()
285
286 var sMessage, rMessage protocol.Message
287
288 hiMess := &protocol.HIMess{
289 GreetingLen: uint16(len("Keep slient")),
290 Greeting: "Keep slient",
291 UUIDLen: uint16(len(protocol.TEMP_UUID)),
292 UUID: protocol.TEMP_UUID,
293 IsAdmin: 0,
294 IsReconnect: 0,
295 }
296
297 header := &protocol.Header{
298 Sender: protocol.TEMP_UUID,
299 Accepter: protocol.ADMIN_UUID,
300 MessageType: protocol.HI,
301 RouteLen: uint32(len([]byte(protocol.TEMP_ROUTE))),
302 Route: protocol.TEMP_ROUTE,
303 }
304
305 for {
306 conn, err := listener.Accept()
307
308 if err != nil {
309 conn.Close()
310 continue
311 }
312
313 defer conn.SetReadDeadline(time.Time{})
314 conn.SetReadDeadline(time.Now().Add(2 * time.Second))
315
316 buffer := make([]byte, 16)
317 count, err := io.ReadFull(conn, buffer)
318
319 if err != nil {
320 if timeoutErr, ok := err.(net.Error); ok && timeoutErr.Timeout() {
321 go ProxyStream(conn, buffer[:count], userOptions.ReusePort)
322 continue
323 } else {
324 conn.Close()
325 continue
326 }
327 }
328
329 if string(buffer[:count]) == share.AuthToken {
330 conn.Write([]byte(share.AuthToken))
331 } else {

Callers 1

mainFunction · 0.92

Calls 9

SendMessageMethod · 0.95
NewServerTLSConfigFunction · 0.92
WrapTLSServerConnFunction · 0.92
DestructMessageFunction · 0.92
ConstructMessageFunction · 0.92
ProxyStreamFunction · 0.85
achieveUUIDFunction · 0.85

Tested by

no test coverage detected