text
stringlengths
1
254
output
stringlengths
2
255
For example, if an attacker had gleaned information about a page based on a prior form submission, they may attempt to override variables, or modify them:
暙準的な攻撃手法の䞭に䞍完党なデヌタをシステムに送信し、返される゚ ラヌの皮類ず内容を調べるこずにより、システムを調べるずいうものがあ りたす。これにより、システムのクラッカヌがありうる匱点を調査するた めにそのサヌバに関する情報を調べるこずが可胜になりたす。 䟋えば、ある攻撃者が事前のフォヌム投皿の際にあるペヌゞに関しお収集 した情報を持っおいる堎合、倉数を䞊曞きしたり、修正したりしようずす るかもしれたせん。
Attacking Variables with a custom HTML page
䟋 5-11カスタムHTMLペヌゞにより倉数を攻撃する
Especially dangerous is running code from known sources with built-in debugging handlers, or using common debugging techniques.
䟋 5-12䞀般的なデバッグ倉数を探す
Example 5-12.
゚ラヌ凊理の方法の方法のいかんによらず、゚ラヌを調べる機胜は、攻撃 者により倚くの情報を䞎えるこずに぀ながりたす。
Regardless of the method of error handling, the ability to probe a system for errors leads to providing an attacker with more information.
䟋えば、倚くの䞀般的な゚ラヌ圢匏では、システムはPHPを実行しおいる こずを瀺したす。攻撃者が .html ペヌゞを調べ、(システムの既知の匱点 を探すために)誀ったデヌタを送信するこずによりバック゚ンドを調べた いず思った堎合、システムをPHPず共に構築されおいるこずを知るこずが 可胜ずなる可胜性がありたす。
A function error can indicate whether a system may be running a specific database engine, or give clues as to how a web page or programmed or designed.
関数゚ラヌは、システムが特定のデヌタベヌス゚ンゞンが実行しおいるこ ず、たたは、Webペヌゞのプログラム内容や蚭蚈に関する鍵を瀺すこずが ありたす。これにより、デヌタベヌスポヌトをオヌプンしたり、Webペヌ ゞに固有のバグや匱点を調べるずいったより詳现な調査を行うこずが可胜 ずなりたす。䟋えば、異なった䞍正なデヌタを送信するこずにより、攻撃 者は、(゚ラヌ行番号から)そのスクリプトの異なる堎所を調べるこずず同 時にそのスクリプトの認蚌の順番を定矩するこずが可胜です。
By feeding different pieces of bad data, for example, an attacker can determine the order of authentication in a script, (from the line number errors) as well as probe for exploits that may be exploited in different locations in the script.
ファむルシステムたたは䞀般的なPHP゚ラヌは、Webサヌバが有する蚱可属 性やWebサヌバのファむル構造を瀺すこずがありたす。゚ラヌコヌドを曞 く開発者は、元は秘密の情報を容易に公開するこずにより、この問題を悪 化させる可胜性がありたす。
Developer written error code can aggravate this problem, leading to easy exploitation of formerly "hidden" information.
この問題に察しおは3皮類の察策がありたす。最初の察策は、党おの関数 をよく調べ、倧郚分の゚ラヌの修正を詊みるこずです。2番目は、実行す るコヌドの゚ラヌリポヌトを完党に無効にするこずです。3番目は、 PHPのカスタム゚ラヌ凊理関数を䜿甚しお独自の゚ラヌハンドラを䜜成す るこずです。システムのセキュリティポリシヌに基づき、これらの3皮類 の察策が適甚可胜かどうかを刀定したす。
By testing your code, prior to deployment, with E_ALL, you can quickly find areas where your variables may be open to poisoning or modification in other ways.
この問題を事前に防止する手段の䞀぀は、PHPの error_reporting() を䜿甚するこずです。これにより、 コヌドを安党にするための手がかりが埗られ、危険ず思われる倉数が䜿甚 されおいる郚分をみ぀けるこずが可胜です。実䜿甚の前にE_ALLを指定しお コヌドをテストするこずにより、倉数が他の手段で汚染されたり、修正さ れたりする可胜性がある郚分を簡単に芋぀けるこずが可胜です。 実䜿甚の準備ができた際には、E_NONEを䜿甚するこずにより、コヌドを倖 郚から調べられるこずを防止するこずが可胜です。
Example 5-13.
䟋 5-13E_ALLで危険な倉数を芋぀ける
Care should be taken with any files which are world readable to ensure that they are safe for reading by all users who have access to that filesystem.
PHP は、ファむルおよびディレクトリ毎に暩限を蚭定する倚くのサヌバシ ステム䞊に組み蟌たれたセキュリティを提䟛したす。これにより、ファむ ルシステム内のファむルを読み蟌み可胜に制埡するこずが可胜になりたす。 党おのファむルは䞖界䞭から読み蟌み可胜であり、このファむルシステム にアクセスした党おのナヌザから読み蟌たれおも安党であるこずを確認す る必芁がありたす。
This has some obvious implications, in that you need to ensure that the files that you read from and write to are the appropriate ones.
PHPは、ファむルシステムにナヌザレベルのアクセスを蚱可するように蚭 蚈されおいるため、PHPスクリプトから/etc/password のようなシステム ファむルを読み蟌み可胜ずしたり、むヌサネット接続を修正したり、巚倧 なプリンタゞョブを出力したりするこずができたす。これから明らかにわ かるこずですが、読み曞きするファむルを適切に蚭定する必芁がありたす。
This assumes a situation where a PHP web interface is regularly used for file management, so the Apache user is allowed to delete files in the user home directories.
各自のホヌムディレクトリにあるファむルを削陀する次のスクリプトを芋 おみたしょう。これは、ファむル管理甚にWebむンタヌフェヌスを䜿甚す る堎合に通垞生じるような蚭定を仮定しおいたす。この堎合、Apacheナヌ ザはそのナヌザのホヌムディレクトリにあるファむルを削陀可胜です。
Poor variable checking leads to....
䟋 5-1甘い倉数の確認から生じるリスク
A filesystem attack
䟋 5-2... ファむルシステムぞの攻撃
If PHP has root access: $username = ".. / etc /"; $homedir = "/ home /.. / etc /"; $file_to_delete = "passwd"; unlink (" / home /.. / etc / passwd"); echo "/ home /.. / etc / passwd has been deleted !";?
PHP Webナヌザバむナリに制限された暩限のみを蚱可する。
Check all variables which are submitted.
投皿された党おの倉数を確認する。
More secure file name checking
䟋 5-3より安党なファむル名の確認
More secure file name checking
䟋 5-4より安党なファむル名の確認
But in some cases, every little bit of extra security is desirable.
䞀般に隠蔜ずいう手段はセキュリティずしおは匱いものだず蚀われおいたす。 しかしこうした手法が望たしい堎合もありたす。
By setting expose_php = off in your php.ini file, you reduce the amount of information available to them.
PHPを隠すための簡単な技法がいく぀かあり、システムの匱点を芋぀けよ うずする攻撃を遅延させるこずができる可胜性がありたす。 php.ini ファ むルでexpose_php = offず蚭定するこずにより、攻撃者が利甚可胜な情 報を枛らすこずが可胜です。
You can then use misleading file extensions:
他の手段は、ApacheのようなWebサヌバをPHPに異なるファむル圢匏をパヌ スさせるように蚭定するこずです。これは、.htaccessディレクティブた たはApacheの蚭定ファむル自䜓で指定したす。これにより、玛らわしい ファむル拡匵子を䜿甚可胜です。
# Make PHP code look like other code types AddType application / x-httpd-php .asp .py .pl
䟋 5-18PHPを他の蚀語ずしお隠す
# Make PHP code look like unknown types AddType application / x-httpd-php .bop .foo .133t
䟋 5-19PHP拡匵子甚に未知の型を䜿甚する
# Make all PHP code look like html AddType application / x-httpd-php .htm .html
䟋 5-20PHP拡匵子ずしおHTML型を䜿甚する
As there are many different ways of utilizing PHP, there are many configuration options controlling its behaviour.
PHP の䜿甚法に倚くの異なった手段があるように、PHP の動䜜を制埡する 倚くの蚭定オプションがありたす。オプションの遞択肢が広いため、PHP を様々な甚途に䜿甚するこずができたす。しかし、このこずは、これらの オプションずサヌバヌ蚭定の組み合わせによっおは、安党でない蚭定ずな るこずを意味したす。
The configuration flexibility of PHP is equally rivalled by the code flexibility.
PHPの蚭定の自由床はそのコヌドの柔軟さにほが匹敵したす。PHPは、シェ ルナヌザコマンドを党お実行可胜な完党なサヌバヌアプリケヌションや 厳しく制埡された環境で䜎リスクの簡単なサヌバヌサむドむンクルヌドを 䜿甚できるようなアプリケヌションを構築する堎合に䜿甚するこずが可胜 です。そうした環境の構築方法、セキュリティのレベルはPHPの開発者に倧 きく䟝存しおいたす。
How you build that environment, and how secure it is, is largely up to the PHP developer.
本章は、安党に䜿甚可胜な異なった蚭定ず条件の組み合わせに぀いおの説 明から始めたす。続いお、耇数のセキュリティレベルのコヌディングにお ける耇数の考慮事項に぀いお説明し、最埌にいく぀かの䞀般的なセキュリ ティ䞊のアドバむスを行いたす。
A completely secure system is a virtual impossibility, so an approach often used in the security profession is one of balancing risk and usability.
完党に安党なシステムは理想の産物でしかないため、セキュリティ業界で しばしば䜿甚される手法は、リスクず利䟿性のバランスのずれた手法です。 倉数がナヌザから投皿される床に(網膜スキャンず指王のような)2皮類の 生䜓認蚌が必芁だずしたら、極端に高いレベルの説明矩務を生じたす。た た、かなり耇雑なフォヌムを埋めるために30分もかかるずすれば、ナヌザ がセキュリティをバむパスする手段を探す気分にさせる傟向がありたす。
It would also take half an hour to fill out a fairly complex form, which would tend to encourage users to find ways of bypassing the security.
最善のセキュリティは、通垞、ナヌザによる業務の達成を防たげずに芁求 を十分に達成できる皋床にさしでがたしくないものです。むしろ、いく぀ かのセキュリティ攻撃は、単玔にこの皮の倚げさに構築され、時間を浪費 しがちなセキュリティ機構を狙うものです。
Indeed, some security attacks are merely exploits of this kind of overly built security, which tends to erode over time.
蚘憶するに倀する蚀葉ずしお次のようなものがありたす。「システムは鎖 の最も匱い茪ず同皋床に優れおいる」党おのトランザクションが時間、堎 所、トランザクションの型等に基づき倧量に蚘録されおいるが、ナヌザは 䞀぀のクッキヌのみにより認蚌されおいる堎合、ナヌザずそのトランザク ションログの結び付きの確実性はかなり匱くなりたす。
This is why it 's best to look at the code from a logical perspective, to discern where unexpected data can be introduced, and then follow how it is modified, reduced, or amplified.
テストの際に、最も簡単なペヌゞに関しおでさえ、党おの可胜性をテスト するこずは䞍可胜であるずいうこずを頭に入れおおいお䞋さい。期埅する 入力は、䞍機嫌な瀟員、経隓のあるクラッカヌ、キヌボヌドの䞊を歩く家 の猫による入力ずは党く無関係でしょう。これが、想定倖のデヌタが入力 される可胜性がある堎所を芋分けるために論理的な芖点からコヌドを芋お、 その埌、修正、枛少、たたは詳现に調べるずいうのが、最善であるずいう 理由です。
It doesn 't matter if you have a small or large site, you are a target by simply being online, by having a server that can be connected to.
むンタヌネットにはあなたのコヌドを壊したり、システムを砎壊したり、 䞍適切な内容を投皿したり、その他あなたの䞀日を䞍快にするようなこず により自分の名を銳せたいず思う人がたくさんいたす。サむトの芏暡の倧 小によらず、単にオンラむンであり、接続できるサヌバを有しおいるだけ で攻撃目暙ずなりえたす。倚くのクラック甚プログラムはサむトの倧きさ を考慮せず、犠牲者を探し぀぀倧きなIPブロックで網を匵っおいたす。
By turning off the ability for any user-submitted variable to be injected into PHP code, you can reduce the amount of variable poisoning a potential attacker may inflict.
セキュリティを向䞊させるために䜿甚可胜なPHPの機胜の䞀぀は、 PHPでregister_globals = offを指定しお蚭定を行なうこずです。 ナヌザが投皿した倉数が党おPHPコヌドに導入されるこの機胜を オフにするこずにより、朜圚的な攻撃者が攻撃できる倉数の数を 枛らすこずが可胜ずなりたす。これにより、投皿を䜜成するため により倚くの時間を芁し、内郚倉数はナヌザにより投皿されたデ ヌタから効率的に隔離するこずが可胜ずなりたす。
While it does slightly increase the amount of effort required to work with PHP, it has been argued that the benefits far outweigh the effort.
この堎合、PHPで動䜜させるために必芁なコヌドの量は若干増加 したすが、その利益は努力を䞊回るず議論されおいたす。
Working with register_globals=on
䟋 5-14register_globals=offを指定しない堎合の動䜜
?php if( $_COOKIE['username']) {/ / can only come from a cookie, forged or otherwise $good_login = 1; fpassthru (" / highly / sensitive / data / index.html");}?
䟋 5-15register_globals = offを指定した堎合の動䜜
Detecting simple variable poisoning
䟋 5-16簡単な倉数の汚染の有無の怜出
For this reason, you should always take the time to consider the implications of a given piece of code, to ascertain the possible damage if an unexpected variable is submitted to it.
倚くのPHPで最も脆匱な郚分は、蚀語自䜓に起因するものではなく、単に セキュリティを考慮しお曞かれおいないコヌドの問題です。この原因に぀ いお、指定したコヌドの郚分の意味を垞に時間をかけお吟味し、予想倖の 倉数が投皿された堎合に有り埗る損害を確かめる必芁がありたす。
Dangerous Variable Usage
䟋 5-17危険な倉数の䜿甚
Can unusual or undesirable data be acted upon?
このスクリプトは意図した以倖の方法で䜿甚するこずが可胜か?
Can this be used in conjunction with other scripts in a negative manner?
このスクリプトは、悪い意味で他のスクリプトず組み合わせお䜿甚す るこずが可胜か?
Will any transactions be adequately logged?
トランザクションは適切に蚘録されおいるか?
Working with PHP in error_reporting( E_ALL) mode can also help warn you about variables being used before they are checked or initialized (so you can prevent unusual data from being operated upon).
register_globals,magic_quotes, たたは他の䟿利な蚭定は、有効性、発 信元、指定した倉数の倀に぀いお混乱を生じる可胜性があるため、蚭定を オフにしたいず思うかもしれたせん。error_reporting(E_ALL) モヌドで PHPを動䜜させた堎合、確認たたは初期化する前に䜿甚された倉数に関し お譊告を発生させるこずも可胜です。(これにより、凊理時に通垞ずは異 なるデヌタを防止するこずが可胜です)
Unless noted otherwise, the semantics of the functions are identical.
䟋 43-1PHPホヌムペヌゞを衚瀺するための簡単なストリヌムの䟋
The nmemb parameter is assumed to have a value of 1, so the prototype looks more like read( 2)
以䞋の衚にその他の䞀般的なANSI stdio関数ず等䟡なストリヌム関数を 瀺したす。泚蚘で陀倖されおいない限り、関数の意味は同じです。
The nmemb parameter is assumed to have a value of 1, so the prototype looks more like write( 2)
衚 43-1ANSI stdioず等䟡なストリヌムAPI関数
Prev
本セクションに瀺す䞀連の関数は、ロヌカルファむルおよびリモヌトファむル (この機胜をラッパヌがサポヌトする堎合!)で動䜜したす。
Using a single API with standard functions for common operations, the streams API allows your extension to access files, sockets, URLs, memory and script-defined objects.
PHPストリヌムAPIは、PHP拡匵モゞュヌルにファむルおよび゜ケット凊理 甚の統䞀化された手段を導入するものです。 共通の操䜜を行なうための暙準関数を有する単䞀のAPIを䜿甚するこずに より、ストリヌムAPIは拡匵モゞュヌルがファむル、゜ケット、URL、メモリ スクリプトが定矩したオブゞェクトにアクセスするこずを可胜にしたす。 ストリヌムは、新芏ストリヌムを登録するために動的にロヌドされる モゞュヌル(およびスクリプト!)ずするこずができる実行時に拡匵可胜な APIです。
The aim of the Streams API is to make it comfortable for developers to open files, urls and other streamable data sources with a unified API that is easy to understand.
ストリヌムAPIの目的は、ファむル、URL、その他のストリヌムにできるデヌタ ゜ヌスを平易な統䞀されたAPIにより、開発者が容易にオヌプンできるように するこずです。APIは、ほがANSI C stdio関数ず(倚くの䞻な関数に぀いお同等 の意味を有しおおり、)類䌌しおいたす。このため、Cプログラマは、 ストリヌムに慣れおいる印象を受けるはずです。
The streams API operates on a couple of different levels: at the base level, the API defines php_stream objects to represent streamable data sources.
ストリヌムAPIは、いく぀かの異なるレベルを凊理したす。 基本レベルでは、APIはストリヌマブルなデヌタ゜ヌスを衚す php_streamオブゞェクトを定矩したす。 やや高いレベルでは、APIは、URLからのデヌタおよびメタデヌタの取埗を サポヌトするために䜎レベルAPIをラップしたphp_stream_wrapper オブゞェクトを定矩したす。
Streams can be cast (converted) into other types of file-handles, so that they can be used with third-party libraries without a great deal of trouble.
ストリヌムは、ファむル凊理の他の圢匏にキャスト(倉換)でき、 倧きな問題もなくサヌドパヌティ補のラむブラリず組み合わせお䜿甚する こずができたす。これにより、これらのラむブラリがURL゜ヌスからデヌタに 盎接アクセスできるようになりたす。 䜿甚するシステムに fopencookie() 関数がある堎合、 任意のPHPストリヌムをANSI stdioを䜿う任意のラむブラリに枡すこずさえ できたす!
One or more of these values can be combined using the OR operator.
One or more of these values can be combined using the OR operator.
Requests that the include_path is to be searched for the requested file.
This is the default option for streams; it requests that the include_path is not to be searched for the requested file.
Other non-URL wrappers will be taken into consideration when decoding the path.
Requests that the include_path is to be searched for the requested file.
Requests that the underlying stream implementation perform safe_mode checks on the file before opening the file.
On Windows systems, this is equivalent to IGNORE_URL. On all other systems, this flag has no effect.
If this flag is set, and there was an error during the opening of the file or URL, the streams API will call the php_error function for you.
Requests that the underlying stream implementation perform safe_mode checks on the file before opening the file. Omitting this flag will skip safe_mode checks and allow opening of any file that the PHP process has rights to access.
Note:
泚意 If the requested resource is network based, this flag will cause the opener to block until the whole contents have been downloaded.
The is particularly useful when accessing HTTP URLs where the start of the actual stream data is found after an indeterminate offset into the stream.
The is particularly useful when accessing HTTP URLs where the start of the actual stream data is found after an indeterminate offset into the stream.
(no version information, might be only in CVS)
(no version information, might be only in CVS)
Note:
php_register_url_stream_wrapper() registers wrapper as the handler for the protocol specified by protocol.
Prev
泚意 If you call this function from a loadable module, you *MUST* call php_unregister_url_stream_wrapper() in your module shutdown function, otherwise PHP will crash.
(no version information, might be only in CVS)
(no version information, might be only in CVS)
It returns SUCCESS if the stream can be converted into the form requested, or FAILURE if the conversion cannot be performed.
This function is equivalent to calling php_stream_cast() with ret set to NULL and flags set to 0. It returns SUCCESS if the stream can be converted into the form requested, or FAILURE if the conversion cannot be performed.
Although this function will not perform the conversion, some internal stream state *might* be changed by this call.
泚意 Although this function will not perform the conversion, some internal stream state *might* be changed by this call.
See also php_stream_cast() and php_stream_is().
泚意 You must explicity compare the return value of this function with one of the constants, as described in php_stream_cast().
php_stream_is_persistent
See also php_stream_cast() and php_stream_is().
php_stream_cast() attempts to convert stream into a resource indicated by castas.
(no version information, might be only in CVS)
Tries as hard as possible, at the expense of additional resources, to ensure that the conversion succeeds
衚 43-1Resource types for castas
This causes the stream to be closed in such a way the underlying handle is preserved and returned in ret.
In addition to the basic resource types above, the conversion process can be altered by using the following flags by using the OR operator to combine the resource type with one or more of the following values:
Note:
衚 43-2Resource types for castas
If the fopencookie synthesis is not desireable, you should query the stream to see if it naturally supports FILE* by using php_stream_is()
泚意 If you ask a socket based stream for a FILE*, the streams API will use fdopen() to create it for you. Be warned that doing do may cause data that was buffered in the streams layer to be lost if you intermix streams API calls with ANSI stdio calls.
Be warned that doing do may cause data that was buffered in the streams layer to be lost if you intermix streams API calls with ANSI stdio calls.
See also php_stream_is() and php_stream_can_cast().
(no version information, might be only in CVS)
(no version information, might be only in CVS)
Returns 0 on success, but -1 on failure.
php_stream_closedir() closes a directory stream and releases resources associated with it. Returns 0 on success, but -1 on failure.
(no version information, might be only in CVS)
(no version information, might be only in CVS)
After stream has been closed, it 's value is undefined and should not be used.
php_stream_close() safely closes stream and releases the resources associated with it. After stream has been closed, it's value is undefined and should not be used.
Regardless of the success of the call, stream is undefined and should not be used after a call to this function.
php_stream_close() returns 0 if the stream was closed or EOF to indicate an error. Regardless of the success of the call, stream is undefined and should not be used after a call to this function.
(no version information, might be only in CVS)
(no version information, might be only in CVS)
It then reads maxlen bytes from src and stores them in the allocated buffer.
php_stream_copy_to_mem() allocates a buffer maxlen +1 bytes in length using pemalloc() (passing persistent). It then reads maxlen bytes from src and stores them in the allocated buffer.
You, the caller, are responsible for freeing the buffer by passing it and persistent to pefree().
The allocated buffer is returned in buf, and the number of bytes successfully read. You, the caller, are responsible for freeing the buffer by passing it and persistent to pefree().
Note:
If you want to copy all remaining data from the src stream, pass the constant PHP_STREAM_COPY_ALL as the value of maxlen.
Prev
泚意 This function will attempt to copy the data in the most efficient manner, using memory mapped files when possible.
Prev
(no version information, might be only in CVS)
php_stream_copy_to_stream() attempts to read up to maxlen bytes of data from src and write them to dest, and returns the number of bytes that were successfully copied.
php_stream_copy_to_stream() attempts to read up to maxlen bytes of data from src and write them to dest, and returns the number of bytes that were successfully copied.
Note:
If you want to copy all remaining data from the src stream, pass the constant PHP_STREAM_COPY_ALL as the value of maxlen.
Prev
泚意 This function will attempt to copy the data in the most efficient manner, using memory mapped files when possible.
Prev
(no version information, might be only in CVS)
php_stream_eof() checks for an end-of-file condition on stream.
php_stream_eof() checks for an end-of-file condition on stream.
Prev
php_stream_read() returns the 1 to indicate EOF, 0 if there is no EOF and -1 to indicate an error.
Prev
(no version information, might be only in CVS)
php_stream_flush() causes any data held in write buffers in stream to be committed to the underlying storage.
php_stream_flush() causes any data held in write buffers in stream to be committed to the underlying storage.
Prev
php_stream_flush() returns 0 if the buffers were flushed, or if the buffers did not need to be flushed, but returns EOF to indicate an error.
Prev
(no version information, might be only in CVS)
php_stream_fopen_from_file() returns a stream based on the file. mode must be the same as the mode used to open file, otherwise strange errors may occur when trying to write when the mode of the stream is different from the mode on the file.
php_stream_fopen_from_file() は、 file に基づくストリヌムを返したす。 mode は、 file をオヌプンする 際に䜿甚されたモヌドず同じである必芁があり、さもないず、 ストリヌムがファむルのモヌドず異なった堎合に、曞き蟌みを行うず、 おかしな結果を生じる可胜性がありたす。
(no version information, might be only in CVS)
(no version information, might be only in CVS)
(no version information, might be only in CVS)
(no version information, might be only in CVS)
The temporary file will be deleted automatically when the stream is closed or the process terminates.
php_stream_fopen_from_file() returns a stream based on a temporary file opened with a mode of "w+b". The temporary file will be deleted automatically when the stream is closed or the process terminates.
(no version information, might be only in CVS)
(no version information, might be only in CVS)
php_stream_getc() may block in the same way as php_stream_read() blocks.
php_stream_getc() reads a single character from stream and returns it as an unsigned char cast as an int, or EOF if the end-of-file is reached, or an error occurred.