'net/ftp': Uncontrolled Resource Consumption (Memory/CPU)
The FTP time-value parser in Ruby's net/ftp library multiplies a user-supplied fractional-seconds string by a power of ten without bounding its length, so a malicious FTP server can send a timestamp with an enormous fractional part. This causes the client process to consume large amounts of memory and CPU, leading to denial of service.
- Triaged in 14 hours
- Disclosed after 6 days
Current TIME_PARSER implementation allows attackers to cause a denial of service (memory consumption) via a large integer value for the fractions property.
The problem code:
TIME_PARSER = ->(value, local = false) {
unless /\A(?<year>\d{4})(?<month>\d{2})(?<day>\d{2})
(?<hour>\d{2})(?<min>\d{2})(?<sec>\d{2})
(?:\.(?<fractions>\d+))?/x =~ value
raise FTPProtoError, "invalid time-val: #{value}"
end
usec = fractions.to_i * 10 ** (6 - fractions.to_s.size)
Time.public_send(local ? :local : :utc, year, month, day, hour, min, sec, usec)
}
PoC
For example, a ran a malicious server that returns "213 20371231000000.".("9"x999999999)."\r\n" for commands that use TIME_PARSER (mlst, mlsd, mdtm, etc). Also, such a response can be spoofed if the attacker is on the same network as the victim.
Here is the result of running of the process for an hour and a half:
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
18644 me 20 0 27.9g 12.3g 64 D 100.0 84.0 89:17.45 ruby
The process kept the CPU load around 90-100% all the time, and slowly but surely, devour all the available memory.
Impact
Denial of Service.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the parser converts an unbounded fractional-seconds string to an integer and raises ten to a power derived from its length, without limiting the input size.
Impact
A malicious or spoofed FTP server can cause the client process to consume memory and CPU until it becomes unusable, resulting in denial of service.
What the attacker needed
Victim connects to a malicious FTP server; attacker on same network can spoof replies
How it was found
- Run a malicious FTP server that replies to commands using the time parser (such as mlst, mlsd or mdtm) with a timestamp containing a very long fractional part.
- Connect a client using net/ftp to that server and issue one of those commands.
- Observe the client process consuming high CPU and steadily growing memory.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
When a program reads a date from a server, it normally expects a short string like a few digits after a dot. Here the program takes whatever number of digits the server sends and does maths on it, so a server can send a huge string of digits and make the program work very hard and use lots of memory. That can freeze or crash the program, which is called a denial of service.
What is DoS?
A request that exhausts resources or crashes a component. Many programs forbid testing it; reports usually show it from code, not by attacking.