Skip to content

Commit

Permalink
Song/feat/mitm disabled cert page (#1869)
Browse files Browse the repository at this point in the history
* feat: mitm新增是否禁用初始页

* fix: 提示问题调整

* feat: 记住禁用初始页缓存

* feat: 禁用初始页调整

* fix: 初始化的时候,禁用初始页拿值问题

* fix: 文案替换
  • Loading branch information
song-xiao-lin authored Aug 2, 2024
1 parent 35ca359 commit 94fc68d
Show file tree
Hide file tree
Showing 8 changed files with 100 additions and 69 deletions.
4 changes: 2 additions & 2 deletions app/main/handlers/chromelauncher.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ module.exports = (win, getClient) => {
})

ipcMain.handle("LaunchChromeWithParams", async (e, params) => {
const {port, host, chromePath, userDataDir, username, password} = params
const {port, host, chromePath, userDataDir, username, password, disableCACertPage} = params
const portInt = parseInt(`${port}`)
const hostRaw = `${host}`
if (hostRaw === "undefined" || hostRaw.includes("/") || hostRaw.split(":").length > 1) {
Expand All @@ -141,7 +141,7 @@ module.exports = (win, getClient) => {
// --no-system-proxy-config-service ⊗ Do not use system proxy configuration service.
// --no-proxy-server ⊗ Don't use a proxy server, always make direct connections. Overrides any other proxy server flags that are passed. ↪
let launchOpt = {
startingUrl: "http://mitm", // 确保在启动时打开 chrome://newtab 页面。
startingUrl: disableCACertPage === false ? "http://mitm" : "chrome://newtab", // 确保在启动时打开 chrome://newtab 页面。
chromeFlags: [
`--no-system-proxy-config-service`, // 禁用系统代理配置服务。
`--proxy-bypass-list=<-loopback>`, // 为代理设置回避列表,不代理回环地址。
Expand Down
7 changes: 4 additions & 3 deletions app/main/handlers/mitm.js
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ module.exports = (win, getClient) => {
ipcMain.handle("mitm-set-downstream-proxy", (e, downstreamProxy) => {
if (stream) {
stream.write({
SetDownstreamProxy : true,
SetDownstreamProxy: true,
downstreamProxy
})
}
Expand All @@ -233,7 +233,7 @@ module.exports = (win, getClient) => {

// 开始调用 MITM,设置 stream
let isFirstData = true
ipcMain.handle("mitm-start-call", (e, host, port, downstreamProxy, enableHttp2, ForceDisableKeepAlive,certificates, extra) => {
ipcMain.handle("mitm-start-call", (e, host, port, downstreamProxy, enableHttp2, ForceDisableKeepAlive, certificates, extra) => {
if (stream) {
if (win) {
win.webContents.send("client-mitm-start-success")
Expand Down Expand Up @@ -325,8 +325,9 @@ module.exports = (win, getClient) => {
if (stream) {
stream.write({
host, port, downstreamProxy,
enableHttp2, ForceDisableKeepAlive ,certificates,
enableHttp2, ForceDisableKeepAlive, certificates,
...extra,
DisableCACertPage: extra.disableCACertPage
})
}
})
Expand Down
8 changes: 6 additions & 2 deletions app/renderer/src/main/src/pages/mitm/MITMChromeLauncher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,13 @@ interface ChromeLauncherButtonProp {
onFished?: (host: string, port: number) => void
isStartMITM?: boolean
repRuleFlag?: boolean
disableCACertPage: boolean
}

interface MITMChromeLauncherProp {
host?: string
port?: number
disableCACertPage: boolean
callback: (host: string, port: number) => void
}

Expand Down Expand Up @@ -84,7 +86,8 @@ const MITMChromeLauncher: React.FC<MITMChromeLauncherProp> = (props) => {
userDataDir?: string
username?: string
password?: string
} = {...params, username, password, userDataDir}
disableCACertPage: boolean
} = {...params, username, password, userDataDir, disableCACertPage: props.disableCACertPage}

setRemoteValue(RemoteGV.MITMUserDataSave, isSaveUserData + "")
userDataDirRef.current.onSetRemoteValues(userDataDir)
Expand Down Expand Up @@ -211,7 +214,7 @@ const MITMChromeLauncher: React.FC<MITMChromeLauncherProp> = (props) => {
}

const ChromeLauncherButton: React.FC<ChromeLauncherButtonProp> = React.memo((props: ChromeLauncherButtonProp) => {
const {isStartMITM, host, port, onFished, repRuleFlag = false} = props
const {isStartMITM, host, port, onFished, repRuleFlag = false, disableCACertPage} = props
const [started, setStarted] = useState(false)
const [chromeVisible, setChromeVisible] = useState(false)

Expand Down Expand Up @@ -319,6 +322,7 @@ const ChromeLauncherButton: React.FC<ChromeLauncherButtonProp> = React.memo((pro
<MITMChromeLauncher
host={host}
port={port}
disableCACertPage={disableCACertPage}
callback={(host, port) => {
setChromeVisible(false)
if (!isStartMITM) {
Expand Down
5 changes: 5 additions & 0 deletions app/renderer/src/main/src/pages/mitm/MITMPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ export const MITMPage: React.FC<MITMPageProp> = (props) => {
const [addr, setAddr] = useState("")
const [host, setHost] = useState("127.0.0.1")
const [port, setPort] = useState(8083)
const [disableCACertPage, setDisableCACertPage] = useState(false)
const [enableInitialMITMPlugin, setEnableInitialMITMPlugin] = useState(false)
const [defaultPlugins, setDefaultPlugins] = useState<string[]>([])
const [tip, setTip] = useState("")
Expand Down Expand Up @@ -272,6 +273,7 @@ export const MITMPage: React.FC<MITMPageProp> = (props) => {
setAddr(`http://${host}:${port} 或 socks5://${host}:${port}`)
setHost(host)
setPort(port)
setDisableCACertPage(extra?.disableCACertPage || false)
setDefaultPlugins(plugins)
setEnableInitialMITMPlugin(enableInitialPlugin)
startMITMServer(host, port, downstreamProxy, enableHttp2, ForceDisableKeepAlive, certs, extra)
Expand Down Expand Up @@ -321,6 +323,7 @@ export const MITMPage: React.FC<MITMPageProp> = (props) => {
port={port}
addr={addr}
host={host}
disableCACertPage={disableCACertPage}
status={status}
setStatus={setStatus}
defaultPlugins={defaultPlugins}
Expand Down Expand Up @@ -420,6 +423,8 @@ export interface ExtraMITMServerProps {
hosts: {Key: string; Value: string}[]
/**@name 过滤WebSocket */
filterWebsocket: boolean
/**禁用初始页 */
disableCACertPage: boolean
}

interface MITMServerProps {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ export interface MITMServerHijackingProp {
addr: string
host: string
port: number
disableCACertPage: boolean
status: MITMStatus
enableInitialMITMPlugin?: boolean
defaultPlugins?: string[]
Expand Down Expand Up @@ -65,6 +66,7 @@ export const MITMServerHijacking: React.FC<MITMServerHijackingProp> = (props) =>
const {
host,
port,
disableCACertPage,
addr,
status,
setStatus,
Expand Down Expand Up @@ -219,7 +221,7 @@ export const MITMServerHijacking: React.FC<MITMServerHijackingProp> = (props) =>
{/* 系统代理*/}
{/*</YakitButton>*/}
<div className={style["mitm-server-chrome"]}>
<ChromeLauncherButton isStartMITM={true} host={host} port={port} />
<ChromeLauncherButton isStartMITM={true} host={host} port={port} disableCACertPage={disableCACertPage} />
</div>
<div className={style["mitm-server-quit-icon"]}>
<QuitIcon onClick={() => stop()} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ import {ExclamationCircleOutlined} from "@ant-design/icons"
import {YakitSwitch} from "@/components/yakitUI/YakitSwitch/YakitSwitch"
import {YakitAutoComplete} from "@/components/yakitUI/YakitAutoComplete/YakitAutoComplete"
import {useWatch} from "antd/lib/form/Form"
import { YakitSelect } from "@/components/yakitUI/YakitSelect/YakitSelect"
import { YakitTag } from "@/components/yakitUI/YakitTag/YakitTag"
import { inputHTTPFuzzerHostConfigItem } from "@/pages/fuzzer/HTTPFuzzerHosts"
import {YakitSelect} from "@/components/yakitUI/YakitSelect/YakitSelect"
import {YakitTag} from "@/components/yakitUI/YakitTag/YakitTag"
import {inputHTTPFuzzerHostConfigItem} from "@/pages/fuzzer/HTTPFuzzerHosts"
import {YakitRoute} from "@/enums/yakitRoute"
import {RemoteGV} from "@/yakitGV"

const MITMAddTLS = React.lazy(() => import("./MITMAddTLS"))
const MITMFiltersModal = React.lazy(() => import("./MITMFiltersModal"))
Expand All @@ -45,6 +46,7 @@ export interface AdvancedConfigurationFromValue {
dnsServers: string[]
etcHosts: any[]
filterWebsocket: boolean
disableCACertPage: boolean
}
const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps> = React.memo(
React.forwardRef((props, ref) => {
Expand All @@ -58,10 +60,11 @@ const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps
const [enableProxyAuthDef, setEnableProxyAuthDef] = useState<boolean>(false)
const [proxyUsernameDef, setProxyUsernameDef] = useState<string>()
const [proxyPasswordDef, setProxyPasswordDef] = useState<string>()
const [dnsServersDef,setDnsServersDef] = useState<string[]>(["8.8.8.8", "114.114.114.114"])
const [etcHostsDef,setEtcHostsDef] = useState<any[]>([])
const [dnsServersDef, setDnsServersDef] = useState<string[]>(["8.8.8.8", "114.114.114.114"])
const [etcHostsDef, setEtcHostsDef] = useState<any[]>([])
const [etcHosts, setEtcHosts] = useState<any[]>([])
const [filterWebsocketDef, setFilterWebsocketDef] = useState<boolean>(false)
const [disableCACertPageDef, setDisableCACertPageDef] = useState<boolean>(false)

const [certificateFormVisible, setCertificateFormVisible] = useState<boolean>(false)
const [filtersVisible, setFiltersVisible] = useState<boolean>(false)
Expand All @@ -76,7 +79,7 @@ const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps
getValue: () => {
const v = form.getFieldsValue()
if (Object.keys(v).length > 0) {
return {...v,etcHosts}
return {...v, etcHosts}
} else {
return {
certs: certsDef,
Expand All @@ -87,7 +90,8 @@ const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps
dnsServers: dnsServersDef,
proxyUsername: enableProxyAuthDef ? proxyUsernameDef : "",
proxyPassword: enableProxyAuthDef ? proxyPasswordDef : "",
filterWebsocket: filterWebsocketDef
filterWebsocket: filterWebsocketDef,
disableCACertPage: disableCACertPageDef
}
}
}
Expand All @@ -101,6 +105,7 @@ const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps
proxyPasswordDef,
dnsServersDef,
filterWebsocketDef,
disableCACertPageDef,
visible,
form
]
Expand Down Expand Up @@ -153,7 +158,7 @@ const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps
if (!!e) {
const dnsServers = JSON.parse(e)
setDnsServersDef(dnsServers)
form.setFieldsValue({dnsServers})
form.setFieldsValue({dnsServers})
}
})
// Host配置
Expand All @@ -171,6 +176,12 @@ const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps
setFilterWebsocketDef(v)
form.setFieldsValue({filterWebsocket: v})
})
// 禁用初始页
getRemoteValue(RemoteGV.MITMDisableCACertPage).then((e) => {
const v = e === "true" ? true : false
setDisableCACertPageDef(v)
form.setFieldsValue({disableCACertPage: v})
})
}, [visible])
/**
* @description 单个导出证书
Expand Down Expand Up @@ -254,29 +265,31 @@ const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps
setRemoteValue(MITMConsts.MITMDefaultDnsServers, JSON.stringify(params.dnsServers))
setRemoteValue(MITMConsts.MITMDefaultEtcHosts, JSON.stringify(etcHosts))
setRemoteValue(MITMConsts.MITMDefaultFilterWebsocket, `${params.filterWebsocket}`)
setRemoteValue(RemoteGV.MITMDisableCACertPage, params.disableCACertPage ? "true" : "")
onSave(params)
})
})
const onClose = useMemoizedFn((jumpPage?:boolean) => {
const onClose = useMemoizedFn((jumpPage?: boolean) => {
const formValue = form.getFieldsValue()
const oldValue:any = {
const oldValue: any = {
certs: certsDef,
dnsServers: dnsServersDef,
etcHosts:etcHostsDef,
etcHosts: etcHostsDef,
enableProxyAuth: enableProxyAuthDef,
filterWebsocket: filterWebsocketDef,
disableCACertPage: disableCACertPageDef,
proxyUsername: proxyUsernameDef,
proxyPassword: proxyPasswordDef,
proxyPassword: proxyPasswordDef
}
if(enableGMTLS){
if (enableGMTLS) {
oldValue.preferGMTLS = preferGMTLSDef
oldValue.onlyEnableGMTLS = onlyEnableGMTLSDef
}
const newValue = {
certs,
...formValue,
proxyUsername:formValue.proxyUsername||'',
proxyPassword:formValue.proxyPassword||'',
proxyUsername: formValue.proxyUsername || "",
proxyPassword: formValue.proxyPassword || "",
etcHosts
}
if (JSON.stringify(oldValue) !== JSON.stringify(newValue)) {
Expand All @@ -300,18 +313,18 @@ const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps
),
onOk: () => {
onSaveSetting()
jumpPage&&ipcRenderer.invoke("open-route-page", {route: YakitRoute.Beta_ConfigNetwork})
jumpPage && ipcRenderer.invoke("open-route-page", {route: YakitRoute.Beta_ConfigNetwork})
},
onCancel: () => {
setVisible(false)
jumpPage&&ipcRenderer.invoke("open-route-page", {route: YakitRoute.Beta_ConfigNetwork})
jumpPage && ipcRenderer.invoke("open-route-page", {route: YakitRoute.Beta_ConfigNetwork})
},
cancelButtonProps: {size: "small", className: "modal-cancel-button"},
okButtonProps: {size: "small", className: "modal-ok-button"}
})
} else {
setVisible(false)
jumpPage&&ipcRenderer.invoke("open-route-page", {route: YakitRoute.Beta_ConfigNetwork})
jumpPage && ipcRenderer.invoke("open-route-page", {route: YakitRoute.Beta_ConfigNetwork})
}
})
return (
Expand Down Expand Up @@ -341,45 +354,45 @@ const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps
maskClosable={false}
>
<Form labelCol={{span: 6}} wrapperCol={{span: 18}} form={form}>
<Form.Item
label='DNS服务器'
name='dnsServers'
help={"指定DNS服务器"}
initialValue={["8.8.8.8", "114.114.114.114"]}
>
<YakitSelect
options={["8.8.8.8", "8.8.4.4", "1.1.1.1", "1.0.0.1"].map((i) => {
return {value: i, label: i}
})}
mode='tags'
allowClear={true}
placeholder={"例如 1.1.1.1"}
/>
</Form.Item>
<Form.Item label={"Hosts配置"} name='etcHosts'>
<Space direction={"horizontal"} wrap>
<YakitButton
onClick={() => {
inputHTTPFuzzerHostConfigItem((obj) => {
setEtcHosts([...etcHosts.filter((i) => i.Key !== obj.Key), obj])
})
}}
>
添加 Hosts 映射
</YakitButton>
{etcHosts.map((i, n) => (
<YakitTag
closable={true}
onClose={() => {
setEtcHosts(etcHosts.filter((j) => j.Key !== i.Key))
<Form.Item
label='DNS服务器'
name='dnsServers'
help={"指定DNS服务器"}
initialValue={["8.8.8.8", "114.114.114.114"]}
>
<YakitSelect
options={["8.8.8.8", "8.8.4.4", "1.1.1.1", "1.0.0.1"].map((i) => {
return {value: i, label: i}
})}
mode='tags'
allowClear={true}
placeholder={"例如 1.1.1.1"}
/>
</Form.Item>
<Form.Item label={"Hosts配置"} name='etcHosts'>
<Space direction={"horizontal"} wrap>
<YakitButton
onClick={() => {
inputHTTPFuzzerHostConfigItem((obj) => {
setEtcHosts([...etcHosts.filter((i) => i.Key !== obj.Key), obj])
})
}}
key={`${i.Key}-${n}`}
>
{`${i.Key} => ${i.Value}`}
</YakitTag>
))}
</Space>
</Form.Item>
添加 Hosts 映射
</YakitButton>
{etcHosts.map((i, n) => (
<YakitTag
closable={true}
onClose={() => {
setEtcHosts(etcHosts.filter((j) => j.Key !== i.Key))
}}
key={`${i.Key}-${n}`}
>
{`${i.Key} => ${i.Value}`}
</YakitTag>
))}
</Space>
</Form.Item>
{enableGMTLS && (
<>
<Form.Item
Expand Down Expand Up @@ -428,10 +441,14 @@ const MITMFormAdvancedConfiguration: React.FC<MITMFormAdvancedConfigurationProps
</Form.Item>
</>
)}
<Form.Item label={"过滤WebSocket"} name='filterWebsocket' valuePropName='checked'>
<YakitSwitch size='large' />
</Form.Item>
<Form.Item
label={"过滤WebSocket"}
name='filterWebsocket'
label={"禁用初始页"}
name='disableCACertPage'
valuePropName='checked'
help={"开启后免配置启动不会访问初始页面"}
>
<YakitSwitch size='large' />
</Form.Item>
Expand Down
Loading

0 comments on commit 94fc68d

Please sign in to comment.