--replace-string and --replace-hex-string options
Subsystems (2)
PATCH 1/1 --replace-string and --replace-hex-string options
The following two patches against the latest iptables/extensions/libipt_string.c in the netfilter cvs and pom-20031219 implement two new options "--replace-string" and "--replace-hex-string" for the string match extension. This allows matching strings to be replaced with strings that are less than or equal in length. The tcp checksum is automatically recalculated, and the udp checksum is recalculated if necessary. iptables-save/restore functions also work.
Here is an example usage:
iptables -A FORWARD -p tcp --dport 80 -m string --string "/usr/bin/id" \
--replace-string "/usr/ben/id" -j LOG --log-prefix "nullify SID 1332"iptables -A FORWARD -p udp --dport 53 -m string --hex-string "|04|bind" \
--replace-hex-string "|05|lind" -j LOG --log-prefix "nullify SID 1435"This patch provides similar functionality to the "replace" rule option in snort_inline. If we are already examining packet contents with the string match extension, then the overhead imposed by this patch is relatively minimal (just enough to copy data and recalculate checksums). Comments/suggestions much appreciated.
--Mike
Michael Rash
http://www.cipherdyne.org/
Key fingerprint = 53EA 13EA 472E 3771 894F AC69 95D8 5D6B A742 839F
include/linux/netfilter_ipv4/ipt_string.h +2 -0
@@ -14,8 +14,10 @@struct ipt_string_info {char string[BM_MAX_NLEN ]; +char replace_str[BM_MAX_NLEN ];u_int16_t invert;u_int16_t len; +u_int16_t replace_len; };#endif /* _IPT_STRING_H */
net/ipv4/netfilter/ipt_string.c +58 -6
109 lines not on this page · raw message
Index: extensions/libipt_string.c
===================================================================
RCS file: /cvspublic/iptables/extensions/libipt_string.c,v retrieving revision 1.11
libipt_string.c +72 -12
162 lines not on this page · raw message