Exploit database

GH-98e3287dac98b34bb9411a96c3ab6763

george-petrakis/log4j-scanner-cve-2021-44228

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2021-44228

465 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files5
george-petrakis/log4j-scanner-cve-2021-44228Revision 79fc3103e979

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

Program.cs

C# · 1,720 bytes
using System.Text.RegularExpressions;

var jndiRegex = @"\$(\{|%7B)jndi:(ldap[s]?|rmi|dns|nis|iiop|corba|nds|http):/[^\n]+";
var obfuscated_regex = @"/[uperlow\x24-\x26\x28\29\x5b\x5d\x7b\x7d\x3a-]+[Jj][uperlow\x24-\x26\x28\29\x5b\x5d\x7b\x7d\x3a-]*[Nn][uperlow\x24-\x26\x28\29\x5b\x5d\x7b\x7d\x3a-]*[Dd][uperlow\x24-\x26\x28\29\x5b\x5d\x7b\x7d\x3a-]*[Ii]/";

//ask user for folder path to search logs
Console.WriteLine("Enter the path to the folder containing the log files");
var path = Console.ReadLine();
//get all files in path and subfolders , handle unauthorised access
try
{
    var files = System.IO.Directory.GetFiles(path,"*", System.IO.SearchOption.AllDirectories);
    //check each file for match with both regex patterns , if match print directory, file name and line number
    var matches = 0;
    foreach (var file in files)
    {
        var fileStream = new System.IO.StreamReader(file);
        var lineNumber = 0;
        while (!fileStream.EndOfStream)
        {
            var line = fileStream.ReadLine();
            lineNumber++;
            if (Regex.IsMatch(line, jndiRegex) || Regex.IsMatch(line, obfuscated_regex))
            {
                matches++;
                Console.WriteLine("{0}\\{1}:{2}", System.IO.Path.GetDirectoryName(file), System.IO.Path.GetFileName(file), lineNumber);
            }
        }
    }
    //print total number of matches
    Console.WriteLine("Total matches: {0}", matches);
    //print total files scanned
    Console.WriteLine("Total files scanned: {0}", files.Length);
    Console.ReadLine();
    Environment.Exit(0);
}
catch (UnauthorizedAccessException)
{
    Console.WriteLine("Unauthorised access to folder, please try again");
    return;
}