github.com/iDigitalFlame/xmt@v0.5.4/c2/u_proxy_none.go (about)

     1  //go:build noproxy
     2  // +build noproxy
     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  	"github.com/iDigitalFlame/xmt/c2/cfg"
    24  	"github.com/iDigitalFlame/xmt/com"
    25  	"github.com/iDigitalFlame/xmt/data"
    26  	"github.com/iDigitalFlame/xmt/util/xerr"
    27  )
    28  
    29  // Proxy is a struct that controls a Proxied connection between a client and a
    30  // server and allows for packets to be routed through a current established
    31  // Session.
    32  type Proxy struct{}
    33  type proxyBase struct{}
    34  
    35  // Close stops the operation of the Proxy and any Sessions that may be connected.
    36  //
    37  // Resources used with this Proxy will be freed up for reuse.
    38  func (Proxy) Close() error {
    39  	return nil
    40  }
    41  func (proxyBase) Close() error {
    42  	return nil
    43  }
    44  func (proxyBase) subsRegister() {}
    45  func (proxyBase) tags() []uint32 {
    46  	return nil
    47  }
    48  func (proxyBase) IsActive() bool {
    49  	return false
    50  }
    51  
    52  // Proxy returns the current Proxy (if enabled). This function take a name
    53  // argument that is a string that specifies the Proxy name.
    54  //
    55  // By default, the name is ignored as multiproxy support is disabled.
    56  //
    57  // When proxy support is disabled, this always returns nil.
    58  func (*Session) Proxy(_ string) *Proxy {
    59  	return nil
    60  }
    61  func (*Session) checkProxyMarshal() bool {
    62  	return true
    63  }
    64  func (proxyBase) accept(_ *com.Packet) bool {
    65  	return false
    66  }
    67  
    68  // Replace allows for rebinding this Proxy to another address or using another
    69  // Profile without closing the Proxy.
    70  //
    71  // The listening socket will be closed and the Proxy will be paused and
    72  // cannot accept any more connections before being reopened.
    73  //
    74  // If the replacement fails, the Proxy will be closed.
    75  func (Proxy) Replace(_ string, _ cfg.Profile) error {
    76  	return xerr.Sub("proxy support disabled", 0x53)
    77  }
    78  func (*Session) writeProxyData(_ bool, w data.Writer) error {
    79  	return w.WriteUint8(0)
    80  }
    81  func readProxyData(f bool, r data.Reader) ([]proxyData, error) {
    82  	n, err := r.Uint8()
    83  	if err != nil {
    84  		return nil, err
    85  	}
    86  	for i := uint8(0); i < n; i++ {
    87  		if _, err = r.Bytes(); err != nil {
    88  			return nil, err
    89  		}
    90  		if _, err = r.Bytes(); err != nil {
    91  			return nil, err
    92  		}
    93  		if !f {
    94  			continue
    95  		}
    96  		if _, err = r.Bytes(); err != nil {
    97  			return nil, err
    98  		}
    99  	}
   100  	return nil, nil
   101  }
   102  
   103  // NewProxy establishes a new listening Proxy connection using the supplied Profile
   104  // name and bind address that will send any received Packets "upstream" via the
   105  // current Session.
   106  //
   107  // Packets destined for hosts connected to this proxy will be routed back and
   108  // forth on this Session.
   109  //
   110  // This function will return an error if this is not a client Session or
   111  // listening fails.
   112  func (*Session) NewProxy(_, _ string, _ cfg.Profile) (*Proxy, error) {
   113  	return nil, xerr.Sub("proxy support disabled", 0x53)
   114  }