snort hex strings and libipt_string.c
PATCH 1/1 snort hex strings and libipt_string.c
(Reposting since I was not subscribed to the list at the time.)
The attached patch adds an option "--hex-string" to the string match module to allow snort-style hex strings to be specified on the command line. This is useful because there are many signatures that consist of non-printable characters and without this patch there is no way to easily tell iptables to search for them.
E.x:
iptables -I INPUT 1 -p udp --dport 53 -m string --hex-string "31 c0 b0 02 cd 80 85 c0 75 4c eb 4c 5e b0" -j LOG --log-prefix "DNS EXPLOIT x86 linux overflow attempt "
(This is my first patch to iptables so let me know if I need to do anything differently).
Thanks,
--Mike
Michael Rash
http://www.cipherdyne.com
Key fingerprint = 4EE3 816C 413A 41AA 72C8 4463 70C3 783C 1B91 F85E
extensions/libipt_string.c renamed from extensions/libipt_string.c.old +34 -1
@@ -31,6 +31,7 @@static struct option opts[] = { {"string" ,1 ,0 ,'1' }, + {"hex-string" ,1 ,0 ,'2' }, {0 } };
@@ -48,6 +49,31 @@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 slen, schar, sindex=0 , i; +char hextmp[3 ]; + slen =strlen (s); +if (slen <=3 *(BM_MAX_NLEN )) {/* hex input like "71 61 7a" */ +for (i=0 ; i<slen; i+=3 ) { + hextmp[0 ] = s[i]; + hextmp[1 ] = s[i+1 ]; +if (s[i+2 ] ==' ' || s[i+2 ] =='\0' ) { + hextmp[2 ] ='\0' ; +if (!sscanf (hextmp,"%x" , &schar)) +exit_error (PARAMETER_PROBLEM ,"Invalid hex char `%c'" , s[i]); + info->string[sindex] = (char ) schar; + sindex++; + }else { +exit_error (PARAMETER_PROBLEM ,"Enter hex chars separated by spaces" ); + } + } + }else { +exit_error (PARAMETER_PROBLEM ,"HEX STRING too long `%s'" , s); + } +} +/* Function which parses command options; returns true if it ate an option */ static int
@@ -67,7 +93,14 @@ 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 ;default :return 0 ; }
Quoted 1 line · Michael Rash
(Reposting since I was not subscribed to the list at the time.)
This is not a problem, all mail from non-subscribes goes through manual moderation (by me).
Quoted 5 lines
The attached patch adds an option "--hex-string" to the string match module to allow snort-style hex strings to be specified on the command line. This is useful because there are many signatures that consist of non-printable characters and without this patch there is no way to easily tell iptables to search for them.
please follow the coding style (8char wide tabs, ...) when creating patches. It looks awful if parts of the code in the same file follow different coding style.
Can you plese fix this cosmetic issue and resubmit?
Quoted 1 line
--Mike
Signature · 5 lines
- Harald Welte <[email protected]> http://www.netfilter.org/ ============================================================================ "Fragmentation is like classful addressing -- an interesting early architectural error that shows how much experimentation was going on while IP was being designed." -- Paul Vixie