patches/kcrapclient.patch
changeset 0 3906ca745819
equal deleted inserted replaced
-1:000000000000 0:3906ca745819
       
     1 --- kcrap-0.2.3/test/Makefile.in	2007-12-13 15:52:14.000000000 -0500
       
     2 +++ kcrap-0.2.3-patched/test/Makefile.in	2013-01-08 16:39:00.915926616 -0500
       
     3 @@ -5,7 +5,7 @@
       
     4  
       
     5  SRCS=kcraptest.c
       
     6  
       
     7 -all: test-ntlm test-ntlmv2 test-ntlmv2s
       
     8 +all: test-ntlm test-ntlmv2 test-ntlmv2s kcrapclient
       
     9  
       
    10  test-ntlm: $(SRCS)
       
    11  	$(CC) -o $@ $(CFLAGS) -DT_NTLM $(SRCS) $(LDFLAGS) $(LIBS)
       
    12 @@ -16,10 +16,13 @@
       
    13  test-ntlmv2s: $(SRCS)
       
    14  	$(CC) -o $@ $(CFLAGS) -DT_NTLM2S $(SRCS) $(LDFLAGS) $(LIBS)
       
    15  
       
    16 +kcrapclient: kcrapclient.c
       
    17 +	$(CC) -o $@ $(CFLAGS) kcrapclient.c $(LDFLAGS) $(LIBS)
       
    18 +
       
    19  install:
       
    20  
       
    21  clean:
       
    22 -	rm -f *.o *~ test-ntlm test-ntlmv2 test-ntlmv2s
       
    23 +	rm -f *.o *~ test-ntlm test-ntlmv2 test-ntlmv2s kcrapclient
       
    24  
       
    25  distclean: clean
       
    26  	rm -f Makefile
       
    27 --- kcrap-0.2.3/test/kcrapclient.c	1969-12-31 19:00:00.000000000 -0500
       
    28 +++ kcrap-0.2.3-patched/test/kcrapclient.c	2012-12-02 22:12:14.000000000 -0500
       
    29 @@ -0,0 +1,130 @@
       
    30 +/*
       
    31 + * Little KCRAP client based on kcraptest.c 
       
    32 + * from http://www.spock.org/kcrap/
       
    33 + */
       
    34 +
       
    35 +/*
       
    36 + * Test KCRAP server with known challange/response pairs
       
    37 + * from http://davenport.sourceforge.net/ntlm.html
       
    38 + */
       
    39 +
       
    40 +#include <stdio.h>
       
    41 +#include <string.h>
       
    42 +#include <unistd.h>
       
    43 +#include <stdlib.h>
       
    44 +#include <sys/types.h>
       
    45 +#include <sys/socket.h>
       
    46 +#include <netinet/in.h>
       
    47 +#include <arpa/inet.h>
       
    48 +#include <netdb.h>
       
    49 +#include <string.h>
       
    50 +#include <strings.h>
       
    51 +#include <errno.h>
       
    52 +#include <time.h>
       
    53 +#include <poll.h>
       
    54 +
       
    55 +#include "../config.h"
       
    56 +#include "kcrap.h"
       
    57 +
       
    58 +// #define OSTREAM stderr
       
    59 +#define OSTREAM stdout
       
    60 +
       
    61 +#define SDATA(VAR,VAL) (VAR).data = (VAL), (VAR).length = strlen((VAR).data)
       
    62 +
       
    63 +static int fillhex(char *dst, char *src) {
       
    64 +  int i = 0;
       
    65 +  char tb[3];
       
    66 +  tb[2] = 0;
       
    67 +  for (i = 0; i*2 < strlen(src); i++) {
       
    68 +    memcpy(tb, src+(i*2), 2);
       
    69 +    if ((!isxdigit(tb[0])) || (!isxdigit(tb[1]))) return -1;
       
    70 +    dst[i] = strtol(tb, NULL, 16);
       
    71 +  }
       
    72 +  return 0;
       
    73 +}
       
    74 +
       
    75 +int main(int argc, char* argv[]) {
       
    76 +    struct kcrap_context *context;
       
    77 +    struct kcrap_auth_req_data req;
       
    78 +    int ret;
       
    79 +    char schal[8];
       
    80 +    char cchal[130];
       
    81 +    char resp[24];
       
    82 +    int auth_status;
       
    83 +    
       
    84 +    if (argc != 4) {
       
    85 +      fprintf(OSTREAM, "Error: Invalid parameters...\n");
       
    86 +      fprintf(OSTREAM, "Usage: %s <username> <challenge> <response>\n", argv[0]);
       
    87 +      exit(1);
       
    88 +    }
       
    89 +
       
    90 +    if (strlen(argv[2]) != 16) {
       
    91 +      fprintf(OSTREAM, "Erroe: Invalid challenge length.\n");
       
    92 +      exit(1);
       
    93 +    }
       
    94 +      
       
    95 +    if (strlen(argv[3]) != 48) {
       
    96 +      fprintf(OSTREAM, "Error: Invalid response length.\n");
       
    97 +      exit(1);
       
    98 +    }
       
    99 +      
       
   100 +    bzero(&req, sizeof(req));
       
   101 +    bzero(&schal, sizeof(schal));
       
   102 +    bzero(&cchal, sizeof(cchal));
       
   103 +    bzero(&resp, sizeof(resp));
       
   104 +    SDATA(req.chal_type, "NTLM");
       
   105 +
       
   106 +    // SDATA(req.principal, "user");
       
   107 +    req.principal.data = argv[1];
       
   108 +    req.principal.length = strlen(argv[1]);
       
   109 +    
       
   110 +    req.server_challenge.length = 8;
       
   111 +    req.server_challenge.data = schal;
       
   112 +    // FILL(schal, "0123456789abcdef");
       
   113 +    if (fillhex(schal, argv[2])) {
       
   114 +      fprintf(OSTREAM, "Error: Invalid challenge string.\n");
       
   115 +      exit(1);
       
   116 +    }      
       
   117 +
       
   118 +    req.response.length = 24;
       
   119 +    req.response.data = resp;
       
   120 +    // FILL(resp, "25a98c1c31e81847466b29b2df4680f39958fb8c213a9cc6");
       
   121 +    if (fillhex(resp, argv[3])) {
       
   122 +      fprintf(OSTREAM, "Error: Invalid response string.\n");
       
   123 +      exit(1);
       
   124 +    }      
       
   125 +
       
   126 +    context = kcrap_init(NULL, NULL);
       
   127 +    if (context == NULL) {
       
   128 +	fprintf(OSTREAM, "Error: %s\n", kcrap_errmsg());
       
   129 +	exit(1);
       
   130 +    }
       
   131 +
       
   132 +    ret = kcrap_try(context, &req, &auth_status);
       
   133 +    if (ret != 0) {
       
   134 +      fprintf(OSTREAM, "Error: %s\n", kcrap_errmsg());
       
   135 +    } else if (auth_status == 0) {
       
   136 +      fprintf(OSTREAM, "Error: %s\n", kcrap_errmsg());
       
   137 +    } else {
       
   138 +      // fprintf(OSTREAM, "Authentication OK\n");
       
   139 +
       
   140 +      struct kcrap_data extra = kcrap_get_extra_data();
       
   141 +
       
   142 +      // echo "NT_KEY: 68ba2d7c88299a123457f6b11c97772f"
       
   143 +
       
   144 +      printf("NT_KEY: ");
       
   145 +
       
   146 +      int my_cnt = 0;
       
   147 +      while (my_cnt < extra.length) printf("%02x", (unsigned char)extra.data[my_cnt++]);
       
   148 +
       
   149 +      printf("\n");
       
   150 +
       
   151 +      // Cancelliamo la chiave (md4(key21)) puntato dalla struttura "extra"
       
   152 +      if (extra.length) {
       
   153 +	memset(extra.data, 0, extra.length);
       
   154 +      }
       
   155 +    }
       
   156 +    
       
   157 +    kcrap_free(context);
       
   158 +    exit((ret!=0) || (auth_status==0));
       
   159 +}