Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix TCP_SYN; fix SNI for big packet #17

Merged
merged 1 commit into from
Apr 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/macronut/ghostcp

go 1.16
go 1.21

require (
github.com/chai2010/winsvc v0.0.0-20200705094454-db7ec320025c
Expand Down
33 changes: 26 additions & 7 deletions header/tcp.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"bytes"
"encoding/binary"
"fmt"
"math"
"log"
"math/rand"
"net"
Expand Down Expand Up @@ -325,14 +326,32 @@ func SendFakePacket(winDivert *godivert.WinDivertHandle, info *ConnInfo, packet
} else {
rawbuf[8] = byte(info.TTL)
}
fake_packet.Raw = rawbuf[:len(packet.Raw)]
interval := 1500
packetCount := math.Ceil(float64(len(packet.Raw)) / float64(interval))
if packetCount > 1 {
for i := 0; i < len(packet.Raw); i += interval {
curLen := min(i+interval,len(packet.Raw))
fake_packet.Raw = rawbuf[i:curLen]

fake_packet.CalcNewChecksum(winDivert)

for i := 0; i < count; i++ {
_, err = winDivert.Send(&fake_packet)
if err != nil {
return 0, err
}
}
}
} else {
fake_packet.Raw = rawbuf[:len(packet.Raw)]

fake_packet.CalcNewChecksum(winDivert)
fake_packet.CalcNewChecksum(winDivert)

for i := 0; i < count; i++ {
_, err = winDivert.Send(&fake_packet)
if err != nil {
return 0, err
for i := 0; i < count; i++ {
_, err = winDivert.Send(&fake_packet)
if err != nil {
return 0, err
}
}
}
}
Expand Down Expand Up @@ -956,7 +975,7 @@ func TCPDaemon(address string, forward bool) {
}
continue
}
} else if packet.Raw[ipheadlen+13] == TCP_SYN {
} else if (packet.Raw[ipheadlen+13] & TCP_SYN) != 0 {
dstIP := packet.DstIP()
dstAddr := dstIP.String()
config, ok := IPLookup(dstAddr)
Expand Down