github.com/iDigitalFlame/xmt@v0.5.4/c2/c2_test.go (about) 1 //go:build !implant 2 // +build !implant 3 4 // Copyright (C) 2020 - 2023 iDigitalFlame 5 // 6 // This program is free software: you can redistribute it and/or modify 7 // it under the terms of the GNU General Public License as published by 8 // the Free Software Foundation, either version 3 of the License, or 9 // any later version. 10 // 11 // This program is distributed in the hope that it will be useful, 12 // but WITHOUT ANY WARRANTY; without even the implied warranty of 13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 // GNU General Public License for more details. 15 // 16 // You should have received a copy of the GNU General Public License 17 // along with this program. If not, see <https://www.gnu.org/licenses/>. 18 // 19 20 package c2 21 22 import ( 23 "testing" 24 25 "github.com/PurpleSec/logx" 26 "github.com/iDigitalFlame/xmt/c2/cfg" 27 "github.com/iDigitalFlame/xmt/c2/task" 28 "github.com/iDigitalFlame/xmt/com" 29 ) 30 31 func TestC2(t *testing.T) { 32 s := NewServer(logx.NOP) 33 s.New = func(x *Session) { 34 t.Logf("TestC2(): New Session %s connected!", x.ID) 35 j, err := x.Task(task.Whoami()) 36 if err != nil { 37 t.Fatalf("TestC2(): %s Job creation for failed: %s!", x.ID, err.Error()) 38 } 39 j.Update = func(z *Job) { 40 if z.Status == StatusError { 41 t.Fatalf("TestC2(): %s Job ID %d returned an error: %s!", x.ID, z.ID, z.Error) 42 } 43 t.Logf("TestC2(): %s Job ID %d returned!", x.ID, j.ID) 44 } 45 t.Logf("TestC2(): %s Job ID %d created!", x.ID, j.ID) 46 } 47 48 c1, err := s.Listen("test1_tcp", "localhost:9091", cfg.Static{L: com.TCP}) 49 if err != nil { 50 t.Fatalf("TestC2(): Listen test1_tcp failed with an error: %s!", err.Error()) 51 } 52 c2, err := s.Listen("test2_tcp", "localhost:9092", cfg.Static{L: com.TCP}) 53 if err != nil { 54 t.Fatalf("TestC2(): Listen test1_udp failed with an error: %s!", err.Error()) 55 } 56 57 for _, v := range s.Sessions() { 58 v.Close() 59 } 60 61 c1.Close() 62 c2.Close() 63 }