Skip to content

Commit

Permalink
修复 TCP 随机端口记录器的小问题
Browse files Browse the repository at this point in the history
  • Loading branch information
v1ll4n committed Apr 20, 2022
1 parent fbb5268 commit 2215b00
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import React, {useEffect, useState} from "react";
import {AutoCard} from "../../components/AutoCard";
import {Alert, Button, Divider, Form, Space, Spin, Table, Tag} from "antd";
import {Alert, Button, Divider, Form, Space, Spin, Table, Tag, Tooltip} from "antd";
import {useMemoizedFn} from "ahooks";
import {randomString} from "../../utils/randomUtil";
import {CopyableField, InputInteger} from "../../utils/inputUtil";
import {formatTimestamp} from "../../utils/timeUtil";
import {ReloadOutlined} from "@ant-design/icons";
import {showModal} from "../../utils/showModal";
import {YakEditor} from "../../utils/editors";

export interface RandomPortLogPageProp {

Expand All @@ -14,7 +16,7 @@ export interface RandomPortLogPageProp {
const {ipcRenderer} = window.require("electron");

interface RandomPortTriggerNotification {
History: string[]
History?: string[]
RemoteAddr: string
RemotePort: number
RemoteIP: string
Expand All @@ -38,7 +40,9 @@ export const RandomPortLogPage: React.FC<RandomPortLogPageProp> = (props) => {
setToken(d.Token)
setExternalAddr(d.Addr)
setRandomPort(d.Port)
setNotification([])
}).catch(() => {
setNotification([])
}).finally(() => {
setTimeout(() => {
setLoading(false)
Expand Down Expand Up @@ -104,6 +108,7 @@ export const RandomPortLogPage: React.FC<RandomPortLogPageProp> = (props) => {

</Alert>
<Table<RandomPortTriggerNotification>
size={"small"}
pagination={false}
rowKey={i => `${i?.RemoteAddr || randomString(12)}`}
dataSource={notification}
Expand All @@ -113,6 +118,37 @@ export const RandomPortLogPage: React.FC<RandomPortLogPageProp> = (props) => {
title: "远端地址",
render: (i: RandomPortTriggerNotification) => <CopyableField text={i?.RemoteAddr}/>
},
{
title: "同主机其他连接(一分钟内)",
render: (i: RandomPortTriggerNotification) => i?.CurrentRemoteCachedConnectionCount || 1
},
{
title: "同端口历史(一分钟内)",
render: (i: RandomPortTriggerNotification) => <Tooltip
title={`对当前端口(${i?.LocalPort})来说,除了当前连接,还有${i?.LocalPortCachedHistoryConnectionCount || 1}个来自其他远端的连接`}>
<a href="#" onClick={(e) => {
e.preventDefault()

console.info(i)

showModal({
title: "查看历史记录",
width: 300,
content: (
<>
<YakEditor
type={"http"}
readOnly={true}
value={(i?.History || []).join("\r\n")}
/>
</>
)
})
}}>
其他连接:{i?.LocalPortCachedHistoryConnectionCount || 1}
</a>
</Tooltip>
},
{
title: "触发时间",
render: (i: RandomPortTriggerNotification) => <Tag>{formatTimestamp(i.TriggerTimestamp)}</Tag>
Expand Down
34 changes: 29 additions & 5 deletions app/renderer/src/main/src/pages/yakitStore/YakitStorePage.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React, {useEffect, useState} from "react"
import {Button, Card, Col, Empty, Form, Input, List, Popover, Row, Space, Tag, Tooltip} from "antd"
import {Alert, Button, Card, Col, Empty, Form, Input, List, Popover, Row, Space, Tag, Tooltip} from "antd"
import {
DownloadOutlined,
PlusOutlined,
Expand Down Expand Up @@ -621,7 +621,7 @@ const YAKIT_DEFAULT_LOAD_LOCAL_PATH = "YAKIT_DEFAULT_LOAD_LOCAL_PATH";
const YAKIT_DEFAULT_LOAD_LOCAL_NUCLEI_POC_PATH = "YAKIT_DEFAULT_LOAD_LOCAL_NUCLEI_POC_PATH";

export const LoadYakitPluginForm = React.memo((p: { onFinished: () => any }) => {
const [gitUrl, setGitUrl] = useState("")
const [gitUrl, setGitUrl] = useState("https://github.com/yaklang/yakit-store")
const [nucleiGitUrl, setNucleiGitUrl] = useState("https://github.com/projectdiscovery/nuclei-templates")
const [proxy, setProxy] = useState("")
const [loadMode, setLoadMode] = useState<"official" | "giturl" | "local" | "local-nuclei">("official")
Expand All @@ -645,8 +645,9 @@ export const LoadYakitPluginForm = React.memo((p: { onFinished: () => any }) =>
}, [])

useEffect(() => {
if (loadMode === "official") {
setGitUrl("https://github.com/yaklang/yakit-store")
if (loadMode === "giturl" && proxy === "") {
setGitUrl("https://ghproxy.com/https://github.com/yaklang/yakit-store")
setNucleiGitUrl("https://ghproxy.com/https://github.com/projectdiscovery/nuclei-templates")
}
}, [loadMode])

Expand Down Expand Up @@ -725,23 +726,46 @@ export const LoadYakitPluginForm = React.memo((p: { onFinished: () => any }) =>
setValue={setLoadMode}
/>
{["official", "giturl"].includes(loadMode) && <>
{loadMode === "official" && <Form.Item label={" "} colon={false}>
<Alert message={<div>
如果因为网络问题无法访问 Github,请切换到第三方仓库源,选择 Gitee 镜像 ghproxy.com 镜像
</div>}/>
</Form.Item>}
<InputItem
disable={loadMode === "official"}
required={true}
label={"Git URL"}
autoComplete={[
"https://github.com/yaklang/yakit-store",
"https://ghproxy.com/https://github.com/yaklang/yakit-store",
"https://gitee.com/wooluo/yakit-store.git",
]}
value={gitUrl}
setValue={setGitUrl}
help={"例如 https://github.com/yaklang/yakit-store"}
/>
<InputItem
required={true}
disable={loadMode === "official"}
autoComplete={[
"https://github.com/projectdiscovery/nuclei-templates",
"https://ghproxy.com/https://github.com/projectdiscovery/nuclei-templates",
"https://gitee.com/wooluo/nuclei-templates.git",
]}
label={"Yaml PoC URL"}
value={nucleiGitUrl}
setValue={setNucleiGitUrl}
help={"nuclei templates 默认插件源"}
/>
<InputItem label={"代理"} value={proxy} setValue={setProxy} help={"访问中国大陆无法访问的代码仓库"}/>
<InputItem
label={"代理"} value={proxy} setValue={setProxy}
help={"通过代理访问中国大陆无法访问的代码仓库:例如" + "http://127.0.0.1:7890"}
/>
{proxy === "" && loadMode === "giturl" && <Form.Item label={" "} colon={false}>
<Alert type={"warning"} message={<div>
无代理设置推荐使用 ghproxy.com / gitee 镜像源
</div>}/>
</Form.Item>}
</>}
{loadMode === "local" && <>
<InputItem label={"本地仓库地址"} value={localPath} setValue={setLocalPath}/>
Expand Down
46 changes: 23 additions & 23 deletions app/renderer/src/main/src/pages/yakitStore/viewers/base.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ import {WebsiteTreeViewer} from "./WebsiteTree";
import {BasicTable} from "./BasicTable";
import {XTerm} from "xterm-for-react";
import {formatDate} from "../../../utils/timeUtil";
import { xtermFit } from "../../../utils/xtermUtils";
import { CVXterm } from "../../../components/CVXterm";
import { AutoCard } from "../../../components/AutoCard";
import {xtermFit} from "../../../utils/xtermUtils";
import {CVXterm} from "../../../components/CVXterm";
import {AutoCard} from "../../../components/AutoCard";

const {ipcRenderer} = window.require("electron");

Expand Down Expand Up @@ -120,21 +120,21 @@ export const PluginResultUI: React.FC<PluginResultUIProp> = React.memo((props) =
xtermFit(xtermRef, 50, 18)
}}
customKeyEventHandler={(e) => {
if (e.keyCode === 67 && (e.ctrlKey || e.metaKey)) {
const str = xtermRef?.current ? (xtermRef.current as any).terminal.getSelection() : ""
if (timer.current) {
clearTimeout(timer.current)
timer.current = null
}
timer.current = setTimeout(() => {
ipcRenderer.invoke("copy-clipboard", str).finally(() => {
timer.current = null
})
}, 300)
}
return true
}}
if (e.keyCode === 67 && (e.ctrlKey || e.metaKey)) {
const str = xtermRef?.current ? (xtermRef.current as any).terminal.getSelection() : ""

if (timer.current) {
clearTimeout(timer.current)
timer.current = null
}
timer.current = setTimeout(() => {
ipcRenderer.invoke("copy-clipboard", str).finally(() => {
timer.current = null
})
}, 300)
}
return true
}}
/>
</div>
</>}
Expand Down Expand Up @@ -199,10 +199,10 @@ export const PluginResultUI: React.FC<PluginResultUIProp> = React.memo((props) =
bodyStyle={{overflowY: "auto"}}
>
<Timeline pending={loading} style={{marginTop: 10, marginBottom: 10}}>
{timelineItemProps.map((e, index) => {
{(timelineItemProps || []).reverse().map((e, index) => {
return <Timeline.Item key={index} color={LogLevelToCode(e.level)}>
<YakitLogFormatter data={e.data} level={e.level} timestamp={e.timestamp}
onlyTime={true}/>
<YakitLogFormatter data={e.data} level={e.level} timestamp={e.timestamp}
onlyTime={true}/>
</Timeline.Item>
})}
</Timeline>
Expand All @@ -211,8 +211,8 @@ export const PluginResultUI: React.FC<PluginResultUIProp> = React.memo((props) =
</Tabs.TabPane>
{!props.debugMode && props.onXtermRef && <Tabs.TabPane tab={"Console"} key={"console"}>
<div style={{width: "100%", height: "100%"}}>
<CVXterm
ref={xtermRef}
<CVXterm
ref={xtermRef}
options={{convertEol: true}}
/>
{/* <XTerm ref={xtermRef} options={{convertEol: true, rows: 8}}
Expand Down
2 changes: 1 addition & 1 deletion app/renderer/src/main/src/utils/inputUtil.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const InputItem: React.FC<InputItemProps> = (props) => {
>
{props.prefixNode}
{props.autoComplete ? <AutoComplete
style={{width: props.width || 200}}
style={{width: props.width || "100%"}}
dropdownMatchSelectWidth={400}
disabled={!!props.disable}
placeholder={props.placeholder}
Expand Down

0 comments on commit 2215b00

Please sign in to comment.