mirror of
https://github.com/bettercap/bettercap
synced 2025-08-14 02:36:57 -07:00
new: basic ipv6 support
This commit is contained in:
parent
d0b5c34763
commit
bef4c6abaa
8 changed files with 115 additions and 35 deletions
|
@ -55,6 +55,11 @@ func httpGrabber(mod *SynScanner, ip string, port int) string {
|
|||
}
|
||||
}
|
||||
|
||||
// https://stackoverflow.com/questions/12260003/connect-returns-invalid-argument-with-ipv6-address
|
||||
if strings.Contains(ip, ":") {
|
||||
ip = fmt.Sprintf("[%s%%25%s]", ip, mod.Session.Interface.Name())
|
||||
}
|
||||
|
||||
url := fmt.Sprintf("%s://%s:%d/", schema, ip, port)
|
||||
resp, err := client.Get(url)
|
||||
if err != nil {
|
||||
|
|
|
@ -167,6 +167,12 @@ type scanJob struct {
|
|||
func (mod *SynScanner) scanWorker(job async.Job) {
|
||||
scan := job.(scanJob)
|
||||
|
||||
fromHW := mod.Session.Interface.HW
|
||||
fromIP := mod.Session.Interface.IP
|
||||
if scan.Address.To4() == nil {
|
||||
fromIP = mod.Session.Interface.IPv6
|
||||
}
|
||||
|
||||
for dstPort := mod.startPort; dstPort < mod.endPort+1; dstPort++ {
|
||||
if !mod.Running() {
|
||||
break
|
||||
|
@ -174,7 +180,7 @@ func (mod *SynScanner) scanWorker(job async.Job) {
|
|||
|
||||
atomic.AddUint64(&mod.stats.doneProbes, 1)
|
||||
|
||||
err, raw := packets.NewTCPSyn(mod.Session.Interface.IP, mod.Session.Interface.HW, scan.Address, scan.Mac, synSourcePort, dstPort)
|
||||
err, raw := packets.NewTCPSyn(fromIP, fromHW, scan.Address, scan.Mac, synSourcePort, dstPort)
|
||||
if err != nil {
|
||||
mod.Error("error creating SYN packet: %s", err)
|
||||
continue
|
||||
|
|
|
@ -2,18 +2,30 @@ package syn_scan
|
|||
|
||||
import (
|
||||
"fmt"
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/evilsocket/islazy/str"
|
||||
"github.com/malfunkt/iprange"
|
||||
)
|
||||
|
||||
func (mod *SynScanner) parseTargets(arg string) error {
|
||||
if list, err := iprange.Parse(arg); err != nil {
|
||||
return fmt.Errorf("error while parsing IP range '%s': %s", arg, err)
|
||||
if strings.Contains(arg, ":") {
|
||||
// parse as IPv6 address
|
||||
if ip := net.ParseIP(arg); ip == nil {
|
||||
return fmt.Errorf("error while parsing IPv6 '%s'", arg)
|
||||
} else {
|
||||
mod.addresses = []net.IP{ip}
|
||||
}
|
||||
} else {
|
||||
mod.addresses = list.Expand()
|
||||
if list, err := iprange.Parse(arg); err != nil {
|
||||
return fmt.Errorf("error while parsing IP range '%s': %s", arg, err)
|
||||
} else {
|
||||
mod.addresses = list.Expand()
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
|
|
|
@ -24,26 +24,40 @@ func (mod *SynScanner) onPacket(pkt gopacket.Packet) {
|
|||
}
|
||||
|
||||
var eth layers.Ethernet
|
||||
var ip layers.IPv4
|
||||
var ip4 layers.IPv4
|
||||
var ip6 layers.IPv6
|
||||
var tcp layers.TCP
|
||||
foundLayerTypes := []gopacket.LayerType{}
|
||||
|
||||
|
||||
|
||||
isIPv6 := false
|
||||
foundLayerTypes := []gopacket.LayerType{}
|
||||
parser := gopacket.NewDecodingLayerParser(
|
||||
layers.LayerTypeEthernet,
|
||||
ð,
|
||||
&ip,
|
||||
&ip4,
|
||||
&tcp,
|
||||
)
|
||||
|
||||
err := parser.DecodeLayers(pkt.Data(), &foundLayerTypes)
|
||||
if err != nil {
|
||||
return
|
||||
// try ipv6
|
||||
parser := gopacket.NewDecodingLayerParser(
|
||||
layers.LayerTypeEthernet,
|
||||
ð,
|
||||
&ip6,
|
||||
&tcp,
|
||||
)
|
||||
err = parser.DecodeLayers(pkt.Data(), &foundLayerTypes)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
isIPv6 = true
|
||||
}
|
||||
|
||||
if tcp.DstPort == synSourcePort && tcp.SYN && tcp.ACK {
|
||||
atomic.AddUint64(&mod.stats.openPorts, 1)
|
||||
|
||||
from := ip.SrcIP.String()
|
||||
port := int(tcp.SrcPort)
|
||||
|
||||
openPort := &OpenPort{
|
||||
|
@ -53,12 +67,28 @@ func (mod *SynScanner) onPacket(pkt gopacket.Packet) {
|
|||
}
|
||||
|
||||
var host *network.Endpoint
|
||||
if ip.SrcIP.Equal(mod.Session.Interface.IP) {
|
||||
host = mod.Session.Interface
|
||||
} else if ip.SrcIP.Equal(mod.Session.Gateway.IP) {
|
||||
host = mod.Session.Gateway
|
||||
|
||||
from := ""
|
||||
|
||||
if isIPv6 {
|
||||
from = ip6.SrcIP.String()
|
||||
if ip6.SrcIP.Equal(mod.Session.Interface.IPv6) {
|
||||
host = mod.Session.Interface
|
||||
} else if ip6.SrcIP.Equal(mod.Session.Gateway.IPv6) {
|
||||
host = mod.Session.Gateway
|
||||
} else {
|
||||
host = mod.Session.Lan.GetByIp(from)
|
||||
}
|
||||
} else {
|
||||
host = mod.Session.Lan.GetByIp(from)
|
||||
from = ip4.SrcIP.String()
|
||||
|
||||
if ip4.SrcIP.Equal(mod.Session.Interface.IP) {
|
||||
host = mod.Session.Interface
|
||||
} else if ip4.SrcIP.Equal(mod.Session.Gateway.IP) {
|
||||
host = mod.Session.Gateway
|
||||
} else {
|
||||
host = mod.Session.Lan.GetByIp(from)
|
||||
}
|
||||
}
|
||||
|
||||
if host != nil {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue