diff --git a/Dockerfile b/Dockerfile index dd54baf..4b18f8c 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,13 +1,13 @@ -FROM python:3.5-alpine +FROM python:3.7-alpine RUN apk add --no-cache nmap nmap-scripts git -RUN pip install --no-cache-dir xmltodict google-cloud-storage boto3 +RUN pip install --no-cache-dir xmltodict google-cloud-storage google-api-python-client boto3 RUN git clone https://github.com/vulnersCom/nmap-vulners /usr/share/nmap/scripts/vulners && nmap --script-updatedb RUN mkdir /shared -COPY run.sh output_report.py latex_header.tex gcp_push.py aws_push.py / +COPY run.sh output_report.py latex_header.tex gcp_push.py aws_push.py list_ip.py / COPY shared /shared RUN chmod +x /run.sh diff --git a/Makefile b/Makefile index f207923..09e3eec 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,6 @@ -build : +build : docker build -t flan_scan . container_name = flan_$(shell date +'%s') -start : +start : docker run --name $(container_name) -v $(shell pwd)/shared:/shared flan_scan diff --git a/README.md b/README.md index 5943951..a7ae88c 100644 --- a/README.md +++ b/README.md @@ -97,6 +97,35 @@ docker run --name \ ``` +Autogenerate IP List +-------------------- + +Flan Scan currenty support autogenerate IP list from your running instances in GCP and AWS. You need additional environment variables to do that which is `generate_ips` which take value of `aws` and/or `gcp`. You can use both by using comma as separator like `aws,gcp`. + +### Example Autogenerate IP List in GCP + +You still need to set `GOOGLE_APPLICATION_CREDENTIALS` but you don't need to mount any volume to the container. + +```bash +docker run --name \ + -e GOOGLE_APPLICATION_CREDENTIALS=.json \ + -e PROJECT_ID= \ + -e generate_ips=gcp \ + flan_scan +``` + +### Example Autogenerate IP List in AWS + +You still need to set `GOOGLE_APPLICATION_CREDENTIALS` but you don't need to mount any volume to the container. + +```bash +docker run --name \ + -e AWS_ACCESS_KEY_ID= \ + -e AWS_SECRET_ACCESS_KEY= \ + -e generate_ips=aws \ + flan_scan +``` + Deploying on Kubernetes ----------------------- diff --git a/list_ip.py b/list_ip.py new file mode 100644 index 0000000..ed6aaa1 --- /dev/null +++ b/list_ip.py @@ -0,0 +1,70 @@ +import boto3 +import googleapiclient.discovery +import os + +def aws_list_ip(): + region_name = os.getenv("AWS_DEFAULT_REGION", "us-east-1") + + session = boto3.Session(region_name=region_name) + client = session.client('ec2') + regions = client.describe_regions() + + ips = [] + + for region in regions['Regions']: + session = boto3.Session(region_name=region['RegionName']) + ec2 = session.resource('ec2') + running_instances = ec2.instances.filter(Filters=[{ + 'Name': 'instance-state-name', + 'Values': ['running']}]) + + for instance in running_instances: + if instance.public_ip_address: + ips.append(instance.public_ip_address) + else: + ips.append(instance.private_ip_address) + return ips + +def gcp_list_ip(): + project_id = os.getenv("PROJECT_ID") + + client = googleapiclient.discovery.build('compute', 'v1') + + compute = client.instances() + zones = client.zones().list(project=project_id).execute() + + ips = [] + + for zone in zones['items']: + result = compute.list( + project=project_id, + zone=zone['name'], + filter="status=RUNNING").execute() + + if 'items' not in result: + continue + + for vm in result['items']: + if 'networkInterfaces' in vm: + for network_interface in vm['networkInterfaces']: + if 'accessConfigs' in network_interface: + ips.extend( + [x['natIP'] for x in network_interface['accessConfigs'] + if x['type'] == 'ONE_TO_ONE_NAT'] + ) + else: + ips.append(network_interface['networkIP']) + return ips + +def write_file(ip_list): + with open('shared/ips.txt', 'a') as f: + f.writelines("%s\n" % ip for ip in ip_list) + + +if __name__ == "__main__": + request = os.getenv("generate_ips") + if "aws" in request: + write_file(aws_list_ip()) + + if "gcp" in request: + write_file(gcp_list_ip()) diff --git a/run.sh b/run.sh index 77ec6d0..1b9b1da 100755 --- a/run.sh +++ b/run.sh @@ -1,5 +1,10 @@ #!/bin/sh +if [[ ! -z $generate_ips ]] +then + python /list_ip.py +fi + current_time=$(date "+%Y.%m.%d-%H.%M") if [[ -z $upload ]] then @@ -13,7 +18,7 @@ fi xml_dir=xml_files/$current_time report_file=reports/report_$current_time.tex -function upload { +function upload() { if [[ -z $upload ]] then return diff --git a/shared/ips.txt b/shared/ips.txt index 89455e6..e69de29 100644 --- a/shared/ips.txt +++ b/shared/ips.txt @@ -1,3 +0,0 @@ -8.17.207.0/24 -198.41.138.128/25 -198.41.138.0/25