Skip to content
This repository was archived by the owner on Dec 4, 2024. It is now read-only.

Commit 5c54160

Browse files
committed
commit
0 parents  commit 5c54160

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+2495
-0
lines changed

.github/workflows/java.yml

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: java action
2+
3+
on:
4+
push:
5+
branches: [ "master" ]
6+
7+
jobs:
8+
9+
build:
10+
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: Set up JDK 8
16+
uses: actions/setup-java@v3
17+
with:
18+
java-version: '8'
19+
distribution: 'temurin'
20+
cache: maven
21+
- name: Build with Maven
22+
run: mvn -B package --file pom.xml

.github/workflows/linux.yml

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
name: linux action
2+
3+
on:
4+
workflow_dispatch:
5+
6+
jobs:
7+
8+
build:
9+
10+
runs-on: ubuntu-latest
11+
if: github.event_name == 'workflow_dispatch'
12+
13+
steps:
14+
- uses: actions/checkout@v3
15+
- name: environment init
16+
run: |
17+
sudo apt-get update
18+
sudo apt-get install -y ca-certificates
19+
sudo apt-get install zip unzip wget ninja-build gcc g++ openjdk-8-jdk nasm python3 execstack
20+
21+
- name: get cmake
22+
run: |
23+
wget https://cmake.org/files/v3.28/cmake-3.28.0-linux-x86_64.tar.gz
24+
tar -zxvf cmake-3.28.0-linux-x86_64.tar.gz
25+
26+
- name: build
27+
run: |
28+
cd native
29+
../cmake-3.28.0-linux-x86_64/bin/cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=ninja -G Ninja -S . -B build-release
30+
../cmake-3.28.0-linux-x86_64/bin/cmake --build build-release --target all
31+
python3 main.py
32+
zip -r build-linux.zip target/*
33+
34+
- name: upload
35+
uses: actions/upload-artifact@v4
36+
with:
37+
name: build-artifact
38+
path: native/build-linux.zip

.gitignore

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
!**/src/main/**/target/
4+
!**/src/test/**/target/
5+
6+
### IntelliJ IDEA ###
7+
.idea/modules.xml
8+
.idea/jarRepositories.xml
9+
.idea/compiler.xml
10+
.idea/libraries/
11+
*.iws
12+
*.iml
13+
*.ipr
14+
15+
### Eclipse ###
16+
.apt_generated
17+
.classpath
18+
.factorypath
19+
.project
20+
.settings
21+
.springBeans
22+
.sts4-cache
23+
24+
### NetBeans ###
25+
/nbproject/private/
26+
/nbbuild/
27+
/dist/
28+
/nbdist/
29+
/.nb-gradle/
30+
build/
31+
!**/src/main/**/build/
32+
!**/src/test/**/build/
33+
34+
### VS Code ###
35+
.vscode/
36+
37+
### Mac OS ###
38+
.DS_Store
39+
40+
### Others ###
41+
.idea/
42+
cmake-build-debug/
43+
cmake-build-release/
44+
build-release/
45+
*.exe

CHANGELOG.MD

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
## 0.1
2+
3+
第一个版本:
4+
- code-encryptor-plus-0.0.1-cli.jar
5+
- code-encryptor-plus-0.0.1-gui.jar
6+
7+
提供 GUI 和 CLI 两个版本,CLI 版本分为 patch 和 export 两个命令
8+
- patch 命令用于加密输入的 jar 包
9+
- export 命令用于导出对应的 dll 解密库
10+
11+
GUI 版本的使用和 CLI 版本基本一致,具体参考 README 文件
12+
13+
目前的加密算法:
14+
- 汇编实现的多层位运算,交换字节等
15+
- 三次XXTEA算法,抽取 10-34 位字节
16+
17+
适用环境:
18+
- Windows 64 位 (Linux环境需要重写)
19+
- JDK 8 (其他版本可以自行编译)
20+
21+
## 0.2
22+
23+
两个重要功能的更新:
24+
- 支持了`linux`系统
25+
- 支持了自定义加密密钥
26+
27+
更新日志:
28+
- 基于`gcc``nasm`支持`linux x86_64 (amd64)`
29+
- 支持`Windows``Linux`任意密钥加密解密
30+
- 使用`execstack``so`库修改堆栈可执行属性
31+
- 汇编中部分寄存器忘记恢复状态导致某些`JVM`崩溃
32+
- 修复`linux`中字符串处理函数的缓冲区溢出问题
33+
- 修改`README`部分应该使用`-agentpath`启动
34+
- 优化重构`Java`层代码,抽出工具类等
35+
- 避免重复宏定义的问题
36+
37+
## 0.3
38+
39+
修改`JVM`阻止通过`HSDB``dump`字节码,支持`linux``windows`
40+
41+
更新日志:
42+
- [FEATURE] 参考`beichen`师傅议题阻止dump字节码的方法 #6
43+
- [FEATURE] 应该对完整的所有的字节码进行加密 #3
44+
[FEATURE] GUI 加入密钥部分 #2
45+
- [FEATURE] GUI 和命令行都应该加入自动生成运行命令部分 #7
46+
- [FEATURE] 优化打印的日志以及调试信息 #4
47+
- [FEATURE] ENGLISH DOC #1
48+
- 代码和文档的优化
49+
50+
提供 GUI 和 CLI 两个版本,CLI 版本分为 patch 和 export 两个命令
51+
- patch 命令用于加密输入的 jar 包
52+
- export 命令用于导出对应的 dll 解密库
53+
54+
GUI 版本的使用和 CLI 版本基本一致,具体参考 README 文件
55+
56+
## 0.4
57+
58+
更新日志:
59+
- 优化`native`层的代码
60+
- 优化`README`说明文档
61+
62+
提供 GUI 和 CLI 两个版本,CLI 版本分为 patch 和 export 两个命令
63+
- patch 命令用于加密输入的 jar 包
64+
- export 命令用于导出对应的 dll/so 解密库
65+
66+
GUI 版本的使用和 CLI 版本基本一致,具体参考 README 文件

Dockerfile

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
FROM ubuntu:22.04
2+
3+
LABEL author="4ra1n"
4+
LABEL github="https://github.com/4ra1n"
5+
6+
ENV CODE_ENC_VER 0.4
7+
8+
WORKDIR /app
9+
10+
RUN apt-get update && apt-get install -y ca-certificates --reinstall
11+
12+
RUN echo "\
13+
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy main restricted universe multiverse\n\
14+
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-updates main restricted universe multiverse\n\
15+
deb https://mirrors.tuna.tsinghua.edu.cn/ubuntu/ jammy-backports main restricted universe multiverse\n\
16+
deb http://security.ubuntu.com/ubuntu/ jammy-security main restricted universe multiverse" | tee /etc/apt/sources.list \
17+
&& apt-get update && apt-get install -y zip unzip wget ninja-build gcc g++ openjdk-8-jdk nasm python3 execstack
18+
19+
COPY . .
20+
21+
RUN wget https://cmake.org/files/v3.28/cmake-3.28.0-linux-x86_64.tar.gz && \
22+
tar -zxvf cmake-3.28.0-linux-x86_64.tar.gz
23+
24+
ENV PATH="${PATH}:/app/cmake-3.28.0-linux-x86_64/bin"
25+
26+
RUN cd native && \
27+
cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE_PROGRAM=ninja -G Ninja -S . -B build-release && \
28+
cmake --build build-release --target all && \
29+
python3 main.py && \
30+
zip -r ../build.zip target/*
31+
32+
CMD ["echo", "build code-encryptor ${CODE_ENC_VER} completed - /app/build.zip"]
33+

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 4ra1n
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
# code-encryptor
2+
3+
[English Doc](doc/README-en.md)
4+
5+
[![](https://img.shields.io/github/v/release/4ra1n/code-encryptor)](https://github.com/4ra1n/code-encryptor/releases/latest)
6+
![](https://img.shields.io/github/downloads/4ra1n/code-encryptor/total)
7+
8+
## 介绍
9+
10+
使用`JNI`加密字节码,通过`JVMTI`解密字节码以保护代码
11+
12+
提供两份`DLL`文件,一份加密一份解密,实际运行只需使用解密`DLL`文件,支持自定义密钥和包名
13+
14+
加密后的`Class`文件变成无法解析的畸形文件
15+
16+
![jd-gui](img/002.png)
17+
18+
除了开头保持了`Magic`部分,后续是无法解析的字节
19+
20+
![hex](img/003.png)
21+
22+
使用指定参数启动即可禁止 `Java Agent` 动态 `dump` 字节码
23+
24+
![](img/007.png)
25+
26+
对于更资深的黑客,他们会想到 `sa-jdi``HSDB``dump` 字节码
27+
28+
我参考 `Beichen` 师傅议题的思路,从 `JVM` 里禁用了 `gHotSpotVMStructs` 函数
29+
30+
支持 `Windows` 系统
31+
32+
![WINDOWS](img/008.png)
33+
34+
支持 `Linux` 系统
35+
36+
![LINUX](img/009.png)
37+
38+
## 快速开始
39+
40+
加密解密部分使用`C`做一层加密,使用汇编做位运算二层加密,已提供编译好的`Release`版本`DLL/SO`文件嵌入`Jar`包中
41+
42+
内置支持是`JDK-8`,其他版本未测试,理论上需要更换`JNI.h`头文件重新编译,已支持`Windows``Linux`
43+
44+
加密你的`Jar`包:(指定`Jar`包和`package`加密包名以及密钥`key`
45+
46+
```shell
47+
java -jar code-encryptor.jar patch --jar your-jar.jar --package com.your.pack --key your-key
48+
```
49+
50+
![](img/004.png)
51+
52+
导出解密`DLL/SO`文件:(默认导出到`code-encryptor-temp`目录不建议修改)
53+
54+
```shell
55+
java -jar code-encryptor.jar export
56+
```
57+
58+
![](img/005.png)
59+
60+
使用解密`DLL/SO`启动`Jar`包:(使用`-agentpath`参数)
61+
62+
注意必须有两个参数`PACKAGE_NAME``KEY`
63+
64+
注意:某些情况下可能第一次无法启动,重复使用命令启动即可
65+
66+
```shell
67+
java -XX:+DisableAttachMechanism -agentpath:D:\abs-path\decrypter.dll=PACKAGE_NAME=com.your.pack,KEY=your-key --jar your-jar.jar
68+
```
69+
70+
![](img/006.png)
71+
72+
## 特点
73+
74+
本项目相比于网上公开的文章/代码,优势和特点有以下几条:
75+
- 原文章固定了包名,用户想加密自己的包名需要重新编译`DLL`
76+
- 原文章加密和解密`DLL`是同一个,这样只用`JNI`调用下加密即可破解
77+
- 原文章的代码仅是`Demo`级别,无法直接上手测试和使用
78+
- 原文章没有加入具体的加密算法,仅是简单的运算,需要加强
79+
- 原文章的代码存在一些`BUG`和优化空间
80+
- 使用某些魔法操作,使字节码无法被 `dump` 进一步保证安全
81+
82+
目前的加密解密算法:
83+
- 多次位运算,交换字节等
84+
- 基于`XXTEA`算法,多轮加密
85+
- 支持自定义密钥,进一步保护
86+
87+
## 构建
88+
89+
编译环境:
90+
- Windows 11 / Ubuntu 22.04
91+
- JDK 8 / Maven
92+
- MSVC + ml64 (Windows) / gcc + nasm (Linux)
93+
- CMake 3.x
94+
- Python 3.x
95+
96+
## 其他
97+
98+
不适用于启动扫描 `class` 的项目(典型的项目比如`SpringBoot`
99+
100+
正在想办法解决这个问题
101+
102+
## 参考
103+
104+
感谢以下项目或文章提供的思路:
105+
- https://mp.weixin.qq.com/s/89Bmvy_uY97TZm3vR9lyWw
106+
- https://juejin.cn/post/6844903487784894477
107+
- https://github.com/sea-boat/ByteCodeEncrypt

0 commit comments

Comments
 (0)