How to get the real file type for images that do not have an extension

I think, you can not exactly determine, but you can assume one with header data.

$headers = wp_get_http_headers( $url );
$mime_type = $headers['content-type'];
$ext="";
foreach ( wp_get_mime_types() as $exts => $mime ) {
    if ( $mime == $mime_type ) {
        $ext = $exts;
        break;
    }
}

Now in the $ext variable, it could be multiple extensions that have been matched, and there’s no way to determine which one the image actually have. But, you could try the first one.

if( $ext ){
    $exts = explode('|', $ext);
    $ext = $exts[0];
}