DNAT/SNAT and logging
Hi all. This is a repost. I first tried the [email protected] list with no luck. Mayby someone here can help me with an answer to this question?
I need a way to log SNAT/DNAT packets. In the log i need all the information about what have happend to the packet. Since the log target is above the actually mangle line, the log target won't know how the packet will be mangle. What i need in the log files are something like:
Original Source
Original SourcePort
Original Destination
Original DestinationPort
Translated Source
Translated SourcePort
Translated Destination
Translated DestinationPort
As an example, take a look at the documentaion about nat and look at the examples below taken from
http://www.netfilter.org/documentation/HOWTO//NAT-HOWTO-6.html
---- SNIP ----
## Change destination addresses to 5.6.7.8, 5.6.7.9 or 5.6.7.10.
# iptables -t nat -A PREROUTING -i eth0 -j DNAT --to 5.6.7.8-5.6.7.10 ## Change source addresses to 1.2.3.4, 1.2.3.5 or 1.2.3.6 # iptables -t nat -A POSTROUTING -o eth0 -j SNAT --to 1.2.3.4-1.2.3.6 ---- SNIP ----
Here you can se that you can do DNAT and SNAT to an range of ipadresse so the question may be a bit clearer when i ask the question like this. How is it possible to log to wich ipadress the connection is translated to? The logs should contain all that the information that is needed to tell what have happend to a packet.
Regards
Johan
Quoted 11 lines · Johan Ankarloo
is above the actually mangle line, the log target won't know how the packet will be mangle. What i need in the log files are something like:
Original Source
Original SourcePort
Original Destination
Original DestinationPort
Translated Source
Translated SourcePort
Translated Destination
Translated DestinationPort
Then you need another LOG type target which logs the conntrack information rather than the packet information, and on NEW packets you need to have this logged after the SNAT rule have been applied.
Maybe ctnetlink can help.
Regards
Henrik
I'm not shure i agree. The problem here is that the logging is done seperate from the modules that mangle the packets. The right way ( for me ) would be to have the mangle modules send the logging information to the logging module. In this way the mangle modules could say what has been altered in the packet.
This information has to be included so that it is possible to trace the packet back. Think of a large company that do a lot of nat for big networks. How is it possible for the IT-staff to see what have happend? In other brands ( read checkpoint, cisco .... ) they include this information.
Regards
Johan
Quoted 22 lines · Henrik Nordstrom
Quoted 11 lines · Johan Ankarloo
is above the actually mangle line, the log target won't know how the packet will be mangle. What i need in the log files are something like:
Original Source
Original SourcePort
Original Destination
Original DestinationPort
Translated Source
Translated SourcePort
Translated Destination
Translated DestinationPortThen you need another LOG type target which logs the conntrack information rather than the packet information, and on NEW packets you need to have this logged after the SNAT rule have been applied.
Maybe ctnetlink can help.
Regards
Henrik
Quoted 2 lines · Johan Ankarloo
I'm not shure i agree. The problem here is that the logging is done seperate from the modules that mangle the packets.
Yes, and so is the NAT rules.
Quoted 3 lines
The right way ( for me ) would be to have the mangle modules send the logging information to the logging module. In this way the mangle modules could say what has been altered in the packet.
If you log the addressing information from conntrack then this is exacly what is done.
Regards
Henrik
So you don't think that this is a lot of work just to get the logging to work correctly? I mean that this is something that ( in my opinion ) should be done out of the box so to say.
How should this be done through /dev/net/ip_conntrack? Do you have any examples?
//Johan
Quoted 16 lines · Henrik Nordstrom
Quoted 2 lines · Johan Ankarloo
I'm not shure i agree. The problem here is that the logging is done seperate from the modules that mangle the packets.
Yes, and so is the NAT rules.
Quoted 3 lines
The right way ( for me ) would be to have the mangle modules send the logging information to the logging module. In this way the mangle modules could say what has been altered in the packet.
If you log the addressing information from conntrack then this is exacly what is done.
Regards
Henrik
Signature · 13 lines
Mvh Johan Ankarloo Volvo IT Network & Security Engineer Tel: +46 31 32 70949 ==================================================================== This message may contain confidential and/or proprietary information, and is intended only for the person/entity to whom it was originally addressed. The content of this message may contain private views and opinions which do not constitute a formal disclosure or commitment unless specifically stated.
Quoted 3 lines · Johan Ankarloo
So you don't think that this is a lot of work just to get the logging to work correctly? I mean that this is something that ( in my opinion ) should be done out of the box so to say.
It is some work, but not very much.
Quoted 1 line
How should this be done through
/dev/net/ip_conntrack?
When I say conntrack I mean in the kernel, not the proc files. By writing another LOG target using the information from conntrack rather than the packet you can log the information you requested.
See the LOG target and the conntrack match for details, also read the NAT & Conntrack sections of the hacking howto.
The most tricky part is when to log the first packet of the session. This has to be done after all information has been entered into the session, i.e. after any SNAT targets have been applied.
Another approach is to look into using ctnetlink for detailed session logging. This is something we are currently implementing.
Regards
Henrik
Ok, i will try to look into that and see what i can find. I still think that the packet should be logged from the SNAT/DNAT module in some way since that is the module that is doing that mangle ( with this i mean that the module changes the packet in some way ) and already has all the information about what has been done to the packet.
The next question then is:
Do you understand why this is important?
Quoted 26 lines · Henrik Nordstrom
Quoted 3 lines · Johan Ankarloo
So you don't think that this is a lot of work just to get the logging to work correctly? I mean that this is something that ( in my opinion ) should be done out of the box so to say.
It is some work, but not very much.
Quoted 1 line
How should this be done through
/dev/net/ip_conntrack?When I say conntrack I mean in the kernel, not the proc files. By writing another LOG target using the information from conntrack rather than the packet you can log the information you requested.
See the LOG target and the conntrack match for details, also read the NAT & Conntrack sections of the hacking howto.
The most tricky part is when to log the first packet of the session. This has to be done after all information has been entered into the session, i.e. after any SNAT targets have been applied.
Another approach is to look into using ctnetlink for detailed session logging. This is something we are currently implementing.
Regards
Henrik
Quoted 1 line · Johan Ankarloo
Do you understand why this is important?
Yes. The existing LOG target is a mess if NAT is used.
Regards
Henrik
So then you agree that this is a problem that has to be fixed one way or another?
I don't want to be a pain in the butt here but this is a really big problem for me. When i have problem with Nat or mangle ( either i haven't understood iptables correctly or there could be a bug ) i can't really tell what has happened with the packet. Or if i get a court order to get the person accessing some specific machine at a specific time i can't rely on the log since all the necessary information about that connection isn't in the logs.
Regards
Johan
Quoted 8 lines · Henrik Nordstrom
Quoted 1 line · Johan Ankarloo
Do you understand why this is important?
Yes. The existing LOG target is a mess if NAT is used.
Regards
Henrik