Skip to content
This repository has been archived by the owner on Dec 28, 2023. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
4ra1n committed Mar 13, 2023
1 parent a5705e6 commit f9345eb
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.MD
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,7 @@ Others:
## 1.6

更新内容:
- [important] RAD联动支持Cookie配置 #153
- [bug] 备份xray目录原来的config.yaml文件 #152
- [feat] RAD 联动支持拖拽功能 #151
- [feat] request 支持自定义 user-agent #149
Expand Down
34 changes: 29 additions & 5 deletions src/main/java/com/chaitin/xray/form/RadForm.form
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
</component>
</children>
</scrollpane>
<grid id="c75a2" binding="radConfigPanel" layout-manager="GridLayoutManager" row-count="3" column-count="2" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="c75a2" binding="radConfigPanel" layout-manager="GridLayoutManager" row-count="4" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="0" fill="3" indent="0" use-parent-layout="false"/>
Expand All @@ -64,7 +64,7 @@
</component>
<component id="3fb0d" class="javax.swing.JTextField" binding="urlText">
<constraints>
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
Expand All @@ -80,7 +80,7 @@
</component>
<component id="3fe05" class="javax.swing.JTextField" binding="radFileText">
<constraints>
<grid row="0" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<grid row="0" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
Expand All @@ -91,20 +91,44 @@
</component>
<component id="8fa81" class="javax.swing.JButton" binding="startRadButton" default-binding="true">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="3" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Start Rad"/>
</properties>
</component>
<component id="a282" class="javax.swing.JLabel" binding="startLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="3" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=" Start"/>
</properties>
</component>
<component id="a2e14" class="javax.swing.JLabel" binding="radCookieLabel">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value=" Cookie"/>
</properties>
</component>
<component id="6eb91" class="javax.swing.JTextField" binding="radCookieText">
<constraints>
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
<preferred-size width="150" height="-1"/>
</grid>
</constraints>
<properties/>
</component>
<component id="b8f0a" class="javax.swing.JButton" binding="confirmButton" default-binding="true">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Confirm"/>
</properties>
</component>
</children>
</grid>
</children>
Expand Down
85 changes: 76 additions & 9 deletions src/main/java/com/chaitin/xray/form/RadForm.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
package com.chaitin.xray.form;

import com.chaitin.xray.model.RadCmd;
import com.chaitin.xray.utils.CheckUtil;
import com.chaitin.xray.utils.ExecUtil;
import com.chaitin.xray.utils.JNAUtil;
import com.chaitin.xray.utils.OSUtil;
import com.chaitin.xray.utils.*;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import org.apache.log4j.LogManager;
import org.apache.log4j.Logger;
import org.yaml.snakeyaml.LoaderOptions;
import org.yaml.snakeyaml.Yaml;
import org.yaml.snakeyaml.constructor.SafeConstructor;

import javax.swing.*;
import javax.swing.border.TitledBorder;
Expand All @@ -21,8 +21,12 @@
import java.awt.dnd.DropTargetDropEvent;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Locale;
import java.util.Map;

public class RadForm {
private static final Logger logger = LogManager.getLogger(RadForm.class);
Expand All @@ -37,6 +41,9 @@ public class RadForm {
private JPanel radConfigPanel;
private JLabel targetLabel;
private JLabel startLabel;
private JTextField radCookieText;
private JLabel radCookieLabel;
private JButton confirmButton;

private static RadCmd radCmd;
public volatile boolean stop = false;
Expand Down Expand Up @@ -124,9 +131,61 @@ private void initLang() {
}
}

@SuppressWarnings("unchecked")
private void initCookie() {
try {
Path path = Paths.get("rad_config.yml");
String data;
if (!Files.exists(path)) {
InputStream radIs = RadForm.class.getClassLoader()
.getResourceAsStream("rad_config.yml");
data = IOUtil.readStringFromIs(radIs);
} else {
data = new String(Files.readAllBytes(path));
}
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
Map<String, Object> obj = yaml.load(data);
List<Object> objList = (List<Object>) obj.get("domain_headers");
Map<String, Object> headers = (Map<String, Object>)
((Map<String, Object>) objList.get(0)).get("headers");
String cookie = (String) headers.get("Cookie");
radCookieText.setText(cookie);
} catch (Exception ex) {
ex.printStackTrace();
}

confirmButton.addActionListener(e -> new Thread(() -> {
try {
Path path = Paths.get("rad_config.yml");
String data;
String co = radCookieText.getText();
if (!Files.exists(path)) {
InputStream radIs = RadForm.class.getClassLoader()
.getResourceAsStream("rad_config.yml");
data = IOUtil.readStringFromIs(radIs);
} else {
data = new String(Files.readAllBytes(path));
}
Yaml yaml = new Yaml(new SafeConstructor(new LoaderOptions()));
Map<String, Object> obj = yaml.load(data);
List<Object> objList = (List<Object>) obj.get("domain_headers");
Map<String, Object> headers = (Map<String, Object>)
((Map<String, Object>) objList.get(0)).get("headers");
headers.put("Cookie", co);
String out = yaml.dump(obj);
Files.write(path, out.getBytes());
JOptionPane.showMessageDialog(radPane, "Success");
} catch (Exception ex) {
ex.printStackTrace();
}
}).start());
}

public RadForm(String inputPort) {
initLang();

initCookie();

DropTarget dt = new DropTarget() {
@SuppressWarnings("unchecked")
public synchronized void drop(DropTargetDropEvent evt) {
Expand Down Expand Up @@ -225,27 +284,35 @@ public synchronized void drop(DropTargetDropEvent evt) {
outputTextArea.setLineWrap(true);
outputPanel.setViewportView(outputTextArea);
radConfigPanel = new JPanel();
radConfigPanel.setLayout(new GridLayoutManager(3, 2, new Insets(0, 0, 0, 0), -1, -1));
radConfigPanel.setLayout(new GridLayoutManager(4, 3, new Insets(0, 0, 0, 0), -1, -1));
radConfigPanel.setBackground(new Color(-12828863));
radPane.add(radConfigPanel, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_BOTH, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, null, null, null, 0, false));
targetLabel = new JLabel();
targetLabel.setText(" Target URL");
radConfigPanel.add(targetLabel, new GridConstraints(1, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
urlText = new JTextField();
radConfigPanel.add(urlText, new GridConstraints(1, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
radConfigPanel.add(urlText, new GridConstraints(1, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
choseRadFileButton = new JButton();
choseRadFileButton.setText("Chose Rad File");
radConfigPanel.add(choseRadFileButton, new GridConstraints(0, 0, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
radFileText = new JTextField();
radFileText.setEditable(false);
radFileText.setEnabled(false);
radConfigPanel.add(radFileText, new GridConstraints(0, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
radConfigPanel.add(radFileText, new GridConstraints(0, 1, 1, 2, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
startRadButton = new JButton();
startRadButton.setText("Start Rad");
radConfigPanel.add(startRadButton, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
radConfigPanel.add(startRadButton, new GridConstraints(3, 1, 1, 2, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
startLabel = new JLabel();
startLabel.setText(" Start");
radConfigPanel.add(startLabel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
radConfigPanel.add(startLabel, new GridConstraints(3, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
radCookieLabel = new JLabel();
radCookieLabel.setText(" Cookie");
radConfigPanel.add(radCookieLabel, new GridConstraints(2, 0, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_NONE, GridConstraints.SIZEPOLICY_FIXED, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
radCookieText = new JTextField();
radConfigPanel.add(radCookieText, new GridConstraints(2, 1, 1, 1, GridConstraints.ANCHOR_WEST, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_WANT_GROW, GridConstraints.SIZEPOLICY_FIXED, null, new Dimension(150, -1), null, 0, false));
confirmButton = new JButton();
confirmButton.setText("Confirm");
radConfigPanel.add(confirmButton, new GridConstraints(2, 2, 1, 1, GridConstraints.ANCHOR_CENTER, GridConstraints.FILL_HORIZONTAL, GridConstraints.SIZEPOLICY_CAN_SHRINK | GridConstraints.SIZEPOLICY_CAN_GROW, GridConstraints.SIZEPOLICY_FIXED, null, null, null, 0, false));
}

/**
Expand Down
60 changes: 60 additions & 0 deletions src/main/resources/rad_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
exec_path: "" # 启动chrome的路径
disable_headless: false # 禁用无头模式
force_sandbox: false # 强制开启sandbox;为 false 时默认开启沙箱,但在容器中会关闭沙箱。为true时强制启用沙箱,可能导致在docker中无法使用。
enable_image: false # 启用图片显示
parent_path_detect: true # 是否启用父目录探测功能
proxy: "" # 代理配置
user_agent: "" # 请求user-agent配置
domain_headers: # 请求头配置:[]{domain,map[headerKey]HeaderValue}
- domain: '*' # 为哪些域名设置header,glob语法
headers: {} # 请求头,map[key]value
max_depth: 10 # 最大页面深度限制
navigate_timeout_second: 10 # 访问超时时间,单位秒
load_timeout_second: 10 # 加载超时时间,单位秒
retry: 0 # 页面访问失败后的重试次数
page_analyze_timeout_second: 300 # 页面分析超时时间,单位秒
max_interactive: 1000 # 单个页面最大交互次数
max_interactive_depth: 10 # 页面交互深度限制
max_page_concurrent: 10 # 最大页面并发(不大于10)
max_page_visit: 1000 # 总共允许访问的页面数量
max_page_visit_per_site: 1000 # 每个站点最多访问的页面数量
element_filter_strength: 0 # 过滤同站点相似元素强度,1-7取值,强度逐步增大,为0时不进行跨页面元素过滤
new_task_filter_config: # 检查某个链接是否应该被加入爬取队列
hostname_allowed: [] # 允许访问的 Hostname,支持格式如 t.com、*.t.com、1.1.1.1、1.1.1.1/24、1.1-4.1.1-8
hostname_disallowed: [] # 不允许访问的 Hostname,支持格式如 t.com、*.t.com、1.1.1.1、1.1.1.1/24、1.1-4.1.1-8
port_allowed: [] # 允许访问的端口, 支持的格式如: 80、80-85
port_disallowed: [] # 不允许访问的端口, 支持的格式如: 80、80-85
path_allowed: [] # 允许访问的路径,支持的格式如: test、*test*
path_disallowed: [] # 不允许访问的路径, 支持的格式如: test、*test*
query_key_allowed: [] # 允许访问的 Query Key,支持的格式如: test、*test*
query_key_disallowed: [] # 不允许访问的 Query Key, 支持的格式如: test、*test*
fragment_allowed: [] # 允许访问的 Fragment, 支持的格式如: test、*test*
fragment_disallowed: [] # 不允许访问的 Fragment, 支持的格式如: test、*test*
post_key_allowed: [] # 允许访问的 Post Body 中的参数, 支持的格式如: test、*test*
post_key_disallowed: [] # 不允许访问的 Post Body 中的参数, 支持的格式如: test、*test*
request_send_filter_config: # 检查某个请求是否应该被发送
hostname_allowed: [] # 允许访问的 Hostname,支持格式如 t.com、*.t.com、1.1.1.1、1.1.1.1/24、1.1-4.1.1-8
hostname_disallowed: [] # 不允许访问的 Hostname,支持格式如 t.com、*.t.com、1.1.1.1、1.1.1.1/24、1.1-4.1.1-8
port_allowed: [] # 允许访问的端口, 支持的格式如: 80、80-85
port_disallowed: [] # 不允许访问的端口, 支持的格式如: 80、80-85
path_allowed: [] # 允许访问的路径,支持的格式如: test、*test*
path_disallowed: [] # 不允许访问的路径, 支持的格式如: test、*test*
query_key_allowed: [] # 允许访问的 Query Key,支持的格式如: test、*test*
query_key_disallowed: [] # 不允许访问的 Query Key, 支持的格式如: test、*test*
fragment_allowed: [] # 允许访问的 Fragment, 支持的格式如: test、*test*
fragment_disallowed: [] # 不允许访问的 Fragment, 支持的格式如: test、*test*
post_key_allowed: [] # 允许访问的 Post Body 中的参数, 支持的格式如: test、*test*
post_key_disallowed: [] # 不允许访问的 Post Body 中的参数, 支持的格式如: test、*test*
request_output_filter_config: # 检查某个请求是否应该被输出
hostname_allowed: [] # 允许访问的 Hostname,支持格式如 t.com、*.t.com、1.1.1.1、1.1.1.1/24、1.1-4.1.1-8
hostname_disallowed: [] # 不允许访问的 Hostname,支持格式如 t.com、*.t.com、1.1.1.1、1.1.1.1/24、1.1-4.1.1-8
port_allowed: [] # 允许访问的端口, 支持的格式如: 80、80-85
port_disallowed: [] # 不允许访问的端口, 支持的格式如: 80、80-85
path_allowed: [] # 允许访问的路径,支持的格式如: test、*test*
path_disallowed: [] # 不允许访问的路径, 支持的格式如: test、*test*
query_key_allowed: [] # 允许访问的 Query Key,支持的格式如: test、*test*
query_key_disallowed: [] # 不允许访问的 Query Key, 支持的格式如: test、*test*
fragment_allowed: [] # 允许访问的 Fragment, 支持的格式如: test、*test*
fragment_disallowed: [] # 不允许访问的 Fragment, 支持的格式如: test、*test*
post_key_allowed: [] # 允许访问的 Post Body 中的参数, 支持的格式如: test、*test*
post_key_disallowed: [] # 不允许访问的 Post Body 中的参数, 支持的格式如: test、*test*

0 comments on commit f9345eb

Please sign in to comment.