Logging SNAT'ed connections
Hi all,
how do you log SNAT'ed connections for further forensic purposes, when somebody complains about your public IP address and you want to be able to find a local user behind NAT?
I used to run something like
conntrack --event --buffer-size 1600000 -o id,timestamp --src-nat >> $LOGFILE
which did what I want. But now I tried to run the same on AlmaLinux9 host, and it seems that --src-nat filter does not get applied - it shows even connections which are not SNAT'ed at all, because they are for my own IP address:
[1780936563.343940] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936563.343994] [UPDATE] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936565.281121] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.11 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308 [1780936565.281167] [UPDATE] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.11 type=8 code=0 id=8724 src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308
Here xx.yy.zz.11 and .13 are my public IP addresses. Why do these connections show up in the conntrack --event --src-nat output? Thanks!
-Yenya
Signature · 4 lines
| Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> |
| https://www.fi.muni.cz/~kas/ GPG: 4096R/A45477D5 |
I don't like Python; its lack of inline, anonymous, multi-statement
functions makes me sad. --Eric WastlQuoted 25 lines · Jan Kasprzak
Hi all,
how do you log SNAT'ed connections for further forensic purposes, when somebody complains about your public IP address and you want to be able to find a local user behind NAT?
I used to run something like
conntrack --event --buffer-size 1600000 -o id,timestamp --src-nat >> $LOGFILE
which did what I want. But now I tried to run the same on AlmaLinux9 host, and it seems that --src-nat filter does not get applied - it shows even connections which are not SNAT'ed at all, because they are for my own IP address:
[1780936563.343940] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936563.343994] [UPDATE] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936565.281121] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.11 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308 [1780936565.281167] [UPDATE] icmp 1 30 src=128.1.227.61
Quoted 5 lines
dst=xx.yy.zz.11 type=8 code=0 id=8724 src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308
Here xx.yy.zz.11 and .13 are my public IP addresses. Why do these connections show up in the conntrack --event --src-nat output? Thanks!
Unfortunately, it appears to be a bug affecting ICMP. Possibly here:
For now, I would suggest filtering with something else.
conntrack -E -o id,timestamp |
perl -ne 'print if /\bsrc=(\S+).*\bdst=(\S+)/ && $1 ne $2'
Signature · 1 line
Kerin Millar
Hi, Kerin,
Quoted 8 lines · Kerin Millar
Unfortunately, it appears to be a bug affecting ICMP. Possibly here:
For now, I would suggest filtering with something else.
conntrack -E -o id,timestamp |
perl -ne 'print if /\bsrc=(\S+).*\bdst=(\S+)/ && $1 ne $2'
Oh, I did not expect it to be a bug.
Anyway, you probably mean src= in both cases. Using backreferences, I did it this way:
perl -nE 'print if /\bsrc=(\S+)\s.*\bsrc=(?!\1\s)/'
Thanks!
-Yenya
Signature · 4 lines
| Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> |
| https://www.fi.muni.cz/~kas/ GPG: 4096R/A45477D5 |
I don't like Python; its lack of inline, anonymous, multi-statement
functions makes me sad. --Eric WastlQuoted 12 lines · Jan Kasprzak
Hi, Kerin,
Quoted 8 lines · Kerin Millar
Unfortunately, it appears to be a bug affecting ICMP. Possibly here:
For now, I would suggest filtering with something else.
conntrack -E -o id,timestamp |
perl -ne 'print if /\bsrc=(\S+).*\bdst=(\S+)/ && $1 ne $2'
Quoted 6 lines
Oh, I did not expect it to be a bug.
Anyway, you probably mean src= in both cases. Using backreferences, I did it this way:
perl -nE 'print if /\bsrc=(\S+)\s.*\bsrc=(?!\1\s)/'
The idea I had in mind was to compare orig.src against reply.dst. Where orig.src != reply.dst, NAT applies. Your approach compares orig.src to reply.src. Those will differ for most flows, whether they were subjected to NAT or not.
I would tend not to use backreferences in that way because it becomes quite easy to make a mistake.
$ printf 'x=123.45 y=123.45\n' | perl -nE 'say "matched: $1" if /x=(\S+).*\by=(?!\1\s)/' matched: 123.4
--
Kerin Millar
Quoted 13 lines · Kerin Millar
Quoted 12 lines · Jan Kasprzak
Hi, Kerin,
Quoted 8 lines · Kerin Millar
Unfortunately, it appears to be a bug affecting ICMP. Possibly here:
For now, I would suggest filtering with something else.
conntrack -E -o id,timestamp |
perl -ne 'print if /\bsrc=(\S+).*\bdst=(\S+)/ && $1 ne $2'
Quoted 8 lines
Quoted 6 lines
Oh, I did not expect it to be a bug.
Anyway, you probably mean src= in both cases. Using backreferences, I did it this way:
perl -nE 'print if /\bsrc=(\S+)\s.*\bsrc=(?!\1\s)/'
The idea I had in mind was to compare orig.src against reply.dst. Where orig.src != reply.dst, NAT applies. Your approach compares orig.src to reply.src. Those will differ for most flows, whether they were subjected to NAT or not.
OK, understood. Thanks for clarification.
Quoted 4 lines
I would tend not to use backreferences in that way because it becomes quite easy to make a mistake.
$ printf 'x=123.45 y=123.45\n' | perl -nE 'say "matched: $1" if /x=(\S+).*\by=(?!\1\s)/' matched: 123.4
This is why I had \s after the first group: (\S+)\s.* instead of (\S+).* But yes, if we are trying to match the first src= against the second dst=, we would hav to avoid .* to match the first dst= instead. Something like this:
perl -nE 'print if /\bsrc=(\S+)\s.*\bdst=.*\bdst=(?!\1\s)/'
-Yenya
Signature · 4 lines
| Jan "Yenya" Kasprzak <kas at {fi.muni.cz - work | yenya.net - private}> |
| https://www.fi.muni.cz/~kas/ GPG: 4096R/A45477D5 |
I don't like Python; its lack of inline, anonymous, multi-statement
functions makes me sad. --Eric WastlQuoted 17 lines · Kerin Millar
Quoted 16 lines · Jan Kasprzak
Hi, Kerin,
Quoted 8 lines · Kerin Millar
Unfortunately, it appears to be a bug affecting ICMP. Possibly here:
For now, I would suggest filtering with something else.
conntrack -E -o id,timestamp |
perl -ne 'print if /\bsrc=(\S+).*\bdst=(\S+)/ && $1 ne $2'Oh, I did not expect it to be a bug.
Anyway, you probably mean src= in both cases. Using backreferences, I did it this way:
Quoted 7 lines
Quoted 1 line
perl -nE 'print if /\bsrc=(\S+)\s.*\bsrc=(?!\1\s)/'
The idea I had in mind was to compare orig.src against reply.dst. Where orig.src != reply.dst, NAT applies. Your approach compares orig.src to reply.src. Those will differ for most flows, whether they were subjected to NAT or not.
I would tend not to use backreferences in that way because it becomes quite easy to make a mistake.
$ printf 'x=123.45 y=123.45\n' | perl -nE 'say "matched: $1" if /x=(\S+).*\by=(?!\1\s)/' matched: 123.4
Exactly, great care needs to be taken with back references; also given 'x=123.4 y=123.45', the \1 will match the '123.4' portion of 'y=123.45', making it seems like they're equal when they're not, so getting it done properly going that route will be far more complex.
Instead, here ...
$ for s in 'x=123.45 y=123.45' 'x=123.4 y=123.45' 'x=123.45 y=123.4' ; do
printf "%s\n" "$s" | perl -nE 'say "x $1 does not match y $2" if m{
\b x=(\S+) .* \b y=(\S+)
}x && $1 ne $2;'
done
x 123.4 does not match y 123.45
x 123.45 does not match y 123.4...is a cleaner way if one wants a more readable version.
Signature · 1 line
gfish
Quoted 29 lines · Kerin Millar
Quoted 28 lines · Jan Kasprzak
Hi all,
how do you log SNAT'ed connections for further forensic purposes, when somebody complains about your public IP address and you want to be able to find a local user behind NAT?
I used to run something like
conntrack --event --buffer-size 1600000 -o id,timestamp --src-nat >> $LOGFILE
which did what I want. But now I tried to run the same on AlmaLinux9 host, and it seems that --src-nat filter does not get applied - it shows even connections which are not SNAT'ed at all, because they are for my own IP address:
[1780936563.343940] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936563.343994] [UPDATE] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936565.281121] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.11 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308 [1780936565.281167] [UPDATE] icmp 1 30 src=128.1.227.61dst=xx.yy.zz.11 type=8 code=0 id=8724 src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308
Quoted 6 lines
Quoted 2 lines
Here xx.yy.zz.11 and .13 are my public IP addresses. Why do these connections show up in the conntrack --event --src-nat output? Thanks!
Unfortunately, it appears to be a bug affecting ICMP. Possibly here:
Maybe then this helps?
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
Quoted 33 lines · Pablo Neira Ayuso
Quoted 32 lines · Kerin Millar
Quoted 30 lines · Jan Kasprzak
Hi all,
how do you log SNAT'ed connections for further forensic purposes, when somebody complains about your public IP address and you want to be able to find a local user behind NAT?
I used to run something like
conntrack --event --buffer-size 1600000 -o id,timestamp --src-nat >> $LOGFILE
which did what I want. But now I tried to run the same on AlmaLinux9 host, and it seems that --src-nat filter does not get applied - it shows even connections which are not SNAT'ed at all, because they are for my own IP address:
[1780936563.343940] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936563.343994] [UPDATE] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936565.281121] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.11 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308 [1780936565.281167] [UPDATE] icmp 1 30 src=128.1.227.61dst=xx.yy.zz.11 type=8 code=0 id=8724 src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308
Here xx.yy.zz.11 and .13 are my public IP addresses. Why do these connections show up in the conntrack --event --src-nat output? Thanks!
Quoted 7 lines
Quoted 3 lines
Unfortunately, it appears to be a bug affecting ICMP. Possibly here:
Maybe then this helps?
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
I have not yet tried it but shouldn't the helper function be checking against the protonum field? Also, the referenced commit appears unrelated to the fix. I think it should refer to b4c3a23c884c.
--
Kerin Millar
Quoted 36 lines · Kerin Millar
Quoted 35 lines · Pablo Neira Ayuso
Quoted 34 lines · Kerin Millar
Quoted 25 lines · Jan Kasprzak
Hi all,
how do you log SNAT'ed connections for further forensic purposes, when somebody complains about your public IP address and you want to be able to find a local user behind NAT?
I used to run something like
conntrack --event --buffer-size 1600000 -o id,timestamp --src-nat >> $LOGFILE
which did what I want. But now I tried to run the same on AlmaLinux9 host, and it seems that --src-nat filter does not get applied - it shows even connections which are not SNAT'ed at all, because they are for my own IP address:
[1780936563.343940] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936563.343994] [UPDATE] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936565.281121] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.11 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308 [1780936565.281167] [UPDATE] icmp 1 30 src=128.1.227.61Quoted 5 lines
dst=xx.yy.zz.11 type=8 code=0 id=8724 src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308
Here xx.yy.zz.11 and .13 are my public IP addresses. Why do these connections show up in the conntrack --event --src-nat output? Thanks!
Unfortunately, it appears to be a bug affecting ICMP. Possibly here:
Quoted 7 lines
Quoted 5 lines
Maybe then this helps?
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
I have not yet tried it but shouldn't the helper function be checking against the protonum field? Also, the referenced commit appears unrelated to the fix. I think it should refer to
b4c3a23c884c.
Thanks for reviewing, v2 is here:
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
Quoted 41 lines · Pablo Neira Ayuso
Quoted 40 lines · Kerin Millar
Quoted 39 lines · Pablo Neira Ayuso
Quoted 29 lines · Kerin Millar
Quoted 28 lines · Jan Kasprzak
Hi all,
how do you log SNAT'ed connections for further forensic purposes, when somebody complains about your public IP address and you want to be able to find a local user behind NAT?
I used to run something like
conntrack --event --buffer-size 1600000 -o id,timestamp --src-nat >> $LOGFILE
which did what I want. But now I tried to run the same on AlmaLinux9 host, and it seems that --src-nat filter does not get applied - it shows even connections which are not SNAT'ed at all, because they are for my own IP address:
[1780936563.343940] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936563.343994] [UPDATE] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936565.281121] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.11 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308 [1780936565.281167] [UPDATE] icmp 1 30 src=128.1.227.61dst=xx.yy.zz.11 type=8 code=0 id=8724 src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308
Quoted 6 lines
Quoted 2 lines
Here xx.yy.zz.11 and .13 are my public IP addresses. Why do these connections show up in the conntrack --event --src-nat output? Thanks!
Unfortunately, it appears to be a bug affecting ICMP. Possibly here:
Maybe then this helps?
Quoted 7 lines
Quoted 3 lines
I have not yet tried it but shouldn't the helper function be checking against the protonum field? Also, the referenced commit appears unrelated to the fix. I think it should refer to
b4c3a23c884c.Thanks for reviewing, v2 is here:
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
Thanks. I'll try v2 out here.
--
Kerin Millar
Quoted 3 lines · Pablo Neira Ayuso
Thanks for reviewing, v2 is here:
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
I have now applied this to a production host and tested it in a number of ways, including the use of the --src-nat option, both with and without an option-argument. In all cases, conntrack(8) behaved perfectly.
--
Kerin Millar
Quoted 6 lines · Kerin Millar
Quoted 3 lines · Pablo Neira Ayuso
Thanks for reviewing, v2 is here:
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
I have now applied this to a production host and tested it in a number of ways, including the use of the --src-nat option, both with and without an option-argument. In all cases, conntrack(8) behaved perfectly.
Thanks for testing, I'll apply this then.
Quoted 15 lines · Jan Kasprzak
Hi all,
how do you log SNAT'ed connections for further forensic purposes, when somebody complains about your public IP address and you want to be able to find a local user behind NAT?
I used to run something like
conntrack --event --buffer-size 1600000 -o id,timestamp --src-nat >> $LOGFILE
which did what I want. But now I tried to run the same on AlmaLinux9 host, and it seems that --src-nat filter does not get applied - it shows even connections which are not SNAT'ed at all, because they are for my own IP address:
Quoted 7 lines
[1780936563.343940] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936563.343994] [UPDATE] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.13 type=8 code=0 id=8724 src=xx.yy.zz.13 dst=128.1.227.61 type=0 code=0 id=8724 id=2525400839 [1780936565.281121] [NEW] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.11 type=8 code=0 id=8724 [UNREPLIED] src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308 [1780936565.281167] [UPDATE] icmp 1 30 src=128.1.227.61 dst=xx.yy.zz.11 type=8 code=0 id=8724 src=xx.yy.zz.11 dst=128.1.227.61 type=0 code=0 id=8724 id=2574615308Here xx.yy.zz.11 and .13 are my public IP addresses. Why do these connections show up in the conntrack --event --src-nat output? Thanks!
Could you check if this fixes the issue for you?
https://patchwork.ozlabs.org/project/netfilter-devel/patch/[email protected]/
Thanks.