Skip to content

Commit

Permalink
Merge branch 'dev'
Browse files Browse the repository at this point in the history
  • Loading branch information
krxkli committed Sep 20, 2024
2 parents e134038 + ddde132 commit 9ca11aa
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 21 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
[submodule "Android/app/src/main/cpp/submodules/zdtun"]
path = Android/app/src/main/cpp/submodules/zdtun
url = [email protected]:KrxkGit/zdtun.git
[submodule "Android/app/src/main/cpp/submodules/libpcap"]
path = Android/app/src/main/cpp/submodules/libpcap
url = [email protected]:the-tcpdump-group/libpcap.git
46 changes: 32 additions & 14 deletions Android/.gitignore
Original file line number Diff line number Diff line change
@@ -1,15 +1,33 @@
*.iml
.gradle
/local.properties
/.idea/caches
/.idea/libraries
/.idea/modules.xml
/.idea/workspace.xml
/.idea/navEditor.xml
/.idea/assetWizardSettings.xml
.DS_Store
/build
/captures
.externalNativeBuild
.cxx
# Gradle files
.gradle/
build/

# Local configuration file (sdk path, etc)
local.properties

# Log/OS Files
*.log

# Android Studio generated files and folders
captures/
.externalNativeBuild/
.cxx/
*.apk
output.json

# IntelliJ
*.iml
.idea/
misc.xml
deploymentTargetDropDown.xml
render.experimental.xml

# Keystore files
*.jks
*.keystore

# Google Services (e.g. APIs or Firebase)
google-services.json

# Android Profiling
*.hprof
9 changes: 6 additions & 3 deletions Android/app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,23 @@ android {
applicationId = "com.krxkli.crackmm"
minSdk = 24
targetSdk = 34
versionCode = 1
versionName = "1.0"
versionCode = 2
versionName = "1.1"

testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner"

// Golang 库为下列架构
ndk {
abiFilters.add("arm64-v8a")
abiFilters.add("armeabi-v7a")
abiFilters.add("x86")
abiFilters.add("x86_64")
}
}

buildTypes {
release {
isMinifyEnabled = false
isMinifyEnabled = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
Expand Down
20 changes: 19 additions & 1 deletion Android/app/proguard-rules.pro
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,22 @@

# If you keep the line number information, uncomment this to
# hide the original source file name.
#-renamesourcefileattribute SourceFile
#-renamesourcefileattribute SourceFile

-keep class com.krxkli.crackmm.* {
native <methods>;
}

-keep class com.krxkli.crackmm.core.PktProcessor {
helpProtectSocket(int);
}

# 输出mapping.txt文件
-printmapping ./build/outputs/mapping/release/mapping.txt

# 输出seeds.txt文件
-printseeds ./build/outputs/mapping/release/seeds.txt

# 输出usage.txt文件
-printusage ./build/outputs/mapping/release/usage.txt

Binary file modified Android/app/release/app-release.apk
Binary file not shown.
Binary file modified Android/app/release/baselineProfiles/0/app-release.dm
Binary file not shown.
Binary file modified Android/app/release/baselineProfiles/1/app-release.dm
Binary file not shown.
4 changes: 2 additions & 2 deletions Android/app/release/output-metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
"type": "SINGLE",
"filters": [],
"attributes": [],
"versionCode": 1,
"versionName": "1.0",
"versionCode": 2,
"versionName": "1.1",
"outputFile": "app-release.apk"
}
],
Expand Down
1 change: 1 addition & 0 deletions Android/app/src/main/cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ add_library(${CMAKE_PROJECT_NAME} SHARED
# List C/C++ source files with relative paths to this CMakeLists.txt.
core/pkt_processor.cpp
core/cheat.cpp
core/pcap_dumper.cpp
)


Expand Down
57 changes: 57 additions & 0 deletions Android/app/src/main/cpp/core/pcap_dumper.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
//
// Created by krxkli on 2024/8/13.
//
#include "pcap_dumper.h"

#define MAX_PACKET_SIZE 65535

FILE *file = nullptr;

void pcap_dump_init(const char* file_name) {
if(file != nullptr) {
return;
}
pcap_file_header file_header;

// 打开输出文件
file = fopen(file_name, "wb");

// 设置pcap文件头部信息
file_header.magic_number = 0xa1b2c3d4; // 网络字节序
file_header.version_major = 2;
file_header.version_minor = 4;
file_header.thiszone = 0;
file_header.sigfigs = 0;
file_header.snaplen = MAX_PACKET_SIZE;
file_header.network = 101; // raw IP

// 写入pcap文件头部
fwrite(&file_header, sizeof(file_header), 1, file);
fflush(file);
}

void pcap_dump_data(u_char* pkt, uint32_t len) {
if(file == nullptr) {
return;
}
pcap_packet_header packet_header;
// 设置数据包头部信息
packet_header.ts_sec = clock() / CLOCKS_PER_SEC;
packet_header.ts_usec = clock() % CLOCKS_PER_SEC;
packet_header.incl_len = len;
packet_header.orig_len = len;

// 写入数据包头部
fwrite(&packet_header, sizeof(packet_header), 1, file);

// 写入数据包
fwrite(pkt, len, 1, file);

// 关闭输出文件
// fflush(file);
}

void pcap_dump_finish() {
fclose(file);
file = nullptr;
}
38 changes: 38 additions & 0 deletions Android/app/src/main/cpp/core/pcap_dumper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
//
// Created by krxkli on 2024/8/13.
//

#ifndef PCAP_DUMPER_H
#define PCAP_DUMPER_H

#include <ctime>
#include <cstdio>

/**
* 请保证全局单例使用本库
*/

// 定义pcap文件头部结构体
typedef struct {
uint32_t magic_number; // 文件魔术数
uint16_t version_major; // 主版本号
uint16_t version_minor; // 次版本号
int32_t thiszone; // 时区修正
uint32_t sigfigs; // 时间戳精度
uint32_t snaplen; // 最大捕获包长度
uint32_t network; // 数据链路类型
} pcap_file_header;

// 定义数据包头部结构体
typedef struct {
uint32_t ts_sec; // 时间戳(秒)
uint32_t ts_usec; // 时间戳(微秒)
uint32_t incl_len; // 捕获包长度
uint32_t orig_len; // 原始包长度
} pcap_packet_header;

void pcap_dump_init(const char* file_name);
void pcap_dump_data(u_char* pkt, uint32_t len);
void pcap_dump_finish();

#endif //CRACKMM_PCAP_DUMPER_H
13 changes: 13 additions & 0 deletions Android/app/src/main/cpp/core/pkt_processor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ extern "C" {
}

#include "cheat.h"
#include "pcap_dumper.h"

// VPN 描述符
int tun_fd;
Expand Down Expand Up @@ -67,6 +68,10 @@ bool activate(zdtun_t *tun, zdtun_pkt_t *pkt, char *origin_data) {

hook_progress = 0;
log("hook: %s", inet_ntoa(target_addr.sin_addr));

// dump pcap
pcap_dump_init("/sdcard/Download/crackmm.pcap");
pcap_dump_data((u_char *)pkt->buf, pkt->len);
return false;
}
}
Expand All @@ -78,6 +83,8 @@ bool activate(zdtun_t *tun, zdtun_pkt_t *pkt, char *origin_data) {
if (pkt->tuple.dst_ip.ip4 == target_addr.sin_addr.s_addr &&
pkt->tuple.dst_port == target_addr.sin_port && pkt->tuple.ipproto == IPPROTO_TCP) {

pcap_dump_data((u_char *)pkt->buf, pkt->len);

uint32_t reply_len = 0;
uint32_t reply_http_len = 0;
char *reply_buf;
Expand All @@ -97,6 +104,7 @@ bool activate(zdtun_t *tun, zdtun_pkt_t *pkt, char *origin_data) {
log("write SYN | ACK: need: %u actual: %zd\n", reply_len,
write_reply_len)
}
pcap_dump_data((u_char *)reply_buf, reply_len);
delete[]reply_buf;
} else if (flags & TH_ACK && !(flags & TH_PUSH) && !(flags & TH_FIN)) { // 第三次握手的ACK
hook_progress += 1;
Expand All @@ -116,12 +124,14 @@ bool activate(zdtun_t *tun, zdtun_pkt_t *pkt, char *origin_data) {
log("write HTTP Response(ACK): need: %u actual: %zd\n", reply_len,
write_reply_len)
}
pcap_dump_data((u_char *)reply_buf, reply_len);
write_reply_len = write(tun_fd, reply_buf + reply_len, reply_http_len);
if (write_reply_len >= reply_http_len) {
log("write: %s", reply_buf + 40 + 40)
log("write HTTP Response(HTTP): need: %u actual: %zd\n", reply_http_len,
write_reply_len)
}
pcap_dump_data((u_char *)reply_buf + reply_len, reply_http_len);
delete[]reply_buf;
} else if (flags & TH_FIN && flags & TH_ACK) {
hook_progress = 0;
Expand All @@ -132,7 +142,10 @@ bool activate(zdtun_t *tun, zdtun_pkt_t *pkt, char *origin_data) {
log("write ACK | FIN: need: %u actual: %zd\n", reply_len,
write_reply_len)
}
pcap_dump_data((u_char *)reply_buf, reply_len);
delete[]reply_buf;

pcap_dump_finish();
} else {
log("Recv other here : 0x%x, len: %hu", pkt->tcp->th_flags, pkt->len)
}
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,22 @@
存在时,软件将直接返回该文件保存的请求。

### 📜安卓端方案
### 📜安卓端方案 - v1.0.0 之前

对于安卓端,由于安卓端播放器未提供配置代理功能,且安卓端播放器不走系统代理,故可通过类似

> Postern
**VPN** 工具设置 **全局 HTTP 代理服务器**(注意:VPN 开启后将导致其他应用无法上网,激活播放器后即可关闭 VPN,往后同系列课程无需再次激活)。

### 📜安卓端方案 - v1.0.0

- 自 v1.0.0 版本起,提供 apk 安装包 全新解决解决方案,安装完成后,请授权 VPN 权限,点击主页面中的🔑图标尝试启动 VPN。

- 当 VPN 成功启动后,打开播放器按正常流程激活,随机输入非空的账号与密码,点击确定首次会提示账号密码错误,此时再次点击确定将成功激活。

- 出于学习研究目的,本方案与播放器的网络交互流程会以 *pcap* 包形式保存到 *下载* 目录,可使用 Wireshark 等工具查看以探究具体流程。

## ❕注意事项

本软件仅供研究学习使用,请勿用于商业途径。请尊重课程内容知识产权。

0 comments on commit 9ca11aa

Please sign in to comment.