identify a machine not by using IP - c#

Suppose I'm programming a game and I want the option of banning people from it after violating the terms. I can ban them per account, I can also ban their IP but it's not going to ban them from my game forever. They will just have to create a new account and change their IP.
Is there something like a machine-ID that is unique for every machine in the world? If there is, is it possible to read it using a program language? Is it possible for the user to change this machine-ID?

Bulletproof solution?
I would say no solution will be 100% secure, even with huge invested money..
What you can do, is to make it as hard as possible for normal users, and this way minimize the cheaters.
You could make a hash id of the pc machine id + the mac address + the motherboard id + the harddisk id, etc. But a clever cracker/hacker could get around this. I mean take a look at companies like Microsoft that uses millions in making a secure way and still people can get around the activation in some way... ;)
In windows there is a hardware id, that you might be intrested in.
HKEY_LOCAL_MACHINE\Software\Microsoft\Cryptography\MachineGuid
Take a look at WMI too, there are examples of how to use it with c++
Windows Management Instrumentation (WMI) is a set of extensions to the Windows Driver Model that provides an operating system interface through which instrumented components.
see WMI c++ exmaples

How about hard disk serial number which you can get in WMI Win32_DiskDrive.
ManagementObjectSearcher searcher = null;
try
{
searcher = new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_DiskDrive");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("SerialNumber: {0}", queryObj["SerialNumber"]);
queryObj.Dispose();
}
}
finally
{
if (searcher != null)
searcher.Dispose();
}

Related

Which one to consider as machine's fixed and unique MAC id?

I need to read a machine's MAC id in C# which stays fixed irrespective of the connection types e.g. connected to Work through network cable, wifi, VPN through Home wifi, through a Dongle or even can be offline.
So basically it need not necessarily be the MAC id of network interface which is "Up", i just need the MAC id which is/stays constant.
With the help of answers in the below link and other suggestions,
Reliable method to get machine's MAC address in C#
I am able to read the MAC ids, but still don't understand which one to consider that will reliably give me the fixed MAC id, which i can use in my application for some sort of verification in that particular system.
Here are the details of all network interfaces of that system, when the system is connected to "Work" through VPN using Home Wifi and connected to "Work" network directly:
Please suggest which one i should consider and what should be the right condition to filter out the interface with fixed MAC id in C#.
As indicated as "Related" to my question and also as pointed by #Caius Jard, i got the solution from the below link which will suit for my need:
How to determine MAC Address of the actual physical network card -- not virtual network interfaces created by VPN's (.NET C#)
because i want to:
-> take the MAC id of the physical card (i.e. excluding all virtual, pseudo, logical, usb) and don't allow my application without any physical card
-> consider the 1st card, in case more than 1 cards are installed
I have modified the query as per my need with the help of details given in below link:
https://weblogs.sqlteam.com/mladenp/2010/11/04/find-only-physical-network-adapters-with-wmi-win32_networkadapter-class/
So, my final solution looks like below:
ManagementObjectSearcher searcher = new ManagementObjectSearcher
(#"SELECT Index,MACAddress,PNPDeviceID
FROM Win32_NetworkAdapter
WHERE MACAddress IS NOT NULL AND PNPDeviceID IS NOT NULL AND Manufacturer != 'Microsoft' AND PNPDeviceID LIKE '%PCI\\%'");
IList<ManagementObject> mObject = searcher.Get()
.Cast<ManagementObject>()
.OrderBy(p => Convert.ToUInt32(p.Properties["Index"].Value))
.ToList();
foreach (var obj in mObject)
{
var mac = obj["MACAddress"].ToString();
mac = mac.Replace(":", string.Empty);
return mac;
}
Your physical (vs. virtual, logical) interface MAC addresses should stay same (at least until the physical device is replaced). Your "Ethernet 3", for example.

Mapping Plug N Play Devices to PCI Slot IDs, C#

I have a certain number of external devices, let's call them Things.
Each Thing interfaces with the computer through a PnP Card plugged into a PCI slot.
Each Card has ports for 4 Things.
I need to obtain a UID for each Thing that persists and is consistent between reboots.
Note that the Things do not have a built in UID that I can access.
My idea to solve this problem is to get a UID for each port on the Cards. It seems to me that I just have to figure out which PCI slot each Card is plugged in to. That isn't going to change on reboot, and certainly the ports are going to be in the same order... so I can essentially label each port with the UID and know which UID each Thing is associated with.
I have done a fair bit of searching to figure out what C# objects would be of most use. The closest I have found is the ManagementObjectSearcher object from the System.Management library. Here is some simple code I wrote to see if this would get me what I want:
static void Main(string[] args)
{
IDsearch();
Console.ReadLine();
}
static void IDsearch()
{
ManagementObjectSearcher searcher =
new ManagementObjectSearcher("root\\CIMV2", "SELECT * FROM Win32_PnPEntity");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("DeviceID: {0}", queryObj["DeviceID"]);
Console.WriteLine("Description: {0}", queryObj["Description"]);
}
}
This produces output like the following for every PnP devices on my computer:
DeviceID: ACPI\GENUINEINTEL_-_INTEL64_FAMILY_6_MODEL_60_-_INTEL(R)_CORE(TM)_I7-4790_CPU_#_3.60GHZ\_1
Description: Intel Processor
DeviceID: USB\VID_0CF3&PID_3004\ALASKA_DAY_2006
Description: Dell Wireless 1535C Bluetooth Device
This would fit my requirements if I could also obtain the PCI slot number.
I also came across the Win32_SystemSlot class, but this does not seem to give me a description of what is actually plugged into the slot! So at this point, I can get descriptions without PCI slots... and PCI slots without descriptions. I just can't map them together, which is what I need. I must be overlooking something or not asking the right question, because this strikes me as a pretty common thing.
Thank you for your help.
That sounds extremely fragile, what if the machine get moved and the devices get plugged into different ports. Is is a personal project or something you are trying to distribute. If the latter you should find another way. Are the "Things" of your own creation? If so you need to include the ability for each to have a unique identifier. If not you should contact the manufacturer and inquire. Trying to identify it by port may cause you lots of headaches down the road
I think you're looking for a combination of the Win32_Bus and the Win32_DeviceBus classes.
The Win32_Bus represents a physical bus as seen by a computer running a Windows operating system (Microsoft Docs). The bus type can be PCI and bus number seems to be an enumeration of the different physical PCI buses.
The Win32_DeviceBus relates a system bus and a logical device using the bus. This class is used to discover which devices are on which bus (Microsoft Docs). On my platform the device associated with a bus was always a Win32_PnPEntity.
Using these classes you should be able to find the physical bus attributes from a given Win32_PnPEntity.

Microsoft App-V and Hardware IDs

I am currently working on a software solution written in C# .NET 4.5. The software uses a licensing system that is based on hardware IDs (for example MAC address or CPU ID).
One user now reported that he has issues with the licensing when using the software with Microsoft App-V. He mentioned that every time a new User wants to use the software the application complains that the license is not valid (due to a change in the hardware).
This also happens if a previously registered user uses the Software on a different client.
My question now is, when running an application via App-V, what does the following snipped of code return, the Mac address of the client or of the server where to application is actually running. If the first is true, is there a way to get the same information from the server too, using some functionality in .NET?
private static string getMAC() {
ManagementClass oMClass = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection MOCol = oMClass.GetInstances();
string mac = "";
foreach (ManagementObject MO in MOCol) {
if (MO != null) {
if (MO["MacAddress"] != null) {
mac = MO["MacAddress"].ToString().Replace(":", "");
if (mac != string.Empty) {
break;
}
}
}
return mac;
}
Next-to-last bullet in the Limitations section in App-V's Wikipedia article fits your problem exactly:
Licensing Policies: Applications with licensing enforcement tied to the machine, e.g. the license is tied to the system’s MAC address or harddisk serial number. This type of application should not be sequenced if the activation can not be done by the user at the first launch of sequenced application, manually or by script.
You'll need to tell your customer that you cannot support App-V if you verify the license on each individual run of the app instead of just once at app install time. If that means that you'll lose a valuable customer then quickly get rid of this scheme, a business decision we cannot make for you.

Remotely determine interactive/active user on Windows 7 machine

Anyone else had to determine who the currently logged on user is remotely in a Windows 7 environment? I am using .NET 4.0 and C#. The environment is mixed XP and 7.
WMI queries involving sessions result in all active sessions, but not the session that is interactive.
UserName from ComputerSystem (WMI) returns null exception if user is connected via Remote Desktop, which is common enough that this method cannot be used.
PsLoggedOn takes too long for my purposes (yes, 300 ms is too long) and is surprisingly not accurate 100% of the time
Using p/invoke for WTSGetActiveConsoleSessionID or LsaEnumerateLogonSessions is too complicated and prone to memory leaks (from what I've read)
tasklist /S <computername> will return information for XP systems, but Windows 7 won't be agreeable thanks to that lovely UAC.
HKCU (win registry) is inaccessible remotely due to permissions restrictions, HKU is accessible, but Volatile Environment doesn't appear to have a tag for "active"
So far, the most reliable way is using PsExec to remotely execute qwinsta from the command line and traverse the output to text remotely. This is annoying and takes time (more than PsLoggedOn), but I'm running out of ideas here for reliability. Reliability before speed, but speed is very important in terms of cost benefit.
Third party tools are not an option, has to be a script, preferably WMI and C#. I delved into hitting the DC using Principal objects, but I'm afraid I might have confused myself more. Also, all user accounts are administrators.
I've done a lot of research over Google, but I am thinking that maybe I am looking in the wrong place.
Any takers?
you can achieve this by browsing Win32_ComputerSystem class's UserName Propperty :
ConnectionOptions con = new ConnectionOptions();
con.Username = "Administrator";
con.Password = "********";
ManagementScope scope = new ManagementScope(#"\\" + strIPAddress + #"\root\cimv2", con);
scope.Connect();
//check for scope.IsConnected, then process
ManagementObjectSearcher searcher =new ManagementObjectSearcher(#"\\" + strIPAddress + #"\root\cimv2", "SELECT * FROM Win32_ComputerSystem");
foreach (ManagementObject queryObj in searcher.Get())
{
Console.WriteLine("-----------------------------------");
Console.WriteLine("Win32_ComputerSystem instance");
Console.WriteLine("-----------------------------------");
Console.WriteLine("UserName: {0}", queryObj["UserName"]);
}

Secure My ASP .NET Code For Presentation?

I have a web application , for presentation to my client they ask me to install it on their local server so they can test it , here is my question !?
Is there any way so i can publish uniquely for that server , i did put some limitation but many features in my app are open , so they can make a disk image from server and use it anywhere else ,
Is there any method to use so my web application check if this server is same server ( by hardware id or anything i don't have any idea ) then start to work !
I saw many codes but they are win forms for generating unique hid , but how can i connect done it with asp .net
EDIT
Could u take a look at this also ,
i am using system.management class
is this reliable i mean are they unique ?
private string GetUniqueID()
{
string cpuInfo = string.Empty;
ManagementClass mc = new ManagementClass("win32_processor");
ManagementObjectCollection moc = mc.GetInstances();
foreach (ManagementObject mo in moc)
{
if (cpuInfo == "")
{
//Get only the first CPU's ID
cpuInfo = mo.Properties["processorID"].Value.ToString();
break;
}
}
ManagementObject dsk = new ManagementObject(#"win32_logicaldisk.deviceid=""" + "C" + #":""");
dsk.Get();
string volumeSerial = dsk["VolumeSerialNumber"].ToString();
string HardWareUniqueID = volumeSerial + cpuInfo;
return HardWareUniqueID;
}
Appreciate your answers,
Thanks in advance
If you want to avoid having it "phone home" an alternative is to generate some kind of certificate and place it on the machine. Use a private key that only you know to encrypt the machine name and/or IP. Then have your app use your public key to decrypt it to verify that it is allowed to run on this server. Nobody who doesn't know your private key will be able to create valid certificates.
You hae a few choices...
Lock your web site to the single IP address you install it on. To make your life easier, check for that IP in a common page base class. (Note, you could also write HTTP handlers, but the base-class approach is easier.)
Put a 'phone home' call in the app that checks with your server every time it's started up. That way you can check if they have moved it or if multiple instances are running.
Use the built-in licensing features of .NET (the same one third-party developers use for controls, etc.)
The easiest... just put in a time-bomb that lets them test it for a few weeks, then automatically blocks access. Be smart though... persist the last-checked time so you can tell if they've rolled back their clock trying to get more usage.
Just make sure to distribute a web application, not a web project so you can distribute your code as a compiled bumary rather than having to ship the code-behind files. That will keep prying eyes out, but does make deployment more a pain since you always have to recompile with every change (as opposed to on-demand compiling.)
I would put in a time bomb. It's trivial to implement. Also, your client's won't think that you don't trust them. A fixed evaluation period in the application is extremely common.
Provide them a VMware image without any user-access just allow them to open the website externally via HTTP in their web browser.

Categories

Resources