add more power

master
兔子 5 months ago
parent c7d94d8f95
commit 23e4443cf4

@ -18,7 +18,7 @@ func init() {
} }
var nattestc NatTesterClient var nattestc NatTesterClient
var nettests NatTesterServer var nattests NatTesterServer
var natc NatClient var natc NatClient
var nats NatServer var nats NatServer
@ -61,6 +61,13 @@ func init() {
CmdNatClient.Flags().IntVarP(&nattestc.Timeout, "timeout", "t", 2, "超时时间") CmdNatClient.Flags().IntVarP(&nattestc.Timeout, "timeout", "t", 2, "超时时间")
CmdNatClient.Flags().StringSliceVarP(&nattestc.dns, "dns", "d", nil, "自定义dns服务器") CmdNatClient.Flags().StringSliceVarP(&nattestc.dns, "dns", "d", nil, "自定义dns服务器")
Cmd.AddCommand(CmdNatClient) 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{ var CmdNatPClient = &cobra.Command{
@ -86,8 +93,8 @@ var CmdNatPServer = &cobra.Command{
var CmdNatClient = &cobra.Command{ var CmdNatClient = &cobra.Command{
Use: "natc", Use: "natc",
Short: "nat类型测试工具", Short: "nat类型测试工具 - 客户端",
Long: "基于RFC3489的nat类型测试工具", Long: "基于RFC3489的nat类型测试工具(客户端)",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
if nattestc.dns != nil { if nattestc.dns != nil {
UseCustomeDNS(nattestc.dns) 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{ var CmdNetTrace = &cobra.Command{
Use: "trace", Use: "trace",
Short: "网络路径追踪", Short: "网络路径追踪",

@ -113,31 +113,12 @@ func (n *NatTesterServer) Analyse(c *net.UDPConn, r *net.UDPAddr, cmds []string)
case "startnat1": case "startnat1":
n.alt.WriteToUDP([]byte("stage1"), r) 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()) 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": case "startnat2":
n.mainb.WriteToUDP([]byte("stage2"), r) 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()) 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": case "startnat3":
n.maina.WriteToUDP([]byte("stage3"), r) 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()) 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 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/starlog"
"b612.me/starnet" "b612.me/starnet"
"crypto/elliptic" "crypto/elliptic"
"encoding/json" "encoding/csv"
"fmt" "fmt"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"golang.org/x/crypto/ssh" "golang.org/x/crypto/ssh"
@ -13,15 +13,17 @@ import (
"os" "os"
"os/signal" "os/signal"
"strings" "strings"
"time"
) )
var ( var (
listenAddr string listenAddr string
keyFile string keyFile string
KeyPasswd string KeyPasswd string
outpath string outpath string
curlUrl string curlUrl string
curlArg []string serverVersion string
curlArg []string
) )
func init() { func init() {
@ -29,6 +31,7 @@ func init() {
cmdSSHJar.Flags().StringVarP(&keyFile, "key", "k", "", "私钥文件") cmdSSHJar.Flags().StringVarP(&keyFile, "key", "k", "", "私钥文件")
cmdSSHJar.Flags().StringVarP(&KeyPasswd, "passwd", "p", "", "私钥密码") cmdSSHJar.Flags().StringVarP(&KeyPasswd, "passwd", "p", "", "私钥密码")
cmdSSHJar.Flags().StringVarP(&outpath, "output", "o", "", "输出文件") cmdSSHJar.Flags().StringVarP(&outpath, "output", "o", "", "输出文件")
cmdSSHJar.Flags().StringVarP(&serverVersion, "version", "v", "OpenSSH", "SSH版本")
} }
var cmdSSHJar = &cobra.Command{ var cmdSSHJar = &cobra.Command{
@ -36,11 +39,11 @@ var cmdSSHJar = &cobra.Command{
Short: "SSH蜜罐", Short: "SSH蜜罐",
Long: "SSH蜜罐", Long: "SSH蜜罐",
Run: func(cmd *cobra.Command, args []string) { 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 f *os.File
var err error var err error
if outpath != "" { if outpath != "" {
@ -50,16 +53,17 @@ func runSSHHoneyJar(listenAddr, keyFile, KeyPasswd, outpath string) {
return return
} }
} }
conn := csv.NewWriter(f)
defer f.Close() defer f.Close()
defer conn.Flush()
config := &ssh.ServerConfig{ config := &ssh.ServerConfig{
ServerVersion: version,
// 密码验证回调函数 // 密码验证回调函数
PasswordCallback: func(c ssh.ConnMetadata, pass []byte) (*ssh.Permissions, error) { 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)) 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)} data := []string{time.Now().Format("2006-01-02 15:04:05"), c.RemoteAddr().String(), c.User(), string(pass)}
bts, _ := json.Marshal(data)
if f != nil { if f != nil {
f.Write(bts) conn.Write(data)
f.Write([]byte("\n"))
} }
if curlUrl != "" { if curlUrl != "" {
go func() { go func() {

Loading…
Cancel
Save