In 2021, Chen Zhaojun reported a Log4j flaw unseen since 2013

Log4j · 2021: Chen Zhaojun reported a Log4j flaw unseen since 2013

A stranger types one crafted string into a login box, and a server he has never touched reaches out to a public URL, loads malicious code and runs it. On November 24, 2021, Chen Zhaojun of Alibaba Cloud's security team decided that only one group should hear about the flaw behind that trick. He sent a private report to the Apache Software Foundation, the group that looks after Log4j. The message described a flaw in a logging library, a tool that writes down what a program is doing, and the flaw had sat unnoticed in that code since 2013. Apache says Chen was the first to disclose the problem.

Few developers would have stopped to think about the library at all. Log4j is open source and reliable, so plugging it into a program instead of building a logging library from scratch has become standard practice. A developer drops it in the way a plumber fits a standard pipe, without a second thought, and goes back to the work that feels more important. Millions of programs ended up carrying the same borrowed piece.

That sharing is what made Chen's report so heavy. The exploit was simple to execute, and its potential reach is estimated at hundreds of millions of devices. One quiet line of logging, written years earlier and trusted by almost everyone, now held a door that anyone who knew about it could open. Someone still had to write the fix, and the clock had begun to run.

One string in a login box

A stranger sits at a keyboard wanting control of a server he has never touched. He has no password and no account. The only thing between him and the machine is a line the program writes down about every visitor.

Log4j writes down more than it seems to. In its default configuration, the library performs substitution on any expression shaped like ${prefix:name} whenever it logs a string. The everyday use is harmless and even handy: a developer logs "Text: ${java:version}", and the record reads "Text: Java version 1.7.0_67". The library looks at the expression, swaps in the answer and moves on.

The stranger turns that courtesy into a weapon. He types a crafted string into a login box, and when the program logs it, Log4j reads the string as an instruction. The server reaches out to a public URL, loads malicious code hosted there and runs it.

The login box is only one place to type. Web servers log HTTP requests constantly, so the string can ride in the request URL or in a header such as User-Agent, which the visitor's own software fills in. Even a first name typed into a form can serve him. The program may not log it right away, but sooner or later some internal step records it, and the contents run.

LunaSec, a security firm, showed how little it takes. A plain header called X-Api-Version, logged back by the server, carried the payload, and one log line triggered remote code execution, meaning a stranger's code running on a machine that belongs to someone else.

The fix that shipped three days early

At Apache, the volunteers who look after Log4j opened Chen's report and went to work. Their job was to shut a door without bricking the house, because developers use lookups every day and defenders need their logs intact. They chose to restrict the servers and protocols that lookups may use, so a log line could no longer send the program off to fetch code from a stranger's machine.

They were not starting from a blank page. An earlier proposal in the JIRA issue LOG4J2-2109, the project's tracker for bugs and ideas, had already added a property called formatMsgNoLookups, which switches lookups off. That change had landed in version 2.10.0, so a careful administrator already had one lever to pull.

The new fix went out on December 6, 2021, in version 2.15.0-rc1, a release candidate that volunteers and users could start testing. The vulnerability itself would not be published for another three days.

Then Apache's security team put out an advisory for CVE-2021-44228, the catalog number that now names the flaw. The foundation gave it a 10 on the CVSS scale, the highest score available.

CVSS score of 10 given by the foundation to the Log4j vulnerability.

The maintainers could not see the other runners. Cloudflare's CEO, Matthew Prince, later said that exploitation or scanning went back as early as December 1, nine days before public disclosure. If he is right, someone was already typing the string into other people's servers while the volunteers were still writing the fix.

9 December: the leak

On Thursday, December 9, the quiet ended with a tweet. Someone posted the 0-day, the flaw with no warning and no patch for the public, and attached a proof of concept on GitHub, a working demonstration that anyone could copy and run.

At LunaSec, a security firm, CEO Free Wortley saw how fast the thing could spread and wanted defenders to understand it before attackers did. LunaSec published a warning and an initial assessment the same day. It said the flaw had surfaced that Thursday and that it led to remote code execution simply by logging a certain string.

Wortley also gave the bug a name. The team needed a handle that people could search for and share, so he called it Log4Shell, and the label first served to track the issue online.

Hours after the first report, a proof of concept was already out on the internet. The patch from December 6 stopped being a secret, because anyone who read it could work backward to the hole it closed.

Friday brought the official alarms. CISA, the United States cybersecurity agency, issued an alert, and so did Australia's CERT, its national computer emergency response team.

Renaming an iPhone to a weapon

One user changed the name of his iPhone to the exploit string and sent what he found to Apple. Simply changing it was shown to trigger the vulnerability in Apple's servers.

Others tried the flaw somewhere less expected, in a game. Microsoft-owned Minecraft had posted detailed patching instructions for players of the Java version on Friday. Screenshots soon circulated on forums that appeared to show players exploiting the flaw from the chat function, the box where players type to each other.

The machines joined in, and they never needed a keyboard. Botnets, networks of hijacked computers run by a single operator, began combing the internet for the flaw. Muhstik, Mirai and Tsunami were among them. Check Point counted more than 1.8 million exploit attempts since Friday, and at some moments more than 100 attempts every minute.

Check Point counted more than 1.8 million exploit attempts since Friday.

Amit Yoran of Tenable, the founding director of US-CERT, looked at the spread and called it the single biggest, most critical vulnerability ever.

For a few days, even the cloud behind the iPhone sat inside the blast radius. Apple's iCloud was demonstrably vulnerable on December 9 and 10. By December 11 it no longer was, so someone at Apple had closed the door in time.

Patch, bypass, patch again

On the weekend after the leak, system administrators did what the first advisories told them. Some started with a simple test: does this application contain the jars log4j-api and log4j-core? If both were present, the rule said, the app was in danger. Teams ran the check across thousands of servers and wrote up long lists of exposed software.

The lists were too long. Several early advisories had exaggerated the number of vulnerable packages, and defenders lost hours chasing false positives. The correction came out in the original issue thread, and outside researchers confirmed it.

An administrator who had pushed out the first patch and gone back to other work saw the news land: it could be bypassed. The advice flipped, and the job became upgrading to 2.15.0-rc2. Then came the second sting. On her machines she had already set the formatMsgNoLookups flag to true, the stopgap so many teams had reached for, and she had counted it as done. It did not stop exploitation of a second flaw, CVE-2021-45046, and it would later be found not to disable message lookups in certain cases.

Then the second flaw grew teeth. On December 17, an administrator reading Britain's National Cyber Security Centre alert saw that it had been updated to upgrade that second flaw to a remote code execution issue, the same class of danger as the original hole. She went back to the patch queue. Another round of patching exposed yet another problem, a denial-of-service flaw that let an attacker knock a system over instead of taking it. Version 2.17.0 fixed it, and LunaSec said that release went out without the remote code execution or denial-of-service vulnerabilities.

The cleanup that took years

A security engineer opened the inventory list, picked the next server on it and went to find who could log in. Too often nobody could. Some of the vulnerable machines had not been touched for years, and Wiz, a cloud security company, said that getting access to them and testing a patch could take weeks.

Six days after disclosure, the average organization had patched only 30% of what it needed to. Wiz, the cloud security company, compared the work to cleaning up an oil spill: the slick keeps spreading while crews are still hunting for the shoreline.

Wiz and EY combed through more than 200 enterprise cloud environments and found that 93% of them were at risk.

Progress came slowly, and by Day 10 only 45% of the vulnerable resources had been patched. Some institutions did not wait for the numbers to improve. The Canada Revenue Agency, the country's tax authority, learned of the exploit and temporarily shut down its online services.

Quebec's government took almost 4,000 of its websites offline. In Beijing, China's Ministry of Industry and Information Technology turned on Chen's own employer. It suspended Alibaba Cloud as a threat intelligence partner for six months, saying the company had not reported the flaw to the government in a timely manner.

Who keeps the code everyone uses

On January 4, 2022, a lawyer at the Federal Trade Commission put the answer in writing: the agency would pursue companies that failed to take reasonable steps to update Log4j software.

Around the same time, a meeting at the White House turned to the question that Chen's report had left hanging. Officials spelled out why maintaining open-source software mattered to national security, and they heard that the work is often carried out largely by a few volunteers. Some open-source projects have many eyes on them. Others have few or none, and nobody is checking whether their code is safe. Log4j had been one of the lucky ones, with a team that answered a private report in days, and it had still taken a crisis to make anyone count the eyes.

The Apache Logging Services threat model today treats application developers and administrators as trusted users. It says that Log4cxx, Log4j and Log4net do not trust log messages, so a string typed by a stranger is data and never a command. And it says that if configuration files use interpolation features such as Log4j Lookups, only trusted data sources should be used.

For eight years, a line of logging had been treated as a harmless note in a diary. The line Chen reported is now a rule, and the diary no longer takes dictation from strangers.

Editorial graphic and headline text by Signal Titans.

Source: One Line of Logging: Chen Zhaojun and the Log4Shell Flaw Hiding in Plain Sight · Alert: Apache Log4j vulnerabilities | National Cyber Security Centre · Log4Shell: RCE 0-day exploit found in log4j, a popular Java logging package | LunaTrace · Worst Apache Log4j RCE Zero day Dropped on Internet – Cyber Kendra · A Log4J Vulnerability Has Set the Internet 'On Fire' | WIRED · Security :: Apache Logging Services · Log4Shell iCloud vulnerability patched; most critical in a decade – 9to5Mac · Log4Shell 10 days later: Enterprises halfway through patching | Wiz Blog · The Next Wave of Log4J Attacks Will Be Brutal | WIRED

Share this article
FacebookThreadsLinkedInX

Leave a Reply

Your email address will not be published. Required fields are marked *