Deepin West Heaven Team: In-depth analysis of the lateral tools in Impacket

0 21
Impacket introductionImpacket is a collection of Python classes for handling net...

Impacket introduction

Impacket is a collection of Python classes for handling network protocols. Impacket focuses on providing simple programming access to packets and certain protocols themselves (such as SMB1-3 and MSRPC) of the protocol implementation. Packets can be built from scratch or parsed from raw data, and the object-oriented API makes it simple to handle the deep structure of the protocol. The library provides a set of tools as examples of operations that can be performed in this library.

Impacket lateral movement tool

psexec.py: The Python version of the Microsoft tool psexec, supporting hash lateral movement and lateral movement through Windows services.

Deepin West Heaven Team: In-depth analysis of the lateral tools in Impacket

smbexec.py: Similar to psexec, it is a customized version that modifies the feature of psexec automatically installing the server to Admin$; smbexec manually installs the server files to a custom location.

atexec: Uses remote scheduled tasks to execute commands and obtain results.

wmiexec.py: Uses the WMI component to perform lateral movement through RPC on port 135.

dcomexec.py: Uses the DCOM interface provided by Windows for lateral movement, currently supporting MMC20.Application, ShellWindows, and ShellBrowserWindow objects.

In-depth analysis of tool features

psexec.py

Prerequisite: Port 445

Parameter usage help:

(1) lget {file} parameter can download the file on the target machine.

(2) The lput {src_file, dst_path} parameter is used to upload files to the target machine.

(3) -codec parameter is used to decode the return results of command execution.

Operation flow:

1. Connect to the admin$ shared folder on the remote computer.

2. Upload the Windows service program to the admin$ shared folder.

In impacket, the service program is located in the /impacket/examples/remcomsvc.py file, saved as binary data. The default exe has been marked by antivirus software of various manufacturers. You can modify the binary data to your own written exe for上线cs.

1651127377_626a3451aafbd04ce5f23.png!small?1651127377326

3. Open the \\target\pipe\svcctl pipe to connect to the remote machine's service control manager SCM, create and start the service.

4. After the service program is started, create the stdin, stdout, and stderr named pipes for command input and result output.

1651127880_626a36481ad9979ee432e.png!small?1651127879591

5. After the command execution is completed, reconnect to the remote computer's service control manager to stop the service, delete the service, and delete the service program.

smbexec.py

Prerequisite: Port 445

Parameter help:

(1) The -share parameter specifies the shared directory to be used, with the default being c$.

(2) The -service-name parameter specifies the name of the server, with the default being BTOBTO.

(3) The -shell_type parameter specifies the command execution environment, with options of cmd or powershell, with the default being cmd.

(4) The -mode parameter specifies the operation mode, supporting SERVER and SHARE modes, with the default being share mode.

Operation flow: (Take the default SHARE mode as an example)

1. Open the \\target\pipe\svcctl pipe to connect to the remote machine's service control manager SCM.

2. Obtain the command execution method as cmd or powershell based on the shell_type command-line parameter.

1651132602_626a48ba5d2ef742e4f5b.png!small?1651132601835

3. Create a service named 'service-name' with the program corresponding to cmd or powershell, which is determined by shell_type.

4. Redirect the command execution results to the __output file.

5. Connect to the remote shared folder and open the __output file to get the command execution results.

atexec.py

Prerequisite: Port 445

Note: atexec.exe creates remote scheduled tasks by initializing COM components, which requires the target to open port 135. Impacket uses RPC protocol, and only port 445 needs to be opened.

Operation flow:

1. Open the \\target\pipe\atsvc pipe to remotely connect to the target machine's remote scheduled task manager.

2. Create a randomly named scheduled task, where the corresponding program for the task is cmd, and the result of the command is redirected to a randomly named file in the c:\windows\temp directory with the .tmp extension.

1651135125_626a52959e6987038d0ee.png!small?1651135125241

The default configuration information for the scheduled task is as follows:

<?xml version="1.0" encoding="UTF-16"?>
<Task version="1.2" xmlns="http://schemas.microsoft.com/windows/2004/02/mit/task">
  <Triggers>
    <CalendarTrigger>
      <StartBoundary>2015-07-15T20:35:13.2757294</StartBoundary>
      <Enabled>true</Enabled>
      <ScheduleByDay>
        <DaysInterval>1</DaysInterval>
      </ScheduleByDay>
    </CalendarTrigger>
  </Triggers>
  <Principals>
    <Principal id="LocalSystem">
      <UserId>S-1-5-18</UserId>
      <RunLevel>HighestAvailable</RunLevel>
    </Principal>
  </Principals>
  <Settings>
    <MultipleInstancesPolicy>IgnoreNew</MultipleInstancesPolicy>
    <DisallowStartIfOnBatteries>false</DisallowStartIfOnBatteries>
    <StopIfGoingOnBatteries>false</StopIfGoingOnBatteries>
    <AllowHardTerminate>true</AllowHardTerminate>
    <RunOnlyIfNetworkAvailable>false</RunOnlyIfNetworkAvailable>
    <IdleSettings>
      <StopOnIdleEnd>true</StopOnIdleEnd>
      <RestartOnIdle>false</RestartOnIdle>
    </IdleSettings>
    <AllowStartOnDemand>true</AllowStartOnDemand>
    <Enabled>true</Enabled>
    <Hidden>true</Hidden>
    <RunOnlyIfIdle>false</RunOnlyIfIdle>
    <WakeToRun>false</WakeToRun>
    <ExecutionTimeLimit>P3D</ExecutionTimeLimit>
    <Priority>7</Priority>
  </Settings>
  <Actions Context="LocalSystem">
    <Exec>
      <Command>%s</Command>
      <Arguments>%s</Arguments>
    </Exec>
  </Actions>
</Task>

3. Wait for the scheduled task to complete and then delete the scheduled task.

4. Connect to the remote ADMIN$ shared folder to obtain the command execution results.

5. Delete the file recording the command execution results.

wmiexec.py

Prerequisites: Port 135, Port 445

Port 135 is used to connect to wmi, and port 445 is responsible for obtaining command execution results.

Parameter help:

(1) The -noOutput parameter specifies whether to obtain the command output results. If this parameter is set to True, wmiexec.py will not rely on port 445 and only need port 135.

(2) The lput {src_file, dst_path} parameter is used to upload files to the target machine.

(3) The lget {file} parameter can download files from the target machine.

(4) The -codec parameter is used to decode the return results of command execution.

(5) The lcd parameter is used to switch the working path.

(6) The -shell_type parameter specifies the command execution environment, which can be cmd or powershell, with cmd as the default.

Operation flow:

1. Determine whether to perform an SMB connection based on the value of the noOutput parameter. If the value is False, first establish an SMB connection. If the value is True, directly connect to the remote computer's //https://www.freebuf.com/articles/system/root/cimv2 via DCOM.

1651136615_626a5867cfbf08314b027.png!small?1651136615417

2. Obtain the Win32_Process object and create a cmd or powershell process based on the shell_type parameter.

1651136778_626a590a1a2f50dc952c3.png!small?1651136777602

3. If command execution results need to be obtained, the results will be redirected to a file under the admin$ shared folder when creating a process, with the file name as "__current_time".

OUTPUT_FILENAME = '__' + str(time.time())

1651137147_626a5a7b83cdafcdbea4a.png!small?1651137147002

4, Obtain the command execution results by connecting to the remote computer's admin$ share.

dcomexec.py

Prerequisites: Port 135, Port 445

Port 135 is used to connect to DCOM, and port 445 is responsible for obtaining the command execution results.

The DCOM interfaces selected by dcomexec.py are as follows:

1, ShellWindows

Applicable to Windows 7, Windows 10, Windows Server 2012R2.

CLSID is: 9BA05972-F6A8-11CF-A442-00A0C90A8F39

2, ShellBrowserWindow

Applicable to Windows 10, Windows Server 2012R2.

CLSID is: C08AFD90-F2A1-11D1-8455-00A0C91F3880

3, MMC20

CLSID is: 49B2791A-B1AE-4C90-9B8E-E860BA07F889

The dcomexec.py process and the wmiexec usage have a high similarity, and the command execution results are redirected to the shared directory and then retrieved through the smb connection.

Summary

The core of the impacket lateral movement tool is actually the smbConnection and RPC protocol. A deep understanding of these protocols can greatly help and enhance our understanding of Windows authentication mechanisms.

你可能想看:

It is possible to perform credible verification on the system boot program, system program, important configuration parameters, and application programs of computing devices based on a credible root,

4.5 Main person in charge reviews the simulation results, sorts out the separated simulation issues, and allows the red and blue teams to improve as soon as possible. The main issues are as follows

As announced today, Glupteba is a multi-component botnet targeting Windows computers. Google has taken action to disrupt the operation of Glupteba, and we believe this action will have a significant i

Git leak && AWS AKSK && AWS Lambda cli && Function Information Leakage && JWT secret leak

(3) Is the national secret OTP simply replacing the SHA series hash algorithms with the SM3 algorithm, and becoming the national secret version of HOTP and TOTP according to the adopted dynamic factor

2021-Digital China Innovation Competition-Huifu Cybersecurity Track-Final-Web-hatenum and source code analysis and payload script analysis

In today's rapidly developing digital economy, data has become an important engine driving social progress and enterprise development. From being initially regarded as part of intangible assets to now

Distributed Storage Technology (Part 2): Analysis of the architecture, principles, characteristics, and advantages and disadvantages of wide-column storage and full-text search engines

2025 latest & emulator WeChat mini-program packet capture & mini-program reverse engineering

Analysis of a Separated Storage and Computing Lakehouse Architecture Supporting Multi-Model Data Analysis Exploration (Part 1)

最后修改时间:
admin
上一篇 2025年03月28日 08:44
下一篇 2025年03月28日 09:07

评论已关闭