Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Kali backport #180

Open
wants to merge 14 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions apps/linode-marketplace-kali-linux/.ansible-lint
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
---
skip_list:
- command-instead-of-shell
- no-changed-when
- no-jinja-when
- fqcn-builtins
exclude_paths:
- .cache/
- .github/
- tests/
38 changes: 38 additions & 0 deletions apps/linode-marketplace-kali-linux/.yamllint
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
---
# Based on ansible-lint config
extends: default

ignore: |
.github/*
.cache/*
tests/*

rules:
braces:
max-spaces-inside: 1
level: error
brackets:
max-spaces-inside: 1
level: error
colons:
max-spaces-after: -1
level: error
commas:
max-spaces-after: -1
level: error
comments: disable
comments-indentation: disable
document-start: disable
empty-lines:
max: 3
level: error
hyphens:
level: error
indentation: disable
key-duplicates: enable
line-length: disable
new-line-at-end-of-file: disable
new-lines:
type: unix
trailing-spaces: disable
truthy: disable
86 changes: 86 additions & 0 deletions apps/linode-marketplace-kali-linux/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
# Linode Kali Deployment One-Click APP



## Software Included

| Software | Version | Description |
| :--- | :---- | :--- |
| Kali | latest | |

**Supported Distributions:**

- Ubuntu 22.04 LTS

## Linode Helpers Included

| Name | Action |
| :--- | :--- |
| Hostname | The Hostname module uses `dnsdomainname -A` to detect the Linode's FQDN and write to the `/etc/hosts` file. This defaults to the Linode's automatically assigned rDNS. To use a custom FQDN see [Configure your Linode for Reverse DNS](https://www.linode.com/docs/guides/configure-your-linode-for-reverse-dns/). |
| Update Packages | The Update Packages module performs apt update and upgrade actions as root. |
| UFW | The UFW module will utilize a list generated by `linode_helpers/ufw/ufwgen.yml` in the `group_vars/linode/vars` and enables the service. |
| Fail2Ban | The Fail2Ban module installs, activates and enables the Fail2Ban service. |

## Use our API

Customers can choose to the deploy the Kali app through the Linode Marketplace or directly using API. Before using the commands below, you will need to create an [API token](https://www.linode.com/docs/products/tools/linode-api/get-started/#create-an-api-token) or configure [linode-cli](https://www.linode.com/products/cli/) on an environment.

Make sure that the following values are updated at the top of the code block before running the commands:
- TOKEN
- ROOT_PASS

SHELL:
```
export TOKEN="YOUR API TOKEN"
export ROOT_PASS="aComplexP@ssword"
export SOA_EMAIL_ADDRESS="[email protected]"

curl -H "Content-Type: application/json" \
-H "Authorization: Bearer ${TOKEN}" \
-X POST -d '{
"backups_enabled": true,
"swap_size": 512,
"image": "linode/ubuntu2204",
"root_pass": "${ROOT_PASS}",
"stackscript_id": 00000000000,
"stackscript_data": {
"disable_root": "no/yes",
"soa_email_address": "${SOA_EMAIL_ADDRESS}"
},
"authorized_users": [
"myUser",
"secondaryUser"
],
"booted": true,
"label": "linode123",
"type": "g6-standard-2",
"region": "us-east",
"group": "Linode-Group"
}' \
https://api.linode.com/v4/linode/instances
```

CLI:
```
export TOKEN="YOUR API TOKEN"
export ROOT_PASS="aComplexP@ssword"
export SOA_EMAIL_ADDRESS="[email protected]"

linode-cli linodes create \
--label linode123 \
--root_pass ${ROOT_PASS} \
--booted true \
--stackscript_id 00000000000 \
--stackscript_data '{"soa_email_address": "${SOA_EMAIL_ADDRESS}", "disable_root": "no/yes" }' \
--region us-east \
--type g6-standard-2 \
--authorized_keys "ssh-rsa AAAA_valid_public_ssh_key_123456785== user@their-computer"
--authorized_users "myUser"
--authorized_users "secondaryUser"
```

## Resources

- [Create Linode via API](https://www.linode.com/docs/api/linode-instances/#linode-create)
- [Stackscript referece](https://www.linode.com/docs/guides/writing-scripts-for-use-with-linode-stackscripts-a-tutorial/#user-defined-fields-udfs)

7 changes: 7 additions & 0 deletions apps/linode-marketplace-kali-linux/ansible.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
[defaults]
host_key_checking = False
enable_plugins = linode
deprecation_warnings = False
interpreter_python = /usr/bin/python3
roles_path=./roles:../linode_helpers/roles
# relative or absolute roles_paths are required.
3 changes: 3 additions & 0 deletions apps/linode-marketplace-kali-linux/collections.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
collections:
- name: linode.cloud
version: 0.16.1
Empty file.
12 changes: 12 additions & 0 deletions apps/linode-marketplace-kali-linux/provision.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
# kali
- name: Setting up environment
hosts: localhost
connection: local
any_errors_fatal: true
user: root
vars_files:
- group_vars/linode/vars
tasks:
- name: Generating sudo user and password
import_tasks: ../linode_helpers/roles/sudouser/tasks/main.yml
7 changes: 7 additions & 0 deletions apps/linode-marketplace-kali-linux/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
ansible==8.3.0
ansible-lint==6.18.0
linode-api4==5.9.0
dnspython==2.4.2
pyyaml==6.0.1
pexpect==4.8.0
jmespath==1.0.1
Empty file.
37 changes: 37 additions & 0 deletions apps/linode-marketplace-kali-linux/roles/common/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
---
# set_hostname
- name: setting up hostname
import_role:
name: hostname

- name: set ssh pubkey
import_role:
name: sshkey

- name: write _domain to vars
lineinfile:
insertafter: EOF
path: group_vars/linode/vars
line: |
_domain: {{ _domain }}
when: _domain is defined

- name: secure ssh
import_role:
name: securessh
when: disable_root is defined

- name: update system packages
import_role:
name: update_pkgs

- name: enabling ufw
import_role:
name: ufw

- name: apply ufw rules
import_tasks: ufw_rules.yml

- name: enabling fail2ban
import_role:
name: fail2ban_install
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
---
# set app specific ufw rules
- name: Allow all access to tcp port 22
community.general.ufw:
rule: allow
port: '22'
proto: tcp

# allow certbot
- name: Allow all access to tcp port 80
community.general.ufw:
rule: allow
port: '80'
proto: tcp

- name: Allow all access to tcp port 443
community.general.ufw:
rule: allow
port: '443'
proto: tcp
Empty file.
Empty file.
36 changes: 36 additions & 0 deletions apps/linode-marketplace-kali-linux/roles/kali/tasks/main.yml
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The only thing that we should have in this file is import_tasks. Break everything out into their own task file if possible to stick to the standard.

Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
- name: Add non-free repository
apt_repository:
repo: deb http://http.kali.org/kali kali-rolling main contrib non-free non-free-firmware
state: present
filename: kali-nonfree

- name: Update apt cache
apt:
update_cache: yes
Comment on lines +8 to +10
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this task. This is redundant with the next task.


- name: Install firmware-misc-nonfree
apt:
name: firmware-misc-nonfree
state: present
update_cache: yes
environment:
DEBIAN_FRONTEND: noninteractive

- name: Fix broken packages
apt:
clean: true
autoclean: true
autoremove: true
environment:
DEBIAN_FRONTEND: noninteractive

- name: Install Kali Linux
apt:
name: "{{ kali_package }}"
state: present
when: kali_package is defined

- name: Set up VNC
import_tasks: vnc_setup.yml
when: vnc_enabled | bool
44 changes: 44 additions & 0 deletions apps/linode-marketplace-kali-linux/roles/kali/tasks/vnc_setup.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
- name: Install XFCE and VNC packages
apt:
name:
- xfce4
- xfce4-goodies
- dbus-x11
- tigervnc-standalone-server
- expect
state: present

- name: Create VNC user
user:
name: "{{ vnc_username }}"
password: "{{ vnc_password | password_hash('sha512') }}"
shell: /bin/bash

- name: Set up VNC password
expect:
command: vncserver
responses:
Password: "{{ vnc_password }}"
Verify: "{{ vnc_password }}"
"Would you like to enter a view-only password (y/n)?": "n"
become: yes
become_user: "{{ vnc_username }}"
Comment on lines +12 to +26
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This output to the log. Use no_log to avoid leaking secrets to the stackscript log.


- name: Kill VNC process
shell: |
killall Xtigervnc
ignore_errors: yes

- name: Create VNC service file
template:
src: [email protected]
dest: /etc/systemd/system/[email protected]
mode: '0644'

- name: Start and enable VNC service
systemd:
name: [email protected]
state: started
enabled: yes
daemon_reload: yes
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
[Unit]
Description=Start TigerVNC server at startup
After=syslog.target network.target

[Service]
Type=forking
User={{ vnc_username }}
Group={{ vnc_username }}
WorkingDirectory=/home/{{ vnc_username }}

ExecStartPre=-/usr/bin/vncserver -kill :%i > /dev/null 2>&1
ExecStart=/usr/bin/vncserver -depth 24 -geometry 1280x800 -localhost :%i
ExecStop=/usr/bin/vncserver -kill :%i

[Install]
WantedBy=multi-user.target
14 changes: 14 additions & 0 deletions apps/linode-marketplace-kali-linux/roles/post/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
# motd and creds gen
- name: copy MOTD template to /etc/motd
template:
src: templates/motd.j2
dest: /etc/motd

- name: writing credentials into file
template:
src: templates/credentials.j2
dest: '/home/{{ username }}/.credentials'
mode: '0600'
owner: '{{ username }}'
group: '{{ username }}'
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Sudo Credentials:
Username: {{ username }}
Password: {{ password }}

{% if vnc_enabled | bool %}
VNC Credentials:
Username: {{ vnc_username }}
Password: {{ vnc_password }}
{% endif %}

{% if kali_package is defined and kali_package != '' %}
Kali Linux Package Installed: {{ kali_package }}
{% endif %}
24 changes: 24 additions & 0 deletions apps/linode-marketplace-kali-linux/roles/post/templates/motd.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
*********************************************************
Akamai Connected Cloud Kali Marketplace App

###################################
# VNC SSH Tunnel Instructions #
###################################

* Ensure you have a VNC Client installed on your local machine
* Run the command below to start the SSH tunnel for VNC

ssh -L 61000:127.0.0.1:5901 -N -l {{ vnc_username }} {{ ansible_default_ipv4.address }}

* For more Detailed documentation please visit the official Documentation below

https://www.linode.com/docs/marketplace-docs/guides/kali-linux/

### To remove this message, you can edit the /etc/motd file ###

Credentials File: /home/{{ username }}/.credentials
*********************************************************
To delete this message of the day: rm /etc/motd



Loading