POC IP range enumeration

This commit is contained in:
Callan Bryant 2020-03-02 18:44:19 +00:00
parent 57002288de
commit 45ec0ff5b8
No known key found for this signature in database
GPG Key ID: C31FA9DF3ACBFFAA
4 changed files with 29 additions and 0 deletions

2
add.go
View File

@ -7,6 +7,8 @@ func Add(hostname string, owner string, description string) {//, publicKey strin
presharedKey := GenerateJSONKey()
publicKey := privateKey.PublicKey()
conf.ChooseIP()
peer := PeerConfig{
Owner: owner,
Hostname: hostname,

1
go.mod
View File

@ -3,6 +3,7 @@ module github.com/naggie/dsnet
go 1.13
require (
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721
golang.org/x/tools v0.0.0-20200302155637-b1e4e04173e0 // indirect
golang.zx2c4.com/wireguard/wgctrl v0.0.0-20200205215550-e35592f146e4
)

1
go.sum
View File

@ -8,6 +8,7 @@ github.com/mdlayher/genetlink v1.0.0/go.mod h1:0rJ0h4itni50A86M2kHcgS85ttZazNt7a
github.com/mdlayher/netlink v0.0.0-20190409211403-11939a169225/go.mod h1:eQB3mZE4aiYnlUsyGGCOpPETfdQq4Jhsgf1fk3cwQaA=
github.com/mdlayher/netlink v1.0.0/go.mod h1:KxeJAFOFLG6AjpyDkQ/iIhxygIUKD+vcwqcnu43w/+M=
github.com/mdlayher/netlink v1.1.0/go.mod h1:H4WCitaheIsdF9yOYu8CFmCgQthAPIWZmcKp9uZHgmY=
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721 h1:RlZweED6sbSArvlE924+mUcZuXKLBHA35U7LN621Bws=
github.com/mikioh/ipaddr v0.0.0-20190404000644-d465c8ab6721/go.mod h1:Ickgr2WtCLZ2MDGd4Gr0geeCH5HybhRJbonOgQpvSxc=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191002192127-34f69633bfdc/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=

View File

@ -6,6 +6,7 @@ import (
"net"
"strings"
"time"
"fmt"
"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
)
@ -81,6 +82,30 @@ func (conf *DsnetConfig) MustAddPeer(peer PeerConfig) {
conf.Peers = append(conf.Peers, peer)
}
// choose a free IP for a new Peer
func (conf DsnetConfig) ChooseIP() net.IP {
network := conf.Network.IPNet
ones, bits := network.Mask.Size()
zeros := bits - ones
min := 1
max := (1 << zeros) -1
for i := min; i <= max; i++ {
IP := make(net.IP, len(network.IP))
copy(IP, network.IP)
// OR the host part with the network part
for j := 0; j < len(IP); j++ {
shift := (len(IP) - j - 1) * 8
IP[j] = IP[j] | byte(i>>shift)
}
fmt.Println(IP)
}
return net.IP{}
}
type Dsnet struct {
Name string
PrivateKey wgtypes.Key