Live data from Hacker News

Python 3.x: RCE in Python applications that accept floats as untrusted input

cve.mitre.org

51–60 of 72 posts

Re: Python 3.x: RCE in Python applications that accept floats as untrusted input

#51

I'd be extremely impressed if someone actually managed to get RCE out of this, considering you'd only be able to use '0' through '9', or 0x30 through 0x39, in your payload.

It sounds like an extreme minimal instruction set computer (MISC), and it's surprising how much is possible with even just one or two opcodes - that can easily be Turing-complete

Re: Python 3.x: RCE in Python applications that accept floats as untrusted input

#52
post #22

Earlier quoted context omitted.

“You would think converting floats to and from strings was a solved problem by now” It is, but it is an extremely difficult problem. I think “How to print floating-point numbers accurately” ( https://dl.acm.org/doi/10.1145/93548.93559 ) was the first correct implementation. That is from 1990 and, according to its authors “was almost 20 years in the making” ( http://kurtstephens.com/files/p372-steele.pdf ) (Faster ver…

...or at least knowing how long the result would be?

That, of course, is easier, but you have to realize that %f never uses scientific notation for its output (something I must have known at some time, but if you had asked, I would have had to google it), and that DBL_MAX has a lot of digits (it is about 1.8 × 10^308)

I think it is unfortunately that %f, the easiest to remember type field for floating point number, is used for this behavior. Most of the time, you’ll want to use %g, which uses scientific notation if it is shorter.

I guess linters should warn about bare %f without length fields.

Re: Python 3.x: RCE in Python applications that accept floats as untrusted input

#53
post #50

We need to delete 'sprintf' forever.

Deleting sprintf by itself wouldn't work, even the "safe" replacement functions rely on the developer providing the safety information manually. C needs a string type. Sadly large parts of the C standard are build around turning plain character arrays into exploits by pretending that they are a sane choice for string manipulation.

asprintf is fine for most cases. For the other cases you probably don't want to dynamically allocate memory so snprintf with a fixed buffer size is fine.

Re: Python 3.x: RCE in Python applications that accept floats as untrusted input

#54

Extremely misleading title. This only affects code that puts untrusted floats into ctypes. An relatively very uncommon case. Please stop the clickbait!

Why the downvotes? CyberRabbi is correct. The title makes it sound like all programs that accept floats from untrusted input are vulnerable.

Re: Python 3.x: RCE in Python applications that accept floats as untrusted input

#55
post #26

Earlier quoted context omitted.

What's the one that also includes Microsoft? FANMAG? I recall there was something but can't remember what...

IIRC that would be FAMANG, but I like FanMag.

I prefer the Spoonerism but I don't think it'll take off

Re: Python 3.x: RCE in Python applications that accept floats as untrusted input

#56

Minimal example: >>> import ctypes >>> x = ctypes.c_double.from_param(1e300) >>> repr(x) Segmentation fault This happens when getting the string representation of a foreign function float. It doesn't affect the standard builtin float type. So it's not extremely common. But I can imagine this cropping up if you e.g. find a way to cause an exception that formats a value. Or if there's aggressive logging.

FWIW this also crashes Python 2.7 on macOS Catalina.

Python 2 is EOL

Re: Python 3.x: RCE in Python applications that accept floats as untrusted input

#57

Minimal example: >>> import ctypes >>> x = ctypes.c_double.from_param(1e300) >>> repr(x) Segmentation fault This happens when getting the string representation of a foreign function float. It doesn't affect the standard builtin float type. So it's not extremely common. But I can imagine this cropping up if you e.g. find a way to cause an exception that formats a value. Or if there's aggressive logging.

For Fedora 32 and 33 it seems to be already fixed:

    >>> repr(x)
    ""

Re: Python 3.x: RCE in Python applications that accept floats as untrusted input

#58
post #26

Earlier quoted context omitted.

What's the one that also includes Microsoft? FANMAG? I recall there was something but can't remember what...

IIRC that would be FAMANG, but I like FanMag.

There are other more offensive anagrams I've seen used...

Re: Python 3.x: RCE in Python applications that accept floats as untrusted input

#59

Minimal example: >>> import ctypes >>> x = ctypes.c_double.from_param(1e300) >>> repr(x) Segmentation fault This happens when getting the string representation of a foreign function float. It doesn't affect the standard builtin float type. So it's not extremely common. But I can imagine this cropping up if you e.g. find a way to cause an exception that formats a value. Or if there's aggressive logging.

FWIW this also crashes Python 2.7 on macOS Catalina.

Python 3.6 is the oldest maintained version.

Re: Python 3.x: RCE in Python applications that accept floats as untrusted input

#60
post #50

We need to delete 'sprintf' forever.

Deleting sprintf by itself wouldn't work, even the "safe" replacement functions rely on the developer providing the safety information manually. C needs a string type. Sadly large parts of the C standard are build around turning plain character arrays into exploits by pretending that they are a sane choice for string manipulation.

That is why I use Pascal and never had a safety problem when processing strings. It is completely baffling that people still use C in production

Only issue is that the default string type requires heap allocations

Post reply on HN