From 1f082d3dd494c13e9b3a09d13f61203f52da9cd7 Mon Sep 17 00:00:00 2001 From: 0x90-n Date: Tue, 30 Jan 2024 20:21:36 -0700 Subject: [PATCH 1/2] adding regtracker --- Makefile | 8 +- cmd/registration-tracker/Makefile | 2 + cmd/registration-tracker/go.mod | 3 + cmd/registration-tracker/go.sum | 130 +++++++++++ cmd/registration-tracker/main.go | 377 ++++++++++++++++++++++++++++++ go.work | 1 + 6 files changed, 519 insertions(+), 2 deletions(-) create mode 100644 cmd/registration-tracker/Makefile create mode 100644 cmd/registration-tracker/go.mod create mode 100644 cmd/registration-tracker/go.sum create mode 100644 cmd/registration-tracker/main.go diff --git a/Makefile b/Makefile index ceb5f130..9f76d732 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,9 @@ CFLAGS = -Wall -DENABLE_BPF -DHAVE_PF_RING -DHAVE_PF_RING_ZC -DTAPDANCE_USE_PF_R PROTO_RS_PATH=src/signalling.rs EXE_DIR=./bin -all: rust libtd conjure app registration-server ${PROTO_RS_PATH} +all: rust libtd conjure app registration-server registration-tracker ${PROTO_RS_PATH} -sim: rust libtd conjure-sim app registration-server ${PROTO_RS_PATH} +sim: rust libtd conjure-sim app registration-server registration-tracker ${PROTO_RS_PATH} rust: ./src/*.rs cargo build --${DEBUG_OR_RELEASE} @@ -40,6 +40,10 @@ registration-server: [ -d $(EXE_DIR) ] || mkdir -p $(EXE_DIR) go build -o ${EXE_DIR}/registration-server ./cmd/registration-server +registration-tracker: + [ -d $(EXE_DIR) ] || mkdir -p $(EXE_DIR) + go build -o ${EXE_DIR}/registration-tracker ./cmd/registration-tracker + PARAMS := det app reg zbalance sim target := unk # makefile arguments take preference, if one is not provided we check the environment variable. diff --git a/cmd/registration-tracker/Makefile b/cmd/registration-tracker/Makefile new file mode 100644 index 00000000..17b539fd --- /dev/null +++ b/cmd/registration-tracker/Makefile @@ -0,0 +1,2 @@ +all: + go build -a . diff --git a/cmd/registration-tracker/go.mod b/cmd/registration-tracker/go.mod new file mode 100644 index 00000000..b6de7dbe --- /dev/null +++ b/cmd/registration-tracker/go.mod @@ -0,0 +1,3 @@ +module github.com/refraction-networking/conjure/cmd/regtracker + +go 1.20 diff --git a/cmd/registration-tracker/go.sum b/cmd/registration-tracker/go.sum new file mode 100644 index 00000000..9ab4fa14 --- /dev/null +++ b/cmd/registration-tracker/go.sum @@ -0,0 +1,130 @@ +filippo.io/bigmod v0.0.1 h1:OaEqDr3gEbofpnHbGqZweSL/bLMhy1pb54puiCDeuOA= +filippo.io/bigmod v0.0.1/go.mod h1:KyzqAbH7bRH6MOuOF1TPfUjvLoi0mRF2bIyD2ouRNQI= +filippo.io/keygen v0.0.0-20230306160926-5201437acf8e h1:+xwUCyMiCWKWsI0RowhzB4sngpUdMHgU6lLuWJCX5Dg= +filippo.io/keygen v0.0.0-20230306160926-5201437acf8e/go.mod h1:ZGSiF/b2hd6MRghF/cid0vXw8pXykRTmIu+JSPw/NCQ= +github.com/BurntSushi/toml v1.3.2 h1:o7IhLm0Msx3BaB+n3Ag7L8EVlByGnpq14C4YWiu/gL8= +github.com/BurntSushi/toml v1.3.2/go.mod h1:CxXYINrC8qIiEnFrOxCa7Jy5BFHlXnUU2pbicEuybxQ= +github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= +github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/dchest/siphash v1.2.3 h1:QXwFc8cFOR2dSa/gE6o/HokBMWtLUaNDVd+22aKHeEA= +github.com/dchest/siphash v1.2.3/go.mod h1:0NvQU092bT0ipiFN++/rXm69QG9tVxLAlQHIXMPAkHc= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= +github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= +github.com/fsnotify/fsnotify v1.4.9 h1:hsms1Qyu0jgnwNXIxa+/V/PDsU6CfLf6CNO8H7IWoS4= +github.com/go-redis/redis/v8 v8.11.5 h1:AcZZR7igkdvfVmQTPnu9WE37LRrO/YrBH5zWyjDC0oI= +github.com/go-redis/redis/v8 v8.11.5/go.mod h1:gREzHqY1hg6oD9ngVRbLStwAWKhA0FEgq8Jd4h5lpwo= +github.com/google/go-cmp v0.5.5 h1:Khx7svrCpmxxtHBq5j2mp/xVjsi8hQMfNLvJFAlrGgU= +github.com/hashicorp/golang-lru v1.0.2 h1:dV3g9Z/unq5DpblPpw+Oqcv4dU/1omnb4Ok8iPY6p1c= +github.com/hashicorp/golang-lru v1.0.2/go.mod h1:iADmTwqILo4mZ8BN3D2Q6+9jd8WM5uGBxy+E8yxSoD4= +github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= +github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= +github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= +github.com/libp2p/go-reuseport v0.4.0 h1:nR5KU7hD0WxXCJbmw7r2rhRYruNRl2koHw8fQscQm2s= +github.com/libp2p/go-reuseport v0.4.0/go.mod h1:ZtI03j/wO5hZVDFo2jKywN6bYKWLOy8Se6DrI2E1cLU= +github.com/mroth/weightedrand v1.0.0 h1:V8JeHChvl2MP1sAoXq4brElOcza+jxLkRuwvtQu8L3E= +github.com/mroth/weightedrand v1.0.0/go.mod h1:3p2SIcC8al1YMzGhAIoXD+r9olo/g/cdJgAD905gyNE= +github.com/nxadm/tail v1.4.8 h1:nPr65rt6Y5JFSKQO7qToXr7pePgD6Gwiw05lkbyAQTE= +github.com/onsi/ginkgo v1.16.5 h1:8xi0RTUf59SOSfEtZMvwTvXYMzG4gV23XVHOZiXNtnE= +github.com/onsi/gomega v1.27.6 h1:ENqfyGeS5AX/rlXDd/ETokDz93u0YufY1Pgxuy/PvWE= +github.com/oschwald/geoip2-golang v1.9.0 h1:uvD3O6fXAXs+usU+UGExshpdP13GAqp4GBrzN7IgKZc= +github.com/oschwald/geoip2-golang v1.9.0/go.mod h1:BHK6TvDyATVQhKNbQBdrj9eAvuwOMi2zSFXizL3K81Y= +github.com/oschwald/maxminddb-golang v1.12.0 h1:9FnTOD0YOhP7DGxGsq4glzpGy5+w7pq50AS6wALUMYs= +github.com/oschwald/maxminddb-golang v1.12.0/go.mod h1:q0Nob5lTCqyQ8WT6FYgS1L7PXKVVbgiymefNwIjPzgY= +github.com/pebbe/zmq4 v1.2.10 h1:wQkqRZ3CZeABIeidr3e8uQZMMH5YAykA/WN0L5zkd1c= +github.com/pebbe/zmq4 v1.2.10/go.mod h1:nqnPueOapVhE2wItZ0uOErngczsJdLOGkebMxaO8r48= +github.com/pelletier/go-toml v1.9.5 h1:4yBQzkHv+7BHq2PQUZF3Mx0IYxG7LsP222s7Agd3ve8= +github.com/pelletier/go-toml v1.9.5/go.mod h1:u1nR/EPcESfeI/szUZKdtJ0xRNbUoANCkoOuaOx1Y+c= +github.com/pion/dtls/v2 v2.2.7 h1:cSUBsETxepsCSFSxC3mc/aDo14qQLMSL+O6IjG28yV8= +github.com/pion/dtls/v2 v2.2.7/go.mod h1:8WiMkebSHFD0T+dIU+UeBaoV7kDhOW5oDCzZ7WZ/F9s= +github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY= +github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms= +github.com/pion/randutil v0.1.0 h1:CFG1UdESneORglEsnimhUjf33Rwjubwj6xfiOXBa3mA= +github.com/pion/randutil v0.1.0/go.mod h1:XcJrSMMbbMRhASFVOlj/5hQial/Y8oH/HVo7TBZq+j8= +github.com/pion/sctp v1.8.8 h1:5EdnnKI4gpyR1a1TwbiS/wxEgcUWBHsc7ILAjARJB+U= +github.com/pion/sctp v1.8.8/go.mod h1:igF9nZBrjh5AtmKc7U30jXltsFHicFCXSmWA2GWRaWs= +github.com/pion/stun v0.6.1 h1:8lp6YejULeHBF8NmV8e2787BogQhduZugh5PdhDyyN4= +github.com/pion/stun v0.6.1/go.mod h1:/hO7APkX4hZKu/D0f2lHzNyvdkTGtIy3NDmLR7kSz/8= +github.com/pion/transport/v2 v2.2.1/go.mod h1:cXXWavvCnFF6McHTft3DWS9iic2Mftcz1Aq29pGcU5g= +github.com/pion/transport/v2 v2.2.3 h1:XcOE3/x41HOSKbl1BfyY1TF1dERx7lVvlMCbXU7kfvA= +github.com/pion/transport/v2 v2.2.3/go.mod h1:q2U/tf9FEfnSBGSW6w5Qp5PFWRLRj3NjLhCCgpRK4p0= +github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/refraction-networking/conjure v0.7.10 h1:QGH2wna/9cxu760a/RbE6GhEaElGk7Uagj0epJeprZg= +github.com/refraction-networking/conjure v0.7.10/go.mod h1:7KuAtYfSL0K0WpCScjN9YKiOZ4AQ/8IzSjUtVwWbSv8= +github.com/refraction-networking/ed25519 v0.1.2 h1:08kJZUkAlY7a7cZGosl1teGytV+QEoNxPO7NnRvAB+g= +github.com/refraction-networking/ed25519 v0.1.2/go.mod h1:nxYLUAYt/hmNpAh64PNSQ/tQ9gTIB89wCaGKJlRtZ9I= +github.com/refraction-networking/obfs4 v0.1.2 h1:J842O4fGSkd2W8ogYj0KN6gqVVY+Cpqodw9qFGL7wVU= +github.com/refraction-networking/obfs4 v0.1.2/go.mod h1:wAl/+gWiLsrcykJA3nKJHx89f5/gXGM8UKvty7+mvbM= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw= +github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo= +github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= +github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= +github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= +github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= +gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.5.0 h1:rzdY78Ox2T+VlXcxGxELF+6VyUXlZBhmRqZu5etLm+c= +gitlab.torproject.org/tpo/anti-censorship/pluggable-transports/goptlib v1.5.0/go.mod h1:70bhd4JKW/+1HLfm+TMrgHJsUHG4coelMWwiVEJ2gAg= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= +golang.org/x/crypto v0.8.0/go.mod h1:mRqEX+O9/h5TFCrQhkgjo2yKi0yYA+9ecGkdQoHrywE= +golang.org/x/crypto v0.12.0/go.mod h1:NF0Gs7EO5K4qLn+Ylc+fih8BSTeIjAP05siRnAh98yw= +golang.org/x/crypto v0.15.0 h1:frVn1TEaCEaZcn3Tmd7Y2b5KKPaZ+I32Q2OA3kYp5TA= +golang.org/x/crypto v0.15.0/go.mod h1:4ChreQoLWfG3xLDer1WdlH5NdlQ3+mwnQq1YTKY+72g= +golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= +golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= +golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= +golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= +golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= +golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= +golang.org/x/net v0.9.0/go.mod h1:d48xBJpPfHeWQsugry2m+kC02ZBRGRgulfHnEXEuWns= +golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= +golang.org/x/net v0.14.0/go.mod h1:PpSgVXXLK0OxS0F31C1/tv6XNguvCrnXIDrFMspZIUI= +golang.org/x/net v0.18.0 h1:mIYleuAkSbHh0tCv7RvjL3F6ZVbLjq4+R7zbOn3Kokg= +golang.org/x/net v0.18.0/go.mod h1:/czyP5RqHAH4odGYxBJ1qz0+CE5WZ+2j1YgoEo8F2jQ= +golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.7.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.11.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.14.0 h1:Vz7Qs629MkJkGyHxUlRHizWJRG2j8fbQKjELVSNhy7Q= +golang.org/x/sys v0.14.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= +golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= +golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= +golang.org/x/term v0.7.0/go.mod h1:P32HKFT3hSsZrRxla30E9HqToFYAQPCMs/zFMBUFqPY= +golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= +golang.org/x/term v0.11.0/go.mod h1:zC9APTIj3jG3FdV/Ons+XE1riIZXG4aZ4GTHiPZJPIU= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= +golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= +golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= +golang.org/x/text v0.12.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= +golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= +golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= +golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4= +google.golang.org/grpc v1.59.0 h1:Z5Iec2pjwb+LEOqzpB2MR12/eKFhDPhuqW91O+4bwUk= +google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= +google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 h1:uRGJdciOHaEIrze2W8Q3AKkepLTh2hOroT7a+7czfdQ= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= +gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/cmd/registration-tracker/main.go b/cmd/registration-tracker/main.go new file mode 100644 index 00000000..80d8f98b --- /dev/null +++ b/cmd/registration-tracker/main.go @@ -0,0 +1,377 @@ +package main + +/* + TODOs: + - Automate prefix discovery + - Restructure regtracker code base +*/ + +import ( + "context" + "errors" + "flag" + "fmt" + golog "log" + "net" + "os" + "sync" + "sync/atomic" + "time" + + "github.com/refraction-networking/conjure/pkg/phantoms" + "github.com/refraction-networking/conjure/pkg/station/geoip" + cj "github.com/refraction-networking/conjure/pkg/station/lib" + "github.com/refraction-networking/conjure/pkg/station/log" + "github.com/refraction-networking/conjure/pkg/transports" + "github.com/refraction-networking/conjure/pkg/transports/connecting/dtls" + "github.com/refraction-networking/conjure/pkg/transports/wrapping/min" + "github.com/refraction-networking/conjure/pkg/transports/wrapping/obfs4" + "github.com/refraction-networking/conjure/pkg/transports/wrapping/prefix" + pb "github.com/refraction-networking/conjure/proto" + + "google.golang.org/protobuf/proto" +) + +var ( + ErrInvalidCC = errors.New("Invalid CC") + ErrIPtoCC = errors.New("IP to CC failed") + ErrIPtoASN = errors.New("IP to ASN failed") + ErrDupReg = errors.New("duplicate registration") +) + + +type transportStats struct { + cc string + minCount int64 + dtlsCount int64 + obfs4Count int64 + unknownTransportCount int64 + prefixCount int64 + prefixMinCount int64 + prefixGetLongCount int64 + prefixPostLongCount int64 + prefixHTTPRespCount int64 + prefixTLSClientHelloCount int64 + prefixTLSServerHelloCount int64 + prefixTLSAlertWarningCount int64 + prefixTLSAlertFatalCount int64 + prefixDNSOverTCPCount int64 + prefixOpenSSH2Count int64 + prefixUnknownCount int64 +} + +type regStats struct { + logger *log.Logger + m *sync.Mutex // Lock for registrations map + v4Registrations map[uint]*transportStats // Map from ASNs to transportStats + v6Registrations map[uint]*transportStats // Map from ASNs to transportStats + currRegIds map[string]int // Map for regIds to their count during the current ticker window + prevRegIds map[string]int // Map for regIds to their count during the previous ticker window + GeoIP geoip.Database +} + +var enabledTransports = map[pb.TransportType]cj.Transport{ + pb.TransportType_Min: min.Transport{}, + pb.TransportType_Obfs4: obfs4.Transport{}, + pb.TransportType_Prefix: prefix.DefaultSet(), + pb.TransportType_DTLS: dtls.Transport{}, +} + +func (c *transportStats) GetCounts() string { + + return fmt.Sprintf("%d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", + atomic.LoadInt64(&c.minCount), + atomic.LoadInt64(&c.dtlsCount), + atomic.LoadInt64(&c.obfs4Count), + atomic.LoadInt64(&c.unknownTransportCount), + atomic.LoadInt64(&c.prefixCount), + atomic.LoadInt64(&c.prefixMinCount), + atomic.LoadInt64(&c.prefixGetLongCount), + atomic.LoadInt64(&c.prefixPostLongCount), + atomic.LoadInt64(&c.prefixHTTPRespCount), + atomic.LoadInt64(&c.prefixTLSClientHelloCount), + atomic.LoadInt64(&c.prefixTLSServerHelloCount), + atomic.LoadInt64(&c.prefixTLSAlertWarningCount), + atomic.LoadInt64(&c.prefixTLSAlertFatalCount), + atomic.LoadInt64(&c.prefixDNSOverTCPCount), + atomic.LoadInt64(&c.prefixOpenSSH2Count), + atomic.LoadInt64(&c.prefixUnknownCount), + ) +} + +func (c *transportStats) IncrementCount(reg *cj.DecoyRegistration) { + transport := *reg.TransportPtr + switch transport.Name() { + case "MinTransport": + atomic.AddInt64(&c.minCount, 1) + case "dtls": + atomic.AddInt64(&c.dtlsCount, 1) + case "obfs4": + atomic.AddInt64(&c.obfs4Count, 1) + case "PrefixTransport": + atomic.AddInt64(&c.prefixCount, 1) + switch prefix.PrefixID(reg.TransportParams().(*pb.PrefixTransportParams).GetPrefixId()).Name() { + // Becuase reg.TransportParams() returns any, we need to cast it to *pb.PrefixTransportParams and + // GetPrefixId() to be able to get the prefix name + case "Min": + atomic.AddInt64(&c.prefixMinCount, 1) + case "GetLong": + atomic.AddInt64(&c.prefixGetLongCount, 1) + case "PostLong": + atomic.AddInt64(&c.prefixPostLongCount, 1) + case "HTTPResp": + atomic.AddInt64(&c.prefixHTTPRespCount, 1) + case "TLSClientHello": + atomic.AddInt64(&c.prefixTLSClientHelloCount, 1) + case "TLSServerHello": + atomic.AddInt64(&c.prefixTLSServerHelloCount, 1) + case "TLSAlertWarning": + atomic.AddInt64(&c.prefixTLSAlertWarningCount, 1) + case "TLSAlertFatal": + atomic.AddInt64(&c.prefixTLSAlertFatalCount, 1) + case "DNSOverTCP": + atomic.AddInt64(&c.prefixDNSOverTCPCount, 1) + case "OpenSSH2": + atomic.AddInt64(&c.prefixOpenSSH2Count, 1) + default: + atomic.AddInt64(&c.prefixUnknownCount, 1) + } + default: + atomic.AddInt64(&c.unknownTransportCount, 1) + } +} + +func (rs *regStats) PrintAndReset() { + rs.m.Lock() + defer rs.m.Unlock() + + for i, val := range [2]map[uint]*transportStats{rs.v4Registrations, rs.v6Registrations} { + ip_ver := 4 + if i == 1 { + ip_ver = 6 + } + for asn, counts := range val { + rs.logger.Infof("regtrack (IPv%d): %d %s %s", + ip_ver, + asn, + counts.cc, + counts.GetCounts(), + ) + } + } + rs.v4Registrations = make(map[uint]*transportStats) + rs.v6Registrations = make(map[uint]*transportStats) + rs.prevRegIds = make(map[string]int) + for key, val := range rs.currRegIds { + rs.prevRegIds[key] = val + } + rs.currRegIds = make(map[string]int) +} + +func (rs *regStats) AddRegistration(asn uint, cc string, isIPv4 bool, reg *cj.DecoyRegistration) error { + rs.m.Lock() + defer rs.m.Unlock() + if cc != "" { + // GeoIP tracking + if isIPv4 { + if _, okAsn := rs.v4Registrations[asn]; !okAsn { + rs.v4Registrations[asn] = &transportStats{} + rs.v4Registrations[asn].cc = cc + } + rs.v4Registrations[asn].IncrementCount(reg) + } else { + if _, okAsn := rs.v6Registrations[asn]; !okAsn { + rs.v6Registrations[asn] = &transportStats{} + rs.v6Registrations[asn].cc = cc + } + rs.v6Registrations[asn].IncrementCount(reg) + } + } else { + return ErrInvalidCC + } + return nil +} + +func (rs *regStats) ProcessRegistration(sourceAddr net.IP, reg *cj.DecoyRegistration) error { + cc, err := rs.GeoIP.CC(sourceAddr) + if err != nil { + return ErrIPtoCC + } + asn, err := rs.GeoIP.ASN(sourceAddr) + if err != nil { + return ErrIPtoASN + } + + isIPv4 := sourceAddr.To4() != nil + + // reg.IDString() could be used instead of string(reg.Keys.SharedSecret), + // but we don't need encoded strings as keys. Using bytes is better in terms + // of performance. Might consider using reg.IDString() in case debugging + // registrations is needed + strSharedKey := string(reg.Keys.SharedSecret) + rs.m.Lock() + if _, foundInCurr := rs.currRegIds[strSharedKey]; foundInCurr { + rs.currRegIds[strSharedKey]++ + rs.m.Unlock() + return ErrDupReg + } else { + if _, foundInPrev := rs.prevRegIds[strSharedKey]; foundInPrev { + rs.prevRegIds[strSharedKey]++ + rs.currRegIds[strSharedKey] = 1 + rs.m.Unlock() + return ErrDupReg + } else { + rs.currRegIds[strSharedKey] = 1 + rs.m.Unlock() + err = rs.AddRegistration(asn, cc, isIPv4, reg) + if err != nil { + // handle err if needed + return err + } + } + } + return nil +} + +func handleC2SError(logger *log.Logger, IPVerSupport string, err error, reg *cj.DecoyRegistration){ + + if errors.Is(err, phantoms.ErrLegacyMissingAddrs) || + errors.Is(err, phantoms.ErrLegacyAddrSelectBug) || + errors.Is(err, phantoms.ErrLegacyV0SelectionBug) || + errors.Is(err, transports.ErrUnknownTransport) { + logger.Debugf("DEBUG: unexpected err creating %s registration: %v, %v", IPVerSupport, err, reg) + } else { + logger.Errorf("unexpected err creating %s registration: %v, %v", IPVerSupport, err, reg) + } +} + +func main() { + var zmqAddress string + flag.StringVar(&zmqAddress, "zmq-address", "ipc://@zmq-proxy", "Address of ZMQ proxy") + flag.Parse() + + logger := log.New(os.Stdout, "[REGTRACK] ", golog.Ldate|golog.Lmicroseconds) + + // parse toml station configuration + conf, err := cj.ParseConfig() + if err != nil { + logger.Fatalf("failed to parse app config: %v", err) + } + + privkey, err := conf.ParsePrivateKey() + if err != nil { + logger.Fatalf("error parseing private key: %s", err) + } + + geoipDB, err := geoip.New(conf.RegConfig.DBConfig) + if err != nil { + logger.Fatalf("failed to create geoip database: %v", err) + } + + regstats := regStats{ + logger: logger, + m: &sync.Mutex{}, + v4Registrations: make(map[uint]*transportStats), + v6Registrations: make(map[uint]*transportStats), + currRegIds: make(map[string]int), + prevRegIds: make(map[string]int), + GeoIP: geoipDB, + } + + ctx, _ := context.WithCancel(context.Background()) + regChan := make(chan interface{}, 10000) + zmqIngester, err := cj.NewZMQIngest(zmqAddress, regChan, privkey, conf.ZMQConfig) + if err != nil { + logger.Fatal("error creating ZMQ Ingest: %w", err) + } + + // Receive registration updates from ZMQ Proxy as subscriber + go zmqIngester.RunZMQ(ctx) + + regManager := cj.NewRegistrationManager(&cj.RegConfig{}) + + // Add supported transport options for registration validation + for transportType, transport := range enabledTransports { + err = regManager.AddTransport(transportType, transport) + if err != nil { + logger.Fatalf("failed to add transport: %v", err) + } + } + + ticker := time.NewTicker(30 * time.Second) + go func() { + for range ticker.C { + regstats.PrintAndReset() + } + }() + + msgChan := make(chan interface{}, 10000) + + // Read from regChan to which the zmqIngester writes + for data := range regChan { + + select { + case <- ctx.Done(): + logger.Fatal("closing all ingest threads") + case msgChan <- data: + default: + logger.Tracef("dropping registration") + } + msg, ok := (<-msgChan).([]byte) + if !ok { + logger.Tracef("failed to convert registration into proper type") + } + + parsed := &pb.C2SWrapper{} + err = proto.Unmarshal(msg, parsed) + if err != nil { + logger.Errorf("failed to unmarshall ClientToStation: %v", err) + } + + if parsed.GetRegistrationAddress() == nil { + parsed.RegistrationAddress = make([]byte, 16) + } + if parsed.GetDecoyAddress() == nil { + parsed.DecoyAddress = make([]byte, 16) + } + + var sourceAddr = net.IP(parsed.GetRegistrationAddress()) + + var reg *cj.DecoyRegistration + + // gotapdance cli support v6 by default, so Getv6Support() will typically be true + // Also, clients IP version support can either be (v6 and v4) or v4 alone + if parsed.GetRegistrationPayload().GetV6Support() { + // registration indicates support for v6 + reg, err = regManager.NewRegistrationC2SWrapper(parsed, true) + if err != nil { + handleC2SError(logger, "v6-supported", err, reg) + continue + } + } else if parsed.GetRegistrationPayload().GetV4Support() && sourceAddr.To4() != nil { + // registration indicates NO support for v6 + reg, err = regManager.NewRegistrationC2SWrapper(parsed, false) + if err != nil { + handleC2SError(logger, "strictly-v4-supported", err, reg) + continue + } + } else { + logger.Errorf("reached an edge case where the client neither supports v4 or v6") + continue + } + + go func(ip net.IP, registration *cj.DecoyRegistration) { + err = regstats.ProcessRegistration(ip, registration) + if err != nil { + if errors.Is(err, ErrInvalidCC) || + errors.Is(err, ErrIPtoCC) || + errors.Is(err, ErrIPtoASN) || + errors.Is(err, ErrDupReg) { + logger.Debugf("DEBUG: unexpected err processing registration: %v", err) + } else { + logger.Errorf("unexpected err processing registration: %v", err) + } + } + }(sourceAddr, reg) + } +} diff --git a/go.work b/go.work index ffeb9611..88b62a40 100644 --- a/go.work +++ b/go.work @@ -4,5 +4,6 @@ use ( . ./cmd/application ./cmd/registration-server + ./cmd/registration-tracker ./util/station-debug ) From a6c4e91343577ae06cce0786938750300c5c7c8e Mon Sep 17 00:00:00 2001 From: 0x90-n Date: Tue, 30 Jan 2024 20:48:41 -0700 Subject: [PATCH 2/2] adding supporting scripts --- scripts/start_registration-tracker.sh | 23 +++++++++++++++++++++++ sysconfig/conjure-reg-tracker.service | 20 ++++++++++++++++++++ sysconfig/conjure_regtrack.conf | 19 +++++++++++++++++++ 3 files changed, 62 insertions(+) create mode 100755 scripts/start_registration-tracker.sh create mode 100644 sysconfig/conjure-reg-tracker.service create mode 100644 sysconfig/conjure_regtrack.conf diff --git a/scripts/start_registration-tracker.sh b/scripts/start_registration-tracker.sh new file mode 100755 index 00000000..d3d31f84 --- /dev/null +++ b/scripts/start_registration-tracker.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +# Run Conjure registration tracker process using configs in environment variables. + +if [ $(id -u) -ne 0 ]; then + echo "$0 must be run as sudo" + exit 1 +fi + +# load config. will access config in /var/lib/conjure for overrides +set -a +source /opt/conjure/sysconfig/conjure_regtrack.conf +set +a + +if [ ! -f $CJ_STATION_CONFIG ]; then + echo "Failed to open \$CJ_STATION_CONFIG=$CJ_STATION_CONFIG." + echo "You may want to set CJ_STATION_CONFIG in the conjure.conf file before running the script" + exit 1 +fi + +echo "station_config path: $CJ_STATION_CONFIG" + +/opt/conjure/bin/registration-tracker diff --git a/sysconfig/conjure-reg-tracker.service b/sysconfig/conjure-reg-tracker.service new file mode 100644 index 00000000..57bd3f96 --- /dev/null +++ b/sysconfig/conjure-reg-tracker.service @@ -0,0 +1,20 @@ +[Unit] +Description=Conjure Registration Tracker + +[Service] +Type=simple + +WorkingDirectory=/opt/conjure/ + +SyslogIdentifier=conjure + +ExecStart=/bin/bash /opt/conjure/scripts/start_registration-tracker.sh + +# send SIGHUP to the station process +ExecReload=/bin/kill -HUP $MAINPID + +# on stop processes will get SIGTERM, and after 10 secs - SIGKILL (default 90) +TimeoutStopSec=10 + +[Install] +WantedBy=multi-user.target diff --git a/sysconfig/conjure_regtrack.conf b/sysconfig/conjure_regtrack.conf new file mode 100644 index 00000000..8c2f13b3 --- /dev/null +++ b/sysconfig/conjure_regtrack.conf @@ -0,0 +1,19 @@ +#!/bin/bash + +# private key used by the detectors +CJ_PRIVKEY=/var/lib/conjure/regtracker_privkey + +# Path to the configuration file for the registratoin tracker +CJ_STATION_CONFIG=/var/lib/conjure/regtrack_config.toml + +# Path to the configuration file containing phantom subnets +PHANTOM_SUBNET_LOCATION=/var/lib/conjure/phantom_subnets.toml + +# Read local configs to allow for override of any of these settings +if [ -r /var/lib/conjure/conjure_regtrack.conf ] && [ -z "${CJ_STOP_RECURSE+x}" ]; then + echo "Applying local configs from /var/lib/conjure/conjure_regtrack.conf" + CJ_STOP_RECURSE="true" + . /var/lib/conjure/conjure_regtrack.conf +fi + +unset CJ_STOP_RECURSE