## https://sploitus.com/exploit?id=KITPLOIT:TOOLS-GITHUB-MY0113-SHIRO-CVE-2022-32532
# Apache Shiro CVE-2022-32532 Π‘ΡΠ΅Π΄Π° Π²ΠΎΡΠΏΡΠΎΠΈΠ·Π²Π΅Π΄Π΅Π½ΠΈΡ
ΠΡΠΎ ΠΌΠΈΠ½ΠΈΠΌΠ°Π»ΡΠ½ΠΎΠ΅ Π²Π΅Π±-ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅ Π΄Π»Ρ Π²ΠΎΡΠΏΡΠΎΠΈΠ·Π²Π΅Π΄Π΅Π½ΠΈΡ **CVE-2022-32532** (ΠΎΠ±Ρ
ΠΎΠ΄ Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΠΈ Apache Shiro RegExPatternMatcher).
## ΠΠΏΠΈΡΠ°Π½ΠΈΠ΅ ΡΡΠ·Π²ΠΈΠΌΠΎΡΡΠΈ
* **CVE** : CVE-2022-32532
* **ΠΠ΅ΡΡΠΈΠΈ ΠΏΠΎΠ΄ ΡΠ³ΡΠΎΠ·ΠΎΠΉ** : Shiro < 1.9.1
* **ΠΡΠΈΡΠΈΠ½Π°** : `RegExPatternMatcher` Π½Π΅ΠΏΡΠ°Π²ΠΈΠ»ΡΠ½ΠΎ Π·Π°ΠΊΡΠ΅ΠΏΠ»ΡΠ΅Ρ ΡΠ΅Π³ΡΠ»ΡΡΠ½ΠΎΠ΅ Π²ΡΡΠ°ΠΆΠ΅Π½ΠΈΠ΅, ΡΡΠΎ ΠΌΠΎΠΆΠ΅Ρ ΠΏΡΠΈΠ²Π΅ΡΡΠΈ ΠΊ ΠΎΠ±Ρ
ΠΎΠ΄Ρ ΠΏΡΡΠΈ. Π ΡΠ°ΡΡΠ½ΠΎΡΡΠΈ, ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΠ΅ΡΡΡ Π»ΠΎΠ³ΠΈΠΊΠ° ΡΠΎΠΏΠΎΡΡΠ°Π²Π»Π΅Π½ΠΈΡ ΡΠ΅Π³Π΅ΠΊΡΠΏΠΎΠ² ΠΏΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ Π² Java, ΠΈ ΠΊΠΎΠ³Π΄Π° Π²ΡΡΡΠ΅ΡΠ°Π΅ΡΡΡ ΡΠΈΠΌΠ²ΠΎΠ» `.` ΠΊΠ°ΠΊ ΡΠ°ΡΡΡ ΡΠ΅Π³Π΅ΠΊΡΠΏΠ°, ΠΈΠ³Π½ΠΎΡΠΈΡΡΡΡΡΡ ΡΠΏΠ΅ΡΠΈΠ°Π»ΡΠ½ΡΠ΅ ΡΠΈΠΌΠ²ΠΎΠ»Ρ, ΡΠ°ΠΊΠΈΠ΅ ΠΊΠ°ΠΊ `\r` (%0d) ΠΈ `\n` (%0a). ΠΠ΅ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΠΌΠΎ ΡΠ²Π½ΠΎ ΠΈΡΠΏΠΎΠ»ΡΠ·ΠΎΠ²Π°ΡΡ ΡΠ΅ΠΆΠΈΠΌ `Pattern.DOTALL` Π΄Π»Ρ ΠΊΠΎΡΡΠ΅ΠΊΡΠ½ΠΎΠΉ ΠΎΠ±ΡΠ°Π±ΠΎΡΠΊΠΈ `\r` ΠΈ `\n`. ΠΠ΅ΡΡΠΈΠΈ Shiro Π½ΠΈΠΆΠ΅ 1.9.1 ΠΈΡΠΏΠΎΠ»ΡΠ·ΡΡΡ Π»ΠΎΠ³ΠΈΠΊΡ ΡΠΎΠΏΠΎΡΡΠ°Π²Π»Π΅Π½ΠΈΡ ΠΏΠΎ ΡΠΌΠΎΠ»ΡΠ°Π½ΠΈΡ, ΠΏΠΎΡΡΠΎΠΌΡ Π½Π΅ ΠΌΠΎΠ³ΡΡ ΠΊΠΎΡΡΠ΅ΠΊΡΠ½ΠΎ ΠΎΠ±ΡΠ°Π±Π°ΡΡΠ²Π°ΡΡ `\r` ΠΈ `\n`, ΡΡΠΎ ΠΏΡΠΈΠ²ΠΎΠ΄ΠΈΡ ΠΊ ΠΎΠ±Ρ
ΠΎΠ΄Ρ Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΠΈ.
## ΠΠ°ΠΊ Π²ΠΎΡΠΏΡΠΎΠΈΠ·Π²Π΅ΡΡΠΈ
1. ΠΠ°ΠΏΡΡΡΠΈΡΠ΅ ΠΏΡΠΈΠ»ΠΎΠΆΠ΅Π½ΠΈΠ΅
root@kitploit:~
ε―ε¨ShiroCve202232532Application
2. URL-Π°Π΄ΡΠ΅Ρ, ΠΊΠΎΡΠΎΡΡΠΉ ΠΏΡΠΈ Π½ΠΎΡΠΌΠ°Π»ΡΠ½ΠΎΠΉ Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΠΈ ΡΠ΅ΡΠ΅Π· Shiro Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ access denied:
http://localhost:8080/permit/xxx, Π³Π΄Π΅ xxx ΠΌΠΎΠΆΠ΅Ρ Π±ΡΡΡ Π»ΡΠ±ΡΠΌΠΈ ΡΠΈΠΌΠ²ΠΎΠ»Π°ΠΌΠΈ
3. URL-Π°Π΄ΡΠ΅Ρ, ΠΊΠΎΡΠΎΡΡΠΉ ΠΎΠ±Ρ
ΠΎΠ΄ΠΈΡ Π°ΡΡΠ΅Π½ΡΠΈΡΠΈΠΊΠ°ΡΠΈΡ Shiro ΠΈ Π²ΠΎΠ·Π²ΡΠ°ΡΠ°Π΅Ρ success:
http://localhost:8080/permit/xxx, ΡΠΎ Π΅ΡΡΡ Π²ΡΡΠ°Π²ΡΡΠ΅ Π² xxx ΡΠΈΠΌΠ²ΠΎΠ»Ρ ΠΏΠ΅ΡΠ΅Π½ΠΎΡΠ° ΡΡΡΠΎΠΊΠΈ \n (%0a) ΠΈ Π²ΠΎΠ·Π²ΡΠ°ΡΠ° ΠΊΠ°ΡΠ΅ΡΠΊΠΈ \r (%0d)
4. ΠΠ΅ΡΠΎΠ΄ ΠΈΡΠΏΡΠ°Π²Π»Π΅Π½ΠΈΡ
1. Π‘ΠΊΠΎΠΏΠΈΡΡΠΉΡΠ΅ ΠΏΠΎΠ»Π½ΠΎΠ΅ ΡΠΎΠ΄Π΅ΡΠΆΠΈΠΌΠΎΠ΅ `RegExPatternMatcher.java` ΠΈ `PatternMatcher.java` ΠΈΠ· https://github.com/apache/shiro/blob/shiro-root-1.9.1/core/src/main/java/org/apache/shiro/util/.
2. Π‘ΠΊΠΎΠΌΠΏΠΈΠ»ΠΈΡΡΠΉΡΠ΅ ΡΡΠΈ Π΄Π²Π° .java ΡΠ°ΠΉΠ»Π° Π² `RegExPatternMatcher.class` ΠΈ `PatternMatcher.class` Ρ ΠΏΠΎΠΌΠΎΡΡΡ JDK 11.
3. ΠΠΎΠΌΠ΅ΡΡΠΈΡΠ΅ ΡΡΠΈ 2 class-ΡΠ°ΠΉΠ»Π° Π² `shiro-core-1.6.0.jar` ΠΏΠΎ ΠΏΡΡΠΈ `org/apache/shiro/util/` Ρ ΠΏΠΎΠΌΠΎΡΡΡ WinRAR.
4. ΠΠ»Ρ ΡΠ΅ΡΡΠΈΡΠΎΠ²Π°Π½ΠΈΡ ΠΈΡΠΏΡΠ°Π²Π»Π΅Π½ΠΈΡ ΡΠΊΠΎΠΏΠΈΡΡΠΉΡΠ΅ ΠΊΠΎΠ΄ ΠΈΠ· `RegExPatternMatcher.java` ΠΈΠ· shiro-core-1.9.1 Π² Π΄Π°Π½Π½ΡΠΉ ΠΏΡΠΈΠΌΠ΅Ρ, ΠΏΠ΅ΡΠ΅ΠΈΠΌΠ΅Π½ΠΎΠ²Π°Π² Π² , Π·Π°ΡΠ΅ΠΌ Π·Π°ΠΌΠ΅Π½ΠΈΡΠ΅ Π² ΡΡΡΠΎΠΊΠ΅ 15 ΠΈ ΡΡΡΠΎΠΊΠ΅ 29 Π½Π° .
root@kitploit:~
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.shiro.util;
import java.util.regex.Pattern;
import java.util.regex.Matcher;
/**
* {@code PatternMatcher} implementation that uses standard {@link java.util.regex} objects.
*
* @see Pattern
* @since 1.0
*/
public class RegExPatternMatcher implements PatternMatcher {
private static final int DEFAULT = Pattern.DOTALL;
private static final int CASE_INSENSITIVE = DEFAULT | Pattern.CASE_INSENSITIVE;
private boolean caseInsensitive = false;
/**
* Simple implementation that merely uses the default pattern comparison logic provided by the
* JDK.
* <p/>This implementation essentially executes the following:
* <pre>
* Pattern p = Pattern.compile(pattern, Pattern.DOTALL);
* Matcher m = p.matcher(source);
* return m.matches();</pre>
* @param pattern the pattern to match against
* @param source the source to match
* @return {@code true} if the source matches the required pattern, {@code false} otherwise.
*/
public boolean matches(String pattern, String source) {
if (pattern == null) {
throw new IllegalArgumentException("pattern argument cannot be null.");
}
Pattern p = Pattern.compile(pattern, caseInsensitive ? CASE_INSENSITIVE : DEFAULT);
Matcher m = p.matcher(source);
return m.matches();
}
/**
* Returns true if regex match should be case-insensitive.
* @return true if regex match should be case-insensitive.
*/
public boolean isCaseInsensitive() {
return caseInsensitive;
}
/**
* Adds the Pattern.CASE_INSENSITIVE flag when compiling patterns.
* @param caseInsensitive true if patterns should match case-insensitive.
*/
public void setCaseInsensitive(boolean caseInsensitive) {
this.caseInsensitive = caseInsensitive;
}
}