Skip to content

Commit 1b0801d

Browse files
committed
ASH Version 1.0
1 parent 4e51a8a commit 1b0801d

File tree

1,915 files changed

+91
-1344122
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

1,915 files changed

+91
-1344122
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
utils/cfn-to-cdk/cfn_to_cdk/

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<a name="1.0.0-e-23Dec2022"></a>
2+
# 1.0.0-e-23Dec2022
3+
### Automated Security Helper
4+
ASH version 1.0.0-e-23Dec2022 is out!
5+
6+
* Speed - running time is shorter by 40-50%
7+
* Frameworks support - we support Java, Go and C# code
8+
* New tool - ASH is running [Semgrep](https://github.com/returntocorp/semgrep) for supported frameworks
9+
* Force scans for specific frameworks - You can use the `--ext` flag to enforce scan for specific framework
10+
For example: `ash --source-dir . --ext py` (Python)
11+
* Versioning - use `ash --version` to check your current version
12+
* Bug fixes and improvements
13+
14+
<!-- CHANGELOG SPLIT MARKER -->

README.md

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,26 @@ The security helper supports the following vectors:
2323
* **[git-secrets](https://github.com/awslabs/git-secrets)** - Find api keys, passwords, AWS keys in the code
2424
* Python
2525
* **[bandit](https://github.com/PyCQA/bandit)** - finds common security issues in Python code.
26-
* **[Grype](https://github.com/anchore/grype)** - checks for vulnerabilities in Python code.
27-
* **[Syft](https://github.com/anchore/grype)** - generates a Software Bill of Materials (SBOM) for Python code.
26+
* **[Semgrep](https://github.com/returntocorp/semgrep)** - finds common security issues in Python code.
27+
* **[Grype](https://github.com/anchore/grype)** - finds vulnerabilities scanner for Python code.
28+
* **[Syft](https://github.com/anchore/grype)** - generating a Software Bill of Materials (SBOM) for Python code.
2829
* Jupyter Notebook
2930
* **[nbconvert](https://nbconvert.readthedocs.io/en/latest/)** - converts Jupyter Notebook (ipynb) files into Python executables. Code scan with Bandit.
3031
* JavaScript; NodeJS
3132
* **[npm-audit](https://docs.npmjs.com/cli/v8/commands/npm-audit)** - checks for vulnerabilities in Javascript and NodeJS.
32-
* **[Grype](https://github.com/anchore/grype)** - checks for vulnerabilities in Javascript and NodeJS.
33-
* **[Syft](https://github.com/anchore/grype)** - generates a Software Bill of Materials (SBOM) for Javascript and NodeJS.
33+
* **[Semgrep](https://github.com/returntocorp/semgrep)** - finds common security issues in JavaScript code.
34+
* **[Grype](https://github.com/anchore/grype)** - finds vulnerabilities scanner for Javascript and NodeJS.
35+
* **[Syft](https://github.com/anchore/grype)** - generating a Software Bill of Materials (SBOM) for Javascript and NodeJS.
36+
* Go
37+
* **[Semgrep](https://github.com/returntocorp/semgrep)** - finds common security issues in Golang code.
38+
* **[Grype](https://github.com/anchore/grype)** - finds vulnerabilities scanner for Golang.
39+
* **[Syft](https://github.com/anchore/grype)** - generating a Software Bill of Materials (SBOM) for Golang.
40+
* C#
41+
* **[Semgrep](https://github.com/returntocorp/semgrep)** - finds common security issues in C# code.
42+
* Java
43+
* **[Semgrep](https://github.com/returntocorp/semgrep)** - finds common security issues in Java code.
44+
* **[Grype](https://github.com/anchore/grype)** - finds vulnerabilities scanner for Java.
45+
* **[Syft](https://github.com/anchore/grype)** - generating a Software Bill of Materials (SBOM) for Java.
3446
* Infrastructure
3547
* Terraform; Cloudformation
3648
* **[checkov](https://github.com/bridgecrewio/checkov)**
@@ -68,6 +80,9 @@ ash --output-dir /my/remote/files
6880
# Force rebuild the entire framework to obtain latests changes and up-to-date database
6981
ash --force
7082
83+
# Force run scan for Python code
84+
ash --source-dir . --ext py
85+
7186
* All commands can be used together.
7287
```
7388

@@ -78,9 +93,11 @@ NAME:
7893
SYNOPSIS:
7994
ash [OPTIONS] --source-dir /path/to/dir --output-dir /path/to/dir
8095
OPTIONS:
96+
-v | --version Prints version number.
8197
-p | --preserve-report Add timestamp to the final report file to avoid overriding it after multiple executions
8298
--source-dir Path to the directory containing the code/files you wish to scan. Defaults to $(pwd)
8399
--output-dir Path to the directory that will contain the report of the scans. Defaults to $(pwd)
100+
--ext | -extension Force a file extension to scan. Defaults to identify files automatically.
84101
--force Rebuild the Docker images of the scanning tools, to make sure software is up-to-date.
85102
-q | --quiet Don't print verbose text about the build process.
86103

ash

Lines changed: 39 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@
33
# SPDX-License-Identifier: Apache-2.0
44
set -e
55
START_TIME=$(date +%s)
6+
VERSION=("1.0.0-e-23Dec2022")
67

78
print_usage() {
89
echo "NAME:"
910
echo -e "\t$(basename $0)"
1011
echo "SYNOPSIS:"
1112
echo -e "\t$(basename $0) [OPTIONS] --source-dir /path/to/dir --output-dir /path/to/dir"
1213
echo "OPTIONS:"
13-
echo -e "\t-p | --preserve-report Add timestamp to the final report file to avoid overriding it after multiple executions"
14+
echo -e "\t-v | --version Prints version number.\n"
15+
echo -e "\t-p | --preserve-report Add timestamp to the final report file to avoid overriding it after multiple executions."
1416
echo -e "\t--source-dir Path to the directory containing the code/files you wish to scan. Defaults to \$(pwd)"
1517
echo -e "\t--output-dir Path to the directory that will contain the report of the scans. Defaults to \$(pwd)"
18+
echo -e "\t--ext | -extension Force a file extension to scan. Defaults to identify files automatically."
1619
echo -e "\t--force Rebuild the Docker images of the scanning tools, to make sure software is up-to-date."
17-
echo -e "\t-q | --quiet Don't print verbose text about the build process.\n"
18-
echo -e "\t-c | --no-color Don't print colorized output"
19-
echo -e "\t-q | --quiet Don't print verbose text about the build process.\n"
20+
echo -e "\t-q | --quiet Don't print verbose text about the build process."
21+
echo -e "\t-c | --no-color Don't print colorized output."
2022
echo -e "For more information please visit https://github.com/aws-samples/automated-security-helper"
2123
}
2224

@@ -26,10 +28,7 @@ PY_EXTENSIONS=("py" "pyc" "ipynb")
2628
INFRA_EXTENSIONS=("yaml" "yml" "tf" "json" "dockerfile")
2729
CFN_EXTENSIONS=("yaml" "yml" "json")
2830
JS_EXTENSIONS=("js")
29-
GRYPE_EXTENSIONS=("js" "py")
30-
31-
# Look for specific files
32-
CDK_FILENAMES=("cdk.json")
31+
GRYPE_EXTENSIONS=("js" "py" "java" "go" "cs")
3332

3433
DOCKERFILE_LOCATION="$(dirname "${BASH_SOURCE[0]}")"/"helper_dockerfiles"
3534
UTILS_LOCATION="$(dirname "${BASH_SOURCE[0]}")"/"utils"
@@ -44,6 +43,7 @@ HIGHEST_RC=0
4443
# Initialize options
4544
#
4645
COLOR_OUTPUT="true"
46+
FORCED_EXT="false"
4747

4848
while (("$#")); do
4949
case $1 in
@@ -55,6 +55,10 @@ while (("$#")); do
5555
shift
5656
OUTPUT_DIR="$1"
5757
;;
58+
--ext | -extenstion)
59+
shift
60+
FORCED_EXT="$1"
61+
;;
5862
--force)
5963
DOCKER_EXTRA_ARGS="${DOCKER_EXTRA_ARGS} --no-cache"
6064
;;
@@ -68,6 +72,11 @@ while (("$#")); do
6872
--no-color | -c)
6973
COLOR_OUTPUT="false"
7074
;;
75+
--version | -v)
76+
echo -n "ASH version $VERSION"
77+
EXITCODE=0
78+
exit $EXITCODE
79+
;;
7180
*)
7281
print_usage
7382
exit 1
@@ -76,11 +85,6 @@ while (("$#")); do
7685
shift
7786
done
7887

79-
print_found_msg() {
80-
EXTENSIONS=$1
81-
echo -e "${LPURPLE}Found one of ${EXTENSIONS} items in your source dir${NC}"
82-
}
83-
8488
TIMESTAMP=$(date +%s)
8589
USERID=$(echo -n "$(whoami)$(hostname)" | openssl dgst -sha512)
8690
TOOLID=$(basename "$0")
@@ -133,20 +137,16 @@ map_extensions_anf_files() {
133137
# Try to locate specific extension type (ie yaml, py) from all the extensions found in $SOURCE_DIR
134138
search_extension() {
135139
items_to_search=("$@") # passed as parameter to the function
136-
item_found=false
140+
local item_found=0
137141
for item in "${items_to_search[@]}"; do
138-
if [[ "${extenstions_found[*]}" =~ ${item} || "${files_found[*]}" =~ ${item} ]]; then
139-
item_found=true
142+
if [[ "${extenstions_found[*]}" =~ ${item} ]]; then
143+
local item_found=1
144+
echo "$item_found"
145+
break
140146
fi
141147
done
142148
}
143149

144-
search_file_content() {
145-
items_to_search=("$@") # passed as parameter to the function
146-
item_found=false
147-
cfn_files=$(grep -lri 'AWSTemplateFormatVersion' ${SOURCE_DIR} --exclude-dir="cdk.out")
148-
}
149-
150150
# Validate the input and set default values
151151
# shellcheck disable=SC2120
152152
validate_input() {
@@ -162,16 +162,14 @@ validate_input() {
162162
# The first argument passed to this method is the dockerfile that executes the actual scan
163163
# The remaining arguments (can be treated as *args in python) are the extensions we wish to scan for
164164
run_security_check() {
165-
EXTENSIONS_USED=( "${EXTENSIONS_USED[@]}" "$1" )
166-
echo "EXTENSIONS_USED is " $1
167-
DOCKERFILE_TO_EXECUTE="$1"
168-
ITEMS_TO_SCAN=("${@:2}") # take all the array of commands which are the extensions to scan (slice 2nd to end)
169-
RUNTIME_CONTAINER_NAME="scan-$RANDOM"
170-
171-
search_extension "${ITEMS_TO_SCAN[@]}" # First lets verify this extension even exists in the $SOURCE_DIR directory
172-
if [[ $item_found == "true" ]]; then
173-
print_found_msg "${ITEMS_TO_SCAN}"
174-
165+
local EXTENSIONS_USED=( "${EXTENSIONS_USED[@]}" "$1" )
166+
local DOCKERFILE_TO_EXECUTE="$1"
167+
local ITEMS_TO_SCAN=("${@:2}") # take all the array of commands which are the extensions to scan (slice 2nd to end)
168+
local RUNTIME_CONTAINER_NAME="scan-$RANDOM"
169+
# First lets verify this extension even exists in the $SOURCE_DIR directory
170+
#echo "${EXTENSIONS_USED[@]}" $(search_extension "${ITEMS_TO_SCAN[@]}")
171+
if [[ " ${ITEMS_TO_SCAN[*]} " =~ " ${FORCED_EXT} " ]] || [[ $(search_extension "${ITEMS_TO_SCAN[@]}") == "1" ]]; then
172+
echo -e "${LPURPLE}Found one of: ${RED}"${ITEMS_TO_SCAN[@]}" ${LPURPLE}items in your source dir,${NC} ${GREEN}running $1 ...${NC}"
175173
docker build -t "${RUNTIME_CONTAINER_NAME}" -f "${DOCKERFILE_LOCATION}"/"${DOCKERFILE_TO_EXECUTE}" ${DOCKER_EXTRA_ARGS} "${SOURCE_DIR}" > /dev/null
176174
set +e # the scan will fail the command if it finds any finding. we don't want it to stop our script execution
177175
docker run --name "${RUNTIME_CONTAINER_NAME}" -v "${CFNRULES_LOCATION}":/cfnrules -v "${UTILS_LOCATION}":/utils -v "${SOURCE_DIR}":/app "${RUNTIME_CONTAINER_NAME}"
@@ -227,13 +225,16 @@ do
227225
done
228226
unset IFS
229227

230-
run_security_check "Dockerfile-git" "${GIT_EXTENSIONS[@]}"
231-
run_security_check "Dockerfile-py" "${PY_EXTENSIONS[@]}"
232-
run_security_check "Dockerfile-yaml" "${INFRA_EXTENSIONS[@]}"
233-
run_security_check "Dockerfile-js" "${JS_EXTENSIONS[@]}"
234-
search_file_content "${CFN_EXTENSIONS}" || echo "No CFN files found"
228+
echo -e "ASH version $VERSION\n"
229+
230+
run_security_check "Dockerfile-git" "${GIT_EXTENSIONS[@]}" &
231+
run_security_check "Dockerfile-py" "${PY_EXTENSIONS[@]}" &
232+
run_security_check "Dockerfile-yaml" "${INFRA_EXTENSIONS[@]}" &
233+
run_security_check "Dockerfile-js" "${JS_EXTENSIONS[@]}" &
234+
run_security_check "Dockerfile-grype" "${GRYPE_EXTENSIONS[@]}" &
235235
run_security_check "Dockerfile-cdk" "${CFN_EXTENSIONS[@]}"
236-
run_security_check "Dockerfile-grype" "${GRYPE_EXTENSIONS[@]}"
236+
wait
237+
237238

238239
# Cleanup any previous file
239240
rm -f "${OUTPUT_DIR}"/"${AGGREGATED_RESULTS_REPORT_FILENAME}"

helper_dockerfiles/Dockerfile-cdk

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
11
# Get Ubuntu Image
22
#FROM public.ecr.aws/ubuntu/ubuntu:latest
3-
FROM public.ecr.aws/ubuntu/ubuntu:20.04
3+
#FROM public.ecr.aws/bitnami/python:latest
4+
FROM public.ecr.aws/docker/library/node:18.0.0
45
ENV TZ=Europe/London
56
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
67

78
# Instal prerequisites
89
RUN apt-get update && \
910
apt-get upgrade -y && \
10-
apt-get install -y python3 python3-pip curl && \
11+
apt-get install -y curl && \
1112
rm -rf /var/lib/apt/lists/*
12-
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash - && apt -y install nodejs
13+
RUN wget https://bootstrap.pypa.io/get-pip.py && python3 get-pip.py
1314
RUN npm install -g aws-cdk
1415
RUN python3 -m pip install -U aws-cdk-lib cdk-nag jinja2
1516
WORKDIR /app

helper_dockerfiles/Dockerfile-git

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Get Ubuntu Image
2-
FROM public.ecr.aws/ubuntu/ubuntu:latest
2+
FROM public.ecr.aws/bitnami/python:latest
33

44
# Instal prerequisites
55
RUN apt-get update && \

helper_dockerfiles/Dockerfile-grype

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ FROM public.ecr.aws/bitnami/python:latest
33

44
# Instal prerequisites
55
RUN curl -sSfL https://raw.githubusercontent.com/anchore/syft/main/install.sh | sh -s -- -b /usr/local/bin && \
6-
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin
6+
curl -sSfL https://raw.githubusercontent.com/anchore/grype/main/install.sh | sh -s -- -b /usr/local/bin && \
7+
python3 -m pip install semgrep
78

89
WORKDIR /app
910
VOLUME /app

helper_dockerfiles/Dockerfile-js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Get NPM Image
2-
FROM public.ecr.aws/docker/library/node:latest
2+
FROM public.ecr.aws/docker/library/node:18.0.0
33

44
WORKDIR /app
55
VOLUME /app

helper_dockerfiles/Dockerfile-yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Get Ubuntu Image
2-
FROM public.ecr.aws/ubuntu/ubuntu:latest
2+
FROM public.ecr.aws/bitnami/python:latest
33

44
ENV TZ=Europe/London
55
RUN ln -snf /usr/share/zoneinfo/$TZ /etc/localtime && echo $TZ > /etc/timezone
66

77
# Instal prerequisites
88
RUN apt-get update && \
99
apt-get upgrade -y && \
10-
apt-get install -y git-all python3 python3-pip ruby-full && \
10+
apt-get install -y ruby-full && \
1111
rm -rf /var/lib/apt/lists/*
1212

1313
RUN pip3 install -U checkov && gem install cfn-nag
1414
WORKDIR /app
1515

16-
CMD bash -C /utils/yaml-docker-execute.sh
16+
CMD bash -C /utils/yaml-docker-execute.sh

utils/cfn-to-cdk/README.md

Lines changed: 0 additions & 65 deletions
This file was deleted.

0 commit comments

Comments
 (0)