Skip to content

Commit

Permalink
code runner 调整
Browse files Browse the repository at this point in the history
  • Loading branch information
v1ll4n committed Oct 19, 2021
1 parent cd310de commit 24f253f
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 19 deletions.
17 changes: 17 additions & 0 deletions app/protos/grpc.proto
Original file line number Diff line number Diff line change
Expand Up @@ -102,16 +102,33 @@ service Yak {

// 端口扫描的封装
rpc PortScan(PortScanRequest) returns (stream ExecResult);
rpc ViewPortScanCode(Empty) returns (SimpleScript);

// 资产管理
rpc QueryPorts(QueryPortsRequest) returns (QueryPortsResponse);
rpc DeletePorts(DeletePortsRequest) returns (Empty);
}

message SimpleScript {
string Content = 1;
}

message PortScanRequest {
string Targets = 1;
string Ports = 2;
string Mode = 3;
repeated string Proto = 4;
int64 Concurrent = 5;
// 主动发包模式
bool Active = 6;
// service / web / all
string FingerprintMode = 7;

// 保存数据库
bool SaveToDB = 8;

// 保存已经关闭的端口
bool SaveClosedPorts = 9;
}

message DeletePortsRequest {
Expand Down
8 changes: 8 additions & 0 deletions app/renderer/src/main/src/pages/assetViewer/PortAssetPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {HTTPFlow, TableFilterDropdownForm} from "../../components/HTTPFlowTable"
import {SearchOutlined, ReloadOutlined} from "@ant-design/icons";
import {SorterResult} from "antd/lib/table/interface";
import {YakEditor} from "../../utils/editors";
import {openExternalWebsite} from "../../utils/openWebsite";

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

Expand Down Expand Up @@ -179,6 +180,13 @@ export const PortAssetTable: React.FC<PortAssetTableProp> = (props) => {
},
},
{title: "最近更新时间", render: (i: PortAsset) => <Tag color={"green"}>{formatTimestamp(i.UpdatedAt)}</Tag>},
{
title: "操作", render: (i: PortAsset) => <Button
size={"small"} type={"link"}
onClick={e => {
openExternalWebsite(`http://${i.Host}:${i.Port}`)
}}>浏览器打开</Button>, fixed: "right",
},
]}
dataSource={response.Data}
pagination={{
Expand Down
48 changes: 33 additions & 15 deletions app/renderer/src/main/src/pages/invoker/YakExecutor.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, {useEffect, useState} from "react";
import React, {useEffect, useRef, useState} from "react";
import {Button, Card, Col, Form, Modal, notification, Popconfirm, Row, Space, Spin, Tag, Typography} from "antd";
import {ExecHistoryTable} from "./YakExecutorHistoryTable";
import "./xtermjs-yak-executor.css"
Expand All @@ -12,8 +12,9 @@ import {ExecResult, YakScript, YakScriptParam} from "./schema";
import {YakScriptParamsSetter} from "./YakScriptParamsSetter";
import {YakExecutorParam} from "./YakExecutorParams";
import {SelectOne} from "../../utils/inputUtil";
import {editor} from "monaco-editor";
import {monacoEditorClear, monacoEditorWrite} from "../fuzzer/fuzzerTemplates";
import {XTerm} from "xterm-for-react";
import {writeExecResultXTerm, writeXTerm, xtermClear, xtermFit} from "../../utils/xtermUtils";

const {Text} = Typography;

Expand All @@ -26,16 +27,25 @@ export const YakExecutor: React.FC<YakExecutorProp> = (props) => {
const [code, setCode] = useState("# input your yak code\nprintln(`Hello Yak World!`)");
const [errors, setErrors] = useState<string[]>([]);
const [executing, setExecuting] = useState(false);
const [currentOutputEditor, setCurrentOutputEditor] = useState<IMonacoEditor>();
const [params, setParams] = useState<{ Key: string, Value: any }[]>([]);
const [yakScript, setYakScript] = useState<YakScript>();
const [outputEncoding, setOutputEncoding] = useState<"utf8" | "latin1">("utf8");
const xtermRef = useRef(null);

// trigger for updating
const [triggerForUpdatingHistory, setTriggerForUpdatingHistory] = useState<any>(0);
const render = ipcRenderer;

useEffect(() => {
if (xtermRef) {
xtermFit(xtermRef, 100, 14)
}
})

useEffect(() => {
if (!xtermRef) {
return
}
// let buffer = "";
render.on("client-yak-error", async (e: any, data) => {
notification["error"]({message: `FoundError: ${JSON.stringify(data)}`})
Expand All @@ -58,16 +68,18 @@ export const YakExecutor: React.FC<YakExecutorProp> = (props) => {
if (data.IsMessage) {
// alert(Buffer.from(data.Message).toString("utf8"))
}
if (data?.Raw && currentOutputEditor) {
monacoEditorWrite(currentOutputEditor, Buffer.from(data.Raw).toString(outputEncoding).replaceAll("\n", "\r\n"))
if (data?.Raw) {
writeExecResultXTerm(xtermRef, data, outputEncoding)
// writeXTerm(xtermRef, Buffer.from(data.Raw).toString(outputEncoding).replaceAll("\n", "\r\n"))
// monacoEditorWrite(currentOutputEditor, )
}
})
return () => {
render.removeAllListeners("client-yak-data")
render.removeAllListeners("client-yak-end")
render.removeAllListeners("client-yak-error")
}
}, [currentOutputEditor])
}, [xtermRef])

return <div style={{margin: 0}}>
<Spin spinning={false}>
Expand Down Expand Up @@ -125,7 +137,7 @@ export const YakExecutor: React.FC<YakExecutorProp> = (props) => {
type={"yak"}
onLoadYakScript={s => {
info(`加载 Yak 模块:${s.ScriptName}`)
monacoEditorClear(currentOutputEditor)
xtermClear(xtermRef)
setCode(s.Content);
setYakScript(s)
setParams([])
Expand Down Expand Up @@ -297,20 +309,26 @@ export const YakExecutor: React.FC<YakExecutorProp> = (props) => {
size={"small"} icon={<DeleteOutlined/>}
danger={true} type={"link"}
onClick={e => {
monacoEditorClear(currentOutputEditor)
xtermClear(xtermRef)
}}
/>
</Space>} size={"small"} bordered={true}
bodyStyle={{padding: 0}}
>
{/*@ts-ignore*/}
<div style={{height: 260}}>
<YakEditor
// value={currentOutput}
readOnly={false}
editorDidMount={setCurrentOutputEditor}
/>
<div style={{width: "100%", overflow: "auto"}}>
<XTerm ref={xtermRef} options={{
convertEol: true,
}} onResize={r => xtermFit(xtermRef, r.cols, 14)}/>
</div>

{/*/!*@ts-ignore*!/*/}
{/*<div style={{height: 260}}>*/}
{/* <YakEditor*/}
{/* // value={currentOutput}*/}
{/* readOnly={false}*/}
{/* editorDidMount={setCurrentOutputEditor}*/}
{/* />*/}
{/*</div>*/}
</Card>
</Col>
</Row>
Expand Down
72 changes: 68 additions & 4 deletions app/renderer/src/main/src/pages/portscan/PortScanPage.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import React, {useEffect, useRef, useState} from "react";
import {Button, Card, Col, Empty, Form, PageHeader, Row, Space, Spin, Tabs, Tag} from "antd";
import {InputItem, SelectOne, SwitchItem} from "../../utils/inputUtil";
import {Button, Card, Col, Divider, Empty, Form, PageHeader, Row, Slider, Space, Spin, Switch, Tabs, Tag} from "antd";
import {InputItem, MultiSelectForString, SelectOne, SwitchItem} from "../../utils/inputUtil";
import {randomString} from "../../utils/randomUtil";
import {ExecResult} from "../invoker/schema";
import {failed, info} from "../../utils/notification";
Expand All @@ -22,13 +22,25 @@ export interface PortScanPageProp {
export interface PortScanParams {
Targets: string
Ports: string
Mode: "syn" | "fingerprint" | "all"
Mode: "syn" | "fingerprint" | "all",
Proto: ("tcp" | "udp")[],
Concurrent: number,
Active: boolean
FingerprintMode: "service" | "web" | "all"
SaveToDB: boolean
SaveClosedPorts: boolean
}

export const PortScanPage: React.FC<PortScanPageProp> = (props) => {
const [params, setParams] = useState<PortScanParams>({
Ports: "22,443,445,80,8000-8004,3306,3389,5432,8080-8084,7000-7005", Mode: "fingerprint",
Targets: "",
Active: true,
Concurrent: 50,
FingerprintMode: "all",
Proto: ["tcp"],
SaveClosedPorts: false,
SaveToDB: true
});
const [loading, setLoading] = useState(false);
const [resettingData, setResettingData] = useState(false);
Expand All @@ -38,6 +50,7 @@ export const PortScanPage: React.FC<PortScanPageProp> = (props) => {
const [openPorts, setOpenPorts] = useState<YakitPort[]>([]);
const [closedPorts, setClosedPorts] = useState<YakitPort[]>([]);
const [port, setPort] = useState<PortAsset>();
const [advanced, setAdvanced] = useState(false);

useEffect(() => {
if (xtermRef) xtermFit(xtermRef, 128, 10);
Expand Down Expand Up @@ -129,7 +142,58 @@ export const PortScanPage: React.FC<PortScanPageProp> = (props) => {
<InputItem label={"扫描目标"} setValue={Targets => setParams({...params, Targets})}
value={params.Targets}/>
<InputItem label={"扫描端口"} setValue={Ports => setParams({...params, Ports})}
value={params.Ports}/>
value={params.Ports}
/>
<Form.Item label={"并发"}
help={`最多同时扫描${params.Concurrent}个端口`} style={{width: "100%"}}
>
<Slider
style={{width: "90%"}}
onChange={value => setParams({...params, Concurrent: value})}
value={params.Concurrent}
min={1} max={200}
/>
</Form.Item>
<Divider orientation={"left"}>高级选项 <Switch size={"small"} checked={advanced}
onChange={setAdvanced}/></Divider>
{advanced && <>
{/*<MultiSelectForString*/}
{/* label={"协议"}*/}
{/* data={[*/}
{/* {value: "tcp", label: "TCP"},*/}
{/* {value: "udp", label: "UDP"},*/}
{/* ]}*/}
{/* setValue={Proto => setParams({...params, Proto: Proto.split(",") as any})}*/}
{/* value={params.Proto.join(",")}*/}
{/*/>*/}
<SwitchItem
label={"主动模式"} help={"允许指纹探测主动发包"}
setValue={Active => setParams({...params, Active})} value={params.Active}
/>
<SwitchItem
label={"扫描结果入库"}
setValue={SaveToDB => {
setParams({...params, SaveToDB, SaveClosedPorts: false})
}} value={params.SaveToDB}
/>
{params.SaveToDB && <SwitchItem
label={"保存关闭的端口"}
setValue={SaveClosedPorts => setParams({...params, SaveClosedPorts})}
value={params.SaveClosedPorts}
/>}
{
params.Mode !== "syn" && <SelectOne
label={"高级指纹选项"}
data={[
{value: "web", text: "仅web指纹"},
{value: "service", text: "仅nmap指纹"},
{value: "all", text: "全部指纹"},
]}
setValue={FingerprintMode => setParams({...params, FingerprintMode})}
value={params.FingerprintMode}
/>
}
</>}
</Spin>

<Form.Item>
Expand Down
34 changes: 34 additions & 0 deletions test.yak
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# input your yak code
wg := sync.NewSizedWaitGroup(20)
defer wg.Wait()

func getTitle(target) {
wg.Add()
go func{
defer wg.Done()

urls = str.ParseStringToUrls(target)
fReq, err := fuzz.UrlsToHTTPRequests(urls...)
if err != nil {
return
}
res, err := fReq.Exec()
if err != nil {
return
}

for r := range res {
title = re.Grok(string(r.ResponseRaw), `<title>%{DATA:title}</title>`)["title"][0]
printf("%v %20s\n", r.Url, title)
}
}
}

for _, i := range str.ParseStringToHosts("47.52.100.1/24") {
getTitle(i)
}

servicescan.proto()
servicescan.service()
servicescan.web()
servicescan.concurrent()

0 comments on commit 24f253f

Please sign in to comment.