diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..a029dc8 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,7 @@ +--- +version: 2 +updates: + - package-ecosystem: github-actions + directory: / + schedule: + interval: monthly \ No newline at end of file diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..ddf461b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,117 @@ +--- +name: Release +'on': + pull_request: + push: + branches: + - main + schedule: + - cron: "0 7 * * 0" + +env: + IMAGE_NAME: yaf + +jobs: + + # Test the image builds and works correctly. + test: + name: Test + runs-on: ubuntu-latest + + steps: + - name: Check out the codebase. + uses: actions/checkout@v4 + + - name: Set up Python 3. + uses: actions/setup-python@v5 + with: + python-version: '3.x' + + - name: Install test dependencies. + run: pip3 install pytest-testinfra + + - name: Build image. + run: docker build -t cmusei/${{ env.IMAGE_NAME }} . + + - name: Run the built image. + run: docker run --name=${{ env.IMAGE_NAME }} --entrypoint=/bin/bash -td cmusei/${{ env.IMAGE_NAME }} + + - name: Test the built image. + run: py.test --hosts='docker://${{ env.IMAGE_NAME }}' + + # If on main branch, build and release image. + release2: + name: Release2 + runs-on: ubuntu-latest + needs: test + if: github.ref == 'refs/heads/main' + + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push image. + uses: docker/build-push-action@v6 + with: + context: ./ + file: Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + tags: | + cmusei/${{ env.IMAGE_NAME }}:latest + cmusei/${{ env.IMAGE_NAME }}:2 + cmusei/${{ env.IMAGE_NAME }}:2.16.1 + ghcr.io/cmu-sei/${{ env.IMAGE_NAME }}:latest + ghcr.io/cmu-sei/${{ env.IMAGE_NAME }}:2 + ghcr.io/cmu-sei/${{ env.IMAGE_NAME }}:2.16.1 + release3: + name: Release3 + runs-on: ubuntu-latest + needs: test + if: github.ref == 'refs/heads/main' + + steps: + - uses: actions/checkout@v4 + - uses: docker/setup-qemu-action@v3 + - uses: docker/setup-buildx-action@v3 + + - name: Login to DockerHub + uses: docker/login-action@v3 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Log in to the Container registry + uses: docker/login-action@v3 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push image. + uses: docker/build-push-action@v6 + with: + context: ./ + file: Dockerfile + platforms: linux/amd64,linux/arm64 + push: true + build-args: | + FIXBUF_VERSION=3 + YAF_VERSION=3.0.0.alpha4 + tags: | + cmusei/${{ env.IMAGE_NAME }}:3 + ghcr.io/cmu-sei/${{ env.IMAGE_NAME }}:3 \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9f84ff9 --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +__pycache__/ +inventory +pytest_junit.xml \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..0222fb0 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,59 @@ +ARG FIXBUF_VERSION=2 +FROM cmusei/fixbuf:${FIXBUF_VERSION} AS build +LABEL maintainer="maheckathorn@cert.org" + +ARG YAF_VERSION=2.16.1 + +# Pre-reqs: +# curl for downloading +# build-essentials for build tools +# ca-certs to download https +# +RUN apt-get update && apt-get install -y --no-install-recommends \ + curl \ + build-essential \ + pkg-config \ + ca-certificates \ + libglib2.0-dev \ + libssl-dev \ + libpcap-dev \ + zlib1g-dev \ + libpcre3-dev \ + && apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +WORKDIR /netsa + +ARG enable_dpi='' + +RUN curl https://tools.netsa.cert.org/releases/yaf-$YAF_VERSION.tar.gz | \ + tar -xz && cd yaf-* && \ + ./configure --prefix=/netsa ${enable_dpi} \ + --enable-plugins \ + --enable-applabel \ + --with-libfixbuf=/netsa/lib/pkgconfig && \ + make && \ + make install && \ + cd ../ && rm -rf yaf-$YAF_VERSION + +FROM debian:11-slim +LABEL maintainer="maheckathorn@cert.org" + +RUN apt-get update && apt-get install -y --no-install-recommends \ + pkg-config \ + libglib2.0-0 \ + libpcap0.8 \ + zlib1g \ + libssl1.1 \ + libpcre3 \ + && apt-get clean && \ + rm -rf /var/lib/apt/lists/* + +COPY --from=build /netsa/ /netsa/ + +COPY docker-entrypoint.sh /usr/local/bin/ +RUN ln -s /usr/local/bin/docker-entrypoint.sh / + +ENV PATH=$PATH:/netsa/bin + +ENTRYPOINT ["docker-entrypoint.sh"] \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..4eb0bf7 --- /dev/null +++ b/LICENSE @@ -0,0 +1,135 @@ +docker-yaf + +Copyright 2024 Carnegie Mellon University. + +Licensed under an MIT (SEI)-style license, please see license.txt or contact permission@sei.cmu.edu for full terms. + +MIT (SEI) + +docker-yaf includes and/or can make use of certain third party software ("Third Party Software"). The Third Party Software that is used by docker-yaf is dependent upon your system configuration, but typically includes the software identified in this license.txt file, and/or described in the documentation and/or read me file. By using docker-yaf, you agree to comply with any and all relevant Third Party Software terms and conditions contained in any such Third Party Software or separate license file distributed with such Third Party Software. The parties who own the Third Party Software ("Third Party Licensors") are intended third party beneficiaries to this License with respect to the terms applicable to their Third Party Software. Third Party Software licenses only apply to the Third Party Software and not any other portion of docker-yaf or docker-yaf as a whole. + +This material is based upon work funded and supported by the Department of Homeland Security under Contract No. FA8702-15-D-0002 with Carnegie Mellon University for the operation of the Software Engineering Institute, a federally funded research and development center sponsored by the United States Department of Defense. + +The view, opinions, and/or findings contained in this material are those of the author(s) and should not be construed as an official Government position, policy, or decision, unless designated by other documentation. + +NO WARRANTY. THIS CARNEGIE MELLON UNIVERSITY AND SOFTWARE ENGINEERING INSTITUTE MATERIAL IS FURNISHED ON AN "AS-IS" BASIS. CARNEGIE MELLON UNIVERSITY MAKES NO WARRANTIES OF ANY KIND, EITHER EXPRESSED OR IMPLIED, AS TO ANY MATTER INCLUDING, BUT NOT LIMITED TO, WARRANTY OF FITNESS FOR PURPOSE OR MERCHANTABILITY, EXCLUSIVITY, OR RESULTS OBTAINED FROM USE OF THE MATERIAL. CARNEGIE MELLON UNIVERSITY DOES NOT MAKE ANY WARRANTY OF ANY KIND WITH RESPECT TO FREEDOM FROM PATENT, TRADEMARK, OR COPYRIGHT INFRINGEMENT. + +[DISTRIBUTION STATEMENT A] This material has been approved for public release and unlimited distribution. Please see Copyright notice for non-US Government use and distribution. + +CERT® is registered in the U.S. Patent and Trademark Office by Carnegie Mellon University. + +This Software includes and/or makes use of Third-Party Software each subject to its own license, including but not limited to the following: + + 1. docker (https://github.com/moby/moby/blob/master/LICENSE) Copyright 2018 Docker, Inc.. + +Apache License + +Version 2.0, January 2004 + +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +a.You must give any other recipients of the Work or Derivative Works a copy of this License; and +b.You must cause any modified files to carry prominent notices stating that You changed the files; and +c.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +d.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + + You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + + 2. testinfra (https://github.com/philpep/testinfra/blob/master/LICENSE) Copyright 2024 Philippe Pepiot. + +Apache License + +Version 2.0, January 2004 + +http://www.apache.org/licenses/ + +TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + +1. Definitions. + +"License" shall mean the terms and conditions for use, reproduction, and distribution as defined by Sections 1 through 9 of this document. + +"Licensor" shall mean the copyright owner or entity authorized by the copyright owner that is granting the License. + +"Legal Entity" shall mean the union of the acting entity and all other entities that control, are controlled by, or are under common control with that entity. For the purposes of this definition, "control" means (i) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (ii) ownership of fifty percent (50%) or more of the outstanding shares, or (iii) beneficial ownership of such entity. + +"You" (or "Your") shall mean an individual or Legal Entity exercising permissions granted by this License. + +"Source" form shall mean the preferred form for making modifications, including but not limited to software source code, documentation source, and configuration files. + +"Object" form shall mean any form resulting from mechanical transformation or translation of a Source form, including but not limited to compiled object code, generated documentation, and conversions to other media types. + +"Work" shall mean the work of authorship, whether in Source or Object form, made available under the License, as indicated by a copyright notice that is included in or attached to the work (an example is provided in the Appendix below). + +"Derivative Works" shall mean any work, whether in Source or Object form, that is based on (or derived from) the Work and for which the editorial revisions, annotations, elaborations, or other modifications represent, as a whole, an original work of authorship. For the purposes of this License, Derivative Works shall not include works that remain separable from, or merely link (or bind by name) to the interfaces of, the Work and Derivative Works thereof. + +"Contribution" shall mean any work of authorship, including the original version of the Work and any modifications or additions to that Work or Derivative Works thereof, that is intentionally submitted to Licensor for inclusion in the Work by the copyright owner or by an individual or Legal Entity authorized to submit on behalf of the copyright owner. For the purposes of this definition, "submitted" means any form of electronic, verbal, or written communication sent to the Licensor or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, the Licensor for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by the copyright owner as "Not a Contribution." + +"Contributor" shall mean Licensor and any individual or Legal Entity on behalf of whom a Contribution has been received by Licensor and subsequently incorporated within the Work. + +2. Grant of Copyright License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare Derivative Works of, publicly display, publicly perform, sublicense, and distribute the Work and such Derivative Works in Source or Object form. + +3. Grant of Patent License. Subject to the terms and conditions of this License, each Contributor hereby grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by such Contributor that are necessarily infringed by their Contribution(s) alone or by combination of their Contribution(s) with the Work to which such Contribution(s) was submitted. If You institute patent litigation against any entity (including a cross-claim or counterclaim in a lawsuit) alleging that the Work or a Contribution incorporated within the Work constitutes direct or contributory patent infringement, then any patent licenses granted to You under this License for that Work shall terminate as of the date such litigation is filed. + +4. Redistribution. You may reproduce and distribute copies of the Work or Derivative Works thereof in any medium, with or without modifications, and in Source or Object form, provided that You meet the following conditions: +a.You must give any other recipients of the Work or Derivative Works a copy of this License; and +b.You must cause any modified files to carry prominent notices stating that You changed the files; and +c.You must retain, in the Source form of any Derivative Works that You distribute, all copyright, patent, trademark, and attribution notices from the Source form of the Work, excluding those notices that do not pertain to any part of the Derivative Works; and +d.If the Work includes a "NOTICE" text file as part of its distribution, then any Derivative Works that You distribute must include a readable copy of the attribution notices contained within such NOTICE file, excluding those notices that do not pertain to any part of the Derivative Works, in at least one of the following places: within a NOTICE text file distributed as part of the Derivative Works; within the Source form or documentation, if provided along with the Derivative Works; or, within a display generated by the Derivative Works, if and wherever such third-party notices normally appear. The contents of the NOTICE file are for informational purposes only and do not modify the License. You may add Your own attribution notices within Derivative Works that You distribute, alongside or as an addendum to the NOTICE text from the Work, provided that such additional attribution notices cannot be construed as modifying the License. + + You may add Your own copyright statement to Your modifications and may provide additional or different license terms and conditions for use, reproduction, or distribution of Your modifications, or for any such Derivative Works as a whole, provided Your use, reproduction, and distribution of the Work otherwise complies with the conditions stated in this License. + +5. Submission of Contributions. Unless You explicitly state otherwise, any Contribution intentionally submitted for inclusion in the Work by You to the Licensor shall be under the terms and conditions of this License, without any additional terms or conditions. Notwithstanding the above, nothing herein shall supersede or modify the terms of any separate license agreement you may have executed with Licensor regarding such Contributions. + +6. Trademarks. This License does not grant permission to use the trade names, trademarks, service marks, or product names of the Licensor, except as required for reasonable and customary use in describing the origin of the Work and reproducing the content of the NOTICE file. + +7. Disclaimer of Warranty. Unless required by applicable law or agreed to in writing, Licensor provides the Work (and each Contributor provides its Contributions) on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are solely responsible for determining the appropriateness of using or redistributing the Work and assume any risks associated with Your exercise of permissions under this License. + +8. Limitation of Liability. In no event and under no legal theory, whether in tort (including negligence), contract, or otherwise, unless required by applicable law (such as deliberate and grossly negligent acts) or agreed to in writing, shall any Contributor be liable to You for damages, including any direct, indirect, special, incidental, or consequential damages of any character arising as a result of this License or out of the use or inability to use the Work (including but not limited to damages for loss of goodwill, work stoppage, computer failure or malfunction, or any and all other commercial damages or losses), even if such Contributor has been advised of the possibility of such damages. + +9. Accepting Warranty or Additional Liability. While redistributing the Work or Derivative Works thereof, You may choose to offer, and charge a fee for, acceptance of support, warranty, indemnity, or other liability obligations and/or rights consistent with this License. However, in accepting such obligations, You may act only on Your own behalf and on Your sole responsibility, not on behalf of any other Contributor, and only if You agree to indemnify, defend, and hold each Contributor harmless for any liability incurred by, or claims asserted against, such Contributor by reason of your accepting any such warranty or additional liability. + +END OF TERMS AND CONDITIONS + +DM24-1332 \ No newline at end of file diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..b9c74db --- /dev/null +++ b/Makefile @@ -0,0 +1,29 @@ +# source: https://jmkhael.io/makefiles-for-your-dockerfiles/ +# Run in parallel via make -j2 see: https://stackoverflow.com/a/9220818 + +NS = cmusei +export SOFTWARE_NAME = yaf + +export IMAGE_NAME += $(NS)/$(SOFTWARE_NAME) + +export WORK_DIR = . + +.PHONY: build build2 build3 test + +build: build2 + +build2: + docker build --build-arg http_proxy --build-arg https_proxy --build-arg no_proxy -t $(IMAGE_NAME):latest -f Dockerfile . + docker tag $(IMAGE_NAME):latest $(IMAGE_NAME):2 + +build3: + docker build --build-arg http_proxy --build-arg https_proxy --build-arg no_proxy --build-arg FIXBUF_VERSION=3 \ + --build-arg YAF_VERSION=3.0.0.alpha4 --build-arg enable_dpi='--enable-dpi' -t $(IMAGE_NAME):3 -f Dockerfile . + +test: + docker rm -f $(SOFTWARE_NAME) + docker run --name=$(SOFTWARE_NAME) -td --entrypoint=/bin/bash $(IMAGE_NAME) + py.test --hosts='docker://$(SOFTWARE_NAME)' + docker rm -f $(SOFTWARE_NAME) + +default: build diff --git a/README.md b/README.md new file mode 100644 index 0000000..f2f047a --- /dev/null +++ b/README.md @@ -0,0 +1,245 @@ +[![Software Engineering Institute](https://avatars.githubusercontent.com/u/12465755?s=200&v=4)](https://www.sei.cmu.edu/) + +[![Blog](https://img.shields.io/static/v1.svg?color=468f8b&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=SEI&message=Blog)](https://insights.sei.cmu.edu/blog/ "blog posts from our experts in Software Engineering.") +[![Youtube](https://img.shields.io/static/v1.svg?color=468f8b&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=SEI&message=Youtube&logo=youtube)](https://www.youtube.com/@TheSEICMU/ "vidoes from our experts in Software Engineering.") +[![Podcasts](https://img.shields.io/static/v1.svg?color=468f8b&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=SEI&message=Podcasts&logo=applepodcasts)](https://insights.sei.cmu.edu/podcasts/ "podcasts from our experts in Software Engineering.") +[![GitHub](https://img.shields.io/static/v1.svg?color=468f8b&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=SEI&message=GitHub&logo=github)](https://github.com/cmu-sei "view the source for all of our repositories.") +[![Flow Tools](https://img.shields.io/static/v1.svg?color=468f8b&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=SEI&message=Flow%20Tools)](https://tools.netsa.cert.org/ "documentation and source for all our flow collection and analysis tools.") + + +At the [SEI](https://www.sei.cmu.edu/), we research software engineering, cybersecurity, and AI engineering problems; create innovative technologies; and put solutions into practice. + +Find us at: + +* [Blog](https://insights.sei.cmu.edu/blog/) - blog posts from our experts in Software Engineering. +* [Youtube](https://www.youtube.com/@TheSEICMU/) - vidoes from our experts in Software Engineering. +* [Podcasts](https://insights.sei.cmu.edu/podcasts/) - podcasts from our experts in Software Engineering. +* [GitHub](https://github.com/cmu-sei) - view the source for all of our repositories. +* [Flow Tools](https://tools.netsa.cert.org/) - documentation and source for all our flow collection and analysis tools. + +# [certcc/yaf](https://tools.netsa.cert.org/yaf2/index.html) + +[![CI](https://img.shields.io/github/actions/workflow/status/cmu-sei/docker-yaf/release.yml?style=for-the-badge&logo=github)](https://github.com/cmu-sei/docker-yaf/actions?query=workflow%3ARelease) [![Docker pulls](https://img.shields.io/docker/pulls/cmusei/yaf?color=468f8b&labelColor=555555&logoColor=ffffff&style=for-the-badge&label=pulls&logo=docker)](https://hub.docker.com/r/cmusei/yaf/) + +[YAF](https://tools.netsa.cert.org/yaf2/index.html) is Yet Another Flowmeter. It processes packet data from pcap dumpfiles as generated by [tcpdump](http://www.tcpdump.org/) or via live capture from an interface using pcap into bidirectional flows, then exports those flows to [IPFIX](http://www.ietf.org/html.charters/ipfix-charter.html) Collecting Processes or in an IPFIX-based file format. YAF's output can be used with the [SiLK flow analysis tools](https://tools.netsa.cert.org/silk/index.html), [super_mediator](https://tools.netsa.cert.org/super_mediator/index.html), [Pipeline 5](https://tools.netsa.cert.org/analysis-pipeline5/index.html), and any other IPFIX compliant toolchain. + +Why does the world need another network flow event generator? yaf was originally intended as an experimental implementation tracking developments in the IETF IPFIX working group, specifically bidirectional flow representation, archival storage formats, and structured data export with Deep Packet Inspection. It is designed to perform acceptably as a flow sensor on any network on which white-box flow collection with commodity hardware is appropriate. yaf can and should be used on specialty hardware when scalability and performance are of concern. + +## Tool Suite + +The YAF toolchain presently consists of two primary tools, [yaf](https://tools.netsa.cert.org/yaf2/yaf.html) itself, and [yafscii](https://tools.netsa.cert.org/yaf2/yafscii.html). The YAF applications require the libairframe and libyaf libraries, which are included and installed as part of the YAF distribution. libairframe installs two additional tools, [filedaemon](https://tools.netsa.cert.org/yaf2/filedaemon.html) and [airdaemon](https://tools.netsa.cert.org/yaf2/airdaemon.html). [libyaf](https://tools.netsa.cert.org/yaf2/libyaf/index.html) implements YAF file and network I/O, and contains YAF packet decoder, fragment assembler, and flow table. In addition, two tools to assist in PCAP analysis are also installed with YAF. + +## Documentation + +More information [here](https://tools.netsa.cert.org/yaf2/docs.html). + +## Usage + +The intention of this container image is to allow for usage of the yaf command-line tool for processing pcap dumpfiles into IPFIX output. Here are some example scenarios to help get you started. + +### FCCX-15 Reference Data + +Example reference pcap data can be found [here](http://tools.netsa.cert.org/silk/referencedata.html). Download and unpack the data set with: + +```bash +curl https://tools.netsa.cert.org/silk/refdata/FCCX-pcap.tar.gz | tar -xz - +``` + +### Index a Single PCAP + +The following example is an update to the one [here](https://tools.netsa.cert.org/yaf/yaf_pcap.html#yp_single). + +Using the FCCX PCAP, we create flow records by yaf from the PCAP file `/data/gatewaySensor-1.pcap` (from `$PWD/FCCX-data/` volume mount on the docker host). We supply parameters that add application labeling, avoid packet truncation by employing a generous packet size restriction, and output records compatible with SiLK conversion into `/tmp/test_FCCX-packets.silk` (to `$PWD/output/` volume mount on the docker host): + +```bash +docker run --rm -it -v $PWD/FCCX-data:/data:ro -v $PWD/output:/tmp \ + cmusei/yaf:latest \ + --in=/data/gatewaySensor-1.pcap \ + --out=/tmp/test_FCCX-packets.silk \ + --applabel \ + --max-payload=1500 \ + --silk +``` + +To generate the restricted record format used by SiLK, including VLAN tags, we make use of the [rwipfix2silk](https://tools.netsa.cert.org/silk/rwipfix2silk.html) command found in the `silk_analysis` container image, read the `/tmp/test_FCCX-packets.silk` input file and output to `/tmp/yaf2flow.rw` (from `$PWD/output/` volume mount from the docker host): + +```bash +docker run --rm -it -v $PWD/output:/tmp \ + cmusei/silk_analysis:latest \ + rwipfix2silk \ + --silk-output=/tmp/yaf2flow.rw \ + --interface-values=vlan \ + /tmp/test_FCCX-packets.silk +``` + +We can then use [rwstats](https://tools.netsa.cert.org/silk/rwstats.html), found in the `silk_analysis` container image, to view the top 20 application protocols used in the flow file (from `$PWD/output/` volume mount on the docker host): + +```bash +docker run --rm -it -v $PWD/output:/tmp \ + cmusei/silk_analysis:latest \ + rwstats \ + --fields=application \ + --top \ + --count=20 \ + /tmp/yaf2flow.rw +``` +``` +INPUT: 69833 Records for 11 Bins and 69833 Total Records +OUTPUT: Top 20 Bins by Records +appli| Records| %Records| cumul_%| + 0| 30454| 43.609755| 43.609755| + 80| 14836| 21.244970| 64.854725| + 53| 13417| 19.212980| 84.067704| + 443| 7648| 10.951842| 95.019547| + 137| 1999| 2.862543| 97.882090| + 389| 716| 1.025303| 98.907393| + 139| 540| 0.773273| 99.680667| + 138| 162| 0.231982| 99.912649| + 67| 25| 0.035800| 99.948448| + 123| 20| 0.028640| 99.977088| + 22| 16| 0.022912|100.000000| +``` + +### Sniff Host Interface + +The following example configures yaf to continuously capture packets from the host `ens192` interface and output them to a file rotated every 30 seconds (to a volume mount from the host): + +```bash + docker run --name yaf --cap-add NET_ADMIN --net=host -v $PWD/test:/tmp/ \ + -d cmusei/yaf:latest \ + --in ens192 \ + --live pcap \ + --out /tmp/flows.yaf \ + --rotate 30 \ + --verbose \ + --silk \ + --applabel \ + --max-payload 2048 \ + --plugin-name=/netsa/lib/yaf/dpacketplugin.so +``` + +We can view output from the running yaf container via: + +```bash +docker logs -f yaf +[2023-10-26 17:59:43] yaf starting +[2023-10-26 17:59:43] Initializing Rules From File: /netsa/etc/yafApplabelRules.conf +[2023-10-26 17:59:43] Application Labeler accepted 49 rules. +[2023-10-26 17:59:43] Application Labeler accepted 0 signatures. +[2023-10-26 17:59:43] DPI Running for ALL Protocols +[2023-10-26 17:59:43] Initializing Rules from DPI File /netsa/etc/yafDPIRules.conf +[2023-10-26 17:59:43] DPI rule scanner accepted 52 rules from the DPI Rule File +[2023-10-26 17:59:43] DPI regular expressions cover 6 protocols +[2023-10-26 17:59:43] running as root in --live mode, but not dropping privilege +``` + +Rotated files are named using the prefix given in the `--out` option, followed by a suffix containing a timestamp in YYYYMMDDhhmmss format, a decimal serial number, and the file extension .yaf. In our example run, the following files were produced: + +```bash +ll +total 16 +-rw-r--r--. 1 root root 4202 Oct 26 14:00 flows.yaf-20231026175944-00000.yaf +-rw-r--r--. 1 root root 2726 Oct 26 14:00 flows.yaf-20231026180016-00001.yaf +-rw-r--r--. 1 root root 2753 Oct 26 14:01 flows.yaf-20231026180046-00002.yaf +``` + +We can quickly view the contents of these files by using [yafscii](https://tools.netsa.cert.org/yaf2/yafscii.html): + +```bash +docker run --rm -it --entrypoint=/netsa/bin/yafscii -v $PWD/test:/tmp/ \ + cmusei/yaf:latest \ + --in /tmp/flows.yaf-20231026175944-00000.yaf \ + --out - +``` +``` +2023-10-26 18:00:00.288 - 18:00:00.384 (0.096 sec) tcp 10.0.0.2:44382 => 10.0.0.3:5666 ffffffff:ffffffff S/APF:AS/APF (11/2511 <-> 7/1425) rtt 0 ms applabel: 443 +2023-10-26 18:00:00.385 - 18:00:00.403 (0.018 sec) tcp 10.0.0.2:48182 => 10.0.0.3:22 ffffffff:ffffffff S/APRF:AS/AP (6/333 <-> 4/1125) rtt 1 ms applabel: 22 +``` + +### Connect to [rwflowpack](https://tools.netsa.cert.org/silk/rwflowpack.html) to output SiLK Flow files + +The following example configures yaf to continuously capture packets from the host `ens192` interface and output them to a container running rwflowpack listening on port 18001 in order to collect and store binary SiLK Flow files. + +First, we start rwflowpack by running the `silk_packing` container. We can make use of the [silk.conf](examples/rwflowpack/silk.conf) and [sensor.conf](examples/rwflowpack/sensor.conf) files included in the [examples](examples/) folder. Make sure to edit the internal-ipblocks in the [sensor.conf](examples/rwflowpack/sensor.conf) to match your network: + +```bash +docker run --name rwflowpack -v $PWD/examples/rwflowpack:/data \ + -p 18001:18001 \ + -d cmusei/silk_packing:latest \ + rwflowpack \ + --input-mode=stream \ + --root-directory=/data \ + --sensor-configuration=/data/sensor.conf \ + --site-config-file=/data/silk.conf \ + --output-mode=local-storage \ + --log-destination=stdout \ + --no-daemon +``` + +Second, we start yaf through the `yaf` container and configure it to continuously capture packets from the host `ens192` interface. This time we have it output to the rwflowpack container listening on port 18001: +```bash +docker run --name yaf --cap-add NET_ADMIN --net=host \ + -d cmusei/yaf:latest \ + --in ens192 \ + --live pcap \ + --ipfix tcp \ + --out localhost \ + --silk \ + --verbose \ + --ipfix-port=18001 \ + --applabel \ + --max-payload 2048 \ + --plugin-name=/netsa/lib/yaf/dpacketplugin.so +``` + +We can check on the status of our containers via: +```bash +docker logs -f yaf +docker logs -f rwflowpack +``` + +Eventually you should see rwflowpack output some log lines similar to the following: +```bash +Oct 30 18:57:43 d23189499d6a rwflowpack[1]: /data/in/2023/10/30/in-S0_20231030.18: 15 recs +Oct 30 18:57:43 d23189499d6a rwflowpack[1]: /data/out/2023/10/30/out-S0_20231030.18: 15 recs +Oct 30 18:57:43 d23189499d6a rwflowpack[1]: /data/inweb/2023/10/30/iw-S0_20231030.18: 1 recs +Oct 30 18:57:43 d23189499d6a rwflowpack[1]: /data/outweb/2023/10/30/ow-S0_20231030.18: 1 recs +``` + +We can confirm SiLK is creating records by using the `silk_analysis` container: +```bash +docker run -v $PWD/examples/rwflowpack:/data --rm -it \ + --entrypoint=/bin/bash \ + cmusei/silk_analysis:latest \ + -c 'rwfilter --proto=0- --type=all --pass=stdout | rwcut | head' +``` +``` + sIP| dIP|sPort|dPort|pro| packets| bytes| flags| sTime| duration| eTime|sen| +10.0.0.1| 10.0.0.2| 9998|33342| 6| 8| 447| PA |2023/10/30T18:49:20.567| 8.201|2023/10/30T18:49:28.768| S0| +10.0.0.1| 10.0.0.2| 9998|33342| 6| 1| 52|F A |2023/10/30T18:49:28.768| 0.000|2023/10/30T18:49:28.768| S0| +10.0.0.3| 10.0.0.2|45476| 5666| 6| 11| 2511|FS PA |2023/10/30T18:49:47.027| 0.296|2023/10/30T18:49:47.323| S0| +10.0.0.4| 10.0.0.2| 9998|42162| 6| 23| 4408| S PA |2023/10/30T18:49:28.675| 29.994|2023/10/30T18:49:58.669| S0| +10.0.0.4| 10.0.0.2| 9998|42162| 6| 1| 52|F A |2023/10/30T18:49:58.669| 0.000|2023/10/30T18:49:58.669| S0| +10.0.0.3| 10.0.0.2|45698| 5666| 6| 15| 2767|FS PA |2023/10/30T18:50:17.146| 0.011|2023/10/30T18:50:17.157| S0| +10.0.0.3| 10.0.0.2|45698| 5666| 6| 1| 52| A |2023/10/30T18:50:17.157| 0.000|2023/10/30T18:50:17.157| S0| +10.0.0.3| 10.0.0.2|45692| 5666| 6| 15| 2767|FS PA |2023/10/30T18:50:17.142| 0.038|2023/10/30T18:50:17.180| S0| +10.0.0.3| 10.0.0.2|45692| 5666| 6| 1| 52| A |2023/10/30T18:50:17.180| 0.000|2023/10/30T18:50:17.180| S0| +``` + +### [Use yaf version 3](https://tools.netsa.cert.org/yaf/new_yaf3.html) + +A yaf version 3 container image is also maintained, it can be made use of through the version 3 tags. For example: + +```bash + docker run --name yaf --cap-add NET_ADMIN --net=host -v $PWD/test:/tmp/ \ + -d cmusei/yaf:3 \ + --in ens192 \ + --live pcap \ + --out /tmp/flows.yaf \ + --rotate 30 \ + --verbose \ + --silk \ + --applabel \ + --max-payload 2048 \ + --dpi +``` diff --git a/docker-entrypoint.sh b/docker-entrypoint.sh new file mode 100755 index 0000000..8968d36 --- /dev/null +++ b/docker-entrypoint.sh @@ -0,0 +1,5 @@ +#!/bin/bash + +set -e + +eval "LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/netsa/lib/ /netsa/bin/yaf "$@"" \ No newline at end of file diff --git a/examples/rwflowpack/sensor.conf b/examples/rwflowpack/sensor.conf new file mode 100644 index 0000000..1976759 --- /dev/null +++ b/examples/rwflowpack/sensor.conf @@ -0,0 +1,10 @@ +probe S0 ipfix + listen-on-port 18001 + protocol tcp +end probe + +sensor S0 + ipfix-probes S0 + internal-ipblocks 10.0.0.0/24 + external-ipblocks remainder +end sensor \ No newline at end of file diff --git a/examples/rwflowpack/silk.conf b/examples/rwflowpack/silk.conf new file mode 100644 index 0000000..6f892e2 --- /dev/null +++ b/examples/rwflowpack/silk.conf @@ -0,0 +1,68 @@ +# silk.conf for the "twoway" site +# RCSIDENT("$SiLK: silk.conf 52d8f4f62ffd 2012-05-25 21:16:30Z mthomas $") + +# For a description of the syntax of this file, see silk.conf(5). + +# The syntactic format of this file +# version 2 supports sensor descriptions, but otherwise identical to 1 +version 2 + +# NOTE: Once data has been collected for a sensor or a flowtype, the +# sensor or flowtype should never be removed or renumbered. SiLK Flow +# files store the sensor ID and flowtype ID as integers; removing or +# renumbering a sensor or flowtype breaks this mapping. + +sensor 0 S0 "Description for sensor S0" +sensor 1 S1 +sensor 2 S2 "Optional description for sensor S2" +sensor 3 S3 +sensor 4 S4 +sensor 5 S5 +sensor 6 S6 +sensor 7 S7 +sensor 8 S8 +sensor 9 S9 +sensor 10 S10 +sensor 11 S11 +sensor 12 S12 +sensor 13 S13 +sensor 14 S14 + +class all + sensors S0 S1 S2 S3 S4 S5 S6 S7 S8 S9 S10 S11 S12 S13 S14 +end class + +# Editing above this line is sufficient for sensor definition. + +# Be sure you understand the workings of the packing system before +# editing the class and type definitions below. In particular, if you +# change or add-to the following, the C code in packlogic-twoway.c +# will need to change as well. + +class all + type 0 in in + type 1 out out + type 2 inweb iw + type 3 outweb ow + type 4 innull innull + type 5 outnull outnull + type 6 int2int int2int + type 7 ext2ext ext2ext + type 8 inicmp inicmp + type 9 outicmp outicmp + type 10 other other + + default-types in inweb inicmp +end class + +default-class all + +# The layout of the tree below SILK_DATA_ROOTDIR. +# Use the default, which assumes a single class. +# path-format "%T/%Y/%m/%d/%x" + +# The plug-in to load to get the packing logic to use in rwflowpack. +# The --packing-logic switch to rwflowpack will override this value. +# If SiLK was configured with hard-coded packing logic, this value is +# ignored. +packing-logic "packlogic-twoway.so" diff --git a/tests/default/test_default.py b/tests/default/test_default.py new file mode 100644 index 0000000..d016d8c --- /dev/null +++ b/tests/default/test_default.py @@ -0,0 +1,8 @@ +def test_yaf_version(host): + version = "2.16.1" + command = """PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/netsa/lib/pkgconfig \ + pkg-config --modversion libyaf""" + + cmd = host.run(command) + + assert version in cmd.stdout