Skip to content

Commit

Permalink
refactor for syn scan on ipv6 and minimal parallelism
Browse files Browse the repository at this point in the history
  • Loading branch information
CyberRoute committed Feb 4, 2024
1 parent 3959eaf commit eeb3801
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 19 deletions.
26 changes: 24 additions & 2 deletions examples/socksynscan6.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"log"
"net"
"os"
"strings"
"sync"
"time"

"github.com/CyberRoute/scanme/scanme"
Expand Down Expand Up @@ -42,10 +42,32 @@ func main() {
log.Fatalf("Unable to create scanner for %v: %v", ip, err)
}

var wg sync.WaitGroup
ports := make(chan layers.TCPPort, 100) // Buffered channel to limit concurrency

// Worker function to scan ports
portScanner := func() {
defer wg.Done()
for port := range ports {
scanner.SendSynTCP6(targetIP, port)
}
}

// Start worker goroutines
for i := 0; i < 20; i++ {
wg.Add(1)
go portScanner()
}

// Enqueue ports to be scanned
for port := 1; port <= 65535; port++ {
scanner.SendSynTCP6(targetIP, layers.TCPPort(port))
ports <- layers.TCPPort(port)
}

close(ports) // Close the channel to signal goroutines to exit

wg.Wait()

defer scanner.Close()

elapsedTime := time.Since(startTime)
Expand Down
18 changes: 1 addition & 17 deletions scanme/scanner.go
Original file line number Diff line number Diff line change
Expand Up @@ -568,23 +568,7 @@ func (s *Scanner) SendSynTCP6(ip string, p layers.TCPPort) {
break
} else if addr.String() == net.ParseIP(ip).String() {
// Decode a packet
packet := gopacket.NewPacket(b[:n], layers.LayerTypeTCP, gopacket.Default)
// Get the TCP layer from this packet
if tcpLayer := packet.Layer(layers.LayerTypeTCP); tcpLayer != nil {
tcp, ok := tcpLayer.(*layers.TCP)
if !ok {
continue
}
if tcp.DstPort == layers.TCPPort(srctcpport) {
if tcp.SYN && tcp.ACK {
log.Printf("Port %v is OPEN\n", tcp.SrcPort)
} else {
// Port is closed
log.Printf("Port %v CLOSED", tcp.SrcPort)
}
return
}
}
s.HandlePacketSock(b[:n], srctcpport)
}
}
}
Expand Down

0 comments on commit eeb3801

Please sign in to comment.