-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added ability to query Hydra * Added new tables to the database to facilitate the new ability to pull Hydra information into the database. Can also be supplemented with wrappers you could write to ingest enumerated services from tools like nmap, masscan, etc. * New functions added to Database to search for ports and neatly return them
- Loading branch information
Showing
25 changed files
with
885 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[flake8] | ||
max-line-length=119 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ on: | |
push: | ||
branches: | ||
- main | ||
- wip-hydra | ||
pull_request: | ||
|
||
jobs: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
#!/bin/bash | ||
|
||
flake8 src test live-tests | ||
coverage run --source=src --omit=src/synack/db/alembic/env.py,src/synack/db/alembic/versions/649443e08834_initial.py -m unittest discover test | ||
coverage run --source=src --omit=src/synack/db/alembic/env.py,src/synack/db/alembic/versions/*.py -m unittest discover test | ||
coverage report | egrep -v "^[^T].*100%" | ||
coverage html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
# Hydra | ||
|
||
## hydra.get_hydra(page, max_page, update_db, **kwargs) | ||
|
||
> Returns information from Synack Hydra Service | ||
> | ||
> | Arguments | Type | Description | ||
> | --- | --- | --- | ||
> | `page` | int | Page of the Hydra Service to start on (Default: 1) | ||
> | `max_page` | int | Highest page that should be queried (Default: 5) | ||
> | `update_db` | bool | Store the results in the database | ||
> | ||
>> Examples | ||
>> ```python3 | ||
>> >>> h.hydra.get_hydra(codename='SLEEPYPUPPY') | ||
>> [{'host_plugins': {}, 'ip': '1.2.3.4', 'last_changed_dt': '2022-01-01T01:02:03Z', ... }, ... ] | ||
>> >>> h.hydra.get_hydra(codename='SLEEPYPUPPY', page=3, max_page=5, update_db=False) | ||
>> [{'host_plugins': {}, 'ip': '3.4.5.6', 'last_changed_dt': '2022-01-01T01:02:03Z', ... }, ... ] | ||
>> ``` | ||
## hydra.build_db_input() | ||
> Builds a list of ports ready to be ingested by the Database from Hydra output | ||
> | ||
>> Examples | ||
>> ```python3 | ||
>> >>> h.hydra.build_db_input(h.hydra.get_hydra(codename='SLEEPYPUPPY', update_db=False)) | ||
>> [ | ||
>> { | ||
>> 'ip': '1.2.3.4', 'source': 'hydra', 'target': '123hg912', | ||
>> 'ports': [ | ||
>> { 'open': True, 'port': '443', 'protocol': 'tcp', 'screenshot_url': '', 'service': 'https - Wordpress', 'updated': 1654840021 }, | ||
>> ... | ||
>> ] | ||
>> }, | ||
>> ... | ||
>> ] | ||
>> ``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/synack/db/alembic/versions/deb7dd07212c_added_ip_port_tables.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
"""Added IP/Port tables | ||
Revision ID: deb7dd07212c | ||
Revises: 649443e08834 | ||
Create Date: 2022-05-23 00:26:08.257745 | ||
""" | ||
from alembic import op | ||
import sqlalchemy as sa | ||
|
||
|
||
# revision identifiers, used by Alembic. | ||
revision = 'deb7dd07212c' | ||
down_revision = '649443e08834' | ||
branch_labels = None | ||
depends_on = None | ||
|
||
|
||
def upgrade(): | ||
op.create_table('ips', | ||
sa.Column('id', sa.Integer, primary_key=True), | ||
sa.Column('ip', sa.VARCHAR(40)), | ||
sa.Column('target', sa.VARCHAR(20), sa.ForeignKey('targets.slug'))) | ||
op.create_table('ports', | ||
sa.Column('id', sa.INTEGER, autoincrement=True, primary_key=True), | ||
sa.Column('ip', sa.VARCHAR(40), sa.ForeignKey('ips.id')), | ||
sa.Column('port', sa.INTEGER), | ||
sa.Column('protocol', sa.VARCHAR(10)), | ||
sa.Column('source', sa.VARCHAR(50)), | ||
sa.Column('open', sa.BOOLEAN, server_default='f'), | ||
sa.Column('service', sa.VARCHAR(200), server_default=''), | ||
sa.Column('updated', sa.INTEGER, server_default='0'), | ||
sa.Column('url', sa.VARCHAR(200), server_default=''), | ||
sa.Column('screenshot_url', sa.VARCHAR(1000), server_default='')) | ||
|
||
|
||
def downgrade(): | ||
op.drop_table('ips') | ||
op.drop_table('ports') |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
"""db/models/ip.py | ||
Database Model for the IP item | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from sqlalchemy.orm import declarative_base | ||
from .target import Target | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class IP(Base): | ||
__tablename__ = 'ips' | ||
id = sa.Column(sa.Integer, autoincrement=True, primary_key=True) | ||
ip = sa.Column(sa.VARCHAR(40)) | ||
target = sa.Column(sa.VARCHAR(20), sa.ForeignKey(Target.slug)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
"""db/models/port.py | ||
Database Model for the Port item | ||
""" | ||
|
||
import sqlalchemy as sa | ||
from sqlalchemy.orm import declarative_base | ||
from .ip import IP | ||
|
||
Base = declarative_base() | ||
|
||
|
||
class Port(Base): | ||
__tablename__ = 'ports' | ||
id = sa.Column(sa.INTEGER, autoincrement=True, primary_key=True) | ||
ip = sa.Column(sa.VARCHAR(40), sa.ForeignKey(IP.id)) | ||
port = sa.Column(sa.INTEGER) | ||
protocol = sa.Column(sa.VARCHAR(10)) | ||
source = sa.Column(sa.VARCHAR(50)) | ||
open = sa.Column(sa.BOOLEAN, default=False) | ||
service = sa.Column(sa.VARCHAR(200), default="") | ||
updated = sa.Column(sa.INTEGER, default=0) | ||
url = sa.Column(sa.VARCHAR(200), default="") | ||
screenshot_url = sa.Column(sa.VARCHAR(1000), default="") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.