sslopensslhandshakeheartbleed-bugafl-fuzz

Trying to recreate Heatbleed with AFL-FUZZ using OpenSSL 1.0.1f


I am here trying to recreate Heartbleed bug on openssl versions prior to 1.0.1g, so I selected openssl 1.0.1f. I installed AFL-FUZZ and then openssl. With help of this and this link I think I have installed openssl but in end it gave me a strange error

../libcrypto.a(x86_64cpuid.o): In function `OPENSSL_cleanse':
(.text+0x1a0): multiple definition of `OPENSSL_cleanse'
../libcrypto.a(mem_clr.o):mem_clr.c:(.text+0x0): first defined here
../libcrypto.a(cmll-x86_64.o): In function `Camellia_cbc_encrypt':
(.text+0x1f00): multiple definition of `Camellia_cbc_encrypt'
../libcrypto.a(cmll_cbc.o):cmll_cbc.c:(.text+0x0): first defined here
../libcrypto.a(aes-x86_64.o): In function `AES_encrypt':
(.text+0x460): multiple definition of `AES_encrypt'
../libcrypto.a(aes_core.o):aes_core.c:(.text+0x62e): first defined here
../libcrypto.a(aes-x86_64.o): In function `AES_decrypt':
(.text+0x9f0): multiple definition of `AES_decrypt'
../libcrypto.a(aes_core.o):aes_core.c:(.text+0xad1): first defined here
../libcrypto.a(aes-x86_64.o): In function `private_AES_set_encrypt_key':
(.text+0xab0): multiple definition of `private_AES_set_encrypt_key'
../libcrypto.a(aes_core.o):aes_core.c:(.text+0x0): first defined here
../libcrypto.a(aes-x86_64.o): In function `private_AES_set_decrypt_key':
(.text+0xd80): multiple definition of `private_AES_set_decrypt_key'
../libcrypto.a(aes_core.o):aes_core.c:(.text+0x403): first defined here
../libcrypto.a(aes-x86_64.o): In function `AES_cbc_encrypt':
(.text+0xfa0): multiple definition of `AES_cbc_encrypt'
../libcrypto.a(aes_cbc.o):aes_cbc.c:(.text+0x0): first defined here
collect2: error: ld returned 1 exit status
make[2]: *** [link_app.] Error 1

I ran openssl version command and it ran successfully giving me output OpenSSL 1.0.1f 6 Jan 2014 so I considered it has been installed properly (not sure about what to do with errors).

Now next step is to simply find a code to use openssl which I found here handshake.c file. However it is not compiling successfully. afl-gcc handshake.c libssl.a libcrypto.a -o handshake -I ssl/include -ldl and the error is

afl-cc 2.52b by <lcamtuf@google.com>
afl-as 2.52b by <lcamtuf@google.com>
[+] Instrumented 15 locations (64-bit, non-hardened mode, ratio 100%).
libcrypto.a(x86_64cpuid.o): In function `OPENSSL_cleanse':
(.text+0x1a0): multiple definition of `OPENSSL_cleanse'
libcrypto.a(mem_clr.o):mem_clr.c:(.text+0x0): first defined here
/tmp/ccJeYtnW.o: In function `Init':
path/openssl-1.0.1/handshake.c:22: undefined reference to `SSL_CTX_set_security_level'
libcrypto.a(c_zlib.o): In function `zlib_stateful_expand_block':
c_zlib.c:(.text+0x59): undefined reference to `inflate'
libcrypto.a(c_zlib.o): In function `zlib_stateful_compress_block':
c_zlib.c:(.text+0xea): undefined reference to `deflate'
libcrypto.a(c_zlib.o): In function `bio_zlib_free':
c_zlib.c:(.text+0x13d): undefined reference to `inflateEnd'
c_zlib.c:(.text+0x15b): undefined reference to `deflateEnd'
libcrypto.a(c_zlib.o): In function `zlib_stateful_finish':
c_zlib.c:(.text+0x1d0): undefined reference to `inflateEnd'
c_zlib.c:(.text+0x1d9): undefined reference to `deflateEnd'
libcrypto.a(c_zlib.o): In function `zlib_stateful_init':
c_zlib.c:(.text+0x268): undefined reference to `inflateInit_'
c_zlib.c:(.text+0x2d9): undefined reference to `deflateInit_'
libcrypto.a(c_zlib.o): In function `bio_zlib_ctrl':
c_zlib.c:(.text+0x54c): undefined reference to `deflate'
c_zlib.c:(.text+0x5f0): undefined reference to `zError'
libcrypto.a(c_zlib.o): In function `bio_zlib_write':
c_zlib.c:(.text+0x809): undefined reference to `deflate'
c_zlib.c:(.text+0x89a): undefined reference to `zError'
c_zlib.c:(.text+0x933): undefined reference to `deflateInit_'
libcrypto.a(c_zlib.o): In function `bio_zlib_read':
c_zlib.c:(.text+0xa13): undefined reference to `inflate'
c_zlib.c:(.text+0xa8d): undefined reference to `zError'
c_zlib.c:(.text+0xafc): undefined reference to `inflateInit_'
collect2: error: ld returned 1 exit status

Please suggest how can I fix these errors.

Thanks in advance.

EDIT:

So what I done so far is install openssl with root privileges. I worked but gave me so many errors regarding manual installation i.e. mostly errors looked like item= expecting something other than a integer. I manually changed these lines to character, =item 1 -> =item '1'. After changes in apps and ssl folder of root directory, I finally made it work. The final installtion looks like after make and make install

installing openssl
installing CA.sh
installing CA.pl
installing tsget
make[1]: Leaving directory `/openssl-1.0.1f/apps'
making install in test...
make[1]: Entering directory `/openssl-1.0.1f/test'
make[1]: Nothing to be done for `install'.
make[1]: Leaving directory `/openssl-1.0.1f/test'
making install in tools...
make[1]: Entering directory `/openssl-1.0.1f/tools'
make[1]: Leaving directory `/openssl-1.0.1f/tools'
installing libcrypto.a
installing libssl.a
cp libcrypto.pc /usr/local/ssl/lib/pkgconfig
chmod 644 /usr/local/ssl/lib/pkgconfig/libcrypto.pc
cp libssl.pc /usr/local/ssl/lib/pkgconfig
chmod 644 /usr/local/ssl/lib/pkgconfig/libssl.pc
cp openssl.pc /usr/local/ssl/lib/pkgconfig
chmod 644 /usr/local/ssl/lib/pkgconfig/openssl.pc
root@ubuntu:/openssl-1.0.1f# openssl
The program 'openssl' is currently not installed. You can install it by   typing:
apt-get install openssl

Now I think installation went without errors but still I dont have yet openssl installed as it says no such package is installed yet.

Please help.


Solution

  • As I have added in Edited post, errors in openssl installation went away when I ran installation as root. I used sequence of following commands;

    make clean
    ./config no-shared no-idea no-mdc2 no-rc5 zlib enable-tlsext
    make depend
    make && make install
    

    As discussed above in Edited version of question, it gave me errors in .pod files which I resolved one by one (would like to know if anyone has any smarter approach).

    After compilation, now the error remained as in edited part which was instantly resolved after adding openssl installation path to $PATH environment variable. I added below line to .basrc and .profile files.

    export PATH="$PATH:/usr/local/ssl/bin" 
    

    Now openssl works fine.

    However compilation of handshake.c with openssl goes with this command

    AFL_USE_ASAN=1 afl-gcc handshake.c -lcrypto -lz libssl.a  -o handshake -ldl
    

    Lastly

    afl-fuzz -i testcases -o findings -m none -- ./handshake
    

    Hope this will help future googlers.

    Thanks.