0%

Build KMS Server in Docker

KMS Server

I see many version of OpenWRT contained the plugin KMS service, so that the office or Windows in the LAN can be activated automatically.

Backgroud

Installing the activation tool on every Windows is trouble and not secure. The self-built KMS activation server is easy to use and secure.

Currently, the commonly used KMS activation server programs are py-kms in Python and vlmcsd in C. It can run on various systems, such as OpenWRT/Android/Linux/Mac OS/iOS/Windows

Download:

  • Github-VLMCSD
  • Github-PyKMS

Here, we use py-kms in Docker.

Install

  1. Install Docker-CE.
  2. Download py-kms.
    1
    :~$ git clone https://github.com/SystemRage/py-kms.git
  3. Foreign users can directly compile the Dockerfile provided by py-kms. However in China, the software download time is very long at compile time, and error messages that cannot be downloaded often appear.
    So I modified the py-kms/docker/docker-py3-kms-minimal/Dockerfile to use Tsinghua mirror to improve the download speed of the software.
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    # This is a minimized version from docker/docker-py3-kms/Dockerfile without SQLLite support to further reduce image size
    # https://raw.githubusercontent.com/SystemRage/py-kms/master/docker/docker-py3-kms-minimal/Dockerfile

    FROM alpine:latest

    ENV IP 0.0.0.0
    ENV PORT 1688
    #ENV EPID ""
    ENV LCID 1033
    ENV CLIENT_COUNT 26
    ENV ACTIVATION_INTERVAL 120
    ENV RENEWAL_INTERVAL 10080
    ENV HWID "RANDOM"
    ENV LOGLEVEL INFO
    ENV LOGFILE /var/log/pykms_logserver.log
    #ENV LOGSIZE ""

    EXPOSE ${PORT}/tcp

    RUN sed -i 's/dl-cdn.alpinelinux.org/mirrors.tuna.tsinghua.edu.cn/' /etc/apk/repositories \
    && apk add --no-cache --update bash git py3-argparse py3-flask py3-pygments python3-tkinter \
    sqlite-libs py3-pip p7zip \
    && pip3 install -i https://pypi.tuna.tsinghua.edu.cn/simple peewee tzlocal \
    && wget --no-check-certificate https://github.com/SystemRage/py-kms/archive/master.zip \
    && 7z x master.zip -o/home/ \
    && mv /home/py-kms-master/py-kms /home/ \
    && rm master.zip && rm -r /home/py-kms-master \
    && apk del git p7zip

    WORKDIR /home/py-kms

    ENTRYPOINT /usr/bin/python3 pykms_Server.py ${IP} ${PORT} -l ${LCID} -c ${CLIENT_COUNT} -a ${ACTIVATION_INTERVAL} -r ${RENEWAL_INTERVAL} -w ${HWID} -V ${LOGLEVEL} -F ${LOGFILE}

    HEALTHCHECK CMD netstat -ln | grep ${PORT} || exit 1
  4. Build the Docker image
    1
    :~$ cd py-kms/docker/docker-py3-kms-minimal && docker build -t haven200/py-kms .
  5. Run image py-kms
    1
    2
    3
    4
    5
    6
    :~$ docker run --detach --name "kms"  \
    --publish 192.168.1.2:1688:1688/tcp \
    --volume /etc/localtime:/etc/localtime:ro \
    --env ACTIVATION_INTERVAL=1440 \
    --env RENEWAL_INTERVAL=20160 \
    "haven200/py-kms"
    • --publish: Mapping port TCP 1688, local ip is 192.168.1.2.
    • --volume: Using the local time zone.
    • --env: Import environment variables.
  6. View container status
    1
    2
    3
    :~$ docker container ls
    CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
    547e355e1b3a haven200/py-kms "/bin/sh -c '/usr/bi…" About an hour ago Up About an hour (healthy) 192.168.100.101:1688->1688/tcp kms
  7. See whether the port is mapped
    1
    2
    :~$ docker container port kms
    1688/tcp -> 192.168.1.2:1688

At this point, our py-kms server is running successfully.

Verify the py-kms service

Use tool pykms_Client.py provided by py-kms.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
:~$ python3 py-kms/py-kms/pykms_Client.py -m Windows10 192.168.1.2
truetruetrueClient generating RPC Bind Request...
Server receiving
<=============== Client sending RPC Bind Request...

Server sending
===============> Client received RPC Bind Response !!!
truetruetrueRPC Bind acknowledged !!!
truetruetrueClient generating Activation Request dictionary...
truetruetrueClient generating Activation Request data...
truetruetrueClient generating RPC Activation Request...

Server receiving
<=============== Client sending RPC Activation Request...

Server sending
===============> Client received Response !!!

truetruetrueActivation Done !!!
  • -m: Which version of the Windows/office is simulated, here we simulate Windows10
  • ip: Here, must use IP address, domain name will cause errors.

Finally, it prompts Activation Done, that is, activation is successful, which shows that our py-kms server has been successfully run without errors.

Configure DNS for Windows to automatically discover kms servers

Here we use dnsmasq as DNS server.

By configuring the SRV parameters of the DNS server, the hosts in the LAN can automatically discover the kms server.
In this way, any pc installed VOL version of office or Windows will automatically activate when connected our local area network.

1
2
3
4
:~$ sudo cat >> /etc/dnsmasq.conf <<EOF
srv-host=_vlmcs._tcp.nas.net,kms.nas.net,1688,0,100
EOF
:~$ sudo systemctl restart dnsmasq
  • _vlmcs: kms server type.
  • _tcp: use tcp.
  • nas.net: suffix domain name of kms server.
  • kms.nas.net: The full domain name of the kms server, which can be used to query the IP address.
  • 1688: port of kms server.
  • 0: priority
  • 100: Weights

Test dns whether set up successfully

1
2
3
4
5
:~$ nslookup -type=srv _vlmcs._tcp.nas.net
Server: 192.168.1.1
Address: 192.168.1.1#53

_vlmcs._tcp.nas.net service = 0 100 1688 kms.nas.net.

Activate office

Let’s take office 2013 as an example.

  • Specify kms server manually.
    1
    2
    3
    4
    cd "%ProgramFiles%\MICROSOFT OFFICE\OFFICE15"
    cscript ospp.vbs /sethst:192.168.1.2
    cscript ospp.vbs /act
    cscript ospp.vbs /dstatus
  • Automatically discover kms server and activate.
    1
    2
    3
    4
    CD "%ProgramFiles(x86)%\MICROSOFT OFFICE\OFFICE15"
    cscript ospp.vbs /remhst
    cscript ospp.vbs /act
    cscript ospp.vbs /dstatus

If the Office key is not available, use the following command to change:

1
cscript ospp.vbs /inpkey:KBKQT-2NMXY-JJWGP-M62JB-92CD4

KMS Keys for office

MS Office edition KMS Setup Key (GVLK keys)
Office 2019 Professional Plus NMMKJ-6RK4F-KMJVX-8D9MJ-6MWKP
Office 2019 Standard 6NWWJ-YQWMR-QKGCB-6TMB3-9D9HK
Office 2016 Professional Plus XQNVK-8JYDB-WJ9W3-YJ8YR-WFG99
Office 2016 Standard JNRGM-WHDWX-FJJG3-K47QV-DRTFM
Office 2013 Professional Plus YC7DK-G2NP3-2QQC3-J6H88-GVGXT
Office 2013 Standard KBKQT-2NMXY-JJWGP-M62JB-92CD4
Office 2010 Professional Plus VYBBJ-TRJPB-QFQRF-QFT4D-H3GVB
Office 2010 Standard V7QKV-4XVVR-XYV4D-F7DFM-8R6BM

activate Windows

  1. Uninstall the original key
    1
    slmgr -upk
  2. Add key, please select the corresponding VOL Key
    1
    slmgr -ipk W269N-WFGWX-YVC9B-4J6C9-T83GX
  3. Change the kms server, if the kms service is already configured on the dns server, ignore this step.
    1
    slmgr -skms kms.nas.net
  4. To activate
    1
    slmgr -ato
  5. View activation information
    1
    slmgr -xpr

KMS (VOL) Keys for Windows

  • Ultimate: refers to the fully functional version.
  • VOL version: Refers to the large-volume licensed version for large customers.

Windows 7 Ultimate cannot be activated through KMS, please use another tool to activate.

Windows Server 2019

System Key
Windows Server 2019 Datacenter WMDGN-G9PQG-XVVXX-R3X43-63DFG
Windows Server 2019 Standard N69G4-B89J2-4G8F4-WWYCC-J464C
Windows Server 2019 Essentials WVDHN-86M7X-466P6-VHXV7-YY726

Windows 10

System Key
Windows 10 Enterprise LTSC 2019 M7XTQ-FN8P6-TTKYV-9D4CC-J462D
Windows 10 Enterprise N LTSC 2019 92NFX-8DJQP-P6BBQ-THF9C-7CG2H
Windows 10 Professional W269N-WFGWX-YVC9B-4J6C9-T83GX
Windows 10 Professional N MH37W-N47XK-V7XM9-C7227-GCQG9
Windows 10 Enterprise NPPR9-FWDCX-D2C8J-H872K-2YT43
Windows 10 Enterprise N DPH2V-TTNVB-4X9Q3-TJR4H-KHJW4
Windows 10 Education NW6C2-QMPVW-D7KKK-3GKT6-VCFB2
Windows 10 Education N 2WH4N-8QGBV-H22JP-CT43Q-MDWWJ
Windows 10 Enterprise 2015 LTSB WNMTR-4C88C-JK8YV-HQ7T2-76DF9
Windows 10 Enterprise 2015 LTSB N 2F77B-TNFGY-69QQF-B8YKP-D69TJ
Windows 10 Enterprise 2016 LTSB DCPHK-NFMTC-H88MJ-PFHPY-QJ4BJ
Windows 10 Enterprise 2016 LTSB N QFFDN-GRT3P-VKWWX-X7T3R-8B639

Windows Server 2016

System Key
Windows Server 2016 Datacenter CB7KF-BWN84-R7R2Y-793K2-8XDDG
Windows Server 2016 Standard WC2BQ-8NRM3-FDDYY-2BFGV-KHKQY
Windows Server 2016 Essentials JCKRF-N37P4-C2D82-9YXRT-4M63B

Windows Server 2012 R2

System Key
Windows Server 2012 R2 Standard D2N9P-3P6X9-2R39C-7RTCD-MDVJX
Windows Server 2012 R2 Datacenter W3GGN-FT8W3-Y4M27-J84CP-Q3VJ9
Windows Server 2012 R2 Essentials KNC87-3J2TX-XB4WP-VCPJV-M4FWM
Windows Server 2012 Core BN3D2-R7TKB-3YPBD-8DRP2-27GG4
Windows Server 2012 Core N 8N2M2-HWPGY-7PGT9-HGDD8-GVGGY
Windows Server 2012 Core Single Language 2WN2H-YGCQR-KFX6K-CD6TF-84YXQ
Windows Server 2012 Core Country Specific 4K36P-JN4VD-GDC6V-KDT89-DYFKP
Windows Server 2012 Server Standard XC9B7-NBPP2-83J2H-RHMBY-92BT4
Windows Server 2012 Standard Core XC9B7-NBPP2-83J2H-RHMBY-92BT4
Windows Server 2012 MultiPoint Standard HM7DN-YVMH3-46JC3-XYTG7-CYQJJ
Windows Server 2012 MultiPoint Premium XNH6W-2V9GX-RGJ4K-Y8X6F-QGJ2G
Windows Server 2012 Datacenter 48HP8-DN98B-MYWDG-T2DCC-8W83P
Windows Server 2012 Datacenter Core 48HP8-DN98B-MYWDG-T2DCC-8W83P

Windows 8.1

System Key
Windows 8.1 Professional GCRJD-8NW9H-F2CDX-CCM8D-9D6T9
Windows 8.1 Professional N HMCNV-VVBFX-7HMBH-CTY9B-B4FXY
Windows 8.1 Enterprise MHF9N-XY6XB-WVXMC-BTDCT-MKKG7
Windows 8.1 Enterprise N TT4HM-HN7YT-62K67-RGRQJ-JFFXW

Windows 8

System Key
Windows 8 Professional NG4HW-VH26C-733KW-K6F98-J8CK4
Windows 8 Professional N XCVCF-2NXM9-723PB-MHCB7-2RYQQ
Windows 8 Enterprise 32JNW-9KQ84-P47T8-D8GGY-CWCK7
Windows 8 Enterprise N JMNMF-RHW7P-DMY6X-RF3DR-X2BQT

Windows Server 2008 R2

System Key
Windows Server 2008 R2 HPC Edition FKJQ8-TMCVP-FRMR7-4WR42-3JCD7
Windows Server 2008 R2 Datacenter 74YFP-3QFB3-KQT8W-PMXWJ-7M648
Windows Server 2008 R2 Enterprise 489J6-VHDMP-X63PK-3K798-CPX3Y
Windows Server 2008 R2 for Itanium-Based Systems GT63C-RJFQ3-4GMB6-BRFB9-CB83V
Windows Server 2008 R2 Standard YC6KT-GKW9T-YTKYR-T4X34-R7VHC
Windows Web Server 2008 R2 6TPJF-RBVHG-WBW2R-86QPH-6RTM4
Windows Server 2008 Datacenter 7M67G-PC374-GR742-YH8V4-TCBY3
Windows Server 2008 Datacenter without Hyper-V 22XQ2-VRXRG-P8D42-K34TD-G3QQC
Windows Server 2008 for Itanium-Based Systems 4DWFP-JF3DJ-B7DTH-78FJB-PDRHK
Windows Server 2008 Enterprise YQGMW-MPWTJ-34KDK-48M3W-X4Q6V
Windows Server 2008 Enterprise without Hyper-V 39BXF-X8Q23-P2WWT-38T2F-G3FPG
Windows Server 2008 Standard TM24T-X9RMF-VWXK6-X8JC9-BFGM2
Windows Server 2008 Standard without Hyper-V W7VD6-7JFBR-RX26B-YKQ3Y-6FFFJ
Windows Web Server 2008 WYR28-R7TFJ-3X2YQ-YCY4H-M249D

Windows 7

System Key
Windows 7 Professional FJ82H-XT6CR-J8D7P-XQJJ2-GPDD4
Windows 7 Professional N MRPKT-YTG23-K7D7T-X2JMM-QY7MG
Windows 7 Enterprise 33PXH-7Y6KF-2VJC9-XBBR8-HVTHH
Windows 7 Enterprise N YDRBP-3D83W-TY26F-D46B2-XCKRJ
Windows 7 Enterprise E C29WB-22CC8-VJ326-GHFJW-H9DH4

Windows Vista

System Key
Windows Vista Business YFKBB-PQJJV-G996G-VWGXY-2V3X8
Windows Vista Business N HMBQG-8H2RH-C77VX-27R82-VMQBT
Windows Vista Enterprise VKK3X-68KWM-X2YGT-QR4M6-4BWMV
Windows Vista Enterprise N VTC42-BM838-43QHV-84HX6-XJXKV

References:

  • bitspace
  • pykms
  • vlmcsd
  • zvv
  • theitbros
---- The End Thanks ----
Donate if you like the article.