Skip to content

Commit

Permalink
[refactor] use new key pair with reserved.
Browse files Browse the repository at this point in the history
  • Loading branch information
peanut996 committed Dec 19, 2023
1 parent e554a8d commit 57663e6
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
3 changes: 3 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ Parameters:
Specify your WireGuard private key
-pub PublicKey
Specify your WireGuard public key, default is the Warp public key
-reserved Reserved
Add custom reserved field. format: [0, 0, 0]
-full
Test all ports; test all ports for each IP in the IP segment
-h
Expand All @@ -75,6 +77,7 @@ Parameters:
flag.StringVar(&utils.Output, "o", "result.csv", "Output result file")
flag.StringVar(&task.PrivateKey, "pri", "", "Specify private key")
flag.StringVar(&task.PrivateKey, "pub", "", "Specify public key")
flag.StringVar(&task.ReservedString, "reserved", "", "Add custom reserved field")
flag.BoolVar(&printVersion, "v", false, "Print program version")

flag.Usage = func() { fmt.Print(help) }
Expand Down
19 changes: 16 additions & 3 deletions task/warping.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ var (

ScanAllPort = false

Reserved = [3]byte{0, 0, 0}
ReservedString = ""

reserved = [3]byte{60, 189, 175}

Routines = defaultRoutines

Expand All @@ -73,7 +75,7 @@ var (

MaxWarpPortRange = 10000

warpHandshakePacket, _ = hex.DecodeString("0100000030ec356d08af3939c1b09d3143c2e3773be539e4c7be2e2996e043f1871497be7ed28138b0473350f28647ca3013fe8de10f1ec7e448542c0ef0f0c5b2976455b6bc3f0224d06f14abfbabb7fc8753865f6dad38d7b1c2156c6cea13f57edc39c6627139659075a1c25d49743a86a40517ec45cf8e151bf0796b3f992070839600000000000000000000000000000000")
warpHandshakePacket, _ = hex.DecodeString("013cbdafb4135cac96a29484d7a0175ab152dd3e59be35049beadf758b8d48af14ca65f25a168934746fe8bc8867b1c17113d71c0fac5c141ef9f35783ffa5357c9871f4a006662b83ad71245a862495376a5fe3b4f2e1f06974d748416670e5f9b086297f652e6dfbf742fbfc63c3d8aeb175a3e9b7582fbc67c77577e4c0b32b05f92900000000000000000000000000000000")
)

type MessageInitiation struct {
Expand Down Expand Up @@ -287,6 +289,17 @@ func shuffleAddrs(udpAddrs *[]*UDPAddr) {
}

func InitHandshakePacket() {
if ReservedString != "" {
if PrivateKey == "" {
log.Fatalln("Reserved field must be used with private key")
}
r, err := utils.ParseReservedString(ReservedString)
if err != nil {
log.Fatalln("Failed to parse reserved, it must be 3 bytes slice: " + err.Error())
}
reserved = r
}

if PrivateKey == "" && PublicKey == "" {
return
}
Expand Down Expand Up @@ -343,7 +356,7 @@ func buildHandshakePacket(pri device.NoisePrivateKey, pub device.NoisePublicKey)
}

func AddReserved(packet []byte) {
packet[1], packet[2], packet[3] = Reserved[0], Reserved[1], Reserved[2]
packet[1], packet[2], packet[3] = reserved[0], reserved[1], reserved[2]
}

func getNoisePrivateKeyFromBase64(b string) (device.NoisePrivateKey, error) {
Expand Down
12 changes: 12 additions & 0 deletions utils/encoding.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package utils

import "encoding/json"

func ParseReservedString(reservedString string) (reserved [3]byte, err error) {
if reservedString == "" {
return
}
reserved = [3]byte{}
err = json.Unmarshal([]byte(reservedString), &reserved)
return
}

0 comments on commit 57663e6

Please sign in to comment.