Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Too small scrape request packets may trip SYN flood detection of some trackers #964

Closed
Piteras00 opened this issue Aug 3, 2019 · 12 comments · Fixed by #3236
Closed

Too small scrape request packets may trip SYN flood detection of some trackers #964

Piteras00 opened this issue Aug 3, 2019 · 12 comments · Fixed by #3236
Assignees
Milestone

Comments

@Piteras00
Copy link

Piteras00 commented Aug 3, 2019

int const sndbuf = isScrape ? 4096 : 1024;
int const rcvbuf = isScrape ? 4096 : 3072;

I have recently stumbled upon a tracker that was moved to another server, after which Transmission users couldn't connect to (resulting in announce and scrape errors), while all other torrent clients worked alright. Turned out the tracker is not responding to any SYN packets smaller than 4096 bytes, forcing the window size to 4096 made it work again - hence the SYN flood detection guess.

As this kind of protection is becoming widespread, so may become this problem. Is there any reason for these packets to be so small, and if so, maybe it would be a good idea to make that configurable?

@itorres
Copy link

itorres commented Aug 4, 2019

It seems this change was introduced by @ckerr on commit 6eec590

The patch to increase it a bit is on 0be5e8d

So the problem is probably that the minimum size should be 4096 both for scrapes and announcements.

@lilws
Copy link

lilws commented Aug 10, 2019

int const sndbuf = isScrape ? 4096 : 1024;
int const rcvbuf = isScrape ? 4096 : 3072;

I have recently stumbled upon a tracker that was moved to another server, after which Transmission users couldn't connect to (resulting in announce and scrape errors), while all other torrent clients worked alright. Turned out the tracker is not responding to any SYN packets smaller than 4096 bytes, forcing the window size to 4096 made it work again - hence the SYN flood detection guess.

As this kind of protection is becoming widespread, so may become this problem. Is there any reason for these packets to be so small, and if so, maybe it would be a good idea to make that configurable?

Hi, I wonder how do you know how much the tracker SYN requires? I recently have the same problem with scrape errors too.

@Piteras00
Copy link
Author

Hi, I wonder how do you know how much the tracker SYN requires? I recently have the same problem with scrape errors too.

I figured it out by simple trial and error using TCPWIN iptables extension:

iptables -t mangle -i OUTPUT -p tcp --tcp-flags SYN SYN -j TCPWIN --tcpwin-set 4096 -d [tracker IP]

Other users of said tracker also confirmed that increasing TCP window scaling works:

sysctl -w net.ipv4.tcp_adv_win_scale=4

I'm not sure how does this affect networking performance of the box you do this on though, since this is a system-wide setting.

@ttyridal
Copy link

Just experienced a tracker (or more likely their new firewall) where 4096 was still not enough. Removed the whole setsocketopt function body and it started working again.

[2019-08-16 23:09:24.228] SO_SNDBUF size is 16384 (fdlimit.c:541)
[2019-08-16 23:09:24.228] SO_RCVBUF size is 87380 (fdlimit.c:543)

neheb added a commit to neheb/packages that referenced this issue Sep 9, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Got rid of transmission-cli. -cli is deprecated and replaced by -remote.

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
neheb added a commit to neheb/packages that referenced this issue Sep 10, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Got rid of transmission-cli. -cli is deprecated and replaced by -remote.

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
@neheb
Copy link
Contributor

neheb commented Sep 10, 2019

sysctl works. Problem should still be fixed here though.

neheb added a commit to neheb/packages that referenced this issue Sep 11, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Got rid of transmission-cli. -cli is deprecated and replaced by -remote.

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
neheb added a commit to neheb/packages that referenced this issue Sep 12, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Got rid of transmission-cli. -cli is deprecated and replaced by -remote.

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
neheb added a commit to neheb/packages that referenced this issue Sep 13, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Got rid of transmission-cli. -cli is deprecated and replaced by -remote.

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
neheb added a commit to neheb/packages that referenced this issue Sep 15, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Got rid of transmission-cli. -cli is deprecated and replaced by -remote.

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
neheb added a commit to neheb/packages that referenced this issue Sep 16, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Got rid of transmission-cli. -cli is deprecated and replaced by -remote.

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
neheb added a commit to neheb/packages that referenced this issue Sep 20, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Got rid of transmission-cli. -cli is deprecated and replaced by -remote.

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
neheb added a commit to neheb/packages that referenced this issue Sep 23, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
@Nadahar
Copy link

Nadahar commented Nov 18, 2019

Is there any progress on this? Sysctl is only a temporary fix that must be reapplied, and it's easy to forget this - including what parameter must be set.

neheb added a commit to openwrt/packages that referenced this issue Nov 25, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
(cherry-picked from 730a169)
neheb added a commit to openwrt/packages that referenced this issue Nov 25, 2019
Some firewalls mandate a minimum size of 4k for SYN packets, which
transmission does not do by default. Upstream issue here:

transmission/transmission#964

Cleanup:

Fixed license info.

Removed two unnecessary patches.

Ran shell script through shellcheck.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
(cherry-picked from 730a169)
@qome
Copy link

qome commented Jan 12, 2020

@Nadahar I agree that it should be changed here, but you don't need to re-apply it every reboot. You can put it in /etc/sysctl.conf.

@zwei7
Copy link

zwei7 commented Apr 15, 2020

Bakabt won't work anymore due to "SYN packets with size smaller than 4096 are being dropped." May you fix this in the next update? Rather not use Vuze. Thanks!

The following is a message on their forum:
Re: No longer able to download or reseed torrent - Transmission 2.94 - (Known Issue)
« Reply #20 on: August 03, 2019, 01:37:11 pm »
Quote
Window size was a good lead. I've done some more research and it would seem SYN packets with size smaller than 4096 are being dropped.

I've done this using a Windows installation of Transmission 2.94. Even though it got a response eventually I still got a scrape error. Not yet sure what caused it to send a larger window. uT 2.2.1 uses window size of 64240, guess that's why it works alright.

I've also learned that something named TCP Small Window Attack Protection exists. You might want to ask your service provider whether they've got something like that installed and if so, is it possible to disable it for your server.

UPDATE: Managed to make Transmission on my seedbox work using TCPWIN iptables extension.

Code: [Select]
iptables -t mangle -i OUTPUT -p tcp --tcp-flags SYN SYN -j TCPWIN --tcpwin-set 4096 -d 78.142.29.192
Edit: typo in the command

This basically forces size of all SYN packets sent to the tracker to have size of 4096 bytes. No doubts about that being a filtering issue now, Transmission's requests are fine.

Of course this isn't a fix suggestion, I think most people would rather find another client that works than go that far to stick with what they have. If there's anyone who wants to try this, I can walk you through (at least on Debian).
« Last Edit: August 03, 2019, 07:05:17 pm by Piteras00 »

@ChaosBlades
Copy link

Bakabt won't work anymore due to "SYN packets with size smaller than 4096 are being dropped." May you fix this in the next update? Rather not use Vuze. Thanks!

The following is a message on their forum:
Re: No longer able to download or reseed torrent - Transmission 2.94 - (Known Issue)
« Reply #20 on: August 03, 2019, 01:37:11 pm »
Quote
Window size was a good lead. I've done some more research and it would seem SYN packets with size smaller than 4096 are being dropped.

I've done this using a Windows installation of Transmission 2.94. Even though it got a response eventually I still got a scrape error. Not yet sure what caused it to send a larger window. uT 2.2.1 uses window size of 64240, guess that's why it works alright.

I've also learned that something named TCP Small Window Attack Protection exists. You might want to ask your service provider whether they've got something like that installed and if so, is it possible to disable it for your server.

UPDATE: Managed to make Transmission on my seedbox work using TCPWIN iptables extension.

Code: [Select]
iptables -t mangle -i OUTPUT -p tcp --tcp-flags SYN SYN -j TCPWIN --tcpwin-set 4096 -d 78.142.29.192
Edit: typo in the command

This basically forces size of all SYN packets sent to the tracker to have size of 4096 bytes. No doubts about that being a filtering issue now, Transmission's requests are fine.

Of course this isn't a fix suggestion, I think most people would rather find another client that works than go that far to stick with what they have. If there's anyone who wants to try this, I can walk you through (at least on Debian).
« Last Edit: August 03, 2019, 07:05:17 pm by Piteras00 »

Change <...>announce.php to <...>announce.php?scrape on BakaBT

3.00 still needs to be whitelisted by the tracker... fyi if you are using it.

@zwei7
Copy link

zwei7 commented May 13, 2020 via email

@ckerr ckerr added this to the 4.0.0-beta.1 milestone Apr 26, 2022
@ckerr
Copy link
Member

ckerr commented May 13, 2022

There is a lot of discussion here, so just to make sure I haven't missed some context: all that's needed here is, when we reduce the sndbuf / rcvbuf size e.g. for scrapes and announces, to use 4096 as the floor, correct?

@neheb
Copy link
Contributor

neheb commented May 13, 2022

Yes.

An alternate fix is with sysctl:

# Some firewalls block SYN packets that are too small
net.ipv4.tcp_adv_win_scale = 4

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Development

Successfully merging a pull request may close this issue.

10 participants