Archive for February, 2004

Simple Secure Data Transfer

SSDT, Simple Secure Data Transfer, utility makes use of sending spoofed ICMP and UDP traffic to send RSA encrypted files. It is based on OpenSSL library.

Version: 0.1

Download source code

As usual here is a bit of code :)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// RSA encryption function
long int rsa_encrypt(char *pubfile, unsigned long int plsz, char *filein, unsigned char *ciphdata)
{
  int ks=0;
  unsigned long size=0, len=0, ctr=0, ciphsz=0;
  RSA* key=NULL;
  FILE *fp=NULL;
  char *tmpciph=NULL, *tmpplain=NULL;
 
  if(!(fp = fopen(filein, "r"))) {
    fprintf(stderr, "Error: Cannot locate input file.\n");
    return -1;
  }
  key = (RSA *)readpubkey(pubfile);
  if (!key) {
    return -1;
  }
  ks = RSA_size(key);
  tmpplain = (unsigned char *)malloc(ks * sizeof(unsigned char));
  tmpciph = (unsigned char *)malloc(ks * sizeof(unsigned char));
  srand(time(NULL));
  while(!feof(fp)) {
    if (ciphsz + ks > plsz) {
      fprintf(stderr, "Error: Size of RSA encrypted data exceeded: %ld bytes.\n", ciphsz);
      fclose(fp);
      return -1;
    }
    memset(tmpplain, '\0', ks);
    memset(tmpciph, '\0', ks);
    len = fread(tmpplain, 1, ks - 11, fp);
    if((size = RSA_public_encrypt(len, tmpplain, tmpciph, key, RSA_PKCS1_PADDING)) == -1) {
      fprintf(stderr, "%s\n", ERR_error_string(ERR_get_error(), NULL));
      return -1;
    }
    for (ctr = 0; ctr < size; ciphsz++, ctr++)
      *(ciphdata + ciphsz) = *(tmpciph + ctr);
  }
  fclose(fp);
  free(tmpciph);
  free(tmpplain);
  RSA_free(key);
  return ciphsz;
}
 
// RSA decryption function
long int rsa_decrypt(char *secfile, unsigned char *ciphdata, unsigned long int ciphsz,unsigned char *plaindata)
{
  unsigned long int plsz=0, size=0, ks=0, ctr=0;
  RSA* key=NULL;
  char *tmpplain=NULL, *tmpciph=NULL;
 
  key = (RSA *)readseckey(secfile);
  ks = RSA_size(key);
  tmpciph = (unsigned char *)malloc(ks * sizeof(unsigned char));
  tmpplain = (unsigned char *)malloc(ks * sizeof(unsigned char));
  while (*ciphdata != '\0' && plsz < ciphsz) {
    memset(tmpciph, '\0', ks);
    memset(tmpplain, '\0', ks);
    bcopy(ciphdata, tmpciph, ks);
    for (ctr=0; ctr < ks; ctr++)
      ciphdata++;
    if((size = RSA_private_decrypt(ks, tmpciph, tmpplain, key, RSA_PKCS1_PADDING)) == -1) {
    //  fprintf(stderr, "%s\n", ERR_error_string(ERR_get_error(), NULL));
    //  exit(EXIT_FAILURE);
      continue;
    }
    for(ctr = 0; ctr < size; plsz++, ctr++)
      *(plaindata + plsz) = *(tmpplain + ctr);
  }
  free(tmpplain);
  free(tmpciph);
  RSA_free(key);
  return plsz;
}