add more power

master
兔子 5 months ago
parent c7d94d8f95
commit 23e4443cf4

@ -18,7 +18,7 @@ func init() {
}
var nattestc NatTesterClient
var nettests NatTesterServer
var nattests NatTesterServer
var natc NatClient
var nats NatServer
@ -61,6 +61,13 @@ func init() {
CmdNatClient.Flags().IntVarP(&nattestc.Timeout, "timeout", "t", 2, "超时时间")
CmdNatClient.Flags().StringSliceVarP(&nattestc.dns, "dns", "d", nil, "自定义dns服务器")
Cmd.AddCommand(CmdNatClient)
CmdNatServer.Flags().StringVarP(&nattests.MainIP, "main-ip", "m", "10.0.0.5", "主IP")
CmdNatServer.Flags().StringVarP(&nattests.AltIP, "alt-ip", "a", "10.0.0.2", "备用IP")
CmdNatServer.Flags().StringVarP(&nattests.MainPort, "main-port", "M", "41127", "主端口")
CmdNatServer.Flags().StringVarP(&nattests.AltPort, "alt-port", "A", "46610", "备用端口")
CmdNatServer.Flags().StringVarP(&nattests.LogPath, "log", "l", "", "日志文件")
Cmd.AddCommand(CmdNatServer)
}
var CmdNatPClient = &cobra.Command{
@ -86,8 +93,8 @@ var CmdNatPServer = &cobra.Command{
var CmdNatClient = &cobra.Command{
Use: "natc",
Short: "nat类型测试工具",
Long: "基于RFC3489的nat类型测试工具",
Short: "nat类型测试工具 - 客户端",
Long: "基于RFC3489的nat类型测试工具(客户端)",
Run: func(cmd *cobra.Command, args []string) {
if nattestc.dns != nil {
UseCustomeDNS(nattestc.dns)
@ -112,6 +119,15 @@ var CmdNatClient = &cobra.Command{
},
}
var CmdNatServer = &cobra.Command{
Use: "nats",
Short: "nat类型测试工具 - 服务端",
Long: "基于RFC3489的nat类型测试工具服务端",
Run: func(cmd *cobra.Command, args []string) {
nattests.Run()
},
}
var CmdNetTrace = &cobra.Command{
Use: "trace",
Short: "网络路径追踪",

@ -113,31 +113,12 @@ func (n *NatTesterServer) Analyse(c *net.UDPConn, r *net.UDPAddr, cmds []string)
case "startnat1":
n.alt.WriteToUDP([]byte("stage1"), r)
starlog.Infof("Start NAT1 Test from %s,Recv Local:%s Send Local:%s\n", r.String(), c.LocalAddr().String(), n.alt.LocalAddr().String())
case "stage1recv":
n.maina.WriteToUDP([]byte("result::nat1"), r)
starlog.Infof("Recv NAT1 Test from %s,Recv Local:%s Send Local:%s\n", r.String(), c.LocalAddr().String(), n.maina.LocalAddr().String())
case "startnat2":
n.mainb.WriteToUDP([]byte("stage2"), r)
starlog.Infof("Start NAT2 Test from %s,Recv Local:%s Send Local:%s\n", r.String(), c.LocalAddr().String(), n.mainb.LocalAddr().String())
case "stage2recv":
n.maina.WriteToUDP([]byte("result::nat2"), r)
starlog.Infof("Recv NAT2 Test from %s,Recv Local:%s Send Local:%s\n", r.String(), c.LocalAddr().String(), n.maina.LocalAddr().String())
case "startnat3":
n.maina.WriteToUDP([]byte("stage3"), r)
starlog.Infof("Start NAT3 Test from %s,Recv Local:%s Send Local:%s\n", r.String(), c.LocalAddr().String(), n.maina.LocalAddr().String())
case "stage3recv":
n.maina.WriteToUDP([]byte("result::nat3"), r)
starlog.Infof("Recv NAT3 Test from %s,Recv Local:%s Send Local:%s\n", r.String(), c.LocalAddr().String(), n.maina.LocalAddr().String())
}
return nil
}
func main() {
server := NatTesterServer{
MainIP: "10.0.0.5",
AltIP: "10.0.0.2",
MainPort: "41127",
AltPort: "46610",
}
fmt.Println(server.Run())
}

@ -5,7 +5,7 @@ import (
"b612.me/starlog"
"b612.me/starnet"
"crypto/elliptic"
"encoding/json"
"encoding/csv"
"fmt"
"github.com/spf13/cobra"
"golang.org/x/crypto/ssh"
@ -13,6 +13,7 @@ import (
"os"
"os/signal"
"strings"
"time"
)
var (
@ -21,6 +22,7 @@ var (
KeyPasswd string
outpath string
curlUrl string
serverVersion string
curlArg []string
)
@ -29,6 +31,7 @@ func init() {
cmdSSHJar.Flags().StringVarP(&keyFile, "key", "k", "", "私钥文件")
cmdSSHJar.Flags().StringVarP(&KeyPasswd, "passwd", "p", "", "私钥密码")
cmdSSHJar.Flags().StringVarP(&outpath, "output", "o", "", "输出文件")
cmdSSHJar.Flags().StringVarP(&serverVersion, "version", "v", "OpenSSH", "SSH版本")
}
var cmdSSHJar = &cobra.Command{
@ -36,11 +39,11 @@ var cmdSSHJar = &cobra.Command{
Short: "SSH蜜罐",
Long: "SSH蜜罐",
Run: func(cmd *cobra.Command, args []string) {
runSSHHoneyJar(listenAddr, keyFile, KeyPasswd, outpath)
runSSHHoneyJar(listenAddr, keyFile, KeyPasswd, outpath, serverVersion)
},
}
func runSSHHoneyJar(listenAddr, keyFile, KeyPasswd, outpath string) {
func runSSHHoneyJar(listenAddr, keyFile, KeyPasswd, outpath, version string) {
var f *os.File
var err error
if outpath != "" {
@ -50,16 +53,17 @@ func runSSHHoneyJar(listenAddr, keyFile, KeyPasswd, outpath string) {
return
}
}
conn := csv.NewWriter(f)
defer f.Close()
defer conn.Flush()
config := &ssh.ServerConfig{
ServerVersion: version,
// 密码验证回调函数
PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) {
starlog.Infof("Login attempt from %s with %s %s\n", c.RemoteAddr(), c.User(), string(pass))
data := []string{c.RemoteAddr().String(), c.User(), string(pass)}
bts, _ := json.Marshal(data)
data := []string{time.Now().Format("2006-01-02 15:04:05"), c.RemoteAddr().String(), c.User(), string(pass)}
if f != nil {
f.Write(bts)
f.Write([]byte("\n"))
conn.Write(data)
}
if curlUrl != "" {
go func() {

Loading…
Cancel
Save