Skip to content

Commit

Permalink
Merge pull request #274 from rackerlabs/issue-271-update-extract_targets
Browse files Browse the repository at this point in the history
Issue 271 update extract targets
  • Loading branch information
derpadoo authored Jul 15, 2021
2 parents 8fe185e + 2742c2f commit 8780362
Show file tree
Hide file tree
Showing 16 changed files with 678 additions and 338 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ creating, retrieving, updating, or deleting sites, scan commands, scans, etc.

* Engine: If you plan on compiling masscan on an engine, you'll need at least 1024 MB of memory. It fails to build with
only 512 MB. If you do not want to build masscan, set `install_masscan_on_engine` to `False` in
`ansible-playbooks/group_vars/all`
`ansible-playbooks/group_vars/all.yml`

* Console: 512 MB of memory was the smallest amount successfully tested, however, if you plan on processing large scan
files (using the scripts found in `console/scan_results`: `masscan_json_to_csv.py`, `nmap_to_csv.py` or
Expand Down Expand Up @@ -120,7 +120,7 @@ The recommendation is to deploy the console first.

#### Update Console Ansible Variables

Edit any variables in `ansible-playbooks/group_vars/all` before running playbook. Note the time zone variables:
Edit any variables in `ansible-playbooks/group_vars/all.yml` before running playbook. Note the time zone variables:

* `timezone_server` - Set this to be the timezone you want the server to be in, usually UTC.
* `timezone_django` - Set this to be your local timezone. It makes dealing with dates, times, and scheduling easier.
Expand Down Expand Up @@ -192,7 +192,7 @@ python3 manage.py changepassword admin

Edit any variables in these files before running playbook:

* `ansible-playbooks/group_vars/all`
* `ansible-playbooks/group_vars/all.yml`
* `ansible-playbooks/roles/engine/vars/main.yml`

#### Ensure proper user permissions
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions ansible-playbooks/roles/console/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
enable_ufw_firewall: true
reboot_box: true
reboot_box: false

install_packages:
- autossh
Expand All @@ -11,8 +11,8 @@ install_packages:
- nmap
- postfix
- postgresql-{{ postgresql_version }}
- python-dev
- python3-pip
- python-dev
- python-virtualenv
- python3-psycopg2 # python3-psycopg2 required for Ansible.
- redis
Expand Down
2 changes: 1 addition & 1 deletion ansible-playbooks/roles/engine/vars/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
enable_ufw_firewall: true
reboot_box: true
reboot_box: false

install_packages:
- autossh
Expand Down
2 changes: 1 addition & 1 deletion console/django_scantron/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "1.45"
__version__ = "1.46.0"
20 changes: 11 additions & 9 deletions console/django_scantron/api/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,16 @@ def validate(self, attrs):
globally_excluded_targets = attrs["globally_excluded_targets"]

target_extractor = extract_targets.TargetExtractor(
targets_string=globally_excluded_targets, private_ips_allowed=True, sort_targets=True
targets_string=globally_excluded_targets, sort_targets=True
)
targets_dict = target_extractor.targets_dict

if targets_dict["invalid_targets"]:
invalid_targets = ",".join(targets_dict["invalid_targets"])
raise serializers.ValidationError(f"Invalid globally excluded targets provided: {invalid_targets}")

attrs["globally_excluded_targets"] = targets_dict["as_nmap"]

return attrs

class Meta:
Expand Down Expand Up @@ -87,36 +89,36 @@ def validate(self, attrs):
if "targets" in attrs:
targets = attrs["targets"]

target_extractor = extract_targets.TargetExtractor(
targets_string=targets, private_ips_allowed=True, sort_targets=True
)
target_extractor = extract_targets.TargetExtractor(targets_string=targets, sort_targets=True)
targets_dict = target_extractor.targets_dict

if targets_dict["invalid_targets"]:
invalid_targets = ",".join(targets_dict["invalid_targets"])
raise serializers.ValidationError(f"Invalid targets provided: {invalid_targets}")

attrs["targets"] = targets_dict["as_nmap"]

# Excluded targets
if "excluded_targets" in attrs:
excluded_targets = attrs["excluded_targets"]

target_extractor = extract_targets.TargetExtractor(
targets_string=excluded_targets, private_ips_allowed=True, sort_targets=True
)
target_extractor = extract_targets.TargetExtractor(targets_string=excluded_targets, sort_targets=True)
targets_dict = target_extractor.targets_dict

if targets_dict["invalid_targets"]:
invalid_targets = ",".join(targets_dict["invalid_targets"])
raise serializers.ValidationError(f"Invalid excluded targets provided: {invalid_targets}")

attrs["excluded_targets"] = targets_dict["as_nmap"]

# Email scan alerts and email address.
if ("email_scan_alerts" in attrs) and ("email_alert_addresses" in attrs):

email_scan_alerts = attrs["email_scan_alerts"]
email_alert_addresses = attrs["email_alert_addresses"]

if email_scan_alerts and not email_alert_addresses:
raise serializers.ValidationError(f"Provide an email address if enabling 'Email scan alerts'")
raise serializers.ValidationError("Provide an email address if enabling 'Email scan alerts'")

# Check for valid email addresseses string.
if "email_alert_addresses" in attrs:
Expand All @@ -134,7 +136,7 @@ def validate(self, attrs):
email_scan_diff_addresses = attrs["email_scan_diff_addresses"]

if email_scan_diff and not email_scan_diff_addresses:
raise serializers.ValidationError(f"Provide an email address if enabling 'Email nmap scan diff'")
raise serializers.ValidationError("Provide an email address if enabling 'Email nmap scan diff'")

# Check for valid email addresseses string.
if "email_scan_diff_addresses" in attrs:
Expand Down
10 changes: 3 additions & 7 deletions console/django_scantron/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def clean(self):

# Globally excluded targets.
target_extractor = extract_targets.TargetExtractor(
targets_string=self.globally_excluded_targets, private_ips_allowed=True, sort_targets=True
targets_string=self.globally_excluded_targets, sort_targets=True
)
targets_dict = target_extractor.targets_dict

Expand Down Expand Up @@ -225,9 +225,7 @@ def clean(self):
raise ValidationError("Select a single scan engine or scan engine pool.")

# Targets
target_extractor = extract_targets.TargetExtractor(
targets_string=self.targets, private_ips_allowed=True, sort_targets=True
)
target_extractor = extract_targets.TargetExtractor(targets_string=self.targets, sort_targets=True)
targets_dict = target_extractor.targets_dict

if targets_dict["invalid_targets"]:
Expand All @@ -237,9 +235,7 @@ def clean(self):
self.targets = targets_dict["as_nmap"]

# Excluded targets
target_extractor = extract_targets.TargetExtractor(
targets_string=self.excluded_targets, private_ips_allowed=True, sort_targets=True
)
target_extractor = extract_targets.TargetExtractor(targets_string=self.excluded_targets, sort_targets=True)
targets_dict = target_extractor.targets_dict

if targets_dict["invalid_targets"]:
Expand Down
2 changes: 1 addition & 1 deletion console/email_validation_utils.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Email validation methods for models.py and DRF's serializers.py. Not kept in utility.py because of Django project
Email validation methods for models.py and DRF's serializers.py. Not kept in utility.py because of Django project
loading issues.
"""
# Standard Python libraries.
Expand Down
Loading

0 comments on commit 8780362

Please sign in to comment.