Packer by Hashicorp (https://www.packer.io/) is used to create AWS AMI (Amazon Machine Image) which are used as images that instances are spun up from. Packer allows you to take a base image and provision it as required. Packer uses json so you can't add comments to your packer files which is a bit annoying. I have commented the packer elements in the example below.
Packer will spin up the 'source_ami' specified and connect with ssh to execute the commands in the 'provisioners' section of the file. The new AMI is created from this instance once all the commands have been run. You can see this instance in the AWS Console which is then immediately terminated once Packer has finished working.
You can see the created AMIs in the AWS Console. Go to
Services - EC2 - AMIs (Left Panel)
Define a set of variables at the top of the file that are easily changed. This way you don't have to hunt through the file to find an instances of these variables that need to be altered later.
{
"variables": {
"region": "<region>",
// This uses the profile from the .aws/credentials file
"profile": "<profile>",
// The base ami that you are starting from
"source_ami": "<base ami>",
// The optional VPC (virtual private cloud) and subnet that you want this ami to be part of
"vpc_id": "<vpc>",
"subnet_id": "<subnet>"
},
"builders": [
{
"ami_name": "<name of the ami created>",
"ami_description": "<description>",
// How is the communication with the packer instance going to be established
"communicator": "ssh",
// Force any AMI with the same name to be removed ('deregistered')
"force_deregister": true,
"instance_type": "t2.micro",
// Use the parameters which are defined in the 'variables' section above
"profile": "{{user `profile`}}",
"region": "{{user `region`}}",
"source_ami": "{{user `source_ami`}}",
"ssh_pty": true,
"ssh_username": "<ssh username that you are going to connect as>",
"subnet_id": "{{user `subnet_id`}}",
"type": "amazon-ebs",
"vpc_id": "{{user `vpc_id`}}"
}
],
// The provisioners section that adds additional files, installs etc to the AMI that is going to be created
"provisioners": [
// This first provisioner installs wget
{
"type": "shell",
"inline": [
"sudo yum update -y",
"sudo yum -y install wget"
]
},
// Perhaps also install java afterwards?
{
"type": "shell",
"inline": [
"sudo yum -y install java-1.8.0-openjdk-devel"
]
},
]
}
Thursday, 22 February 2018
Parameter Store in AWS
Using the parameter store in AWS is pretty straight forward. You can use the command line to get and put parameters and therefore not have to store them in source control. You can use the IAM roles in AWS to limit access to the values.
Find the Parameter Store by logging in to the AWS console and navigating to
Services - Systems Manager - Parameter Store (Left panel)
aws ssm put-parameter --region <region> --name <parameterName> --type SecureString --value "my secure value"
To store the contents of a file you can use
aws ssm put-parameter --region <region> --name <parameterName> --type SecureString --value file://my_file_to_store.anything
Use the simple command line to get a parameter value.
aws ssm get-parameter --region <region> --name <parameterName>
If you SecureString was used as a type then the --with-decryption value can be used to see the actual value.
aws ssm get-parameter --region <region> --name <parameterName> --with-decryption
This output in json isn't always useful. A --query parameter can be added to specify the actual output needed
aws ssm get-parameter --region <region> --name <parameterName> --with-decryption --query Parameter.Value
Add | cut -d "\"" -f 2 to remove the quotes and using 'echo -e' will restore any line breaks which are encoded as \n
Similarly if a profile is needed then --profile <profileName> can be used
Find the Parameter Store by logging in to the AWS console and navigating to
Services - Systems Manager - Parameter Store (Left panel)
Put Parameter
There are a number of types of value that can be stored in the parameter store. String, StringList and SecureString. To put a parameter useaws ssm put-parameter --region <region> --name <parameterName> --type SecureString --value "my secure value"
To store the contents of a file you can use
aws ssm put-parameter --region <region> --name <parameterName> --type SecureString --value file://my_file_to_store.anything
Get Parameter
Use the simple command line to get a parameter value.aws ssm get-parameter --region <region> --name <parameterName>
If you SecureString was used as a type then the --with-decryption value can be used to see the actual value.
aws ssm get-parameter --region <region> --name <parameterName> --with-decryption
This output in json isn't always useful. A --query parameter can be added to specify the actual output needed
aws ssm get-parameter --region <region> --name <parameterName> --with-decryption --query Parameter.Value
Add | cut -d "\"" -f 2 to remove the quotes and using 'echo -e' will restore any line breaks which are encoded as \n
Similarly if a profile is needed then --profile <profileName> can be used
IAM Role
To allow access the arn:aws:iam::aws:policy/AmazonSSMReadOnlyAccess role can be added to a instance that needs to have read-only access.Wednesday, 1 November 2017
SMB / Netbios Enumeration
SMB / Netbios
# Search for SMB services (open ports only reported)
nmap -p139,445 a.a.a.a-b --open
# Specific nbt span
nbtscan a.a.a.a-b
SMB Null Session
This is valid for Windows machines before 2003 Server and XP
rpcclient -U "" a.a.a.a
Password: <leave empty>
> srvinfo
... (server info)
> enumdomusers
... (users defined on server)
> getdompwinfo
... (password policy info)
enum4linux
enum4linux -v a.a.a.a
nmap using 'nse'
# Enumerate SMB users
nmap -p139,445 --script smb-enum-users a.a.a.a
# Check for SMB Vunerabilities
nmap -p139,445 --script smb-check-vulns --script-args=unsafe=1 a.a.a.a
# Search for SMB services (open ports only reported)
nmap -p139,445 a.a.a.a-b --open
# Specific nbt span
nbtscan a.a.a.a-b
SMB Null Session
This is valid for Windows machines before 2003 Server and XP
rpcclient -U "" a.a.a.a
Password: <leave empty>
> srvinfo
... (server info)
> enumdomusers
... (users defined on server)
> getdompwinfo
... (password policy info)
enum4linux
enum4linux -v a.a.a.a
nmap using 'nse'
# Enumerate SMB users
nmap -p139,445 --script smb-enum-users a.a.a.a
# Check for SMB Vunerabilities
nmap -p139,445 --script smb-check-vulns --script-args=unsafe=1 a.a.a.a
SNMP Enumeration
SNMP Enumeration
# SNMP scan for open 161 ports
nmap -sU -p 161 --open a.a.a.a-b
onesixtyone
# Use the 161 tool
# community is a file which contains a list of community strings eg
public
private
manager
# ips is a file which contains a list of ip addresses. It can be generated easily using
for ip in (seq 50 100); do
echo a.a.a.$ip >> ips
done
# Now invoke the onesixtyone tool with these files
onesixtyone -c community -i ips
snmpwalk
# Use snmpwalk to get the values of each leaf of the snmp server using community string 'public' and version 1
snmpwalk -c public -v1 a.a.a.a
# Search for a particular MiB value
snmpwalk -c public -v1 a.a.a.a 1.2.3.4.5.6.7.8.9
snmpenum
snmpcheck
# SNMP scan for open 161 ports
nmap -sU -p 161 --open a.a.a.a-b
onesixtyone
# Use the 161 tool
# community is a file which contains a list of community strings eg
public
private
manager
# ips is a file which contains a list of ip addresses. It can be generated easily using
for ip in (seq 50 100); do
echo a.a.a.$ip >> ips
done
# Now invoke the onesixtyone tool with these files
onesixtyone -c community -i ips
snmpwalk
# Use snmpwalk to get the values of each leaf of the snmp server using community string 'public' and version 1
snmpwalk -c public -v1 a.a.a.a
# Search for a particular MiB value
snmpwalk -c public -v1 a.a.a.a 1.2.3.4.5.6.7.8.9
snmpenum
snmpcheck
SMTP Enumeration
SMTP Enumeration
# Scan for open port 25
nmap -sT -p 25 --open a.a.a.a-b
# Connect to an SMTP server
nc -nv a.a.a.a 25
220 ... server details
# Verify that a user exists.
> VRFY ******
250 ... ******
where a.a.a.a-b is an ip range such as 192.168.1.100-150
# Scan for open port 25
nmap -sT -p 25 --open a.a.a.a-b
# Connect to an SMTP server
nc -nv a.a.a.a 25
220 ... server details
# Verify that a user exists.
> VRFY ******
250 ... ******
where a.a.a.a-b is an ip range such as 192.168.1.100-150
nmap & Port Scanning
# ICMP / ping sweep
nmap -sn a.a.a.a-b
# Output to a grepable file
nmap -sn a.a.a.a-b -oG nmap-ping-sweep.txt
grep Up nmap-ping-sweep.txt
# Specific port scan
nmap -p 22 a.a.a.a-b -oG nmap-ssh-scan.txt
Port Scanning
# Connect scan
nmap -sT a.a.a.a-b
# Syn / half open scan
nmap -sS a.a.a.a-b
# Syn scan on the top 100 ports
nmap -sS --top-ports 100 a.a.a.a-b
# ACK scan
nmap -sA --top-ports 100 a.a.a.a-b
# SNMP scan for open 161 ports
nmap -sU -p 161 --open a.a.a.a-b
# Banner grabbing
nmap -sV a.a.a.a-b
# Operating system fingerprinting
nmap -O a.a.a.a-b
# Comprehensive scan
nmap -A a.a.a.a-b
nse = nmap scripting engine
where a.a.a.a-b is an ip range such as 192.168.1.100-150
nmap -sn a.a.a.a-b
# Output to a grepable file
nmap -sn a.a.a.a-b -oG nmap-ping-sweep.txt
grep Up nmap-ping-sweep.txt
# Specific port scan
nmap -p 22 a.a.a.a-b -oG nmap-ssh-scan.txt
Port Scanning
# Connect scan
nmap -sT a.a.a.a-b
# Syn / half open scan
nmap -sS a.a.a.a-b
# Syn scan on the top 100 ports
nmap -sS --top-ports 100 a.a.a.a-b
# ACK scan
nmap -sA --top-ports 100 a.a.a.a-b
# SNMP scan for open 161 ports
nmap -sU -p 161 --open a.a.a.a-b
# Banner grabbing
nmap -sV a.a.a.a-b
# Operating system fingerprinting
nmap -O a.a.a.a-b
# Comprehensive scan
nmap -A a.a.a.a-b
nse = nmap scripting engine
where a.a.a.a-b is an ip range such as 192.168.1.100-150
Thursday, 14 September 2017
Using hping3
A quick cheat sheet for using hping3 for port scanning,
-c 1 Only send one request per port (c = count)
-v Verbose, show response for each port
-1 Sends a ping request (ICMP echo request) This number one not letter ell
-2 Send as UDP packet
-S Send a SYN scan, open ports will send a SYN-ACK packet back (a half-open scan)
-A Send an ACK packet
-F Send packet with a FIN flag
-8 1-500 Scan a range of ports equivalent of --span
-p 80 Scan a particular port
Examples
Send one request with a half-open scan to port 80
> hping3 -c 1 -S <www.website.somewhere> -p 80
HPING <www.website.somewhere> (eth1 <website ip>): S set, 40 headers + 0 data bytes
len=46 ip=<website ip> ttl=64 id=31610 sport=80 flags=SA seq=0 win=65535 rtt=14.8 ms
--- <www.website.somewhere> hping statistic ---
1 packets transmitted, 1 packets received, 0% packet loss
Send one request per port using a half-open scan against a Windows XP machine with no firewall
>hping3 -c 1 -S --scan 1-10000 <ip address>
Scanning <ip address>, port 1-10000
10000 ports to scan, use -V to see all the replies
+----+-----------+---------+---+-----+-----+-----+
|port| serv name | flags |ttl| id | win | len |
+----+-----------+---------+---+-----+-----+-----+
445 microsoft-d: .S..A... 64 33955 65535 46
139 netbios-ssn: .S..A... 64 46756 65535 46
135 loc-srv : .S..A... 64 47780 65535 46
3389 .S..A... 64 58947 65535 46
All replies received. Done.
Not responding ports:
Flags
The S and A flags show that the target system responded with a SYN-ACK which means the port is open and can be explored further.
-c 1 Only send one request per port (c = count)
-v Verbose, show response for each port
-1 Sends a ping request (ICMP echo request) This number one not letter ell
-2 Send as UDP packet
-S Send a SYN scan, open ports will send a SYN-ACK packet back (a half-open scan)
-A Send an ACK packet
-F Send packet with a FIN flag
-8 1-500 Scan a range of ports equivalent of --span
-p 80 Scan a particular port
Examples
Send one request with a half-open scan to port 80
> hping3 -c 1 -S <www.website.somewhere> -p 80
HPING <www.website.somewhere> (eth1 <website ip>): S set, 40 headers + 0 data bytes
len=46 ip=<website ip> ttl=64 id=31610 sport=80 flags=SA seq=0 win=65535 rtt=14.8 ms
--- <www.website.somewhere> hping statistic ---
1 packets transmitted, 1 packets received, 0% packet loss
Send one request per port using a half-open scan against a Windows XP machine with no firewall
>hping3 -c 1 -S --scan 1-10000 <ip address>
Scanning <ip address>, port 1-10000
10000 ports to scan, use -V to see all the replies
+----+-----------+---------+---+-----+-----+-----+
|port| serv name | flags |ttl| id | win | len |
+----+-----------+---------+---+-----+-----+-----+
445 microsoft-d: .S..A... 64 33955 65535 46
139 netbios-ssn: .S..A... 64 46756 65535 46
135 loc-srv : .S..A... 64 47780 65535 46
3389 .S..A... 64 58947 65535 46
All replies received. Done.
Not responding ports:
Flags
The S and A flags show that the target system responded with a SYN-ACK which means the port is open and can be explored further.
Subscribe to:
Posts (Atom)