--hex-string
PATCH 1/1 --hex-string
Per the earlier thread, here is a patch that leaves the original --string option alone, and implements a new --hex-string option.
The --hex-string option will accept both hex and ascii data, like so:
iptables -A INPUT -m string --hex-string "|4e 45|blah|5d5d|" -j LOG
This patch is against libipt_string.c v1.7 in CVS.
--Mike
Michael Rash
http://www.cipherdyne.com
Key fingerprint = 53EA 13EA 472E 3771 894F AC69 95D8 5D6B A742 839F
libipt_string.c renamed from libipt_string.c.old +21 -1
@@ -32,6 +32,7 @@static struct option opts[] = { {"string" ,1 ,0 ,'1' }, + {"hex-string" ,1 ,0 ,'2' }, {0 } };
@@ -45,6 +46,13 @@static void parse_string (const unsigned char *s,struct ipt_string_info *info) { +if (strlen (s) <=BM_MAX_NLEN )strcpy (info->string, s); +else exit_error (PARAMETER_PROBLEM ,"STRING too long `%s'" , s); +} + +static void +parse_hex_string (const unsigned char *s,struct ipt_string_info *info) +{int i=0 , slen, sindex=0 , schar;short hex_f =0 , literal_f =0 ;char hextmp[3 ];
@@ -90,6 +98,10 @@/* must end with a "|" */ exit_error (PARAMETER_PROBLEM ,"Invalid hex block" ); } +if (!isxdigit (s[i]))/* check for valid hex char */ +exit_error (PARAMETER_PROBLEM ,"Invalid hex char `%c'" , s[i]); +if (!isxdigit (s[i+1 ]))/* check for valid hex char */ +exit_error (PARAMETER_PROBLEM ,"Invalid hex char `%c'" , s[i+1 ]); hextmp[0 ] = s[i]; hextmp[1 ] = s[i+1 ]; hextmp[2 ] ='\0' ;
@@ -127,7 +139,15 @@parse_string (argv[optind-1 ], stringinfo);if (invert) stringinfo->invert =1 ; - stringinfo->len=strlen ((char *)&stringinfo->string); + stringinfo->len=strlen ((char *)&stringinfo->string); + *flags =1 ; +break ; +case '2' : +check_inverse (optarg, &invert, &optind,0 ); +parse_hex_string (argv[optind-1 ], stringinfo); +if (invert) + stringinfo->invert =1 ; + stringinfo->len=strlen ((char *)&stringinfo->string); *flags =1 ;break ;