License介绍+设计+绕过相关

License介绍

许多混乱就始于你不知道License到底是什么,到底有什么含义。当你对你的产品使用License时,并不意味着你放弃了任何权利,你依然对其拥有原著作权。License只是授予他们于特定权利来使用你的产品。
License只是把你的作品释放到公有领域,或者给各个拷贝赋予权限。也意味着你放弃了版权收入,别人也没有义务把你列为原作者或贡献者。

License 种类

License 种类说明,如下图:

License设计

License设计需求:

软件可以创建并验证license
License基于硬件特征进行绑定
软件和License都要防止用户随意拷贝
License可以是永久性的或者临时性的
License要进行加密和解密
License的验证由某种可靠的数字签名机制来实现
License模块需要用特殊机制对其进行保护,以防被反编译轻易破解

License设计Cases:

实体机 Licenses 重复使用(部分/整体)
虚拟机 Licenses 重复使用(部分/整体)
Docker Licenses 重复使用(部分/整体)
实体机 Licenses 增删改
虚拟机 Licenses 增删改
Docker Licenses 增删改

收集的设备信息 增删改
设备信息 传输被篡改 (收集过程中)
设备信息 传输被篡改 (服务器验证过程中)
绕过license授权(实体机),模拟被Agent设备收集
绕过license授权(虚拟机),模拟被Agent设备收集
绕过license授权(Docker),模拟被Agent设备收集

客户端agent实体机 重复使用 
客户端agent虚拟机 重复使用 
客户端agent的docker容器 重复使用 

License反编译,License猜测

License内容

LicenseType=许可证类型,目前分为 [空,试用,其他] 三类。
CompanyName=公司名称,即使用客户的信息,可以是除换行外的任意字符串。
AppName=软件名称,是除换行外的任意字符串。
AppVersion=软件版本,根据标准方式命名。

MachineCode=机器特征码,使用机器的mac地址作为唯一码。 
MC_CPU=处理器名称
MC_mac=mac地址

InstallDate=安装日期,yyyyMMddHHmmss 的格式。
ExpireDate=过期日期,yyyyMMdd的格式。
TryDays=试用日期,默认为30。
IsAuthenticated=是否已经授权,1表示授权,其他值表示未授权。

License技术

1. 签名注册

public Interface LecenseFactory{
    /** 
     *生成公钥、私钥对。公钥公开,注意保管好私钥(如果泄露,则有可能被hacker随意创建license
     */
    public static void generateKey() throws Exception;
    /** 用私钥对license进行数据签名*/
    public static synchronized void sign(License license) throws Exception;
    /**
     * 验证license是否合法。
     * 首先验证Mac地址是否有改变,有的话则非法。(防止用户自由拷贝软件)。
     * 然后根据公钥验证签名是否合法。
     */
    boolean validate(License license) throws Exception ;
}

第一步:生成公钥、私钥对。公钥公开,注意保管好私钥(如果泄露,则有可能被随意创建license)。
LicenseFactory.generateKey();
第二步:根据产品、版本、Mac地址、有效期等信息,签名产生注册号,并将该注册号复制到license中。
第三步:利用公钥对license进行合法性验证。可以在软件代码的重要模块中加入下面的验证,比如登录模块

2. 获得客户端IP地址

public String getIp(HttpServletRequest request) throws Exception {
  String ip = request.getHeader("X-Forwarded-For");
  if (ip != null) {
    if (!ip.isEmpty() && !"unKnown".equalsIgnoreCase(ip)) {
      int index = ip.indexOf(",");
      if (index != -1) {
        return ip.substring(0, index);
      } else {
        return ip;
      }
    }
  }
  ip = request.getHeader("X-Real-IP");
  if (ip != null) {
    if (!ip.isEmpty() && !"unKnown".equalsIgnoreCase(ip)) {
      return ip;
    }
  }
  return request.getRemoteAddr();
 
解决用localhost访问ip为0:0:0:0:0:0:0:1的问题
 
public String getIp(HttpServletRequest request) throws Exception {
  String ip = request.getHeader("X-Forwarded-For");
  if (ip != null) {
    if (!ip.isEmpty() && !"unKnown".equalsIgnoreCase(ip)) {
      int index = ip.indexOf(",");
      if (index != -1) {
        return ip.substring(0, index);
      } else {
        return ip;
      }
    }
  }
  ip = request.getHeader("X-Real-IP");
  if (ip != null) {
    if (!ip.isEmpty() && !"unKnown".equalsIgnoreCase(ip)) {
      return ip;
    }
  }
  ip = request.getHeader("Proxy-Client-IP");
  if (ip != null) {
    if (!ip.isEmpty() && !"unKnown".equalsIgnoreCase(ip)) {
      return ip;
    }
  }
  ip = request.getHeader("WL-Proxy-Client-IP");
  if (ip != null) {
    if (!ip.isEmpty() && !"unKnown".equalsIgnoreCase(ip)) {
      return ip;
    }
  }
  ip = request.getRemoteAddr();
  return ip.equals("0:0:0:0:0:0:0:1") ? "127.0.0.1" : ip;
}
 

3. 获取客户端MAC地址

UdpGetClientMacAddr umac = new UdpGetClientMacAddr(sip);
String smac = umac.GetRemoteMacAddr();
 
添加一个获取MAC的时间限制
 
final UdpGetClientMacAddr umac = new UdpGetClientMacAddr(sip);
//---长时间获取不到MAC地址则放弃
ExecutorService exec = Executors.newFixedThreadPool(1);
Callable<String> call = new Callable<String>() {
  public String call() throws Exception {
    return umac.GetRemoteMacAddr();
  }
};
try {
  Future<String> future = exec.submit(call);
  String smac = future.get(1000 * 1, TimeUnit.MILLISECONDS);
  loginMonitor.setMacAddress(smac);
} catch (TimeoutException ex) {
  loginMonitor.setMacAddress("获取失败");
  logger.info("获取MAC地址超时");
  ex.printStackTrace();
}
// 关闭线程池 
exec.shutdown();
//---
 
需要先获取IP地址作为参数构造一个UdpGetClientMacAddr
 
UdpGetClientMacAddr.java
 
package shmc.commonsys.security.controller;
 
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
 
/** 
 * 主机A向主机B发送“UDP-NetBIOS-NS”询问包,即向主机B的137端口,发Query包来询问主机B的NetBIOS Names信息。 
 * 其次,主机B接收到“UDP-NetBIOS-NS”询问包,假设主机B正确安装了NetBIOS服务........... 而且137端口开放,则主机B会向主机A发送一个“UDP-NetBIOS-NS”应答包,即发Answer包给主机A。 
 * 并利用UDP(NetBIOS Name Service)来快速获取远程主机MAC地址的方法 
 * 
 */ 
public class UdpGetClientMacAddr { 
  private String sRemoteAddr; 
  private int iRemotePort=137; 
  private byte[] buffer = new byte[1024]; 
  private DatagramSocket ds=null; 
 
  public UdpGetClientMacAddr(String strAddr) throws Exception{ 
    sRemoteAddr = strAddr; 
    ds = new DatagramSocket(); 
  } 
 
  public final DatagramPacket send(final byte[] bytes) throws IOException { 
    DatagramPacket dp = new DatagramPacket(bytes,bytes.length,InetAddress.getByName(sRemoteAddr),iRemotePort); 
    ds.send(dp); 
    return dp; 
  } 
 
  public final DatagramPacket receive() throws Exception { 
    DatagramPacket dp = new DatagramPacket(buffer,buffer.length); 
    ds.receive(dp); 
    return dp; 
  } 
  public byte[] GetQueryCmd() throws Exception { 
    byte[] t_ns = new byte[50]; 
    t_ns[0] = 0x00; 
    t_ns[1] = 0x00; 
    t_ns[2] = 0x00; 
    t_ns[3] = 0x10; 
    t_ns[4] = 0x00; 
    t_ns[5] = 0x01; 
    t_ns[6] = 0x00; 
    t_ns[7] = 0x00; 
    t_ns[8] = 0x00; 
    t_ns[9] = 0x00; 
    t_ns[10] = 0x00; 
    t_ns[11] = 0x00; 
    t_ns[12] = 0x20; 
    t_ns[13] = 0x43; 
    t_ns[14] = 0x4B; 
 
    for(int i = 15; i < 45; i++){ 
      t_ns[i] = 0x41; 
    } 
    t_ns[45] = 0x00; 
    t_ns[46] = 0x00; 
    t_ns[47] = 0x21; 
    t_ns[48] = 0x00; 
    t_ns[49] = 0x01; 
    return t_ns; 
  } 
  public final String GetMacAddr(byte[] brevdata) throws Exception { 
    // 获取计算机名 
    int i = brevdata[56] * 18 + 56; 
    String sAddr=""; 
    StringBuffer sb = new StringBuffer(17); 
    // 先从第56字节位置,读出Number Of Names(NetBIOS名字的个数,其中每个NetBIOS Names Info部分占18个字节) 
    // 然后可计算出“Unit ID”字段的位置=56+Number Of Names×18,最后从该位置起连续读取6个字节,就是目的主机的MAC地址。 
    for(int j = 1; j < 7;j++) 
    { 
      sAddr = Integer.toHexString(0xFF & brevdata[i+j]); 
      if(sAddr.length() < 2) 
      { 
        sb.append(0); 
      } 
      sb.append(sAddr.toUpperCase()); 
      if(j < 6) sb.append(':'); 
    } 
    return sb.toString(); 
  } 
 
  public final void close() throws Exception { 
    ds.close(); 
  } 
 
  public final String GetRemoteMacAddr() throws Exception { 
    byte[] bqcmd = GetQueryCmd(); 
    send(bqcmd); 
    DatagramPacket dp = receive(); 
    String smac = GetMacAddr(dp.getData()); 
    close(); 
 
    return smac; 
  } 
   
  public static void main(String args[]) throws Exception{ 
    UdpGetClientMacAddr umac=new UdpGetClientMacAddr("172.19.1.198"); 
    umac=new UdpGetClientMacAddr("192.168.16.83"); 
    System.out.println(umac.GetRemoteMacAddr()); 
  } 
} 
 

License反编译

 jar包反编译工具,破解绕过License授权。

参考链接:

1. https://www.jb51.net/article/121571.htm

2. https://blog.csdn.net/weixin_34364135/article/details/86113557

原文链接:https://blog.csdn.net/m0_37268841/article/details/118388309

给TA打赏
共{{data.count}}人
人已打赏
技术教程投稿

Spring 在多线程环境下如何确保事务一致性?

2023-9-26 19:32:36

技术教程投稿

Electron新手入门

2023-10-10 19:45:16

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索