MCPcopy Create free account
hub / github.com/chainreactors/EvilProxy / sessionREPL

Function sessionREPL

cmd/inject-cli/main.go:442–567  ·  view source on GitHub ↗
(c *apiClient, sess *SessionDetail)

Source from the content-addressed store, hash-verified

440}
441
442func sessionREPL(c *apiClient, sess *SessionDetail) {
443 agentName := sess.UserAgent
444 if idx := strings.Index(agentName, " "); idx > 0 {
445 agentName = agentName[:idx]
446 }
447 if idx := strings.Index(agentName, "/"); idx > 0 {
448 agentName = agentName[:idx]
449 }
450 if len(agentName) > 15 {
451 agentName = agentName[:12] + "..."
452 }
453
454 prompt := fmt.Sprintf("\033[36m[%s %s]\033[0m$ ", sess.ID, agentName)
455
456 rl, err := readline.NewEx(&readline.Config{
457 Prompt: prompt,
458 AutoComplete: sessionCompleter(),
459 InterruptPrompt: "^C",
460 EOFPrompt: "exit",
461 })
462 if err != nil {
463 fmt.Printf(" readline init failed: %v\n", err)
464 return
465 }
466 defer rl.Close()
467
468 // WebSocket for result streaming.
469 wsURI := c.wsURL(sess.ID)
470 header := http.Header{}
471 if c.secret != "" {
472 header.Set("Authorization", "Bearer "+c.secret)
473 }
474 conn, _, wsErr := websocket.DefaultDialer.Dial(wsURI, header)
475 if wsErr != nil {
476 fmt.Printf(" ws connect failed: %v (results won't stream)\n", wsErr)
477 conn = nil
478 }
479
480 var wsDone chan struct{}
481 var resultMu sync.Mutex
482 var latestResult *CommandResult
483
484 if conn != nil {
485 defer conn.Close()
486 wsDone = make(chan struct{})
487 go func() {
488 defer close(wsDone)
489 for {
490 var result CommandResult
491 if err := conn.ReadJSON(&result); err != nil {
492 return
493 }
494 resultMu.Lock()
495 latestResult = &result
496 resultMu.Unlock()
497 fmt.Printf("\n%s\n", result.Output)
498 rl.Refresh()
499 }

Callers 1

cmdUseFunction · 0.85

Calls 11

sessionCompleterFunction · 0.85
showSessionToolsFunction · 0.85
showSessionInfoFunction · 0.85
cmdObserveFunction · 0.85
wsURLMethod · 0.80
DialMethod · 0.80
execCommandMethod · 0.80
CloseMethod · 0.65
RefreshMethod · 0.65
StopMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected