Skip to content

Templates

Pinaki Mondal edited this page Jan 22, 2021 · 3 revisions

About

Templates are nothing but a simple, yet very powerful feature of this tool. Usually they come very handy when you have a multi-purpose template and you want to use it for different purposes at different times.

Structure

Templates are very similar to normal configuration files except for the fact that they have a command directive within them that lets you assign a command to them during runtime/creation of a new workflow.

Command Directive

The command directive is simply a {command} format string within the config file. Example: basic-shell.yml.

The command directive should exist only at one place in your config file where an aggregation of commands could be run. You'll probably want to specify a command directive after you've setup your dependencies within the config file.

Writing a template

Well, lets directly look at an example. The below template installs nmap which is a multipurpose network mapping toolkit.

name: Nmap Setup

on:
  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v2

      - name: Update the packages
        run: sudo apt-get update -y

      - name: Install nmap
        run: sudo apt-get install -y nmap

      - name: Run nmap on a set of targets
        run: {command}

      - name: Commit and push
        uses: stefanzweifel/git-auto-commit-action@v4.2.0
        with:
          commit_message: Commit nmap results
          commit_user_name: 'Nmap Runner'
          commit_user_email: 'github-actions.nmap@github.com'

With this template ready, you can name it nmap.yml and place it in the templates/ folder. Lets execute it!

$ ./bludger.py -n testingnmap -T nmap -C 'nmap -T4 -p 1-1024 -A 1.1.1.1 -oX 1.1.1.1.xml' -v

  Bludger - A GitHub Actions Automation Framework
               Version : v0.1.0

[*] INFO: Trying to create the repository...
[+] Successfully created: https://github.com/0xInfection/testingnmap
[+] File successfully committed to GitHub: .github/workflows/nmap.yml
[!] WARNING: Pausing for a few seconds to prevent race condition between API endpoints...
[+] Successfully triggered a workflow for: nmap.yml
[*] INFO: Entering monitor mode...
[*] INFO: Pausing for a few seconds for the workflow to trigger...
[+] Job ID: 502024293
[*] Last step executed: None
[*] Last step executed: Set up job
[*] Last step executed: Run actions/checkout@v2
[*] Last step executed: Install nmap
[*] Last step executed: Install nmap
[*] Last step executed: Run nmap on a set of targets
[+] Job seems to have successfully completed!

Now you can either clone the repository to see the resultant file 1.1.1.1.xml or you can utilize the -S/--save-logs feature to download the logs!

Its as simple as that. 🤷

Few important things

  • The tool uses workflow_dispatch to trigger workflows, so your YAML templates MUST HAVE the workflow dispatch switch.
  • GitHub doesn't allow committing files greater than 100MB in size, so make sure to prune files just before the committing step in your workflow like the example below:
    - name: Pruning files greater than 100MB
      run: find . -size +99M -delete
    
  • Your templates should have the yml extension, GitHub understands YAML config files only.

Wiki Index

Clone this wiki locally