Jump to content
  • Entries

    16114
  • Comments

    7952
  • Views

    863106687

Contributors to this blog

  • HireHackking 16114

About this blog

Hacking techniques include penetration testing, network security, reverse cracking, malware analysis, vulnerability exploitation, encryption cracking, social engineering, etc., used to identify and fix security flaws in systems.

0x00脆弱性の説明

1.5.2より前のApache Shiroにはセキュリティの脆弱性があります。攻撃者は、認証をバイパスするために特別に作成されたリクエストを使用できます。 Shiro Frameworkは、Anon、AuthC、その他のインターセプターなどのインターセプター機能を通じてユーザーアクセス権を制御します。 Anonは匿名のインターセプターであり、アクセスにログインする必要はありません。 AUTHCはログインインターセプターであり、アクセスするためにログインする必要があります。 ShiroのURLパス式はANT形式です。パスワイルドカード *は、ゼロ以上の文字列を一致させることを意味します。/* hello /helloですが、hello /hello /はできません *ワイルドカードはパスに一致できないためです。 /helloインターフェイスにAuthCインターセプターセットがあると仮定すると、アクセス /helloは許可判断を下しますが、 /hello /にアクセスすると、URLと正しく一致することができず、直接リリースしてスプリングインターセプターを入力します。 Form /helloおよび /hello /hello /hello /hello /hello /hello /hello /hello /hello /hello /hello /hello /hello /hello /hello /helloでアクセスしたリソースは、許可バイパスを達成します。

0x01脆弱性の影響

Apache Shiro 1.5.2

0x02 shiro interceptor

Shiro Frameworkは、インターセプター関数を使用して、ユーザーアクセス権を制御およびインターセプトします。 Shiroの一般的なインターセプターには、Anon、AuthC、その他のインターセプターが含まれます。 1.アノンは匿名のインターセプターであり、ログインせずにアクセスできます。一般に、静的リソースまたはモバイルインターフェイスに使用されます。

2.AUTHCは、アクセスするためにログイン認証を必要とするリソースです。ユーザーは、一致するURL構成をshiro.iniに記述することができます。これにより、一致するURLがインターセプトされ、応答インターセプターが実行されます。これにより、URLのアクセス制御が実現し、URLパス式は通常ANT形式です。次の構成として、 /index.htmlホームページにアクセスする場合、shiroはログイン判断を下さず、アノンインターセプターはログインせずにアクセスできます。 [urls]

/index.html=anon

/user/**=authc

ShiroのURLパス式はアリの形式であり、パスワイルドカードがサポートしていますか?***。文字を一致させます

*:ゼロ以上の文字列を一致させます

**:パスのゼロ以上のパスを一致させます

ここで、 *はゼロ以上の文字列を一致させることを意味します。/*は/* helloと一致することができますが、 /hello /ではありません *ワイルドカードはパスに一致できないためです。 /helloインターフェイスにAuthCインターセプターがあると仮定すると、アクセス /Helloは許可を得るために判断されます。要求されたuriが /hello /である場合、 /*urlパス式は正しく一致して解放されません。次に、スプリング(サーブレット)インターセプターを入力すると、 /helloフォームと /hello /formのURLでアクセスされるリソースが同じです。

0x03環境構築

ダウンロードデモコード:https://github.com/lenve/javaboy-code-samples/master/shiro/shiro-basicImport Ideashiroバージョン1.4.2 Groupidorg.apache.shiro/groupid artifactidshiro-spring/artifactid version1.4.2/version/dependencymodify shiroconfig configurationファイルとauthcインターセプター@bean shirofiltorybean shirofilterfactorybean(){shirofilterfactorybean bean() . //map.put('/d '、' authc '); map.put( '/hello/*'、 'authc'); bean.setFilterChainDefinitionMap(Map);豆を返します。 }ルーティングコントローラーメソッド@getMapping( '/hello/{currentPage}')public string hello( @pathvariable integer currentPage){return 'hello';}アイデアをコンパイルすると、戦争パッケージを取得できます。 Here you can quickly build the vulnerability environment through docker: docker pull vulfocus/shiro-cve_2020_1957 1049983-20201129040308848-1645994369.pngdocker images 1049983-20201129040310600-1437781155.pngdocker run -d -p 8080:8080 -v /var/run/docker.sock:/var/run/docker.sock -e vul_ip=192.168.1.14 29136b1d3c61 1049983-20201129040311058-1699321640.png-V/var/run/docker.sock:/var/run/docker.sockはドッカーインタラクティブ接続です。 -e docker_urlはDocker接続法です。デフォルトでは、unix: //var/run/docker.sock、またはtcp: //xxx.xxx.xxx.xxx:2375(ポート2375を開く必要があります)を介して接続できます。 -v /vulfocus-api/db.sqlite3:db.sqlite3マップデータベースはローカルファイルです。 -e vul_ip=xxx.xxx.xxx.xxxはDockerサーバーIPであり、127.0.0.1.1.http://192.168.1.1.14:8080/ログイン1049983-20201129040312412-1520455583.png

0x04脆弱性の再発

1。 AuthCインターセプターによって傍受され、ログインのためにログインインターフェイスにジャンプすることがわかります。1049983-20201129040312899-107128082.pngアクセス/hello/1/、authcインターセプターを正常にバイパスし、リソースを取得しました。

1049983-20201129040313397-685140363.png2、Shiro 1.4.2バージョンバイパス脆弱性分析脆弱性は、PathMatchingFilterChainResolverのゲットチェーン関数の下に配置できます。この関数は、URLパスマッチングで構成されたURLパス式に基づいて入力URLと一致し、インターセプターが一致するかどうかを判断します。正常に一致すると、応答インターセプター実行チェーンが返され、Shirofitherが許可操作を実行できます。 URLパス式と入力URLの一致は、主にPathmathches関数を介して一致します。1enxkmd2er37651.pngPathMatches関数は、最終的にaNT形式でDomatchのPathpatternとRequesturiを呼び出して、shiro.util.antpathmatcherクラスのdomatchのpathpatternとrequesturiに一致します。 //pathmatches:135、pathmatchingfilterchainresolver(org.apache.shiro.web.filter.mgt)

保護されたブールパスマッチ(String Pattern、String Path){

patternMatcher pathMatcher=this.getPathMatcher();

pathmatcher.matches(パターン、パス)を返す;

}

domatch:109、antpathmatcher(org.apache.shiro.util)、shiroのアリ形式のpathpatternのワイルドカードが一致するパスをサポートしない場合、/hello/*は正常に一致することはできません。これにより、Shiroインターセプターをうまくバイパスし、スプリングインターセプターに入りました。 /hello/1/and//hello/1は同じリソースを取得できます。1049983-20201129040314275-1093796335.jpg3、shiro≤1.5.1バージョンバージョン1.5.1のバージョンバイパス、/hello/はログイン1049983-20201129040314835-1924922284.pngバイパスペイロード、/fdsf;1049983-20201129040315283-20701281.pngまたはその他のペイロード、xxxx/./hello/1、suctionfully bypassed(shiro 1.5.1 and its以前のバージョン) /xxxx/./hello/1、最終リクエスト/こんにちは、バックグラウンドリクエストに正常にアクセスされました。 Shiro≤1.5.1の脆弱性分析の問題は、Getchain関数に配置して、Requesturiを取得することもできます。下の図に示すように、this.getPathWithinApplication(要求)によって取得されたrequesturiは/fdsfではなく、/fdsfではありません。wpemiyal5b17655.png webutils(org.apache.shiro.web.util)のgetRequesturi関数は、requesturiを取得するために呼び出されます。 public static string getRequesturi(httpservletrequestリクエスト){

string uri=(string)request.getattribute( 'javax.servlet.include.request_uri');

if(uri==null){

uri=request.getRequesturi();

}

return remormize(decodeandcleanuristring(request、uri));

}

DeCodeandCleanuristring関数は、URIをクリーニングするためにRequesturi関数で最終的に呼び出されます。

private static string decodeandcleanuristring(httpservletrequest request、string uri){

uri=decoderequestString(request、uri);

int semicolonindex=uri.indexof(59); //番号の場所を取得します

return semicolonindex!=-1? uri.substring(0、semicolonindex): uri;

}

ある場合; URIの番号、すべての文字が削除されます。 /fdsf;/./hello/1/は最終的に/fdsfになりました。t22s543k1xb7656.png5。脆弱性の概要WebコンテナのShiroのインターセプターは、最初にSpring(サーブレット)で実行されます。 2つのインターセプター間のURIパターンマッチングの違いは、シロインターセプターをバイパスすることにつながります。シロはそれを2回修理しました。 Shiro 1.4.2の脆弱性は、Requesturiの後に /番号を削除するためのURLパスに一致する脆弱性でした。メソッドを追加/番号を追加するための簡単な修正と見なされます。次に、1.5.2で、Requesturiの自律的スプライシングを使用した方法が修正されました。 /fdsf; /./hello/1/など。 requesturiを使用してメソッドをバイパスします。

0x05修理計画

1。シロ1.5.2にバージョン1.5.2以上に追加されたフィルタールールをアップグレードします。 dottestgetpathwithinapplicationfromrequest( ''、 '/servlet'、 '/foobar'、 '/servlet/foobar') '/foobar'、 '/servlet/foobar')dottestgetpathwithinapplicationfromrequest( '/'、 'servlet'、 '/foobar'、 '/servlet/foobar') dottestgetpathwithinapplicationfromrequest( '//'、 '//servlet'、 '/servlet/foobar')dottestgetpathwithinapplicationfromrequest( '/context-path'、 '/servlet'、 '/foobar'、 '/servet/foobar')DottestetheTheThiNInplicationFromequest( 「//サーブレット」、 '//foobar'、 '/servlet/foobar')dottestgetpathwithinapplicationfromrequest( '//context-path'、 '/servlet'、 '/asdf'、 '//servlet/other'、 '/servet/other')dottesttetpathin fromrequest ';/./servlet/other'、 '/asdf')dottestgetpathwithinapplicationfromrequest( '/context%2525path'、 '/servlet'、 '/foobar'、 '/servlet/foobar')dottestgetpathwithinapplicationfromrequest( '/c%6fnext%20path'、fobar '/servlet/foobar')dottestgetpathwithinapplicationfromrequest( '/context path'、 '/servlet'、 '/foobar'、 '/servlet/foobar')dottestgetpathwithinapplicationfromrequest( ''、 ''、null、 '/' null、 '/index.jsp')}

2。ダイナミックルーティングインターセプターのURLパス式として *ワイルドカードを使用しないようにしてください。

0x06参照

https://www.zhihuifly.com/t/topic/2822 https://paper.sebug.org/1196/https://xz.aliyun.com/t/8281