Over the weekend, the infosec community put together many tools for scanning and identifying vulnerable Apache Log4j instances for CVE-2021-44228. ...
Brandon Radosevich
5 min. read
15 Dec 2021
Over the weekend, the infosec community put together many tools for scanning and identifying vulnerable Apache Log4j instances for CVE-2021-44228. Information security practitioners have posted Proof of Concept (PoC) code on Github for scanning and exploiting this CVE. In this blog post, we will be walking through taking a PoC to a SCYTHE Module.
If you are a SCYTHE operator and want to use the new module, it is available on our marketplace where you can download it and test your environment quickly.
Researching the Log4J Exploit
We began by looking at this blog post, https://www.lunasec.io/docs/blog/log4j-zero-day/, which provided a good tutorial of how the exploit works, and what it is actually doing. Then we began by writing proof of concept code to see how this exploit will work.
We looked at the vulnerable code and found a docker container which allows us to test exploits.
docker run -p 8080:8080 ghcr.io/christophetd/log4shell-vulnerable-app
From another window, we can test if our connection using the User-Agent header will work.
If you use the command “${jndi:ldap://127.0.0.1/a” you will get a “Hello World” which will show the code is vulnerable.
Writing the Log4J PoC for SCYTHE
Now we can begin writing the python script to test this. Open up your favorite editor and create a new python script called log4j_poc.py. We can now install the following code.
B. The SCYTHE “server” file, which is the code the SCYTHE server uses to define arguments sent to the client, server-side formatting, etc., is located at:
We need to now add any 3rd party packages to our SCYTHE module. To do this we need to go look in our /.env/Lib/site-packages, and get the certifi, idna, requests, and urllib3 and copy them into our environment, ../src/py/ directory.
Modifying the POC for SCYTHE
We can now start working on the source code for our SCYTHE module. If we open a text editor to .../src/py/log4j_scanner.py. Here we will change our code around a little bit to work in the SCYTHE environment.
result = log4j_scanner.main(targets=message_dict["targets"],payload=message_dict['payload'])
result = ''.join([c for c in result if ord(c) > 31 or ord(c) == 9])
message = result.encode("utf-8")
return message
The lines we’ve added will parse the dictionary we get from the SCYTHE server, and will call our main function from the PoC code we just modified in the log4j_scanner, in the top directory of py. We can now work on the server side code for us to pass in command line arguments to our code.
Modifying Server Code
We can now modify the code under .../src/artifacts/scripts/test_company/log4j_scanner/log4j_scanner.py.
First we will modify the code to pass in our command line arguments. When we call the module from our server we want to provide the end user two options.
First they should be able to pass a list of targets for our code to scan. Next, they should be able to pass a different payload to try on the clients.
To accomplish this, we will change the create_parser function first.
parser = ArgumentParser(prog="log4j_scanner", description="Test a server for Log4j CVE-2021-44228E.",
epilog=epilog)
parser.add_argument("--targets", help="List of target servers to scan",required=True,nargs="*",type=str, default=[])
parser.add_argument("--payload",help="Payload to try on list of servers. Default: '${jndi:ldap://127.0.0.1:80/a}'",required=False,default="${jndi:ldap://127.0.0.1:80/a}")
return parser
Now we can pass in a command line argument as follows.
raise ValueError(f"Error: --targets could not be parsed {args.targets}")
if not args.payload:
raise ValueError(f"Error: --payload could not be parsed {args.payload}")
dict_to_send = {
"targets" : args.targets,
"payload" : args.payload
}
return json.dumps(dict_to_send).encode("utf-8")
This now allows us to pass the list of our targets to the SCYTHE client to test. We now just need to modify one more function.
Testing our Module
Now that we have the 3 components of our codebase written, we can test our codebase in module buster by performing the following commands.
On Windows:
In a developer command prompt, change directories to your C:\Users\<YOUR_USERNAME>\Desktop\modules\python3\log4j_scanner\windows and run the following command.
> ./build.bat
On Linux or macOS:
In a terminal windows, change directories to /Users/<YOUR_USERNAME>/Desktop/modules/python3/log4j_scanner/<linux,macos>/
> make
If there are no compilation options, we can now try running our codebase.
This post discusses active research by SCYTHE and other cited third parties into an ongoing threat. The information in this post should be considered preliminary and may be updated as research continues. This information is provided “as-is” without any warranty or condition of any kind, either express or implied.
About SCYTHE
SCYTHE provides an advanced attack emulation platform for the enterprise and cybersecurity consulting market. The SCYTHE platform enables Red, Blue, and Purple teams to build and emulate real-world adversarial campaigns in a matter of minutes. Customers are in turn enabled to validate the risk posture and exposure of their business and employees and the performance of enterprise security teams and existing security solutions. Based in Arlington, VA, the company is privately held and is funded by Gula Tech Adventures, Paladin Capital, Evolution Equity, and private industry investors. For more information email info@scythe.io, visit https://scythe.io, or follow on Twitter @scythe_io.