Exploit databaseDownload repository ZIP
GH-05cf3ce8b766a1bf27bf9a3c64392d57
0xxon/cve-2020-0601-utils
Sources for CVE-2020-0601
29 sourcesPreferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source
Repository files12
0xxon/cve-2020-0601-utilsRevision dced9cce3b3b
- cppcodec/
- examples/
- fast-hex/
- tools/
- .gitignore
- LICENSE
- Makefile
- certificates
- certificates.hex
- checkCerts.cc
- checkCerts.hex.cc
- openssl_curves.c
Files from this repository share one source choice. Supporting files may cover other vulnerabilities.
checkCerts.hex.cc
Text · 3,205 bytes// See the file "COPYING" in the main distribution directory for copyright.
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cstring>
#include "fast-hex/hex.h"
extern "C" {
#include <unistd.h>
#include <openssl/x509.h>
#include <openssl/x509v3.h>
#include <openssl/asn1.h>
#include <openssl/opensslconf.h>
#include <openssl/err.h>
#include <openssl/sha.h>
#include "openssl_curves.c"
}
std::string toHex(const std::string& s, bool upper_case = false) {
std::ostringstream ret;
for (std::string::size_type i = 0; i < s.length(); ++i) {
uint8_t p = s[i];
ret << std::hex << std::setfill('0') << std::setw(2) << (upper_case ? std::uppercase : std::nouppercase) << (int)p;
}
return ret.str();
}
template <typename T>
std::string sha256(T from) {
unsigned char* out = SHA256(reinterpret_cast<const unsigned char*>(&from[0]), from.size(), nullptr);
std::string outstr(reinterpret_cast<const char*>(out), 32);
return outstr;
}
template <typename T>
std::string sha1(T from) {
unsigned char* out = SHA1(reinterpret_cast<const unsigned char*>(&from[0]), from.size(), nullptr);
std::string outstr(reinterpret_cast<const char*>(out), 20);
return outstr;
}
int parseCert(X509* cert) {
EVP_PKEY *pkey = X509_extract_key(cert);
if ( ! pkey )
return -3;
if ( EVP_PKEY_base_id(pkey) == EVP_PKEY_EC ) {
const EC_GROUP *group;
if ( (group = EC_KEY_get0_group(EVP_PKEY_get0_EC_KEY(pkey))) == NULL )
// I guess we could not parse this
return -4;
auto ctx = BN_CTX_new();
auto ret = ec_curve_nid_from_params(group, ctx);
BN_CTX_free(ctx);
return ret;
}
return -5;
}
int main(int argc, char** argv) {
if ( argc != 2 ) {
std::cerr << "Expecting 1 argument: input file-name" << std::endl;
exit(-1);
}
std::string infile = argv[1];
std::ifstream ifs(infile);
std::ofstream out;
std::string line;
auto pid = getpid();
if ( !ifs && infile != "-" ) {
std::cerr << "Could not open source certificate file \"certificates\"" << std::endl;
return -1;
}
std::istream& in = ifs ? ifs : std::cin;
while ( std::getline(in, line) ) {
auto tab = line.find("\t");
if ( tab == std::string::npos )
tab = line.size();
if ( tab % 2 != 0 ) {
std::cerr << "Invalid length " << tab << " for line " << line;
continue;
}
std::string decoded(tab/2, '\0');
decodeHexLUT(reinterpret_cast<unsigned char*>(&decoded[0]), reinterpret_cast<const unsigned char*>(line.data()), tab/2);
const unsigned char* cert_char = reinterpret_cast<const unsigned char*>(&decoded[0]);
int ret = 0;
X509* cert = d2i_X509(nullptr, &cert_char, tab/2);
if ( ! cert )
ret = -2;
else
ret = parseCert(cert);
if ( ret == 0 || ret == -1 || ret == -4 ) {
// 0 is the actual interesting ones - the other 2 are kind of just in case...
if ( ! out.is_open() ) {
out.open(infile + ".cve-2020-0601." + std::to_string(pid) + ".out");
if ( ! out.is_open() ) {
std::cerr << "cannot open output file" << std::endl;
exit(-1);
}
}
out << ret << "\t" << line << std::endl;
}
//std::cout << ret << std::endl;
X509_free(cert);
}
std::cerr << "Done" << std::endl;
if ( ifs )
ifs.close();
return 0;
}