| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537 |
- package main
- import (
- "bufio"
- "crypto/rand"
- "encoding/base64"
- "encoding/json"
- "flag"
- "fmt"
- "io"
- "log"
- mathrand "math/rand"
- "os"
- "qianxin-inc.cn/common/utils/encode"
- "strings"
- v2 "sinohorizon.com/scan-probe/pkg/common/types/v2"
- "sinohorizon.com/traffic-analysis-server/pkg/common/types/v1/utils/mixer"
- probetypes "sinohorizon.com/traffic-analysis-server/pkg/common/types/v1/types"
- "sinohorizon.com/traffic-analysis-server/pkg/common/types/v1/utils/decode"
- )
- var clients []string
- var mixStr string
- var auth string
- var getPortsV2Map map[string]string
- func init() {
- var err error
- var basic string
- var res []byte
- mixStr, err = mixer.GetDeMixStr(mixer.Code1)
- basic, err = decode.DecodeCBC(probetypes.BASIC, mixStr)
- if err != nil {
- fmt.Fprintf(os.Stdout, "decode error")
- panic(fmt.Errorf("failed to get auth token"))
- }
- basic = strings.Split(basic, " ")[1]
- //fmt.Println(basic)
- res, err = base64.StdEncoding.DecodeString(basic)
- if err != nil {
- fmt.Fprintf(os.Stdout, "base64 decode error")
- panic(fmt.Errorf("failed to get auth token"))
- }
- auth = string(res)
- //fmt.Println(auth)
- }
- func main(){
- var portsCount int
- var probesCount int
- var matchCount int
- var heartbeatCount int
- flag.IntVar(&portsCount, "ports-count", 0, "")
- flag.IntVar(&probesCount, "probes-count", 0, "")
- flag.IntVar(&matchCount, "match-count", 0, "")
- flag.IntVar(&heartbeatCount, "heartbeat-count", 0, "")
- flag.Parse()
- BuildGetPortsV2Mesg(portsCount)
- BuildGetProbesMesg(probesCount)
- BuildMatchMesg(matchCount)
- BuildHreatBeatMesg(heartbeatCount)
- //DataForPre()
- //BuildBusinessUrl(pppoeCount)
- //BuildClientUrl(clientCount)
- //BuildPocUrl(pocCount)
- }
- func BuildHreatBeatMesg(count int){
- filePath := "./data/heartBeat.txt"
- _, err := os.Create(filePath)
- if err != nil {
- log.Fatal("Create poc file error: ",err.Error())
- return
- }
- file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
- if err != nil {
- log.Fatal("Open poc file error:", err.Error())
- return
- }
- defer func() {
- err = file.Close()
- if err != nil{
- log.Fatal("Close poc file error:", err.Error())
- }
- }()
- writer := bufio.NewWriter(file)
- product_class:="ZNHE600-REALTEK+RTL9600"
- domain_ip:="114.217.26.173"
- cloud_tasktime:="4.416 ms"
- e8ctmp_log:="3.0-0.0.12-1#1624935018#1624935018#57324#0#1#1#10800#10800#1624935018#3720#R4036"
- for i:=1;i<=count;i++{
- //mac:=fmt.Sprintf("%012d",i)
- pppoe:=fmt.Sprintf("test%d",i)
- gateway_mac :=fmt.Sprintf("2%011d",i)
- loid:= fmt.Sprintf("%016d",i)
- data:=fmt.Sprintf("%s|%s|%s|%s|%s|%s|%s|3.0.01|0.0.01",pppoe,gateway_mac,loid,product_class,domain_ip,cloud_tasktime,e8ctmp_log)
- sendDataPre := fmt.Sprintf("%s|||qianxinBasicAuth:qianxinBasicAuth#@!ZXC|||HeartBeat|||00000000000000000001|||%d|||%s", pppoe, len(data), data)
- es, _ := encode.Encrypt(sendDataPre, mixStr)
- //getPortsV2Map[mac]=es
- _, err = writer.WriteString(fmt.Sprintf("%s:%s\n",gateway_mac,es))
- if err != nil {
- continue
- }
- }
- err = writer.Flush()
- if err != nil {
- log.Fatal("Write poc file failed: ",err.Error())
- }
- }
- func BuildMatchMesg(count int){
- filePath := "./data/match.txt"
- _, err := os.Create(filePath)
- if err != nil {
- log.Fatal("Create poc file error: ",err.Error())
- return
- }
- file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
- if err != nil {
- log.Fatal("Open poc file error:", err.Error())
- return
- }
- defer func() {
- err = file.Close()
- if err != nil{
- log.Fatal("Close poc file error:", err.Error())
- }
- }()
- writer := bufio.NewWriter(file)
- req := &v2.Request{}
- target := v2.Target{
- IP: "192.168.16.6",
- Port:23,
- Protocol:"tcp",
- }
- config := v2.Config{
- Rarity:9,
- SendTimeout:1000000000,
- ReadTimeout:1000000000,
- }
- probe := v2.ProbeBase{
- Name:"tn3270",
- Data:"Ly9zWS8vb1lBRWxDVFMwek1qYzVMVFF0UmYvdy8vc1ovLzBaLy9zQS8vMEE=",
- Protocol:"tcp",
- }
- req.Config=config
- req.Target=target
- req.Probe=probe
- req.DeviceAllScanCount=1
- req.DevicePortScanIndex=1
- req.DevicePortAllScanCount=1
- req.DeviceScanIndex=1
- req.ScanID="0012222222222"
- req.Count=1
- req.Index=1
- for i:=1;i<=count;i++{
- mac:=fmt.Sprintf("%012d",i)
- pppoe:=fmt.Sprintf("test%d",i)
- gateway_mac :=fmt.Sprintf("2%011d",i)
- loid:= fmt.Sprintf("%016d",i)
- req.Mac = mac
- req.DevName = "miuyedeMBP"
- req.PPPOEName=pppoe
- req.GatewayMac=gateway_mac
- req.LoID=loid
- data,_:=json.Marshal(req)
- sendDataPre := fmt.Sprintf("%s|||qianxinBasicAuth:qianxinBasicAuth#@!ZXC|||Match|||00000000000000000001|||%d|||%s", pppoe, len(data), data)
- es, _ := encode.Encrypt(sendDataPre, mixStr)
- //getPortsV2Map[mac]=es
- _, err = writer.WriteString(fmt.Sprintf("%s:%s\n",gateway_mac,es))
- if err != nil {
- continue
- }
- }
- err = writer.Flush()
- if err != nil {
- log.Fatal("Write poc file failed: ",err.Error())
- }
- }
- func BuildGetPortsV2Mesg(count int){
- filePath := "./data/getPortsV2.txt"
- _, err := os.Create(filePath)
- if err != nil {
- log.Fatal("Create poc file error: ",err.Error())
- return
- }
- file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
- if err != nil {
- log.Fatal("Open poc file error:", err.Error())
- return
- }
- defer func() {
- err = file.Close()
- if err != nil{
- log.Fatal("Close poc file error:", err.Error())
- }
- }()
- writer := bufio.NewWriter(file)
- req := &v2.Request{}
- for i:=1;i<=count;i++{
- mac:=fmt.Sprintf("%012d",i)
- pppoe:=fmt.Sprintf("test%d",i)
- gateway_mac :=fmt.Sprintf("2%011d",i)
- req.Mac=mac
- req.ScanType="completescan"
- data,_:=json.Marshal(req)
- sendDataPre := fmt.Sprintf("%s|||qianxinBasicAuth:qianxinBasicAuth#@!ZXC|||GetPortsV2|||00000000000000000001|||%d|||%s",pppoe , len(data), data)
- es, _ := encode.Encrypt(sendDataPre, mixStr)
- //getPortsV2Map[mac]=es
- _, err = writer.WriteString(fmt.Sprintf("%s:%s\n",gateway_mac,es))
- if err != nil {
- continue
- }
- }
- err = writer.Flush()
- if err != nil {
- log.Fatal("Write poc file failed: ",err.Error())
- }
- }
- func BuildGetProbesMesg(count int){
- filePath := "./data/getProbes.txt"
- _, err := os.Create(filePath)
- if err != nil {
- log.Fatal("Create poc file error: ",err.Error())
- return
- }
- file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
- if err != nil {
- log.Fatal("Open poc file error:", err.Error())
- return
- }
- defer func() {
- err = file.Close()
- if err != nil{
- log.Fatal("Close poc file error:", err.Error())
- }
- }()
- writer := bufio.NewWriter(file)
- req := &v2.Request{}
- target := v2.Target{
- IP: "192.168.15.1",
- Port:9090,
- Protocol:"udp",
- }
- config := v2.Config{
- Rarity:9,
- SendTimeout:1000000000,
- ReadTimeout:1000000000,
- }
- req.Config=config
- req.Target=target
- req.DeviceAllScanCount=1
- req.DevicePortScanIndex=1
- req.DevicePortAllScanCount=1
- req.DeviceScanIndex=1
- req.ScanID="0012222222222"
- for i:=1;i<=count;i++{
- mac:=fmt.Sprintf("%012d",i)
- pppoe:=fmt.Sprintf("test%d",i)
- gateway_mac :=fmt.Sprintf("2%011d",i)
- loid:= fmt.Sprintf("%016d",i)
- req.Mac = mac
- req.DevName = "miuyedeMBP"
- req.PPPOEName=pppoe
- req.GatewayMac=gateway_mac
- req.LoID=loid
- data,_:=json.Marshal(req)
- sendDataPre := fmt.Sprintf("%s|||qianxinBasicAuth:qianxinBasicAuth#@!ZXC|||GetProbes|||00000000000000000001|||%d|||%s", pppoe, len(data), data)
- es, _ := encode.Encrypt(sendDataPre, mixStr)
- //getPortsV2Map[mac]=es
- _, err = writer.WriteString(fmt.Sprintf("%s:%s\n",gateway_mac,es))
- if err != nil {
- continue
- }
- }
- err = writer.Flush()
- if err != nil {
- log.Fatal("Write poc file failed: ",err.Error())
- }
- }
- func BuildDeviceRecognise(){
- filePath := "./data/recognise.txt"
- _, err := os.Create(filePath)
- if err != nil {
- log.Fatal("Create poc file error: ",err.Error())
- return
- }
- file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
- if err != nil {
- log.Fatal("Open poc file error:", err.Error())
- return
- }
- defer func() {
- err = file.Close()
- if err != nil{
- log.Fatal("Close poc file error:", err.Error())
- }
- }()
- }
- func BuildPocUrl(pocCount int){
- filePath := "./data/poc.txt"
- _, err := os.Create(filePath)
- if err != nil {
- log.Fatal("Create poc file error: ",err.Error())
- return
- }
- file, err := os.OpenFile(filePath, os.O_WRONLY|os.O_CREATE, 0666)
- if err != nil {
- log.Fatal("Open poc file error:", err.Error())
- return
- }
- defer func() {
- err = file.Close()
- if err != nil{
- log.Fatal("Close poc file error:", err.Error())
- }
- }()
- writer := bufio.NewWriter(file)
- buf := make([]byte, 6)
- clientLen := len(clients)
- i := 0
- count := 0
- clientNum := 0
- var mac string
- var url string
- for i < pocCount {
- count ++
- if count > pocCount*2 {
- log.Fatal("Build poc url failed")
- }
- clientNum = mathrand.Intn(clientLen)
- _, err = rand.Read(buf)
- if err != nil {
- fmt.Println("Get mac buf failed: ", err.Error())
- continue
- }
- buf[0] |= 2
- mac=fmt.Sprintf("%02x%02x%02x%02x%02x%02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5])
- url = fmt.Sprintf("https://security-iot.189smarthome.com:9092/api/v2/poc?vendor=%s&version=0.0.01&mac=%s\n",clients[clientNum],strings.ToUpper(mac))
- _, err = writer.WriteString(url)
- if err != nil {
- continue
- }
- i++
- }
- err = writer.Flush()
- if err != nil {
- log.Fatal("Write poc file failed: ",err.Error())
- }
- }
- func BuildBusinessUrl(pppoeCount int){
- var err error
- exists := Exists("./data")
- if exists {
- err = os.RemoveAll("./data")
- if err != nil {
- log.Fatal(" Remove data failed: ", err.Error())
- }
- }
- err = os.Mkdir("./data", os.ModePerm)
- if err != nil {
- log.Fatal(" Mkdir data failed: ", err.Error())
- }
- businessFile := "./data/business.txt"
- _, err = os.Create(businessFile)
- if err != nil {
- log.Fatal("Create business file error: ",err.Error())
- return
- }
- file, err := os.OpenFile(businessFile, os.O_WRONLY|os.O_CREATE, 0666)
- if err != nil {
- log.Fatal("Open business file error:", err.Error())
- return
- }
- defer func() {
- err = file.Close()
- if err != nil{
- log.Fatal("Close business file error:", err.Error())
- }
- }()
- pppoe := 0
- i :=0
- count :=0
- var businessUrl string
- writer := bufio.NewWriter(file)
- for i<pppoeCount{
- count ++
- if count > pppoeCount*2 {
- log.Fatal("Build business url failed")
- }
- pppoe = mathrand.Intn(99999999)
- businessUrl = fmt.Sprintf("https://security-iot.189smarthome.com:9092/api/v2/check_pppoe_business?pppoe=0250%08d\n",pppoe)
- _, err = writer.WriteString(businessUrl)
- if err != nil {
- continue
- }
- i++
- }
- err = writer.Flush()
- if err != nil {
- log.Fatal("Write business file failed: ",err.Error())
- }
- }
- func BuildClientUrl(clientCount int){
- clientFilePath := "./data/client.txt"
- _, err := os.Create(clientFilePath)
- if err != nil {
- log.Fatal("Create client file error: ",err.Error())
- return
- }
- clientFile, err := os.OpenFile(clientFilePath, os.O_WRONLY|os.O_CREATE, 0666)
- if err != nil {
- log.Fatal("Open client file error:", err.Error())
- return
- }
- defer func() {
- err = clientFile.Close()
- if err != nil{
- log.Fatal("Close client file error:", err.Error())
- }
- }()
- clientWriter := bufio.NewWriter(clientFile)
- buf := make([]byte, 6)
- clientLen := len(clients)
- i := 0
- count := 0
- clientNum := 0
- var mac string
- var clientUrl string
- for i < clientCount {
- count ++
- if count > clientCount*2 {
- log.Fatal("Build client url failed")
- }
- clientNum = mathrand.Intn(clientLen)
- _, err = rand.Read(buf)
- if err != nil {
- fmt.Println("Get mac buf failed: ", err.Error())
- continue
- }
- buf[0] |= 2
- mac=fmt.Sprintf("%02x%02x%02x%02x%02x%02x", buf[0], buf[1], buf[2], buf[3], buf[4], buf[5])
- clientUrl = fmt.Sprintf("https://security-iot.189smarthome.com:9092/api/v2/probe-client?vendor=%s&version=3.0.01&mac=%s\n",clients[clientNum],strings.ToUpper(mac))
- _, err = clientWriter.WriteString(clientUrl)
- if err != nil {
- continue
- }
- i++
- }
- err = clientWriter.Flush()
- if err != nil {
- log.Fatal("Write business file failed: ",err.Error())
- }
- }
- func DataForPre(){
- var err error
- exists := Exists("./data")
- if exists {
- err = os.RemoveAll("./data")
- if err != nil {
- log.Fatal(" Remove data failed: ", err.Error())
- }
- }
- err = os.Mkdir("./data", os.ModePerm)
- if err != nil {
- log.Fatal(" Mkdir data failed: ", err.Error())
- }
- preClientFilePath := "./predata/client.txt"
- preClientFile, err := os.Open(preClientFilePath)
- if err != nil {
- log.Fatal("Open pre client file error:", err.Error())
- return
- }
- defer func() {
- err = preClientFile.Close()
- if err != nil{
- log.Fatal("Close pre client file error:", err.Error())
- }
- }()
- reader := bufio.NewReader(preClientFile)
- var line []byte
- for{
- line,_,err = reader.ReadLine()
- if err == io.EOF{
- break
- }
- clients = append(clients,string(line))
- }
- }
- func Exists(name string) bool {
- if _, err := os.Stat(name); err != nil {
- if os.IsNotExist(err) {
- return false
- }
- }
- return true
- }
|