need a second socket for injecting
This commit is contained in:
parent
e745141b51
commit
7bc90f02b8
12
tcp_syni.nim
12
tcp_syni.nim
|
@ -56,7 +56,7 @@ proc injectTcpPacket(rawFd: AsyncFD, ipPacket: IpPacket) {.async.} =
|
|||
cast[ptr SockAddr](addr sockaddr), sockaddrLen)
|
||||
echo &"injected {ipPacket.ipAddrSrc}:{ipPacket.tcpPortSrc.int} -> {ipPacket.ipAddrDst}:{ipPacket.tcpPortDst.int} (seq {ipPacket.tcpSeqNumber})"
|
||||
except OSError as e:
|
||||
echo &"cannot inject {ipPacket.ipAddrSrc}:{ipPacket.tcpPortSrc.int} -> {ipPacket.ipAddrDst}:{ipPacket.tcpPortDst.int} (seq {ipPacket.tcpSeqNumber})", e.msg
|
||||
echo &"cannot inject {ipPacket.ipAddrSrc}:{ipPacket.tcpPortSrc.int} -> {ipPacket.ipAddrDst}:{ipPacket.tcpPortDst.int} (seq {ipPacket.tcpSeqNumber}): ", e.msg
|
||||
raise newException(PunchHoleError, e.msg)
|
||||
|
||||
proc captureSeqNumbers(puncher: TcpSyniPuncher, rawFd: AsyncFD,
|
||||
|
@ -80,9 +80,10 @@ proc captureSeqNumbers(puncher: TcpSyniPuncher, rawFd: AsyncFD,
|
|||
break
|
||||
await cb(seqNums)
|
||||
|
||||
proc captureAndResendAck(puncher: TcpSyniPuncher, rawFd: AsyncFD) {.async.} =
|
||||
proc captureAndResendAck(puncher: TcpSyniPuncher, captureFd: AsyncFD,
|
||||
injectFd: AsyncFD) {.async.} =
|
||||
while true:
|
||||
let packet = await rawFd.recv(4000)
|
||||
let packet = await captureFd.recv(4000)
|
||||
if packet == "":
|
||||
break
|
||||
let parsed = parseEthernetPacket(packet)
|
||||
|
@ -101,7 +102,7 @@ proc captureAndResendAck(puncher: TcpSyniPuncher, rawFd: AsyncFD) {.async.} =
|
|||
tcpPortDst: parsed.tcpPortDst,
|
||||
tcpSeqNumber: parsed.tcpSeqNumber,
|
||||
tcpFlags: parsed.tcpFlags)
|
||||
await rawFd.injectTcpPacket(ipPacket)
|
||||
await injectFd.injectTcpPacket(ipPacket)
|
||||
break
|
||||
|
||||
proc initPuncher*(srcPort: Port, dstIp: IpAddress, dstPorts: array[3, Port],
|
||||
|
@ -159,8 +160,9 @@ proc connect*(puncher: TcpSyniPuncher,
|
|||
let iface = fromIpAddress(puncher.srcIp)
|
||||
let captureSeqFd = setupEthernetCapturingSocket(iface)
|
||||
let captureAckFd = setupEthernetCapturingSocket(iface)
|
||||
let injectAckFd = setupTcpInjectingSocket()
|
||||
asyncCheck puncher.captureSeqNumbers(captureSeqFd, progressCb)
|
||||
asyncCheck puncher.captureAndResendAck(captureAckFd)
|
||||
asyncCheck puncher.captureAndResendAck(captureAckFd, injectAckFd)
|
||||
await puncher.addFirewallRules()
|
||||
try:
|
||||
result = await puncher.connectParallel()
|
||||
|
|
Loading…
Reference in New Issue