简体   繁体   English

了解smb和DCERPC的远程命令执行功能

[英]Understanding smb and DCERPC for remote command execution capabilities

I'm trying to understand all the methods available to execute remote commands on Windows through the impacket scripts: 我试图通过impacket脚本了解在Windows上执行远程命令的所有可用方法:

https://www.coresecurity.com/corelabs-research/open-source-tools/impacket https://www.coresecurity.com/corelabs-research/open-source-tools/impacket

https://github.com/CoreSecurity/impacket https://github.com/CoreSecurity/impacket

I understand the high level explanation of psexec.py and smbexec.py, how they create a service on the remote end and run commands through cmd.exe -c but I can't understand how can you create a service on a remote windows host through SMB. 我理解psexec.py和smbexec.py的高级解释,他们如何在远程端创建服务并通过cmd.exe -c运行命令,但我无法理解如何在远程Windows主机上创建服务通过SMB。 Wasn't smb supposed to be mainly for file transfers and printer sharing? smb应该主要用于文件传输和打印机共享? Reading the source code I see in the notes that they use DCERPC to create this services, is this part of the smb protocol? 阅读他在使用DCERPC创建此服务的注释中看到的源代码,这是smb协议的一部分吗? All the resources on DCERPC i've found were kind of confusing, and not focused on its service creating capabilities. 我发现DCERPC上的所有资源都令人困惑,并没有专注于其服务创建功能。 Looking at the sourcecode of atexec.py, it says that it interacts with the task scheduler service of the windows host, also through DCERPC. 查看atexec.py的源代码,它表示它还通过DCERPC与Windows主机的任务调度程序服务进行交互。 Can it be used to interact with all services running on the remote box? 它可以用于与远程盒上运行的所有服务进行交互吗?

Thanks! 谢谢!

DCERPC ( https://en.wikipedia.org/wiki/DCE/RPC ) : the initial protocol, which was used as a template for MSRPC ( https://en.wikipedia.org/wiki/Microsoft_RPC ). DCERPChttps://en.wikipedia.org/wiki/DCE/RPC ):初始协议,用作MSRPC的模板( https://en.wikipedia.org/wiki/Microsoft_RPC )。

MSRPC is a way to execute functions on the remote end and to transfer data (parameters to these functions). MSRPC是一种在远程端执行功能并传输数据(参数到这些功能)的方法。 It is not a way to directly execute remote OS commands on the remote side. 它不是在远程端直接执行远程OS命令的方法。

SMB ( https://en.wikipedia.org/wiki/Server_Message_Block ) is the file sharing protocol mainly used to access files on Windows file servers. SMBhttps://en.wikipedia.org/wiki/Server_Message_Block )是文件共享协议,主要用于访问Windows文件服务器上的文件。 In addition, it provides Named Pipes ( https://msdn.microsoft.com/en-us/library/cc239733.aspx ), a way to transfer data between a local process and a remote process. 此外,它还提供了命名管道( https://msdn.microsoft.com/en-us/library/cc239733.aspx ),这是一种在本地进程和远程进程之间传输数据的方法。

One common way for MSRPC is to use it via Named Pipes over SMB, which has the advantage that the security layer provided by SMB is directly approached for MSRPC. MSRPC的一种常见方式是通过SMB上的命名管道使用它,其优点是SMB提供的安全层直接用于MSRPC。

In fact, MSRPC is one of the most important, yet very less known protocols in the Windows world. 事实上,MSRPC是Windows世界中最重要但却鲜为人知的协议之一。

Neither MSRPC, nor SMB has something to do with remote execution of shell commands. MSRPC和SMB都没有与远程执行shell命令有关。

One common way to execute remote commands is: 执行远程命令的一种常用方法是:

  • Copy files (via SMB) to the remote side (Windows service EXE) 将文件(通过SMB)复制到远程端(Windows服务EXE)
  • Create registry entries on the remote side (so that the copied Windows Service is installed and startable) 在远程端创建注册表项(以便安装并启动复制的Windows服务)
  • Start the Windows service. 启动Windows服务。 The started Windows service can use any network protocol (eg MSRPC) to receive commands and to execute them. 启动的Windows服务可以使用任何网络协议(例如MSRPC)来接收命令并执行它们。
  • After the work is done, the Windows service can be uninstalled (remove registry entries and delete the files). 完成工作后,可以卸载Windows服务(删除注册表项并删除文件)。

In fact, this is what PSEXEC does. 事实上,这就是PSEXEC所做的。

All the resources on DCERPC i've found were kind of confusing, and not focused on its service creating capabilities. 我发现DCERPC上的所有资源都令人困惑,并没有专注于其服务创建功能。

Yes, It's just a remote procedure call protocol. 是的,它只是一个远程过程调用协议。 But it can be used to start a procedure on the remote side, which can just do anything, eg creating a service. 但它可用于在远程端启动程序,这可以做任何事情,例如创建服务。

Looking at the sourcecode of atexec.py, it says that it interacts with the task scheduler service of the windows host, also through DCERPC. 查看atexec.py的源代码,它表示它还通过DCERPC与Windows主机的任务调度程序服务进行交互。 Can it be used to interact with all services running on the remote box? 它可以用于与远程盒上运行的所有服务进行交互吗?

There are some MSRPC commands which handle Task Scheduler, and others which handle generic service start and stop commands. 有一些MSRPC命令可以处理任务调度程序,还有一些命令可以处理通用服务启动和停止命令。

A few final words at the end: 最后几句话:

SMB / CIFS and the protocols around are really complex and hard to understand. SMB / CIFS及其周围的协议非常复杂且难以理解。 It seems ok trying to understand how to deal with eg remote service control, but this can be a very long journey. 似乎可以尝试理解如何处理例如远程服务控制,但这可能是一个非常漫长的旅程。

Perhaps this page (which uses Java for trying to control Windows service) may also help understanding. 也许这个页面(使用Java试图控制Windows服务)也可能有助于理解。

https://dev.c-ware.de/confluence/pages/viewpage.action?pageId=15007754 https://dev.c-ware.de/confluence/pages/viewpage.action?pageId=15007754

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM