diff options
author | Emiliano Ciavatta | 2020-09-21 17:08:35 +0000 |
---|---|---|
committer | GitHub | 2020-09-21 17:08:35 +0000 |
commit | 8c8487b79300342b4c6dafe9c3691d43b8dc8e37 (patch) | |
tree | def44b1d04e689b1f4e8e25e5ca9c5cff7abe557 | |
parent | 98355cdf838d8c18e9a28176ae7a847770545395 (diff) | |
parent | 65f9bb547a24dd851d366f22950cb4301f3e8ae4 (diff) |
Merge pull request #17 from therealbobo/file-load
File load
-rw-r--r-- | .dockerignore | 5 | ||||
-rw-r--r-- | Dockerfile | 23 | ||||
-rw-r--r-- | frontend/src/views/Upload.js | 118 | ||||
-rw-r--r-- | frontend/yarn.lock | 41 | ||||
-rwxr-xr-x | scripts/example_commands.sh | 63 |
5 files changed, 215 insertions, 35 deletions
diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..c18c661 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,5 @@ +# pcaps +pcaps/*.pcap +pcaps/*.pcapng +pcaps/processing/*.pcap +pcaps/processing/*.pcapng @@ -3,29 +3,28 @@ FROM ubuntu:20.04 AS BUILDSTAGE # Install tools and libraries RUN apt-get update && \ - DEBIAN_FRONTEND=noninteractive apt-get install -qq git golang-1.14 pkg-config libpcap-dev libhyperscan-dev yarnpkg curl - -RUN ln -sf ../lib/go-1.14/bin/go /usr/bin/go - + DEBIAN_FRONTEND=noninteractive apt-get install -qq golang-1.14 pkg-config libpcap-dev libhyperscan-dev yarnpkg COPY . /caronte WORKDIR /caronte -RUN go mod download && go build - -RUN cd frontend && \ +RUN ln -sf ../lib/go-1.14/bin/go /usr/bin/go && \ + go mod download && \ + go build && \ + cd frontend && \ yarnpkg install && \ - yarnpkg build --production=true -RUN curl -sf https://gobinaries.com/tj/node-prune | sh && cd /caronte/frontend && node-prune + yarnpkg build --production=true && \ + cd - && \ + mkdir -p /caronte-build/frontend && \ + cp -r caronte pcaps/ scripts/ shared/ test_data/ /caronte-build && \ + cp -r frontend/build/ /caronte-build/frontend # LAST STAGE FROM ubuntu:20.04 -COPY --from=BUILDSTAGE /caronte/caronte /caronte/caronte -COPY --from=BUILDSTAGE /caronte/frontend /caronte/frontend -COPY --from=BUILDSTAGE /caronte/shared /caronte/shared +COPY --from=BUILDSTAGE /caronte-build /caronte RUN apt-get update && \ DEBIAN_FRONTEND=noninteractive apt-get install -qq libpcap-dev libhyperscan-dev && \ diff --git a/frontend/src/views/Upload.js b/frontend/src/views/Upload.js index 522afe8..29d514d 100644 --- a/frontend/src/views/Upload.js +++ b/frontend/src/views/Upload.js @@ -1,6 +1,6 @@ import React, {Component} from 'react'; import './Upload.scss'; -import {Button, ButtonGroup, Col, Container, Form, FormControl, InputGroup, Modal, Row, Table} from "react-bootstrap"; +import {Button, ButtonGroup, ToggleButton, Col, Container, Form, FormFile, InputGroup, Modal, Row, Table} from "react-bootstrap"; import bsCustomFileInput from 'bs-custom-file-input' import {createCurlCommand} from '../utils'; @@ -11,11 +11,34 @@ class Upload extends Component { this.state = { selectedFile: null, + removeOriginal: false, + flushAll: false, errors: "" }; + this.flushAllChanged = this.flushAllChanged.bind(this); + this.removeOriginalChanged = this.removeOriginalChanged.bind(this); + + + } + + flushAllChanged() { + this.setState({flushAll: !this.value}); + this.checked = !this.checked; + this.value = !this.value; + } + + removeOriginalChanged() { + this.setState({removeOriginal: !this.value}); + this.checked = !this.checked; + this.value = !this.value; } + onLocalFileChange = event => { + this.setState({ selectedFile: event.target.value }); + + }; + onFileChange = event => { this.setState({ selectedFile: event.target.files[0] }); @@ -25,6 +48,30 @@ class Upload extends Component { bsCustomFileInput.init() } + onFileProcess = () => { + const data = { + "file": this.state.selectedFile, + "flush_all": this.state.flushAll, + "delete_original_file": this.state.removeOriginal}; + + fetch('/api/pcap/file', { + method: 'POST', + body: JSON.stringify(data) + }) + .then(response => { + if (response.status === 202 ){ + this.props.onHide(); + } else { + response.json().then(data => { + this.setState( + {errors : data.error.toString()} + ); + }); + } + } + ); + } + onFileUpload = () => { const formData = new FormData(); formData.append( @@ -65,12 +112,31 @@ class Upload extends Component { > <Modal.Header> <Modal.Title id="services-dialog"> - /usr/bin/upload + /usr/bin/load_pcap </Modal.Title> </Modal.Header> <Modal.Body> <Container> <Row> + <Col> + --local + </Col> + <Col> + --upload + </Col> + </Row> + <Row> + <Col> + <Form.Control + type="text" + id="pcap-upload" + className="custom-file" + onChange={this.onLocalFileChange} + placeholder="local .pcap/.pcapng" + custom + /> + </Col> + <Col> <Form.File type="file" className="custom-file" @@ -79,7 +145,54 @@ class Upload extends Component { id="custom-file" custom /> + </Col> + </Row> + <br/> + <Row> + <Col> + <ButtonGroup toggle className="mb-2"> + <ToggleButton + type="checkbox" + variant="secondary" + checked={this.state.removeOriginal} + value={this.state.removeOriginal} + onChange={() => this.removeOriginalChanged()} + > + --remove-original-file + </ToggleButton> + </ButtonGroup> + </Col> + <Col> + </Col> + </Row> + <Row> + <Col> + <ButtonGroup toggle className="mb-2"> + <ToggleButton + type="checkbox" + variant="secondary" + checked={this.state.flushAll} + value={this.state.flushAll} + onChange={() => this.flushAllChanged()} + > + --flush-all + </ToggleButton> + </ButtonGroup> + </Col> + <Col> + </Col> + </Row> + <Row> + <Col> + <br/> + <Button variant="blue" onClick={this.onFileProcess}>process_local</Button> + </Col> + <Col> + <br/> + <Button variant="green" onClick={this.onFileUpload}>upload</Button> + </Col> </Row> + <hr/> <Row> <div class="error"> <b> @@ -95,7 +208,6 @@ class Upload extends Component { </Modal.Body> <Modal.Footer className="dialog-footer"> - <Button variant="green" onClick={this.onFileUpload}>upload</Button> <Button variant="red" onClick={this.props.onHide}>close</Button> </Modal.Footer> </Modal> diff --git a/frontend/yarn.lock b/frontend/yarn.lock index 7517add..39d346b 100644 --- a/frontend/yarn.lock +++ b/frontend/yarn.lock @@ -1691,9 +1691,9 @@ integrity sha512-tHq6qdbT9U1IRSGf14CL0pUlULksvY9OZ+5eEgl1N7t+OA3tGvNpxJCzuKQlsNgCVwbAs670L1vcVQi8j9HjnA== "@types/node@*": - version "14.10.1" - resolved "https://registry.yarnpkg.com/@types/node/-/node-14.10.1.tgz#cc323bad8e8a533d4822f45ce4e5326f36e42177" - integrity sha512-aYNbO+FZ/3KGeQCEkNhHFRIzBOUgc7QvcVNKXbfnhDkSfwUv91JsQQa10rDgKSTSLkXZ1UIyPe4FJJNVgw1xWQ== + version "14.10.2" + resolved "https://registry.yarnpkg.com/@types/node/-/node-14.10.2.tgz#9b47a2c8e4dabd4db73b57e750b24af689600514" + integrity sha512-IzMhbDYCpv26pC2wboJ4MMOa9GKtjplXfcAqrMeNJpUUwpM/2ATt2w1JPUXwS6spu856TvKZL2AOmeU2rAxskw== "@types/parse-json@^4.0.0": version "4.0.0" @@ -2805,6 +2805,7 @@ bs-custom-file-input@^1.3.4: version "1.3.4" resolved "https://registry.yarnpkg.com/bs-custom-file-input/-/bs-custom-file-input-1.3.4.tgz#c275cb8d4f1c02ba026324292509fa9a747dbda8" integrity sha512-NBsQzTnef3OW1MvdKBbMHAYHssCd613MSeJV7z2McXznWtVMnJCy7Ckyc+PwxV6Pk16cu6YBcYWh/ZE0XWNKCA== +>>>>>>> 98355cdf838d8c18e9a28176ae7a847770545395 bser@2.1.1: version "2.1.1" @@ -2983,9 +2984,9 @@ caniuse-api@^3.0.0: lodash.uniq "^4.5.0" caniuse-lite@^1.0.0, caniuse-lite@^1.0.30000981, caniuse-lite@^1.0.30001035, caniuse-lite@^1.0.30001109, caniuse-lite@^1.0.30001125: - version "1.0.30001129" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001129.tgz#e6514b94c0ef50f98cf7476daa91228ddd2ef7bc" - integrity sha512-9945fTVKS810DZITpsAbuhQG7Lam0tEfVbZlsBaCFZaszepbryrArS05PWmJSBQ6mta+v9iz0pUIAbW1eBILIg== + version "1.0.30001131" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001131.tgz#afad8a28fc2b7a0d3ae9407e71085a0ead905d54" + integrity sha512-4QYi6Mal4MMfQMSqGIRPGbKIbZygeN83QsWq1ixpUwvtfgAZot5BrCKzGygvZaV+CnELdTwD0S4cqUNozq7/Cw== capture-exit@^2.0.0: version "2.0.0" @@ -4152,9 +4153,9 @@ ee-first@1.1.1: integrity sha1-WQxhFWsK4vTwJVcyoViyZrxWsh0= electron-to-chromium@^1.3.378, electron-to-chromium@^1.3.564: - version "1.3.567" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.567.tgz#7a404288952ac990e447a7a86470d460ea953b8f" - integrity sha512-1aKkw0Hha1Bw9JA5K5PT5eFXC/TXbkJvUfNSNEciPUMgSIsRJZM1hF2GUEAGZpAbgvd8En21EA+Lv820KOhvqA== + version "1.3.570" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.3.570.tgz#3f5141cc39b4e3892a276b4889980dabf1d29c7f" + integrity sha512-Y6OCoVQgFQBP5py6A/06+yWxUZHDlNr/gNDGatjH8AZqXl8X0tE4LfjLJsXGz/JmWJz8a6K7bR1k+QzZ+k//fg== elliptic@^6.5.3: version "6.5.3" @@ -4305,9 +4306,9 @@ es6-symbol@^3.1.1, es6-symbol@~3.1.3: ext "^1.1.2" escalade@^3.0.2: - version "3.0.2" - resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.0.2.tgz#6a580d70edb87880f22b4c91d0d56078df6962c4" - integrity sha512-gPYAU37hYCUhW5euPeR+Y74F7BL+IBsV93j5cvGriSaD1aG6MGsqsV1yamRdrWrb2j3aiZvb0X+UBOWpx3JWtQ== + version "3.1.0" + resolved "https://registry.yarnpkg.com/escalade/-/escalade-3.1.0.tgz#e8e2d7c7a8b76f6ee64c2181d6b8151441602d4e" + integrity sha512-mAk+hPSO8fLDkhV7V0dXazH5pDc6MrjBTPyD3VeKzxnVFjH1MIxbCdqGZB9O8+EwWakZs3ZCbDS4IpRt79V1ig== escape-html@~1.0.3: version "1.0.3" @@ -7454,10 +7455,10 @@ no-case@^3.0.3: lower-case "^2.0.1" tslib "^1.10.0" -node-forge@0.9.0: - version "0.9.0" - resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.9.0.tgz#d624050edbb44874adca12bb9a52ec63cb782579" - integrity sha512-7ASaDa3pD+lJ3WvXFsxekJQelBKRpne+GOVbLbtHYdd7pFspyeuJHnWfLplGf3SwKGbfs/aYl5V/JCIaHVUKKQ== +node-forge@^0.10.0: + version "0.10.0" + resolved "https://registry.yarnpkg.com/node-forge/-/node-forge-0.10.0.tgz#32dea2afb3e9926f02ee5ce8794902691a676bf3" + integrity sha512-PPmu8eEeG9saEUvI97fm4OYxXVB6bFvyNTyiUOBichBpFG8A1Ljw3bY62+5oOjDEMHRnd0Y7HQ+x7uzxOzC6JA== node-gyp@^3.8.0: version "3.8.0" @@ -9958,11 +9959,11 @@ select-hose@^2.0.0: integrity sha1-Yl2GWPhlr0Psliv8N2o3NZpJlMo= selfsigned@^1.10.7: - version "1.10.7" - resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-1.10.7.tgz#da5819fd049d5574f28e88a9bcc6dbc6e6f3906b" - integrity sha512-8M3wBCzeWIJnQfl43IKwOmC4H/RAp50S8DF60znzjW5GVqTcSe2vWclt7hmYVPkKPlHWOu5EaWOMZ2Y6W8ZXTA== + version "1.10.8" + resolved "https://registry.yarnpkg.com/selfsigned/-/selfsigned-1.10.8.tgz#0d17208b7d12c33f8eac85c41835f27fc3d81a30" + integrity sha512-2P4PtieJeEwVgTU9QEcwIRDQ/mXJLX8/+I3ur+Pg16nS8oNbrGxEso9NyYWy8NAmXiNl4dlAp5MwoNeCWzON4w== dependencies: - node-forge "0.9.0" + node-forge "^0.10.0" "semver@2 || 3 || 4 || 5", semver@^5.4.1, semver@^5.5.0, semver@^5.5.1, semver@^5.6.0: version "5.7.1" diff --git a/scripts/example_commands.sh b/scripts/example_commands.sh new file mode 100755 index 0000000..4664235 --- /dev/null +++ b/scripts/example_commands.sh @@ -0,0 +1,63 @@ +#!/bin/bash + +function setup_service(){ + PORT="$1" + NAME="$2" + COLOR="$3" + curl --request PUT \ + --url http://localhost:3333/api/services \ + --header 'content-type: application/json' \ + --data "{\"port\":$PORT,\"name\":\"$NAME\",\"color\":\"#$COLOR\",\"notes\":\"\"}" +} + +BACKEND=false +FRONTEND=false +SETUP=true +IMPORT=true +START=false + + +if $START; then + pkill caronte +fi + +if $BACKEND ; then + go mod download && go build || exit -1 +fi + +if $FRONTEND ; then + cd frontend && yarnpkg install && yarnpkg build || exit -2 + cd - +fi + +if $START; then + docker run -d -p 27017-27019:27017-27019 --name mongodb mongo:4 && sleep 3 + ./caronte & + sleep 2 +fi + +# setup +if $SETUP ; then + curl \ + --header "Content-Type: application/json" \ + --request POST \ + --data '{"config": {"server_address": "10.10.1.1", "flag_regex": "flg[a-zA-Z0-9]{25}", "auth_required": false}, "accounts": {"usr1": "pwd1"}}' \ + http://localhost:3333/setup + + setup_service 8080 crashair E53935 + setup_service 27017 aircnc 5E35B1 + setup_service 80 lostpropertyhub F9A825 + setup_service 5555 theone F9A435 + #setup_service 3306 crashair E53935 +fi + + +# import pcaps +if $IMPORT ; then + PCAP_DIR="~/pcaps" + for PCAP in $PCAP_DIR/*.pcap ; do + echo "[+] Uploading $PCAP" && \ + curl -F "file=@$PCAP" "http://localhost:3333/api/pcap/upload" + done +fi + |