Skip to main content

aws-kommandos

Advisory Infrastructure Setup Scripts

About

Have you ever been bothered with setting up your C2 infrastructure on AWS prior to/during a red team engagement? Having to deal with logging in, configuring security groups, going through the process of creating DNS record sets and such?

If you hate doing this time after time and just wanna have a script that does everything for you - you've come to the right place.

AWS Kommandos automates the process of creating cloud instances for various purposes - as C2 servers, for example. It also helps you to manage your AWS console - from changing firewall rules and managing your SSH access keys to adjusting the DNS record sets. All in one damn script.

You're only expected to create an AWS account and configure the access keys for running Kommandos locally.

See the Usage section for getting an idea how to use it.

Kommandos automatically creates its directory under the ~/.aws-kommandos path to store SSH private keys it creates.

Installation

Install the toolset

apt install python3 python3-pip
pip3 install aws-kommandos

Configure the AWS credentials

The first option is to use the awscli client to configure your AWS credentials used by Kommandos. aws configure

The second options is to export the AWS credentials as environment variables

export AWS_ACCESS_KEY_ID=key_id
export AWS_ACCESS_KEY_SECRET=secret
export AWS_REGION=region

The third option is to use the command-line arguments to pass credentials to Kommandos aws-kommandos --access-key-id <key_id> --access-key-secret <secret> --region-name <region>

Usage

Print Kommandos options

aws-kommandos --help

aws-kommandos -h

Print AWS stats (instances, security groups, ssh keys, DNS hosted zones)

aws-kommandos --stats

Print detailed AWS stats

aws-kommandos --stats --verbose

aws-kommandos --stats -v

Terminate all running EC2 instances

╰$ aws-kommandos --terminate-all
Terminating all running instances
Terminating i-0df15af122876dd62

Search AMI images

╰$ aws-kommandos --search-ami "ubuntu*server*20.04*"
{'CreationDate': '2021-07-27T16:45:08.000Z',
 'ImageId': 'ami-06e715bf46b6caf71',
 'State': 'available',
 'Name': 'ubuntu-pro-server/images/hvm-ssd/ubuntu-focal-20.04-amd64-pro-serve-ae7ed378-8838-4fcf-842d-d1d09b34f116-ami-005f184e361f78579.4',
 'ImageLocation': 'aws-marketplace/ubuntu-pro-server/images/hvm-ssd/ubuntu-focal-20.04-amd64-pro-serve-ae7ed378-8838-4fcf-842d-d1d09b34f116-ami-005f184e361f78579.4',
 'Description': 'Canonical, Ubuntu Server Pro, 20.04 LTS, amd64 focal image '
                'build on 2021-07-20',
 'ImageOwnerAlias': 'aws-marketplace'}
1 AMI images found

Start a new instance (minimal configuration)

╰$ aws-kommandos --security-group sg-66666666661488666 --start
Creating a new SSH key pair: proxy-key
The SSH key pair with the name 'proxy-key' already exists
Starting a new instance: ami-0746eb3cb5c684ae6 proxy-key sg-030abb524637009f3 t2.micro proxy-instance
The instance has been created
Waiting for the server boot...
The server is up and running at 18.197.229.100
Waiting until the SSH service is available...
The default user of the AMI 'ami-0746eb3cb5c684ae6' has been identified as 'ubuntu'
Use the following command for connecting to the instance: ssh ubuntu@18.197.229.100 -i proxy-key.pem

Oh, and did I mention that if you don't have an SSH access key the script automatically creates one for you? Use --force-recreate-key to force the script into creating a new key even if one with the same name exists.

Start a new instance and autoconfigure the DNS record sets

This command starts a new instance and uses the domain name supplied with the --fqdn argument to create A and MX record sets pointing to the IP address of the newly created EC2 instance.

╰$ aws-kommandos --security-group sg-66666666661488666 --start --link-fqdn --fqdn virtualsquad.ninja
Creating a new SSH key pair: proxy-key
The SSH key pair with the name 'proxy-key' already exists
Starting a new instance: ami-0746eb3cb5c684ae6 proxy-key sg-030abb524637009f3 t2.micro proxy-instance
The instance has been created
Waiting for the server boot...
The server is up and running at 18.184.218.238
Waiting until the SSH service is available...
The default user of the AMI 'ami-0746eb3cb5c684ae6' has been identified as 'ubuntu'
Use the following command for connecting to the instance: ssh ubuntu@18.184.218.238 -i proxy-key.pem
A new record set virtualsquad.ninja. A 18.184.218.238 has been created
A new record set virtualsquad.ninja. MX 1 18.184.218.238 has been created

Create an inbound firewall rule

╰$ aws-kommandos --security-group sg-66666666661488666 --allow-inbound 443/tcp:0.0.0.0/0         
Authorizing ingress '[443/tcp -> 0.0.0.0/0] - ' on 'sg-66666666661488666'
Operation performed successfully

Revoke an inbound firewall rule

╰$ aws-kommandos --security-group sg-66666666661488666 --delete-inbound 443/tcp:0.0.0.0/0
Revoking ingress '[443/tcp -> 0.0.0.0/0] - ' on 'sg-66666666661488666'
Operation performed successfully

Create an outbound firewall rule

╰$ aws-kommandos --security-group sg-66666666661488666 --allow-outbound 443/tcp:0.0.0.0/0         
Authorizing egress '[443/tcp -> 0.0.0.0/0] - ' on 'sg-66666666661488666'
Operation performed successfully

Revoke an outbound firewall rule

╰$ aws-kommandos --security-group sg-66666666661488666 --delete-outbound 443/tcp:0.0.0.0/0
Revoking egress '[443/tcp -> 0.0.0.0/0] - ' on 'sg-66666666661488666'
Operation performed successfully

Create a security group w/o description

╰$ aws-kommandos --create-security-group NinjaGroup                                         
A new security group with the name 'NinjaGroup' has been created

Create a security group w description

╰$ aws-kommandos --create-security-group "NinjaGroup: My Awesome Security Group"
A new security group with the name 'NinjaGroup' has been created

Delete a security group

╰$ aws-kommandos --delete-security-group --security-group-id sg-0b2d1b55354c531bd
The security group with id 'sg-0b2d1b55354c531bd' has been deleted

Create a new A record set for domain

╰$ aws-kommandos --fqdn virtualsquad.ninja --add-record --record-type A --record-value 55.55.55.55
A new record set virtualsquad.ninja. A 55.55.55.55 has been created

Delete a record set from domain

╰$ aws-kommandos --fqdn virtualsquad.ninja --delete-record --record-type A --record-value 55.55.55.55
The record set virtualsquad.ninja. A 55.55.55.55 has been deleted

And many more! Please use --help to see what else you could do with Kommandos.

Release files for aws-kommandos 1.0.14

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for aws-kommandos 1.0.14
File Size Uploaded
aws-kommandos-1.0.14.tar.gz 23.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for aws-kommandos 1.0.14
File Interpreter ABI Platform
aws_kommandos-1.0.14-py3-none-any.whl Python 3 none any Details

Total release size: 45.9 kB

Release files / aws-kommandos-1.0.14.tar.gz

Download URL aws-kommandos-1.0.14.tar.gz
Size 23.2 kB
Tags Source
SHA-256 checksum
How to use checksums
fc515969fa8646ebe075b23a790a7db7a2ff6a372523d2ecaac9f0ffde8742a4
BLAKE2b-256 checksum
How to use checksums
b98e5a9930a13ff92ca59cd9147af306851811cb3049d6744af3df8ef7e652ac
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release files / aws_kommandos-1.0.14-py3-none-any.whl

Download URL aws_kommandos-1.0.14-py3-none-any.whl
Size 22.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
717bb8806de308cf398e2da309d1013b06876dce560acb98f2b0e36db21566e3
BLAKE2b-256 checksum
How to use checksums
7b7a2aff69e6d46bdc41831f63fe4af07e001012c2cf7a81cc7d5049a7597708
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.9.14

Release history Release notifications | RSS feed

This release

1.0.14 This release

2 release files

1.0.13

2 release files

1.0.12

2 release files

1.0.11

2 release files

1.0.10

2 release files

1.0.9

2 release files

1.0.8

2 release files

1.0.7

2 release files

1.0.6

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page