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

Function cmdObserve

cmd/inject-cli/main.go:861–906  ·  view source on GitHub ↗

----- observe command -----

(c *apiClient, sessionID string)

Source from the content-addressed store, hash-verified

859// ----- observe command -----
860
861func cmdObserve(c *apiClient, sessionID string) {
862 sess, err := c.getSession(sessionID)
863 if err != nil {
864 fmt.Printf(" error: %v\n", err)
865 return
866 }
867
868 wsURI := c.observeWsURL(sessionID)
869 header := http.Header{}
870 if c.secret != "" {
871 header.Set("Authorization", "Bearer "+c.secret)
872 }
873 conn, _, wsErr := websocket.DefaultDialer.Dial(wsURI, header)
874 if wsErr != nil {
875 fmt.Printf(" ws connect failed: %v\n", wsErr)
876 return
877 }
878 defer conn.Close()
879
880 agentName, _ := formatAgent(sess.UserAgent)
881 fmt.Printf("\n \033[35mObserving\033[0m session \033[36m%s\033[0m (%s) — press Ctrl+C to stop\n\n", sessionID, agentName)
882
883 // Use a signal channel so Ctrl+C stops observe without killing the process.
884 sigCh := make(chan os.Signal, 1)
885 signal.Notify(sigCh, os.Interrupt)
886 defer signal.Stop(sigCh)
887
888 done := make(chan struct{})
889 go func() {
890 defer close(done)
891 for {
892 var event ObserveEvent
893 if err := conn.ReadJSON(&event); err != nil {
894 return
895 }
896 printObserveEvent(&event)
897 }
898 }()
899
900 select {
901 case <-sigCh:
902 fmt.Println("\n (stopped observing)")
903 case <-done:
904 fmt.Println("\n (observe connection closed)")
905 }
906}
907
908func printObserveEvent(event *ObserveEvent) {
909 ts := event.Timestamp.Format("15:04:05")

Callers 2

sessionREPLFunction · 0.85
mainFunction · 0.85

Calls 8

formatAgentFunction · 0.85
printObserveEventFunction · 0.85
getSessionMethod · 0.80
observeWsURLMethod · 0.80
DialMethod · 0.80
CloseMethod · 0.65
StopMethod · 0.65
SetMethod · 0.45

Tested by

no test coverage detected