Protect your APPs with Mother board serial

Share your advanced PureBasic knowledge/code with the community.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 552
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Protect your APPs with Mother board serial

Post by minimy »

As title said. :mrgreen:

Code: Select all

Procedure.s CLIreturn(prg.s, comando.s)
  Protected salida.s
  comando = ReplaceString(comando,"'",Chr(34))
  idprg= RunProgram(prg, comando, GetPathPart(prg), #PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide)
  If IsProgram(idprg)
    While ProgramRunning(idprg)
      If AvailableProgramOutput(idprg)
        salida + ReadProgramString(idprg) + #CRLF$
      EndIf
      error$ = ReadProgramError(idprg)
      If error$ <> ""
        salida + error$ + #CRLF$
      EndIf
    Wend
  EndIf
  ProcedureReturn salida
EndProcedure

Procedure.s motherBoardserial()
  ;   wmic baseboard get product,Manufacturer,version,serialnumber
  ;   wmic baseboard get serialnumber
  Protected.s r= CLIreturn("cmd","/c wmic baseboard get serialnumber")
  ProcedureReturn StringField(r,2,#CRLF$)
EndProcedure

Debug motherBoardserial()
If translation=Error: reply="Sorry, Im Spanish": Endif
moricode
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 25, 2023 3:55 am

Re: Protect your APPs with Mother board serial

Post by moricode »

minimy wrote: Sat Oct 12, 2024 9:53 pm As title said. :mrgreen:

Code: Select all

Procedure.s CLIreturn(prg.s, comando.s)
  Protected salida.s
  comando = ReplaceString(comando,"'",Chr(34))
  idprg= RunProgram(prg, comando, GetPathPart(prg), #PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide)
  If IsProgram(idprg)
    While ProgramRunning(idprg)
      If AvailableProgramOutput(idprg)
        salida + ReadProgramString(idprg) + #CRLF$
      EndIf
      error$ = ReadProgramError(idprg)
      If error$ <> ""
        salida + error$ + #CRLF$
      EndIf
    Wend
  EndIf
  ProcedureReturn salida
EndProcedure

Procedure.s motherBoardserial()
  ;   wmic baseboard get product,Manufacturer,version,serialnumber
  ;   wmic baseboard get serialnumber
  Protected.s r= CLIreturn("cmd","/c wmic baseboard get serialnumber")
  ProcedureReturn StringField(r,2,#CRLF$)
EndProcedure

Debug motherBoardserial()
hi , dude , what i get is this in return string : " To be filled by O.E.M. "

:)
moricode
Enthusiast
Enthusiast
Posts: 162
Joined: Thu May 25, 2023 3:55 am

Re: Protect your APPs with Mother board serial

Post by moricode »

Code: Select all


  Debug  CLIreturn("cmd","/c wmic baseboard get product")
  Debug  CLIreturn("cmd","/c wmic baseboard get Manufacturer")
  Debug  CLIreturn("cmd","/c wmic baseboard get version")
  Debug  CLIreturn("cmd","/c wmic baseboard get serialnumber")
  

This is what i get :
Product
B85M-D3H-A


Manufacturer
Gigabyte Technology Co., Ltd.


Version
x.x


SerialNumber
To be filled by O.E.M.
:wink: :mrgreen:
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: Protect your APPs with Mother board serial

Post by BarryG »

Pro Tip: Don't do this. I did this with my app and got CONSTANT support emails about my app's license keys not working because the user updated their BIOS. It happened quite a lot (well, about 10 emails per month from different users) and just became too much hassle to deal with. I don't know if they were just saying it to get extra free keys or not (likely), so I switched to an email-based key (using their PayPal email) and left it at that. That way the key still works if their BIOS is "upgraded", and they're less likely to share their key because spammers will get their valid email address. It also removed the work at my end to send out new keys every month.

Also, calling WMIC in your app is a trigger for anti-virus apps and can give it a false-positive. Personal experience.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 552
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: Protect your APPs with Mother board serial

Post by minimy »

BarryG wrote: Mon Oct 14, 2024 8:54 am Pro Tip: Don't do this. I did this with my app and got CONSTANT support emails about my app's license keys not working because the user updated their BIOS. It happened quite a lot (well, about 10 emails per month from different users) and just became too much hassle to deal with. I don't know if they were just saying it to get extra free keys or not (likely), so I switched to an email-based key (using their PayPal email) and left it at that. That way the key still works if their BIOS is "upgraded", and they're less likely to share their key because spammers will get their valid email address. It also removed the work at my end to send out new keys every month.

Also, calling WMIC in your app is a trigger for anti-virus apps and can give it a false-positive. Personal experience.
Hello Barry, thanks for comments and help. Right is not the best practic to protect, i think DriveGUID combined with another unique ID is better
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
NicTheQuick
Addict
Addict
Posts: 1503
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Protect your APPs with Mother board serial

Post by NicTheQuick »

This is also not a safe way to do it. Calling an external command with no absolute path means that you could simply write your own `wmic` command, put it in the working directory and it will return whatever you want it to return.
Better use an API for that and if you need to load it dynamically, use absolute paths.

And yes, I know that someone could replace `wmic` in system folders too but that's at least a bit less likely.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
BarryG
Addict
Addict
Posts: 4122
Joined: Thu Apr 18, 2019 8:17 am

Re: Protect your APPs with Mother board serial

Post by BarryG »

@minimy: Also, your code in your first post returns an empty string for me, so it doesn't work on all PCs anyway.
User avatar
Paul
PureBasic Expert
PureBasic Expert
Posts: 1282
Joined: Fri Apr 25, 2003 4:34 pm
Location: Canada
Contact:

Re: Protect your APPs with Mother board serial

Post by Paul »

Is it possible WMIC command will disappear at some point?

https://learn.microsoft.com/en-us/windo ... misdk/wmic
Important

WMIC is deprecated as of Windows 10, version 21H1; and as of the 21H1 semi-annual channel release of Windows Server. This utility is superseded by Windows PowerShell for WMI; see Chapter 7 - Working with WMI. This deprecation applies only to the WMIC utility. Windows Management Instrumentation (WMI) itself is not affected. Also see Windows 10 features we're no longer developing.
Image Image
User avatar
NicTheQuick
Addict
Addict
Posts: 1503
Joined: Sun Jun 22, 2003 7:43 pm
Location: Germany, Saarbrücken
Contact:

Re: Protect your APPs with Mother board serial

Post by NicTheQuick »

If you're using Linux you can look into the virtual directory `/sys/class/dmi/id/`. There you can find all sorts of information about your system:

Code: Select all

$ ll /sys/class/dmi/id/
insgesamt 0
drwxr-xr-x 3 root root    0 Okt 14 14:27 ./
drwxr-xr-x 3 root root    0 Okt  7 19:35 ../
-r--r--r-- 1 root root 4096 Okt 12 16:53 bios_date
-r--r--r-- 1 root root 4096 Okt 12 16:53 bios_release
-r--r--r-- 1 root root 4096 Okt  7 19:35 bios_vendor
-r--r--r-- 1 root root 4096 Okt  8 09:48 bios_version
-r--r--r-- 1 root root 4096 Okt 12 16:53 board_asset_tag
-r--r--r-- 1 root root 4096 Okt  8 09:48 board_name
-r-------- 1 root root 4096 Okt 12 16:53 board_serial
-r--r--r-- 1 root root 4096 Okt  7 19:35 board_vendor
-r--r--r-- 1 root root 4096 Okt 12 16:53 board_version
-r--r--r-- 1 root root 4096 Okt 12 16:53 chassis_asset_tag
-r-------- 1 root root 4096 Okt 12 16:53 chassis_serial
-r--r--r-- 1 root root 4096 Okt  8 09:48 chassis_type
-r--r--r-- 1 root root 4096 Okt 12 16:53 chassis_vendor
-r--r--r-- 1 root root 4096 Okt 12 16:53 chassis_version
-r--r--r-- 1 root root 4096 Okt  7 19:35 modalias
drwxr-xr-x 2 root root    0 Okt  8 10:23 power/
-r--r--r-- 1 root root 4096 Okt  8 09:48 product_family
-r--r--r-- 1 root root 4096 Okt  7 19:35 product_name
-r-------- 1 root root 4096 Okt 12 16:53 product_serial
-r--r--r-- 1 root root 4096 Okt  8 09:48 product_sku
-r-------- 1 root root 4096 Okt  7 19:35 product_uuid
-r--r--r-- 1 root root 4096 Okt  7 19:35 product_version
lrwxrwxrwx 1 root root    0 Okt  7 19:35 subsystem -> ../../../../class/dmi/
-r--r--r-- 1 root root 4096 Okt  7 19:35 sys_vendor
-rw-r--r-- 1 root root 4096 Okt  7 19:35 uevent
But as you can see the serial and uuid numbers are not accessible without becoming root. And you can see the difference between `board_serial` and `product_serial`. The latter also shows "To be filled by O.E.M." on my PC because I built it by myself and no OEM was involved in any way. But `board_serial` contains the correct serial number of my mainboard.
The english grammar is freeware, you can use it freely - But it's not Open Source, i.e. you can not change it or publish it in altered way.
tj1010
Enthusiast
Enthusiast
Posts: 716
Joined: Mon Feb 25, 2013 5:51 pm

Re: Protect your APPs with Mother board serial

Post by tj1010 »

Oreans Code Virtualizer supports PB across Windows, Linux, and MacOS. Put a server license check in it with a embedded x.509 for TLS and a xor cipher in the VM incase they hook calls to TLS buffers. An attacker can't just patch some jumps or intercept network calls to crack your product..

Even this will be defeated the second your product gets an audience, though.. You'd need something like Intel SGX across all CPUs to actually keep someone from opening up a binary and reverse engineering important parts of it.. This is why you can't play UHD blueray on non-SGX processors; AACS 2.x code isn't decrypted till in a Intel SGX enclave loaded by a licensed player software.. AMD has a SGX equivalent called Presidio, but nobody uses it for anything..
Post Reply