Rory McCune
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    --- title: Containers for Pentesters description: description tags: talks, container_security type: slide slideOptions: theme: blood allottedMinutes: 30 --- ## Containers for Pentesters --- ### About Me - Ex-Pentester/IT Security person - Senior Security Advocate at Datadog - CIS Benchmark author, Docker and Kubernetes - Member of Kubernetes SIG-Security & CNCF TAG-Security --- ### What's a container then? ![](https://hackmd.io/_uploads/B1hnceK7h.png) Note: Here we'll discuss how containers are literally just Linux processes --- # Demo Note: The goal of this demo is to show that containers are just processes. ps -fC nginx docker run --name webserver -d nginx ps -fC nginx docker exec webserver touch /my_new_file sudo ls /proc/PID/root --- ### What Does Docker do? ![](https://hackmd.io/_uploads/SyxXXZFQn.png) --- # Demo Note: sudo socat -v UNIX-LISTEN:/tmp/tempdock.sock,fork UNIX-CONNECT:/var/run/docker.sock sudo docker -H unix:///tmp/tempdock.sock images --- ### Docker Desktop ![](https://hackmd.io/_uploads/rJBlsYkHh.png) Note: This is to talk about Docker for Windows/Mac and how it complicates matters. --- ### An important Aside : Docker Security model ```bash= docker run -ti --privileged --net=host --pid=host --ipc=host --volume /:/host busybox chroot /host ``` --- ### Demo Note: docker run -ti --privileged --net=host --pid=host --ipc=host --volume /:/host busybox chroot /host --- #### Why do we need these things as pentesters? Note: We can talk about a load of things here - keeping clean laptops, to avoid tool contamination - Use legacy tools that don't work with modern distros - Updating tools - Making it easy to send tools to clients for on-sites --- ### VM vs Container Note: We're looking here at contrasting VMs and containers. The major difference is in likely size. It's kind of difficult to get smaller VM images, to roughly the size of container images. Also if you need old obscure pentest tools, you can containerize them so they can get all the old libs they rely on. Also you can avoid splatting one set of python/php/node/ruby libs with another. --- ### Docker Hub ![](https://hackmd.io/_uploads/SyoIu7Fm2.png) Note: Images from Docker Hub Generally you should not use people's images directly from Docker hub, instead you can get inspiration from Dockerfiles and build your own. Outside of the base images. Important point is that a) there could be malware and b) more likely it just hasn't been patched in years. --- ![](https://hackmd.io/_uploads/BJohxmY7h.png) Note: These are some of my images, the point here is to talk about the fact that other people are using them. This is basically not a good idea, as apart from me, no-one has any idea that these images are maintained, secure and not actively malicious. --- ### Make your own Images Note: Before we go on to talk about approaches, the point of the last two slides has essentially been about the dangers of using someone else's images. --- ### Tool specific ### vs ### Kitchen Sink Note: There are two approaches we can take to using Containers for pentesting, one is image per tool, the other is kitchen sink containers. Whilst purists will say that the Tool specific option is the only correct one, in reality it's a lot easier to maintain a couple of kitchen sink images. --- ### Choosing a base distro - Scratch - Alpine - Debian/Ubuntu - Red Hat - Not CentOS* Note: This is an important choice. - One of the main things is picking something consistent. This helps a lot with build size - Alpine is small but has some compatibility issues - Generally pick a base that is what you're used to. - CentOS is bad because the CentOS images on Docker hub are all deprecated/unmtaintained --- ### Dockerfile Basics - Single command image ```Dockerfile= FROM ubuntu:22.04 RUN apt update && apt install -y nmap && apt-get clean ENTRYPOINT ["nmap"] ``` Note: Here we're showing a very simple example of a single tool container image. --- ### Demo - Using the Basic image ```bash= docker build -t nmap -f Dockerfile.nmap . ``` ```bash= docker run --net=host nmap -v -n -sT 127.0.0.1 ``` Note: the point of this demonstration is to show how to use a single command container. --- ### Root vs Non-Root Note: an important determination is whether to run as root or non-root inside the cotainer. root is easier (obviously) but non-root might be needed for customer requirements. --- ### Trick - Getting root back in non-root envs Note: It's possible to have an image that can still do root things even if it's not root, using file capabilities --- ```dockerfile FROM ubuntu:22.04 RUN cp /bin/bash /bin/setuidbash && chmod 4755 /bin/setuidbash RUN adduser tester USER tester CMD ["/bin/bash"] ``` Note: This works in Ubuntu but does not work in Alpine?! --- ### Getting Data in and out of containers ```bash= docker run -it -v ~/testdata:/testdata [image] /bin/bash ``` Note: This is an important point about how you get data in and out of your containers. We should also mention that permissions are important. If you're root (or sudo root) locally it's fine, if you're running as a standard user, some finagling might be needed. --- ## Conclusion - Containers are quite easy to use once you understand what they do. - Very helpful for keeping tool envs clean - Very helpful for jobs that use Kubernetes --- ### Resources and Links - https://github.com/raesene/alpine-containertools - Example kitchen sink image! - https://github.com/raesene/dockerized-security-tools - Example Tool specific images (old) - https://securitylabs.datadoghq.com - Blog series on container security fundamentals - https://container-security.site - General container security resources - https://talks.container-security.site - Archive of Container/Cloud Native security talks --- ### Thanks - E-Mail: rory.mccune@datadoghq.com - Mastodon: @raesene@infosec.exchange - Twitter: @raesene

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password

    or

    By clicking below, you agree to our terms of service.

    Sign in via Facebook Sign in via Twitter Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully