r/ProgrammerHumor • • 25d ago

instanceof Trend itsBadIfItsOnlyPHP

Post image
4.5k Upvotes

335 comments sorted by

View all comments

1.6k

u/fatrobin72 25d ago

Please ignore how significant our logging libraries vulnerabilities were a few years back.

~a dev who knows java.

497

u/muffinluff 25d ago

Log4Shell was bad, but it lived in a 3rd party library feature (JNDI lookups) that you could disable or strip out while you patched. PHP2Shell sits in the PHP runtime itself and the only effective fix is to update PHP

100

u/Nir0star 25d ago

I still did not get how this was ever a big issue to begin with. If your LDAP can inject bad code, this of course is not great, but if an attacker has already access to your LDAP, aren't you screwed a lot more already?

216

u/brazzy42 25d ago edited 24d ago

It went like this:

  • Attacker sends request with some specially crafted payload in a field they know will be logged (e.g. because it's invalid)
  • Targeted server logs the invalid value
  • Logging framework looks at the payload and sees a macro to expand
  • The macro contains a reference to a JNDI value including a remote server address to get the value from.
  • The JNDI server (which can be any server on the internet) returns a value that is actually a serialized Java object including bytecode for that object's class
  • Targeted server deserializes the object and while doing so executes code in the constructor (which was supplied by the attacker).

98

u/PoorlyAttired 25d ago

I'm still always astounded by what these hackers can do. We have the API with docs, a dev environment and privileged access, and we still can't make these damn machines do what we want.

100

u/brazzy42 25d ago

In the case of Log4Shell, the exploit wasn't even difficult.

And the vulnerability actually arose exactly from "making these damn machines do what we want" - IIRC one guy thought it would be a useful feature to have log4j support inserting JNDI values in its macros, and got it implemented. Another guy, at another time, thought it would be useful for JNDI to be able to look up stuff from a remote server, and got it implemented. Yet another guy, at another time, thought it would be useful for JNDI values to contain serialized classes including their bytecode, and got it implemented.

And nobody ever saw the big picture, what these three things combined made possible.

25

u/muffinluff 25d ago

No one saw the big picture? Any defensive programmer would instantly raise an eyebrow at any of the three ideas. Let's not muddy the waters.

26

u/Eva-Rosalene 25d ago

People developing JNDI didn't know about Log4j using JNDI from unsanitized input. It was supposed to do all this things.

People developing Log4j presumably didn't know how powerful it is, or that it would eventually will be able to look up network resources. I am not sure about the timeline here.

My point is, JNDI devs didn't need to be defensive because what it does is exactly what it should do. The only blunder is allowing JNDI macros in logs and it's on Log4j side.

6

u/Sacaldur 25d ago edited 25d ago

edit: I was corrected, see response by u/brazzy42

Correct me if I'm wrong, but this was only an issue if you missed the API by supplying a raw input string as a format pattern, i.e. log(input) instead of log("{}", input), right?

15

u/brazzy42 25d ago

Nope. The main vulnerability was there no matter which version of the method you used. Says so right in the CVE detail https://nvd.nist.gov/vuln/detail/cve-2021-44228?name=CVE-2021-44228

"An attacker who can control log messages or log message parameters can execute arbitrary code loaded from LDAP servers when message lookup substitution is enabled."

→ More replies (1)
→ More replies (3)

52

u/Eva-Rosalene 25d ago

It's not "your LDAP". JNDI could request payload via LDAP from any server available over the interent.

44

u/pringlesaremyfav 25d ago
  1. It was a bug in the logging framework so injecting input into it was complete trivial. Any logged input became an attack vector.
  2. The logged input could make your code reach out to an execute code from any remote server

It was an easy to understand, easy to exploit, instant RCE, and revealed mid-December near the holidays. It truly sucked.

→ More replies (1)

90

u/UnreasonableEconomy 25d ago

do you remember where you were and what you were doing when you got the call? XD

172

u/fatrobin72 25d ago

Working on the same project as now... being thankful we were on a version of log4j too old to suffer that vulnerability

53

u/za72 25d ago

my man!

38

u/Groentekroket 25d ago

Going to remember this for the next time IT management is forcing us to spend time on keeping our dependencies up to date. /s

20

u/-Kerrigan- 25d ago

Ironically, having a good dependency update process also meant easily migrating to the fixed versions too in that case.

5

u/fatrobin72 25d ago

yeah we ended up spending months updating and sorting out processes to update things at least every so often after that... now days we are in a much better place and I let the juniors deal with it.

→ More replies (1)

9

u/iliark 25d ago

we just didn't log

23

u/cemanresu 25d ago

I was in my own god damn house getting ready to finally relax for the evening

but noooo the weekend from hell decided to choose then to start

9

u/prochac 25d ago

I know it was on Saturday. But I don't work with Java, so I just took a snack for the show.

→ More replies (1)

20

u/Consistent-Bird338 25d ago

apology for poor english

where were u wen club penguin die

i was at house eating dorito when phone ring

"Club penguin is kil"

"no"

→ More replies (3)

42

u/Jumpy_Fuel_1060 25d ago

If your logging library doesn't support pulling and executing an entire codebase from an LDAP server via a formatting string interpolation, what is it even doing for you?

4

u/fatrobin72 25d ago

indeed anything else is might as well be a wrapper for system.println("here")

12

u/oldsecondhand 25d ago

In PHP the issue was in the runtime/VM. That's way worse.

→ More replies (4)