slimm609/checksec.sh

Duplicate keys in json

Artoria2e5 opened this issue · 1 comments

checksec --output=json --fortify-file=/bin/bash gives a json with duplicate keys

{
  "fortify-test": {
    "name": "/bin/bash",
    "libc_fortify_source": "yes",
    "binary_compiled_with_fortify": "yes",
    "function": { "name": "asprintf_chk", "libc": "asprintf", "fortifiable": "no" },
    "function": { "name": "confstr", "libc": "confstr", "fortifiable": "yes" },
    "function": { "name": "fdelt_chk", "libc": "fdelt", "fortifiable": "no" },
    "function": { "name": "fgets", "libc": "fgets", "fortifiable": "yes" },
    "function": { "name": "fprintf_chk", "libc": "fprintf", "fortifiable": "no" },
    "function": { "name": "getcwd", "libc": "getcwd", "fortifiable": "yes" },
    "function": { "name": "getgroups", "libc": "getgroups", "fortifiable": "yes" },
    "function": { "name": "gethostname", "libc": "gethostname", "fortifiable": "yes" },
    "function": { "name": "longjmp_chk", "libc": "longjmp", "fortifiable": "no" },
    "function": { "name": "mbsnrtowcs", "libc": "mbsnrtowcs", "fortifiable": "yes" },
    "function": { "name": "mbsrtowcs", "libc": "mbsrtowcs", "fortifiable": "yes" },
    "function": { "name": "mbstowcs", "libc": "mbstowcs", "fortifiable": "yes" },
    "function": { "name": "memcpy", "libc": "memcpy", "fortifiable": "yes" },
    "function": { "name": "memcpy_chk", "libc": "memcpy", "fortifiable": "no" },
    "function": { "name": "memmove", "libc": "memmove", "fortifiable": "yes" },
    "function": { "name": "memmove_chk", "libc": "memmove", "fortifiable": "no" },
    "function": { "name": "memset", "libc": "memset", "fortifiable": "yes" },
    "function": { "name": "read", "libc": "read", "fortifiable": "yes" },
    "function": { "name": "readlink", "libc": "readlink", "fortifiable": "yes" },
    "function": { "name": "snprintf_chk", "libc": "snprintf", "fortifiable": "no" },
    "function": { "name": "sprintf_chk", "libc": "sprintf", "fortifiable": "no" },
    "function": { "name": "strcat", "libc": "strcat", "fortifiable": "yes" },
    "function": { "name": "strcpy", "libc": "strcpy", "fortifiable": "yes" },
    "function": { "name": "strcpy_chk", "libc": "strcpy", "fortifiable": "no" },
    "function": { "name": "strncpy", "libc": "strncpy", "fortifiable": "yes" },
    "function": { "name": "strncpy_chk", "libc": "strncpy", "fortifiable": "no" },
    "function": { "name": "vfprintf_chk", "libc": "vfprintf", "fortifiable": "no" },
    "function": { "name": "vsnprintf_chk", "libc": "vsnprintf", "fortifiable": "no" },
    "function": { "name": "wcrtomb", "libc": "wcrtomb", "fortifiable": "yes" },
    "function": { "name": "wcsrtombs", "libc": "wcsrtombs", "fortifiable": "yes" },
    "function": { "name": "wctomb", "libc": "wctomb", "fortifiable": "yes" },
    "stats": { "nb_libc_func": "79", "nb_total_func": "1899", "nb_fortifiable_func": "31", "nb_checked_func": "12", "nb_unchecked_func": "19" }
  }
}

The same will happen when you try to do multiple files, such as via --dir.

What are the problems?

  • "function" as aforementioned. We need to:
    • move the type marker from the key to inside the object when things can repeat. So instead of { "function": { ... } }, we simply have { "type": "function" }. But the stats don't need changing.
    • insert an array [ {...} , {...} ] around it (XML needs no such thing)
  • "nb_fortifiable_func" and "fortifiable" count different things. This affects XML too. Maybe rename "fortifiable" to "unchecked".

This will be resolved with the upcoming 3.0 release, which changes to golang and includes a json library to assist with formatting.