Author Topic: Server Error Reports  (Read 777742 times)

0 Members and 2 Guests are viewing this topic.

Offline magic

  • Super Contributor
  • ***
  • Posts: 7242
  • Country: pl
Re: Server Error Reports
« Reply #325 on: September 01, 2020, 06:25:36 am »
Hmm, I found this, which suggests that thumbnails are core SMF functionality. I have no idea, never administrated SMF myself.
https://wiki.simplemachines.org/smf/SMF2.0:Attachments_and_Avatars

RCE could possibly be an option if it's some old lousy C program which generates those thumbnails. If they actually wrote their own PHP scripts to parse those PNGs then maybe not. Again, no idea how they actually do it.
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 7242
  • Country: pl
Re: Server Error Reports
« Reply #326 on: September 01, 2020, 06:40:37 am »
Isn't this the culprit?
https://github.com/SimpleMachines/SMF2.1/blob/release-2.1/Sources/Subs-Graphics.php#L395

It seems to use one of three libraries, depending on availability. I suppose you could see if installing a different backend solves it, or file a bug with the backend's vendor. I'm not sure if I would want to run remotely executable C binary which can't even recognize that it's being fed a BMP instead of PNG and tries to process it instead of bailing out.

Or maybe the backend does bail out and SMF goes nuts? Then it would be an SMF bug.
 

Offline gnifTopic starter

  • Administrator
  • *****
  • Posts: 1707
  • Country: au
  • Views and opinions are my own
    • AMD
Re: Server Error Reports
« Reply #327 on: September 01, 2020, 06:47:12 am »
It needs to be fixed in SMF, it just hands everything to `imagecreatefrom` based on the extension.

```
Code: [Select]
        // A known and supported format?
        if (isset($default_formats[$sizes[2]]) && function_exists('imagecreatefrom' . $default_formats[$sizes[2]]))
        {
                $imagecreatefrom = 'imagecreatefrom' . $default_formats[$sizes[2]];
                if ($src_img = $imagecreatefrom($destination))
                {
                        resizeImage($src_img, $destination, imagesx($src_img), imagesy($src_img), $max_width === null ? imagesx($src_img) : $max_width, $max_height === null ? imagesy($src_img) : $max_height, true, $preferred_format);
                        $success = true;
                }
        }

This will call `imagecreatefrom` + extension, ie `imagecreatefrompng` with invalid data. It's just plain dumb. Tell a library that this is a PNG and hand it something else, expect things to break.

The solution here is to actually open the file and read the header to determine it's type. I am in the middle of writing a fix in now :)
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 7242
  • Country: pl
Re: Server Error Reports
« Reply #328 on: September 01, 2020, 07:02:08 am »
And what if I take a BMP file and patch the PNG magic number into it? :P
Calling wrong function is one thing, the library being rubbish and failing to sanitize untrusted input is another :scared:
 

Offline gnifTopic starter

  • Administrator
  • *****
  • Posts: 1707
  • Country: au
  • Views and opinions are my own
    • AMD
Re: Server Error Reports
« Reply #329 on: September 01, 2020, 07:10:55 am »
That's just it, the library is not failing, it's doing exactly what it's supposed to. The issue is that it's slow at it, and consumes a ton of ram, hitting the PHP limits and it gets terminated.
A highly compressed PNG with large dimensions will do exactly the same thing.

> And what if I take a BMP file and patch the PNG magic number into it?

gd will bomb out and stop, the issue is that GD can and will load a BMP as it's a generic image processing library that PHP wraps.

At it's core, the issue is SMF's poor design, image thumbnail generation should be a background task done by the server, NOT as part of a HTTP request.
 
The following users thanked this post: mnementh

Offline magic

  • Super Contributor
  • ***
  • Posts: 7242
  • Country: pl
Re: Server Error Reports
« Reply #330 on: September 01, 2020, 07:22:26 am »
This function should return an error when it's presented with a BMP file, not eat RAM like crazy. A BMP is not a highly compressed PNG.

the issue is that GD can and will load a BMP as it's a generic image processing library that PHP wraps
Does that mean that uploading the very same BMP with BMP extension causes the same problem?
Because if not, that's still a bug in libgd's PNG loader, rather than any problem with BMPs.
 

Offline gnifTopic starter

  • Administrator
  • *****
  • Posts: 1707
  • Country: au
  • Views and opinions are my own
    • AMD
Re: Server Error Reports
« Reply #331 on: September 01, 2020, 07:28:38 am »
>Does that mean that uploading the very same BMP with BMP extension causes the same problem?
>Because if not, that's still a bug in libgd's PNG loader, rather than any problem with BMPs.

No idea, feel free to debug this and chase it with them. Simple fact of the matter is, we need a fix now. Fixing this issue is already well beyond the scope of the services I render for dave as it is.
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23096
  • Country: gb
Re: Server Error Reports
« Reply #332 on: September 01, 2020, 09:29:51 am »
It's definitely libgd's fault. A DoS attack from malformed input is definitely CVE-worthy. It should return E_WHAT_THE_FUCK_DID_YOU_GIVE_ME error or something if it can't parse the file.

Workaround....

Assumption: this is a FPM process or something running with nginx in front of it. Issue is memory ballooning

1. Set proper memory limits in systemd for the FPM process. See: https://www.freedesktop.org/software/systemd/man/systemd.exec.html#LimitCPU=
2. Set systemd to auto restart the FPM process: Restart=always
3 (optional but recommended): run more than one FPM instance and use nginx as a balancer so that if one fails there's more left.

This will mean if it does crash or start gobbling RAM it'll restart.

Edit: can someone send me the file? I'll create a marketing web site for it "phpb0rk" and make £50k from selling it to some terrorists in NK  :-DD :-DD
« Last Edit: September 01, 2020, 09:32:13 am by bd139 »
 

Offline gnifTopic starter

  • Administrator
  • *****
  • Posts: 1707
  • Country: au
  • Views and opinions are my own
    • AMD
Re: Server Error Reports
« Reply #333 on: September 01, 2020, 09:32:37 am »
Quote
This will mean if it does crash or start gobbling RAM it'll restart.

Why do you think the site didn't die? Solutions/protections for these issues are already in place. It doesn't however stop a bunch of people consuming all available PHP processes because of a "slow page load" hitting refresh.
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23096
  • Country: gb
Re: Server Error Reports
« Reply #334 on: September 01, 2020, 09:39:40 am »
Well it's hard to debug from the outside. I'm pissing in the dark here :-DD

Add more cycles is about all you can do then.
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 7242
  • Country: pl
Re: Server Error Reports
« Reply #335 on: September 01, 2020, 09:55:53 am »
I did a quick test on a Debian 10 system with PHP 7.3.19. Not sure how to test libdg version, I don't have root on that box and can't find a file like that in /usr/lib.

Code: [Select]
<?php
$i
=imagecreatefrompng("test.bmp");
for(;;);
?>

PHP Warning:  imagecreatefrompng(): 'test.bmp' is not a valid PNG file in
Standard input code on line 2
^C
Memory usage didn't increase at all after hitting CTRL+D to execute the typed code. Maybe I need some special BMP file, maybe it's fixed in this version.
Memory usage did increase a few megs if I used frombmp instead or converted the file to PNG.

So dunno, check if everything is up to date and pray that there are no serious vulns in there, I guess.
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23096
  • Country: gb
Re: Server Error Reports
« Reply #336 on: September 01, 2020, 10:01:03 am »
It's probably a broken BMP file that just happens to skip whatever validation is. It might even be intentionally malformed. I hope your FPM is running as an unprivileged process  :popcorn:

To note libgd has a hell of a lot of CVEs against it which are similar: https://www.cvedetails.com/vulnerability-list/vendor_id-6668/Libgd.html
 

Offline magic

  • Super Contributor
  • ***
  • Posts: 7242
  • Country: pl
Re: Server Error Reports
« Reply #337 on: September 01, 2020, 10:02:21 am »
Well, I could try to upload my test.bmp here as killeevblog.png and see what happens :-DD
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23096
  • Country: gb
Re: Server Error Reports
« Reply #338 on: September 01, 2020, 10:06:16 am »
 :-DD

Really to debug this we'd need:

1. PFP FPM version
2. OS version
3. Libgd version
4. Exploding BMP of doom.
5. Probably about 3 hours of pain

 

Offline gnifTopic starter

  • Administrator
  • *****
  • Posts: 1707
  • Country: au
  • Views and opinions are my own
    • AMD
Re: Server Error Reports
« Reply #339 on: September 01, 2020, 10:11:56 am »
Quote
1. PFP FPM version
2. OS version
3. Libgd version
4. Exploding BMP of doom.
5. Probably about 3 hours of pain

Not going to happen for obvious reasons.

Please though stop posting about this here as this topic is special and I am alerted to responses to this topic. It's intended for actual outage reports.
 
The following users thanked this post: bd139

Offline mansaxel

  • Super Contributor
  • ***
  • Posts: 3558
  • Country: se
  • SA0XLR
    • My very static home page
Re: Server Error Reports
« Reply #340 on: September 01, 2020, 10:45:57 am »
Yup,

Issue fixed, another windows bitmap uploaded with a png extension. SMF goes nuts trying to load it and just hangs consuming tons of RAM.

Code: [Select]
FILE(1)                   BSD General Commands Manual                  FILE(1)

NAME
     file -- determine file type

<snip>

     The magic tests are used to check for files with data in particular fixed
     formats.  The canonical example of this is a binary executable (compiled
     program) a.out file, whose format is defined in <elf.h>, <a.out.h> and pos-
     sibly <exec.h> in the standard include directory.  These files have a
     ``magic number'' stored in a particular place near the beginning of the file
     that tells the UNIX operating system that the file is a binary executable,
     and which of several types thereof.  The concept of a ``magic'' has been
     applied by extension to data files.  Any file with some invariant identifier
     at a small fixed offset into the file can usually be described in this way.
     The information identifying these files is read from the compiled magic file
     /usr/share/file/magic.mgc, or the files in the directory
     /usr/share/file/magic if the compiled file does not exist.

<snip>

HISTORY
     There has been a file command in every UNIX since at least Research Version
     4 (man page dated November, 1973). 


Why does SMF degrade itself to using MS-DOS heuristics, when this is and has been available for some time?

Offline joeqsmith

  • Super Contributor
  • ***
  • Posts: 11940
  • Country: us
Re: Server Error Reports
« Reply #341 on: November 14, 2020, 11:46:41 pm »
In the last few days I have notices that some PNG files captured with snippet fail security.  It seems to be hit and miss.   


Offline jchw4

  • Regular Contributor
  • *
  • Posts: 204
  • Country: 00
Re: Server Error Reports
« Reply #342 on: November 22, 2020, 09:33:14 am »
One of my JPGs failed security test too.
Could somebody explain what it means?

Upd: It's interesting that recoding it into .png did not help.

Upd1: Switching off "Progressive JPEG" option did help  :)
« Last Edit: November 22, 2020, 09:39:35 am by jchw4 »
 

Offline McBryce

  • Super Contributor
  • ***
  • Posts: 2713
  • Country: de
Re: Server Error Reports
« Reply #343 on: November 22, 2020, 10:54:14 am »
I've found that all pictures saved with the 64bit version of irfanview fail, but if I save them using Photoshop or MSPaint they get through.

McBryce.
30 Years making cars more difficult to repair.
 

Offline SilverSolder

  • Super Contributor
  • ***
  • Posts: 6126
  • Country: 00
Re: Server Error Reports
« Reply #344 on: November 22, 2020, 01:46:57 pm »

Just wait till the security software gets smart enough to actually look at the pictures!  :D
 

Offline Yansi

  • Super Contributor
  • ***
  • Posts: 3893
  • Country: 00
  • STM32, STM8, AVR, 8051
Re: Server Error Reports
« Reply #345 on: November 22, 2020, 04:27:10 pm »
Just wanted to let you know and confirm the above, there seems to be a bug in the "attachment security check", as now out of nowhere, some JPG files seems to be failing the check. And nothing has changed on my software side of things for years, I still use the same software to process JPG (or any) mages. Yet now they seem to fail randomly. And I am pretty sure, the file is clean of any kind of malicious sh!t.
 

Offline McBryce

  • Super Contributor
  • ***
  • Posts: 2713
  • Country: de
Re: Server Error Reports
« Reply #346 on: November 22, 2020, 05:40:45 pm »
Yes, but it's not just this forum. Other forums that use the same software are experiencing the same issue.

McBryce.
30 Years making cars more difficult to repair.
 

Online tggzzz

  • Super Contributor
  • ***
  • Posts: 20752
  • Country: gb
  • Numbers, not adjectives
    • Having fun doing more, with less
Re: Server Error Reports
« Reply #347 on: November 22, 2020, 06:12:58 pm »

Just wait till the security software gets smart enough to actually look at the pictures!  :D

I thought all that mattered was how much pink there is in the pictures.

Quote from: Terry Pratchett, The Colour of Magic
The box said, "It's no good. I've run out of pink."

A hitherto unnoticed door opened in front of his eyea. A small, green and hideously warty humanoid figure leaned out, pointed at a colour-encrusted palette in one clawed hand, and screamed at him.

"No pink, See?" screeched the homunculus."No good you going on pressing the lever when there's no pink, is there? If you wanted pink you shouldn't of took all those pictures of young ladies, should you? It's monochrome from now on, friend. Alright?"
There are lies, damned lies, statistics - and ADC/DAC specs.
Glider pilot's aphorism: "there is no substitute for span". Retort: "There is a substitute: skill+imagination. But you can buy span".
Having fun doing more, with less
 

Offline bd139

  • Super Contributor
  • ***
  • Posts: 23096
  • Country: gb
Re: Server Error Reports
« Reply #348 on: November 22, 2020, 06:15:44 pm »

People will just upload smurf porn instead.
 
The following users thanked this post: mnementh

Offline StillTrying

  • Super Contributor
  • ***
  • Posts: 2850
  • Country: se
  • Country: Broken Britain
Re: Server Error Reports
« Reply #349 on: December 21, 2020, 05:36:11 pm »
Login password failed twice, even though I'd made the characters visible. :-//

Checked there were only the two failed login emails, came back and then the same EEV password worked. :-//

Is it just me. :)
.  That took much longer than I thought it would.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf