• Stars
    star
    105
  • Rank 317,835 (Top 7 %)
  • Language
    Python
  • License
    Apache License 2.0
  • Created over 1 year ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

commons-text-tools

Quick links

Click to find:

Overview

CVE-2022-42889 may pose a serious threat to a wide range of Java-based applications. The important questions a developer may ask in this context are:

1. Does my code include commons-text? Which versions?

Does the released code include commons-text? Which version of the library is included there? Answering these questions may not be immediate due to two factors:

  1. Transitive dependencies: while commons-text may not be in the direct dependency list of the project, it may be used indirectly by some other dependency.

  2. The code of this library may not appear directly as a separate file, but rather be bundled in some other code jar file.

JFrog is releasing a tool to help resolve this problem: scan_commons_text_versions. The tool looks for the class code of StringLookupFactory (regardless of containing .jar file names and content of pom.xml files), and attempts to fingerprint the versions of the objects to report whether the included version of commons-text is vulnerable.

2. Does my code use vulnerable commons-text functions?

The question is relevant for the cases where the developer would like to verify if the calls to commons-text in the codebase may pass potentially attacker-controlled data. While the safest way to fix the vulnerability, as discussed in the advisories, is to apply the appropriate patches, controlling for and verifying the potential impact under assumption of unpatched commons-text may be valuable in many situations.

scan_commons_text_calls_jar.py, which locates the calls to the vulnerable functions in compiled .jars, and reports the findings as class name and method names in which each call appears.

3. I have vulnerable commons-text jar files in my system, how can I quickly disable the dangerous behavior?

  • Updating remains the best solution - this solution is intented for fast hot patching

  • In the context of CVE-2022-42889 vulnerability, the class org/apache/commons/text/lookup/ScriptStringLookup in commons-text enables execution of scripts which may be embedded in a string received from an attacker-controlled source through ${script}. Therefore, invocations of ScriptStringLookup.lookup function are indicative of the functionality being activated.

  • We provide a tool, Text4ShellPatch, allowing to patch this specific call so that the script execution functionality cannot be utilized. After applying the patch, the library will always execute a script returning a warning message (instead of the potentially attacker-controlled code)

  • Similarly, DNS and URL lookup can load untrusted content if controlled by an attacker through ${dns} and ${url}, thus, their respective lookup DnsStringLookup and UrlStringLookup respectively can be disabled through patch to return a warning message,

  • The patch can be applied to a specific jar file, for the script lookup only or script, dns and url for a better protection in case it is not meant to be used in the application,

  • A backup is generated in the same location as the original jar before being replaced with the patch one. The backup filename follows the following pattern: <original_jar_name>_YYYY.MM.DD_HH.mm.ss.orig.jar where YYYY, MM, DD are respectively the year, the month and the day, and HH, mm, ss are respectively the hour, the minutes and the second.

  • It is also possible to locate vulnerable versions of commons-text and patch them automatically as the next question answers to it.

4. Can I automate scanning and patching of vulnerable commons-text jar?

Two of our tools together offers the ability to scan and patch the vulnerable commons-text jar files.

An example bash script is present in this Github repository under the name of scan_and_patch.sh. Basically, it is using the scan_commons_text_versions.py script to find under a specific root-folder the vulnerable commons-text jar files with a vulnerable version and run the Text4ShellPatch tool against them as follows.

Example of automation


scan_commons_text_versions.py

Usage
python scan_commons_text_versions.py root-folder [-quiet] [-exclude folder1 folder2 ..]

The tool will scan root_folder recursively for .jar and .war files; in each located file the tool looks for a StringLookupFactory.class (recursively in each .jar file). If at least one of the classes is found, the tool attempts to fingerprint its version (including some variations found in patches and backport patches) in order to report whether the code is vulnerable.

With -quiet flag, only version conclusions are printed out, and other messages (files not found/ archives failed to open/ password protected archives) are muted.

Folders appearing after -exclude (optional) are skipped.


scan_commons_text_calls_jar.py

The tool requires python 3 and the following 3rd party libraries: jawa, tqdm, easyargs, colorama

Dependencies installation
pip install -r requirements.txt
Usage

The default use case:

python scan_commons_text_calls_jar.py root-folder

will recursively scan all .jar files in root-folder, for each printing out locations (class name and method name) of calls to lookup/replace/replaceIn methods of StringSubstitutor/StringLookup.

The tool may be configured for additional use cases using the following command line flags.

Flag Default value Use
--class_regex (.*StringSubstitutor|.*StringLookup) Regular expression for required class name
--method_regex (lookup|replace|replaceIn) Regular expression for required method name
--quickmatch_string (StringLookup|StringSubstitutor) Pre-condition for file analysis: .jar files not containing the specified regex will be ignored
--class_existence Not set When not set, look for calls to class::method as specified by regexes. When set, --method_regex is ignored, and the tool will look for existence of classes specified by --class_regex in the jar.
--no_quickmatch Not set When set, the value of --quickmatch_string is ignored and all jar files are analyzed
--caller_block .*org/apache/commons/text If caller class matches this regex, it will not be displayed

text_4_shell_patch

Usage
java -jar Text4ShellPatch.jar TARGET_JAR [PATCHING_MODE]
  Where TARGET_JAR is the application to patch and PATCHING_MODE is
    0 (default): Patch Script lookup
    1:           Patch Script + DNS + URL lookups
  [Note: The original Jar will be kept in the same folder with the .orig.jar extension]  

The tool will look for the org/apache/commons/text/lookup/ScriptStringLookup class in the commons-text jar given and replaces the lookup() function's content by a warning message and return out of the function. Thus, the eval will not exist in the new ScriptStringLookup class.

It can also patch the DnsStringLookup and URLStringLookup classes and disable the lookup() function when setting the PATCHING_MODE option to 1.

A backup file is generated through the process in the same path with the .orig.jar extension.

Generation from Code-Source

Text4ShellPatch can be edited and compiled with Maven with the simple command: mvn clean assembly:single. It will create a Text4ShellPatch.jar file in the target/ folder.

More Repositories

1

project-examples

Small projects in universal build ecosystems to configure CI and Artifactory
C#
974
star
2

jfrog-cli

JFrog CLI is a client that provides a simple interface that automates access to the JFrog products.
Go
513
star
3

artifactory-user-plugins

Sample Artifactory User Plugins
Groovy
356
star
4

artifactory-docker-examples

Examples for using Artifactory Docker distribution in various environments
Shell
331
star
5

artifactory-client-java

Artifactory REST Client Java API bindings
Java
315
star
6

frogbot

🐸 Scans your Git repository with JFrog Xray for security vulnerabilities. 🤖
Go
277
star
7

terraform-provider-artifactory

Terraform provider to manage JFrog Artifactory
Go
271
star
8

charts

JFrog official Helm Charts
Shell
247
star
9

setup-jfrog-cli

Set up JFrog CLI in your GitHub Actions workflow
TypeScript
230
star
10

jfrog-client-go

All go clients for JFrog products
Go
211
star
11

log4j-tools

Java
169
star
12

gocenter

The Github README for JFrog Go-center. Use this for reporting issues
164
star
13

jfrog-idea-plugin

JFrog IntelliJ IDEA plugin
Java
153
star
14

jfrog-vscode-extension

JFrog VS-Code Extension
TypeScript
151
star
15

terraform-provider-project

Terraform provider to manage JFrog Projects
Go
147
star
16

build-info

Artifactory's open integration layer for CI build servers
Java
146
star
17

terraform-provider-xray

Terraform provider to manage JFrog Xray
Go
145
star
18

artifactory-scripts

Scripts for Artifactory (Usually, for REST API), community driven.
Groovy
143
star
19

jfrog-spring-tools

Python
84
star
20

JFrog-Cloud-Installers

Template to deploy Artifactory Enterprise cluster.
CSS
78
star
21

jfrog-docker-desktop-extension

🐸 Scans any of your local Docker images for security vulnerabilities. 🐋
TypeScript
74
star
22

nexus2artifactory

NexusToArtifactory - A tool designed to ease migration from Sonatype Nexus to JFrog Artifactory.
Python
67
star
23

nimbuspwn-tools

Shell
65
star
24

build-info-go

build-info-go is a Go library and a CLI, which allows generating build-info for a source code project.
Go
56
star
25

cocoapods-art

CocoaPods Plugin to work against Artifactory Repository
Ruby
53
star
26

jfrog-cli-plugins-reg

Go
52
star
27

jfrog-npm-tools

Python
52
star
28

kubenab

Kubernetes Admission Webhook to enforce pulling of Docker images from the private registry.
Go
46
star
29

jfrog-CVE-2023-25136-OpenSSH_Double-Free

Python
43
star
30

teamcity-artifactory-plugin

TeamCity plugin that enables traceable build artifacts with Artifactory
Java
42
star
31

froggit-go

Froggit-Go is a universal Go library, allowing to perform actions on VCS providers.
Go
42
star
32

jfrog-azure-devops-extension

JavaScript
41
star
33

chartcenter

The Central Helm Repository for the Community
Dockerfile
41
star
34

jfrog-CVE-2022-21449

Python
40
star
35

bamboo-artifactory-plugin

Atlassian Bamboo plugin that enables traceable build artifacts with Artifactory
Java
40
star
36

jfrog-docker-repo-simple-example

Getting started with JFrog Docker Repos - Example
Dockerfile
39
star
37

vault-plugin-secrets-artifactory

HashiCorp Vault Secrets Plugin for Artifactory
Go
38
star
38

artifactory-cli-go

Artifactory CLI written in Golang
Go
33
star
39

jfrog-cli-core

Go
32
star
40

docker2artifactory

Python
29
star
41

mlflow-jfrog-plugin

Python
27
star
42

artifactory-docker-builder

Groovy
27
star
43

gitlab-templates

Templates for CI/CD in GitLab using JFrog CLI
26
star
44

auto-mat

A docker container to generate heap dump reports and indexes for eclipse MAT
Java
25
star
45

kubexray

JFrog KubeXray scanner on Kubernetes
Go
25
star
46

log-analytics-prometheus

JFrog Prometheus Log Analytics Integration
23
star
47

artifactory-maven-plugin

A Maven plugin to resolve artifacts from Artifactory, deploy artifacts to Artifactory, capture and publish build info.
Java
23
star
48

cve-2024-3094-tools

Shell
21
star
49

polkit-tools

Shell
18
star
50

jfrog-registry-operator

Enhancing AWS Security: JFrog's Seamless Integration and the Power of AssumeRole
Go
18
star
51

jfrog-cli-plugins

Go
17
star
52

artifactory-gradle-plugin

JFrog Gradle plugin for Build Info extraction and Artifactory publishing.
Java
17
star
53

log-analytics

JFrog Log Analytics
Shell
17
star
54

gofrog

A collection of go utilities
Go
15
star
55

bower-art-resolver

JavaScript
15
star
56

jfrog-openssl-tools

Python
14
star
57

gradle-dep-tree

Gradle plugin that reads the Gradle dependencies of a given Gradle project, and generates a dependency tree.
Java
13
star
58

DevRel

Java
12
star
59

artifactory-sbt-plugin

The SBT Plugin for Artifactory resolve and pulish
Scala
12
star
60

artifactory-user-plugins-devenv

Development Environment for writting Artifactory User Plugins
Shell
12
star
61

aws-codestar

Artifactory-Code Star integration
Shell
12
star
62

SwampUp2022

Shell
12
star
63

jfrog-client-js

Xray Javascript Client
TypeScript
11
star
64

maven-anno-mojo

Write Maven plugins using annotations
Java
11
star
65

jfrog-ecosystem-integration-env

A Docker image containing all the tools JFrog CLI integrates with and supports.
Dockerfile
11
star
66

bamboo-jfrog-plugin

Easy integration between Bamboo and the JFrog Platform.
Java
10
star
67

xray-client-java

Xray Java Client
Java
9
star
68

artifactory-bosh-release

Bosh release of Artifactory for the PCF
HTML
9
star
69

msbuild-artifactory-plugin

Artifactory integration with MSBuild
C#
8
star
70

jfrog-ide-webview

JFrog-IDE-Webview is a React-based HTML page designed to be seamlessly embedded within JFrog VS Code Extension and the JFrog IDEA Plugin.
TypeScript
8
star
71

docker-compose-demos

JFrog example demos using docker compose
Shell
8
star
72

jfrog-visual-studio-extension

C#
8
star
73

log-analytics-elastic

JFrog Elastic Fluentd Kibana Log Analytics Integration
8
star
74

jfrog-ui-essentials

JavaScript
8
star
75

go-mockhttp

Go
7
star
76

ide-plugins-common

Common code used by the JFrog Idea Plugin and the JFrog Eclipse plugin
Java
7
star
77

jfrog-pipelines-task

7
star
78

nuget-deps-tree

This npm package reads the NuGet dependencies of a .NET project, and generates a dependencies tree object.
TypeScript
7
star
79

knife-art

Knife Artifactory integration
Ruby
7
star
80

jfrog-pipelines-go-task

Makefile
7
star
81

jfrog-mission-control-2.0

Jfrog Mission Control 2.0 example scripts
Groovy
7
star
82

log-analytics-splunk

JFrog Splunk Log Analytics Integration
JavaScript
6
star
83

go-license-discovery

A go library for matching text against known OSS licenses
Go
6
star
84

npm_domain_check

Python
6
star
85

jfrog-cli-plugin-template

Go
6
star
86

jfrog-distroless

Starlark
6
star
87

terraform-provider-pipeline

Terraform provider to manage Artifactory Pipelines
Go
6
star
88

docker-remote-util

A groovy util library to interact with docker remote api
Groovy
6
star
89

webapp-examples

Examples of Web Application that use Artifactory as a backend
CSS
6
star
90

jfrog-pipelines-jenkins-example

Go
5
star
91

maven-dep-tree

Maven plugin that reads the Maven dependencies of a given Maven project, and generates a dependency tree.
Java
5
star
92

log-analytics-datadog

JFrog Datadog Log Analytics Integration
Dockerfile
5
star
93

jfrog-apps-config

The configuration file allows you to refine your JFrog Advanced Security scans behavior according to your specific project needs and structures, leading to better and more accurate scan results.
Go
5
star
94

fan4idea

Java
4
star
95

live-logs

Go
4
star
96

gocmd

Go
4
star
97

jfrog-pipelines-docker-sample

Shell
4
star
98

SwampUp2023

HCL
4
star
99

jfrog-testing-infra

Common testing code used by integration tests of Jenkins and Bamboo Artifactory plugins.
Java
4
star
100

wharf

Wharf resolver
Java
4
star