Topic (netsniff-ng-0.5.9-rc4):
Using the option -F with mausezahn, to read input out of a hexfile, results in 
corrupt data transmitted (first byte will always be 0).

in Detail:
1) netsniff-ng-0.5.9-rc4\staging\mausezahn.c adds ",p=" in front of the hex 
payload.
//<...>
case 'F': // HEX payload in FILE
                        afp = fopen(optarg, "r");
                        i=0;
                        while ( (hexpld[i]=fgetc(afp))!=EOF ) {
                                if (isspace(hexpld[i])) {
                                        hexpld[i]=':';
                                }
                                i++;
                        }
                        hexpld[i]='\0';
                        fclose(afp);
                        hexpld_specified=1;
                        break;
//<...>
        if (hexpld_specified) {
                strcat(tx.arg_string, ",p=");
                strcat(tx.arg_string, hexpld);
        }
//<...>

2) netsniff-ng-0.5.9-rc4\staging\layer1.c has the need to convert the hexdata 
to binary, using the function str2hex().
//<...>
bytestring_s = str2hex (tx.arg_string, bytestring, MAX_PAYLOAD_SIZE);
//<...>

3) netsniff-ng-0.5.9-rc4\staging\str2hex.c uses the function strtok() and 
strtol() to separate and convert the hex data.
//<...>
        hs=(char*)strtok(tmp,"-:., ");

        i=0;
        do
        {       n--;
                curval=strtol(hs,NULL,16);
                if (curval>0xff) return -1;
                hp[i]=(u_int8_t) curval;
                i++;
        }
        while ((n) && ((hs=(char*)strtok(NULL,"-:., "))!= NULL));
//<...>
As the first token consists of ",p=" and the hex chars, strtol() can't convert 
this. Therefor strtol() always returns 0 for this first value.

Solution:
(I have to admit that I don't fully read all code, it's only a copy&paste 
solution from netsniff-ng-0.5.9-rc4\staging\layer3.c or 
netsniff-ng-0.5.9-rc4\staging\layer4.c and so on)

diff -urN netsniff-ng-0.5.9-rc4.orig/staging/layer1.c 
netsniff-ng-0.5.9-rc4/staging/layer1.c
--- netsniff-ng-0.5.9-rc4.orig/staging/layer1.c 2014-09-01 11:43:50.000000000 
+0200
+++ netsniff-ng-0.5.9-rc4/staging/layer1.c      2015-02-18 10:34:17.311806118 
+0100
@@ -58,7 +58,8 @@
      j=0;
    char 
      err_buf[LIBNET_ERRBUF_SIZE],
-     message[MAX_PAYLOAD_SIZE*3];
+     message[MAX_PAYLOAD_SIZE*3],
+     argval[MAX_PAYLOAD_SIZE*2];
      
    u_int8_t       bytestring[MAX_PAYLOAD_SIZE];
    libnet_ptag_t  t;
@@ -100,7 +101,10 @@
    // Create a temporal, local bytestring:
    //
    for (i=0; i<MAX_PAYLOAD_SIZE; i++) bytestring[i]=0x00;
-   bytestring_s = str2hex (tx.arg_string, bytestring, MAX_PAYLOAD_SIZE);
+   if ( (getarg(tx.arg_string,"payload", argval)==1) || 
(getarg(tx.arg_string,"p", argval)==1))
+     {
+       bytestring_s = str2hex (argval, bytestring, MAX_PAYLOAD_SIZE);
+     }
    
    // Set the flags to shorten subsequent decisions:
    src = strlen(tx.eth_src_txt);


-- 
You received this message because you are subscribed to the Google Groups 
"netsniff-ng" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to