Skip to content

Instantly share code, notes, and snippets.

@ioxorg
Created March 6, 2025 20:01
Show Gist options
  • Save ioxorg/49af6eb61ac8fa477dc79dfd1a46969c to your computer and use it in GitHub Desktop.
Save ioxorg/49af6eb61ac8fa477dc79dfd1a46969c to your computer and use it in GitHub Desktop.
Block BitTorrent via iptabls.
#!/usr/bin/env bash
echo "Applying Torrent blocking rules..."
# Block Torrent algo string using Boyer-Moore (bm)
BLOCK_STRINGS_BM=(
"BitTorrent"
"BitTorrent protocol"
"peer_id="
".torrent"
"announce.php?passkey="
"torrent"
"announce"
"info_hash"
"/default.ida?"
".exe?/c+dir"
".exe?/c_tftp"
)
# Block Torrent keys using Knuth-Morris-Pratt (kmp)
BLOCK_STRINGS_KMP=(
"peer_id"
"BitTorrent"
"BitTorrent protocol"
"bittorrent-announce"
"announce.php?passkey="
"find_node"
"info_hash"
"get_peers"
"announce"
"announce_peers"
)
# Apply rules for Boyer-Moore algorithm
for STRING in "${BLOCK_STRINGS_BM[@]}"; do
echo "Blocking (BM): $STRING"
iptables -A FORWARD -m string --algo bm --string "$STRING" -j DROP
done
# Apply rules for Knuth-Morris-Pratt algorithm
for STRING in "${BLOCK_STRINGS_KMP[@]}"; do
echo "Blocking (KMP): $STRING"
iptables -A FORWARD -m string --algo kmp --string "$STRING" -j DROP
done
echo "All BitTorrent blocking rules applied successfully!"
@ioxorg
Copy link
Author

ioxorg commented Mar 6, 2025

run it via the following command :

sudo bash -c "$(curl -sL https://gist.githubusercontent.com/alirezahabibzadeh/49af6eb61ac8fa477dc79dfd1a46969c/raw/2d31bd14c4fb23922fb1efcb3645b1f1c9e04614/block_bittorrent.sh)"

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