简体   繁体   English

如何阻止 USB 阻止笔式驱动器和外部硬盘驱动器

[英]How to Block USB to block Pen Drive and External Hard Drives

I want to make a program to block USB so that no one can access USB port to transfer media.我想编写一个程序来阻止 USB 以便没有人可以访问 USB 端口来传输媒体。

I don't want to block USB port from BIOS because I use USB Key-board and Mouse.我不想阻止 BIOS 中的 USB 端口,因为我使用 USB 键盘和鼠标。

Note: I want to give Administrator Privilege to all the systems but want to block just USB.注意:我想为所有系统授予管理员权限,但只想阻止 USB。 In my office people need admin privilege to access other registries and windows services because those are programmers.在我的办公室里,人们需要管理员权限才能访问其他注册表和 windows 服务,因为这些是程序员。 Few Antivirus like Norton have options of blocking USB whether system is running in Admin or User mode.很少有像诺顿这样的防病毒软件有阻止 USB 的选项,无论系统是在管理员模式还是用户模式下运行。 In this every system Client Antivirus runs and Server Antivirus runs in Server.在这个每个系统中客户端防病毒运行和服务器防病毒在服务器中运行。 We do settings in Server and in all clients USB gets blocked.我们在服务器和所有客户端中进行设置 USB 被阻止。 Now please dont say that have Norton Antivirus:) I want to know that there must be any way like these Fundu programers did in Norton Antivirus.现在请不要说有Norton Antivirus :) 我想知道这些Fundu 程序员在Norton Antivirus 中一定有什么方法。

Now what I did to achieve this so far.现在我做了什么来实现这一点。

I created two windows service.我创建了两个 windows 服务。 One service is continuously changing USBSTOR's Start value to 4 by using timer, to make USB disable always.一项服务是使用定时器不断将 USBSTOR 的 Start 值更改为 4,以使 USB 始终禁用。 Also first service is checking continuously whether Second service is running or not.第一个服务也在不断检查第二个服务是否正在运行。 If not then they are sending notification mail to me that some one has tried to stop the service.如果不是,那么他们会向我发送通知邮件,告知有人试图停止该服务。

Second service is checking continuously whether First service is running or not.第二个服务不断检查第一个服务是否正在运行。 If not then they are sending notification mail to me.如果没有,那么他们正在向我发送通知邮件。

I made this so that People should not be able to stop service to unblock USB.我这样做是为了让人们不能停止服务来解锁 USB。

Now the problem is that people can disable my service and the service will not work.现在的问题是人们可以禁用我的服务并且该服务将无法工作。 At this stage the STATUS of Service is Running but actually its Disabled.在此阶段,服务状态正在运行,但实际上已禁用。 So I can only check the STATE (Disabled/Enabled/Automatic) from the Registry Key (Start) of my Service which will be at the location所以我只能从我的服务的注册表项(开始)中检查 STATE (禁用/启用/自动),它将位于该位置

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/services/MyServiceName

If Start's value is 2(Automatic), 3(Manual), 4(Disabled) we can check via our service every 2 seconds (for example) whether Start value got changed to 4, if yes then We can reset it to 2.如果 Start 的值为 2(Automatic)、3(Manual)、4(Disabled),我们可以通过我们的服务每 2 秒检查一次(例如)Start 值是否已更改为 4,如果是,则我们可以将其重置为 2。

But here problem is that from service I am able to access USBSTOR's values but not any Service's Registies (Because of security issue)但这里的问题是,我可以从服务中访问 USBSTOR 的值,但不能访问任何服务的注册表(因为安全问题)

I used this code to access USBSTOR registry with having write permission我使用此代码访问具有写入权限的 USBSTOR 注册表

Microsoft.Win32.RegistryKey key;
string user = Environment.UserDomainName + "\\" + Environment.UserName;
RegistrySecurity rs = new RegistrySecurity();
rs.AddAccessRule(new RegistryAccessRule(user, RegistryRights.WriteKey, InheritanceFlags.None, PropagationFlags.None, AccessControlType.Allow));
key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SYSTEM\\CurrentControlSet\\services\\USBSTOR", true);
key.SetAccessControl(rs);
key.SetValue("Start", "4",RegistryValueKind.DWord);

This code is working fine.这段代码工作正常。 (I kept this code in timer function to make Start value = 4 every time, to block USB every time if any third party tool is trying to enable USB by registry fix) (我将此代码保存在计时器 function 中,以使 Start value = 4 每次,如果任何第三方工具试图通过注册表修复启用 USB,则每次都阻止 USB)

But the problem is that I want to get notification when ever some one is disabling Service.但问题是我想在有人禁用服务时收到通知。 I can not access我无法访问

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/services/MyServiceName

registry through due to security created by Windows.由于 Windows 创建的安全性,注册表通过。

But via Windows Application we can access但是通过 Windows 应用我们可以访问

HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/services/MyServiceName

registry.注册表。 So I created an application which will run every time windows get started and will check that some one has disabled my service which blocks USB.因此,我创建了一个应用程序,该应用程序将在每次 windows 启动时运行,并将检查是否有人禁用了我的服务,从而阻止了 USB。

But here also problem is that user can go to但这里还有一个问题是用户可以 go 到

HKEY_LOCAL_MACHINE/SOFTWARE/Microsoft/Windows/CurrentVersion/Run

and delete my key to prevent my application to Run.并删除我的密钥以防止我的应用程序运行。

Now my actual question after a long story is that现在我的实际问题是,经过一个长篇故事

  1. How to block USB so that any one cant access it [Can we block it by blocking it on hardware level or by making some changes in its Driver.如何阻止 USB 使任何人都无法访问它[我们可以通过在硬件级别阻止它或通过对其驱动程序进行一些更改来阻止它。 If yes then How?]如果是,那么如何?]

  2. Can we make a windows service which cant be Disabled [If Yes then How?.我们可以制作一个无法禁用的 windows 服务 [如果是,那么如何? We can make it CanPauseAndContinue = False, CanShutDown = False, CanStop = False.我们可以让它 CanPauseAndContinue = False,CanShutDown = False,CanStop = False。 But is there any way to avoid Disable it?]但是有什么办法可以避免禁用它?]

  3. Can we prevent Access to Registries (Specific Keys) [ Antivirus software can do this, then how they do this?我们可以阻止访问注册表(特定密钥)[杀毒软件可以做到这一点,那么它们是如何做到的? Does anyone have any idea or knowledge to such an extent?有没有人有这种程度的想法或知识? I want if some one is trying to edit USBSTOR value then it must say that Access is denied]我想如果有人试图编辑 USBSTOR 值,那么它必须说访问被拒绝]

Please Every Geeks, Programmers, Hackers are invited to answer this question.请每一位极客、程序员、黑客都被邀请回答这个问题。 By answering this various newbie also get an idea to make security softwares.通过回答这个问题,各种新手也有了制作安全软件的想法。 Please try to give solution to my problem.请尝试解决我的问题。

Thanks in Advance.提前致谢。

  • Rahul拉胡尔

You could detect and remove any USB drivers for mass storage devices.您可以检测并删除任何用于大容量存储设备的 USB 驱动程序。 If a driver gets reinstalled you could delete it automatically or even watch for new hardware inserted.如果驱动程序被重新安装,您可以自动删除它,甚至观察插入的新硬件。 If it is USB based disable it via API calls.如果它是基于 USB 的,则通过 API 调用禁用它。

You might just overwrite USBSTOR.SYS with garbage, or delete it entirely (make sure to also nuke SFP's copy).您可能只是用垃圾覆盖USBSTOR.SYS ,或者完全删除它(确保也核对 SFP 的副本)。

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

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