Although the dynamic linker allows to reach for the symbols defined in plugin, recovering plugin metadata is somewhat complicated, as (due to historical reasons) C does not mangle symbol names. Thus, the usual approach is to make both the core program and plugins include the same header, defining an interaction api.
hello_plugin.h
, defining structure struct plugin_info
.
Have the structure define attributes:const char *name
,uint32_t version
.hello_plugin_info
, with attributes set to plugin's name and version defined as reference to macro constant VERSION.-Wl,-soname,GLOBALLY_UNIQUE_VALUE
).hello.c
, that will try to dlopen()
the 3 plugins one-by-one and print plugin name and version.objdump -x
and explain how did the global variable in plugin got it's value, given the section it resides in.plugin_info
a function returning the requested info through value.A crutial task in cryptography is to generate sufficient random numbers.
rand()
and after first 10
invokations starts returning always 9 as guaranteed by fair dice roll.malicious.so
.LD_PRELOAD=malicious.so ssh-keygen -f malicious_id_rsa
.
Pay attention to the image output, does it show the expected output?nm
, objdump -x
, gdb
.