8. TCP¶
8.1. Types¶
8.2. Dissectors¶
8.2.1. TCP¶
- tcp.create(ip)¶
Create a new TCP packet on top of the given IP packet.
- class tcp.tcp¶
Dissector data for a TCP packet. This dissector is state-less. It will only parse the packet headers.
See also
- srcport¶
- dstport¶
- seq¶
- ack_seq¶
- res¶
- hdr_len¶
- window_size¶
- checksum¶
- urgent_pointer¶
TCP fields as numbers.
- ip¶
IPv4 packet.
- payload¶
Payload of the packet. Class that contains the TCP data payload. The data can be accessed using the standard Lua operators # to get the length and [] to access the bytes.
- verify_checksum()¶
Verify if the checksum is correct.
- compute_checksum()¶
Recompute the checksum and set the resulting value in the packet.
- newconnection()¶
Creates a new TCP connection from this packet.
- getconnection()¶
Gets the connection if any associated with this packet.
Returns: - The TCP connection as tcp.tcp_connection.
- A boolean containing the direction of this packet in the connection.
- A boolean indicating if the packet is part of a dropped connection.
- drop()¶
Drop the TCP packet.
8.2.2. TCP connection¶
- class tcp-connection.connection¶
State-full dissector for TCP which define one additional hook tcp-connection-new that is called whenever a packet will create a new TCP connection.
See also
- connection¶
Contains the current TCP connection.
- stream¶
Contains the stream associated with the connection.
- direction¶
Contains the direction of the current packet.
- drop()¶
Drop the TCP connection. All future packets that belong to this connection will be silently dropped.
- reset()¶
Reset the TCP connection. A RST packet will be sent to both end and all future packet that belong to this connection will be silently dropped.
8.3. Example¶
------------------------------------
-- Firewall rules
------------------------------------
local client_network = ipv4.network("192.168.10.0/25");
local server_network = ipv4.network("192.168.20.0/25");
local group = haka.rule_group{
name = "group",
init = function (self, pkt)
haka.log.debug("filter", "entering packet filtering rules : %d --> %d",
pkt.tcp.srcport, pkt.tcp.dstport)
end,
fini = function (self, pkt)
haka.alert{
description = "Packet dropped : drop by default",
sources = haka.alert.address(pkt.tcp.ip.src, pkt.tcp.srcport),
targets = haka.alert.address(pkt.tcp.ip.dst, pkt.tcp.dstport)
}
pkt:drop()
end,
continue = function (self, pkt, ret)
return not ret
end
}
group:rule{
hooks = { 'tcp-connection-new' },
eval = function (self, pkt)
local tcp = pkt.tcp
if client_network:contains(tcp.ip.src) and
server_network:contains(tcp.ip.dst) and
tcp.dstport == 80 then
haka.log.warning("filter", "authorizing http traffic")
pkt.next_dissector = "http"
return true
end
end
}
group:rule{
hooks = { 'tcp-connection-new' },
eval = function (self, pkt)
local tcp = pkt.tcp
if client_network:contains(tcp.ip.src) and
server_network:contains(tcp.ip.dst) and
tcp.dstport == 22 then
haka.log.warning("filter", "authorizing ssh traffic")
haka.log.warning("filter", "no available dissector for ssh")
return true
end
end
}