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

feat: add autogenerate IP list for AWS & GCP #50

Open
wants to merge 5 commits into
base: master
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
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -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
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,35 @@ docker run --name <container-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 <container-name> \
-e GOOGLE_APPLICATION_CREDENTIALS=<your-service-account>.json \
-e PROJECT_ID=<your-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 <container-name> \
-e AWS_ACCESS_KEY_ID=<your-aws-access-key-id> \
-e AWS_SECRET_ACCESS_KEY=<your-aws-secret-access-key> \
-e generate_ips=aws \
flan_scan
```

Deploying on Kubernetes
-----------------------

Expand Down
70 changes: 70 additions & 0 deletions list_ip.py
Original file line number Diff line number Diff line change
@@ -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())
7 changes: 6 additions & 1 deletion run.sh
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down
3 changes: 0 additions & 3 deletions shared/ips.txt
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
8.17.207.0/24
198.41.138.128/25
198.41.138.0/25