must use sendTo to inject ip packet
This commit is contained in:
parent
32060fe9dc
commit
c5f6348cf2
16
tcp_syni.nim
16
tcp_syni.nim
|
@ -1,6 +1,6 @@
|
||||||
import asyncdispatch, asyncnet, strformat
|
import asyncdispatch, asyncnet, strformat
|
||||||
from net import IpAddress, Port, `$`, `==`, getPrimaryIPAddr
|
from net import IpAddress, Port, `$`, `==`, getPrimaryIPAddr, toSockAddr
|
||||||
from nativesockets import setSockOptInt
|
from nativesockets import SockAddr, Sockaddr_storage, SockLen, setSockOptInt
|
||||||
import asyncutils
|
import asyncutils
|
||||||
import ip_packet
|
import ip_packet
|
||||||
import network_interface
|
import network_interface
|
||||||
|
@ -90,7 +90,17 @@ proc injectSyns(rawFd: AsyncFD, srcIp: IpAddress, srcPort: Port,
|
||||||
tcpPortDst: srcPort,
|
tcpPortDst: srcPort,
|
||||||
tcpSeqNumber: seqNum,
|
tcpSeqNumber: seqNum,
|
||||||
tcpFlags: {SYN})
|
tcpFlags: {SYN})
|
||||||
asyncCheck rawFd.send(serialize(ipPacket))
|
echo &"injecting {srcIP}:{srcPort.int} -> {dstIp}:{dstPort.int} (seq {seqNum})"
|
||||||
|
try:
|
||||||
|
let packet = serialize(ipPacket)
|
||||||
|
var sockaddr: Sockaddr_storage
|
||||||
|
var sockaddrLen: SockLen
|
||||||
|
toSockAddr(dstIp, dstPort, sockaddr, sockaddrLen)
|
||||||
|
await rawFd.sendTo(packet.cstring, packet.len,
|
||||||
|
cast[ptr SockAddr](addr sockaddr), sockaddrLen)
|
||||||
|
echo &"injected {srcIP}:{srcPort.int} -> {dstIp}:{dstPort.int} (seq {seqNum})"
|
||||||
|
except OSError as e:
|
||||||
|
echo "cannot inject: ", e.msg
|
||||||
|
|
||||||
proc initPuncher*(srcPort: Port, dstIp: IpAddress, dstPorts: array[3, Port],
|
proc initPuncher*(srcPort: Port, dstIp: IpAddress, dstPorts: array[3, Port],
|
||||||
seqNums: seq[uint32] = @[]): Future[TcpSyniPuncher] {.async.} =
|
seqNums: seq[uint32] = @[]): Future[TcpSyniPuncher] {.async.} =
|
||||||
|
|
Loading…
Reference in New Issue