Skip to content

Commit

Permalink
Merge pull request #17 from yfdyh000/2024-04-29_fixes
Browse files Browse the repository at this point in the history
fix TCP_SYN; fix SNI for big packet
  • Loading branch information
CallCateIn58 authored Apr 29, 2024
2 parents d67da67 + de16def commit a4e60c5
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 8 deletions.
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

0 comments on commit a4e60c5

Please sign in to comment.