Blog

Pythonのtarfile モジュールパトラバーサバグキンクー

October 3, 2022
ローラ・バーハイド

最近、あるチーム セキュリティ研究者 Python の tar ファイル抽出機能に 15 年前のバグが見つかったことを発表しました。この脆弱性は 2007 年に初めて公開され、次のように追跡されました。 CVE-2007-4559。Python の公式ドキュメントに注意書きが追加されたが、バグ自体はパッチされていないままだった。

この脆弱性は何千ものソフトウェアプロジェクトに影響を与える可能性がありますが、多くの人が状況や対処方法に慣れていません。だからこそ、ここ セキュア・コード・ウォリアー、この脆弱性の悪用を自分でシミュレートして影響を直接確認し、この永続的なバグの仕組みを実際に体験する機会を提供します。これにより、アプリケーションの保護を強化できます。

シミュレートしてみる ミッション 今。

脆弱性:tar ファイル抽出中のパストラバーサル

パストラバーサルまたはディレクトリトラバーサルは、サニタイズされていないユーザー入力を使用してファイルパスを作成したときに発生し、攻撃者がファイルにアクセスして上書きしたり、任意のコードを実行したりする可能性があります。

この脆弱性はPythonに存在します タルファイル モジュール。tar (テープアーカイブ) ファイルはアーカイブと呼ばれる 1 つのファイルです。複数のファイルとそのメタデータをまとめてパッケージ化したもので、通常は tar.gz または tgz 拡張子。アーカイブ内の各メンバーは TAR 情報 オブジェクトには、ファイル名、変更時間、所有権などのメタデータが含まれます。

リスクは、アーカイブを再度抽出できることに起因します。

抽出時には、すべてのメンバーに書き込むパスが必要です。この場所は、ベースパスとファイル名を結合して作成されます。

Python のスニペット Tarfile.py


このパスが作成されると、に渡されます tar ファイル. 抽出 または tar ファイル. すべて抽出 抽出を実行する関数:

Python のスニペット Tarfile.py

ここでの問題は、ファイル名がサニタイズされていないことです。攻撃者は、次のようなパストラバーサル文字を含むようにファイルの名前を変更する可能性があります。 ドットドットスラッシュ (../)。これにより、ファイルは本来あるべきディレクトリから移動し、任意のファイルを上書きします。これにより、最終的にはリモートでコードが実行され、悪用されやすくなります。

脆弱性は、特定方法がわかっていれば、他のシナリオでも発生します。Python による tar ファイルの処理に加えて、この脆弱性は zip ファイルの抽出。これは別の名前でもおなじみかもしれません。たとえば、 ジップスリップの脆弱性これはPython以外の言語でも明らかになっています!

ミッションへのリンク 

どうすればリスクを軽減できますか?

この脆弱性は何年も前から知られていましたが、Python の保守担当者は抽出機能に期待しています。 本来やるべきこと。この場合、「バグではなく機能だ」と言う人もいるかもしれません。残念なことに、開発者は未知のソースから tar ファイルや zip ファイルを抽出することを常に避けられるとは限りません。安全な開発プラクティスの一環として、信頼できない入力をサニタイズしてパストラバーサルの脆弱性を防ぐのは開発者次第です。

Python で安全なコードを書いてリスクを軽減する方法についてもっと知りたいですか?

私たちを試してみてください 無料のパイソンチャレンジ

無料のコーディングガイドラインをもっと入手したい場合は、チェックしてください セキュア・コード・コーチ 安全なコーディング方法を常に把握するのに役立ちます。

キャッチフレーズ

Govern AI-driven development before it ships

Measure AI-assisted risk, enforce secure coding policy at commit, and accelerate secure delivery across your SDLC.

book a demo
キャッチフレーズ

Explore more blogs

これは、オーラが射手と鼻の穴を広げることによって、腸管を熱的に発芽させ、臭いを帯びていることを防ぐためのものです。

browse all
Case Study
Filter Label
This is some text inside of a div block.

Supercharged Security Awareness: How Tournaments are Inspiring Developers at Erste Group

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Suspendisse varius enim in eros elementum tristique. Duis cursus, mi quis viverra ornare, eros dolor interdum nulla, ut commodo diam libero vitae erat. Aenean faucibus nibh et justo cursus id rutrum lorem imperdiet. Nunc ut sem vitae risus tristique posuere.

Learn More
Case Study
Filter Label
This is some text inside of a div block.

Security as culture: How Blue Prism cultivates world-class secure developers

Learn how Blue Prism, the global leader in intelligent automation for the enterprise, used Secure Code Warrior's agile learning platform to create a security-first culture with their developers, achieve their business goals, and ship secure code at speed

Learn More
Case Study
Filter Label
This is some text inside of a div block.

One Culture of Security: How Sage built their security champions program with agile secure code learning

Discover how Sage enhanced security with a flexible, relationship-focused approach, creating 200+ security champions and achieving measurable risk reduction.

Learn More
Blog
Filter Label
This is some text inside of a div block.

The Future of AI Software Governance Is Built on Strong Partnerships

Discover why Secure Code Warrior is becoming a channel-first company and how trusted partners help organizations adopt AI Software Governance securely and at scale.

Learn More
Blog
Filter Label
This is some text inside of a div block.

Citizen AI by Secure Code Warrior: Build an AI-Ready Workforce

Secure Code Warrior's AI literacy program for non-developer employees.

Learn More
Blog
Filter Label
This is some text inside of a div block.

Why most CISOs are navigating AI adoption blindfolded (and how they can remove it)

Today, Secure Code Warrior issued an all-new white paper covering a prescriptive, directional AI adoption model that security leaders can use to identify their adoption stage and make real progress in bringing the AI security risks within their organization under control.

Learn More

Secure AI-driven development before it ships

See developer risk, enforce policy, and prevent vulnerabilities across your software development lifecycle.

Book a demo