1

I'm a complete n00b to C and have tried googling the errors, but haven't been able to figure out what to change for this to work. I'm trying to compile an exploitdb .c file (764.c). Following this guide, I've made all the changes, but it still won't compile.

Error:

$gcc exploit2.c -o 764 -lcrypto
exploit2.c: In function ‘send_ssl_packet’:
exploit2.c:641:27: error: assignment of read-only location ‘*p’
  641 | #define s2n(s,c)    ((c[0]=(unsigned char)(((s)>> 8)&0xff), c[1]=(unsigned char)(((s)    )&0xff)),c+=2)
      |                           ^
exploit2.c:908:2: note: in expansion of macro ‘s2n’
  908 |  s2n(tot_len, p);
      |  ^~~
exploit2.c:641:65: error: assignment of read-only location ‘*(p + 1)’
  641 | #define s2n(s,c)    ((c[0]=(unsigned char)(((s)>> 8)&0xff), c[1]=(unsigned char)(((s)    )&0xff)),c+=2)
      |                                                                 ^
exploit2.c:908:2: note: in expansion of macro ‘s2n’
  908 |  s2n(tot_len, p);
      |  ^~~
exploit2.c:920:13: warning: passing argument 1 of ‘MD5_Final’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  920 |   MD5_Final(p, &ctx);
      |             ^
In file included from exploit2.c:27:
/usr/include/openssl/md5.h:42:30: note: expected ‘unsigned char *’ but argument is of type ‘const unsigned char *’
   42 | int MD5_Final(unsigned char *md, MD5_CTX *c);
      |               ~~~~~~~~~~~~~~~^~
exploit2.c:924:10: warning: passing argument 1 of ‘memcpy’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  924 |   memcpy(p, rec, rec_len);
      |          ^
In file included from exploit2.c:17:
/usr/include/string.h:43:14: note: expected ‘void * restrict’ but argument is of type ‘const unsigned char *’
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,
      |              ^~~~~~
exploit2.c:931:10: warning: passing argument 1 of ‘memcpy’ discards ‘const’ qualifier from pointer target type [-Wdiscarded-qualifiers]
  931 |   memcpy(p, rec, rec_len);
      |          ^
In file included from exploit2.c:17:
/usr/include/string.h:43:14: note: expected ‘void * restrict’ but argument is of type ‘const unsigned char *’
   43 | extern void *memcpy (void *__restrict __dest, const void *__restrict __src,

Any help would be greatly appreciated.

  • 2
    In the case of `memcpy` the destination cannot be `const` because it is protected from writing. – Weather Vane Feb 21 '20 at 19:32
  • It looks like you are trying to compile code that tries to do illegal things (to break something, as the "exploit" name gives away). It might have been written with a more permissive compiler in mind (how old is that code?), or the code it is trying to break has been fixed in the meantime. And yes, you won't understand many of the detailed error messages of your compiler without solid understanding of C. Look for tutorials. Check out e.g. [this tutorial](https://www.cprogramming.com/tutorial/c-tutorial.html) – vonbrand Feb 21 '20 at 21:40
  • Please provide files that you changed the code from. – Cahit Gungor Feb 21 '20 at 21:41
  • I'm compiling this within Kali Linux in my home lab network attacking the vulnhub box Kioptrix1 to practice for the OSCP. Nothing illegal, but I understand the concern. Thanks for the tutorial! I'm away for the weekend and will post the code if Reinier's suggestion doesn't work. – Craig Bartoshesky Feb 22 '20 at 20:50

1 Answers1

0

It seems like you have made a mistake when applying Step 3 Insert “const”

// unsigned char *p, *end;
const unsigned char *p, *end;

The code contains declarations of unsigned char *p in three different places and you modified the wrong one to be const, with the errors and warnings that you showed as the consequence. Only the one in the function get_server_hello() should be changed.

By the way, At the top of 764 it says there is an update to it, 47080. The latter has all the modifications (and more) applied already and builds fine with OpenSSL 1.1.1d.

Reinier Torenbeek
  • 16,669
  • 7
  • 46
  • 69