add
This commit is contained in:
parent
2259019410
commit
d64d4b8511
116
20251016.md
116
20251016.md
@ -1,71 +1,17 @@
|
|||||||
## 1、下载并上传 openjdk zulu 21 压缩包
|
## 新建目录
|
||||||
|
|
||||||
- 下载地址:https://www.azul.com/downloads/?version=java-21-lts&package=jdk#zulu
|
|
||||||
- 解压到 /hook/jdk21 目录下
|
|
||||||
|
|
||||||
## 2、上传 TShark.java 文件,源码如下
|
|
||||||
|
|
||||||
```java
|
|
||||||
import java.io.*;
|
|
||||||
import java.nio.file.Path;
|
|
||||||
import java.time.ZoneId;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.TimeZone;
|
|
||||||
|
|
||||||
public final class TShark {
|
|
||||||
public static void main(String[] args) throws Exception {
|
|
||||||
TimeZone.setDefault(TimeZone.getTimeZone(ZoneId.of("Asia/Shanghai")));
|
|
||||||
Path path = Path.of("shark.log");
|
|
||||||
File sharkLog = path.toFile();
|
|
||||||
if (!sharkLog.exists() && !sharkLog.createNewFile()) {
|
|
||||||
throw new RuntimeException("create shark.log failure");
|
|
||||||
}
|
|
||||||
// DateTimeFormatter timeFormatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
|
|
||||||
Process process = startSharkProcess();
|
|
||||||
System.out.println("start tshark success");
|
|
||||||
startProcessSharkThread(process, sharkLog);
|
|
||||||
System.out.println("start process thread success");
|
|
||||||
int exitCode = process.waitFor();
|
|
||||||
System.out.println("tshark process is dead, exit code: " + exitCode);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void startProcessSharkThread(Process process, File sharkLog) {
|
|
||||||
Thread thread = new Thread(() -> {
|
|
||||||
try (BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
|
|
||||||
BufferedWriter fileWriter = new BufferedWriter(new FileWriter(sharkLog, true))) {
|
|
||||||
String line;
|
|
||||||
while ((line = reader.readLine()) != null) {
|
|
||||||
fileWriter.write(line + System.lineSeparator());
|
|
||||||
}
|
|
||||||
fileWriter.flush();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
thread.setName("TShark-thread");
|
|
||||||
thread.start();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Process startSharkProcess() throws IOException {
|
|
||||||
List<String> cmd = List.of(
|
|
||||||
"tshark",
|
|
||||||
"-l",
|
|
||||||
"-i",
|
|
||||||
"\\Device\\NPF_{807C63AC-179D-4AC8-BD56-85CE8AA179DB}",
|
|
||||||
"-Y",
|
|
||||||
"tcp.port == 33000 && http.request.method == \"POST\"",
|
|
||||||
"-V"
|
|
||||||
);
|
|
||||||
ProcessBuilder processBuilder = new ProcessBuilder(cmd);
|
|
||||||
processBuilder.redirectErrorStream(true);
|
|
||||||
return processBuilder.start();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
```
|
```
|
||||||
|
mkdir -p /hook/java
|
||||||
|
mkdir -p /hook/jdk21
|
||||||
|
```
|
||||||
|
## 上传文件
|
||||||
|
|
||||||
## 3、修改网卡名称
|
- JDK解压到 /hook/jdk21 目录下,注意目录结构,确保 /hook/jdk21 目录下包含**/bin**目录
|
||||||
|
- 将 TShark.java 上传到 /hook/java 目录下
|
||||||
|
|
||||||
##### 编辑`TShark.java`文件,找到 **startSharkProcess** 函数
|
## 修改 TShark.java 文件中的一行
|
||||||
|
|
||||||
|
##### 找到 **startSharkProcess** 函数
|
||||||
|
|
||||||
```java
|
```java
|
||||||
public static Process startSharkProcess() throws IOException {
|
public static Process startSharkProcess() throws IOException {
|
||||||
@ -73,7 +19,8 @@ public static Process startSharkProcess() throws IOException {
|
|||||||
"tshark",
|
"tshark",
|
||||||
"-l",
|
"-l",
|
||||||
"-i",
|
"-i",
|
||||||
"\\Device\\NPF_{807C63AC-179D-4AC8-BD56-85CE8AA179DB}",
|
// 把这一行网卡名称,替换成正确的网卡名称,下面这个是我自己电脑上的网卡名称
|
||||||
|
"\\Device\\NPF_{807C63AC-179D-4AC8-BD56-85CE8AA179DB}",// 修改后应该是:"ethxxx",
|
||||||
"-Y",
|
"-Y",
|
||||||
"tcp.port == 33000 && http.request.method == \"POST\"",
|
"tcp.port == 33000 && http.request.method == \"POST\"",
|
||||||
"-V"
|
"-V"
|
||||||
@ -83,13 +30,42 @@ public static Process startSharkProcess() throws IOException {
|
|||||||
return processBuilder.start();
|
return processBuilder.start();
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
##### 把这一行网卡名称,替换成正确的网卡名称,下面这个是我自己电脑上的网卡名称
|
|
||||||
|
|
||||||
```
|
##### 查本机IP网卡的命令
|
||||||
"\\Device\\NPF_{807C63AC-179D-4AC8-BD56-85CE8AA179DB}"
|
|
||||||
```
|
|
||||||
|
|
||||||
不确定当前IP使用的哪个网卡,可以用下面这个命令查询
|
|
||||||
```
|
```
|
||||||
ip a
|
ip a
|
||||||
|
```
|
||||||
|
|
||||||
|
## 创建一个 shell 脚本,用于后台运行 java 脚本
|
||||||
|
|
||||||
|
##### 创建脚本
|
||||||
|
```
|
||||||
|
vi /hook/tshark_bash.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 复制粘贴下面内容然后保存
|
||||||
|
|
||||||
|
```bash
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
export JAVA_HOME=/hook/jdk21
|
||||||
|
export PATH=$JAVA_HOME/bin:$PATH
|
||||||
|
export CLASSPATH=.:$JAVA_HOME/lib
|
||||||
|
java /hook/java/TShark.java
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 赋予执行权限
|
||||||
|
```
|
||||||
|
sudo chmod +x /hook/tshark_bash.sh
|
||||||
|
```
|
||||||
|
|
||||||
|
##### 后台运行
|
||||||
|
```
|
||||||
|
sudo nohup bash /hook/tshark_bash.sh >> /hook/tshark_bash.log 2>&1 & echo $! > /hook/tshark_bash.pid
|
||||||
|
```
|
||||||
|
|
||||||
|
#### 停止运行
|
||||||
|
```
|
||||||
|
kill -9 $(cat /hook/tshark_bash.pid)
|
||||||
```
|
```
|
||||||
Loading…
Reference in New Issue
Block a user