Db

This plugin deals with interacting with the database.

This plugin is a little different in most in that it has a couple functions which deal with database queries, in addition to many properties. Some properties are Read-Only, while others can be Set. Additionally, some properties can be overridden by the State, which allows you to change the way one Handler instance runs without affecting others.

PropertyRead-OnlyState OverrideDescription
api_tokenNoNoSynack Access Token used to authenticate requests
categoriesYesNoAll cached Categories
debugNoYesChanges the verbosity of some actions, such as network requests
emailNoYesThe email used to log into Synack
http_proxyNoYesThe http web proxy (Burp, etc.) to use for requests
https_proxyNoYesThe https web proxy (Burp, etc.) to use for requests
ipsYesNoAll cached IPs
notifications_tokenNoNoSynack Notifications Token used to authenticate requests
otp_secretNoYesSynack OTP Secret
passwordNoYesThe password used to log into Synack
portsYesNoAll cached Ports
proxiesYesYesA dict built from http_proxy and https_proxy
scratchspace_dirNoYesThe path to a directory where your working files (scopes, scans, etc.) are stored
slack_urlNoYesThe Slack API URL used for Notifications
smtp_email_fromNoYesEmail Source for SMTP Notifications
smtp_email_toNoYesEmail Destination for SMTP Notifications
smtp_passwordNoYesPassword to use for SMTP Server Auth
smtp_portNoYesPort of SMTP Server (Ex: 465)
smtp_serverNoYesURL of SMTP Server (Ex: smtp.gmail.com)
smtp_starttlsNoYesBoolean to determine whether TLS is used for SMTP
smtp_usernameNoYesUsername to use for SMTP Server Auth
targetsYesNoAll cached Targets
template_dirNoYesThe path to a directory where your templates are stored
use_proxiesNoYesChanges whether or not http_proxy and https_proxies are used
user_idNoNoYour Synack User ID used for requests

db.add_categories(categories)

Add Target Categories from the Synack API to the Database This is most often used with the targets.get_assessments() function so that you are only returned information about Categories you have access to.

ArgumentTypeDescription
categorieslistA list of Category dictionaries returned from the Synack API

Examples

>>> h.db.add_categories([{...}, {...}, {...}])

db.add_ips(results, session=None)

Add IP Addresses to the database

ArgumentTypeDescription
resultslist(dict)A list of dictionaries containing ip addresses and target slugs
sessionsqlalchemy.orm.sessionmaker()A database session. This function is often used with db.add_ports() and can have a session passed into it

Examples

>>> h.db.add_ips([{'ip': '1.1.1.1', 'target': '230h94ei'}, ...])

db.add_organizations(targets, session)

Add Organizations from the Synack API to the Database

ArgumentTypeDescription
targetslistA list of Target dictionaries returned from the Synack API
sessionsqlalchemy.orm.sessionmaker()A database session. This function is most often used with db.add_targets() and I was having issues getting it to work when it would create a new session

Examples

>>> h.db.add_organizations([{...}, {...}, {...}])

db.add_ports(results)

Add port results to the database

ArgumentsTypeDescription
resultslist(dict)A list of dictionaries containing results from some scan, Hydra, etc.

Examples

>>> results = [
...     {
...         "ip": "1.1.1.1",
...         "target": "7gh33tjf72",
...         "source": "nmap",
...         "ports": [
...             {
...                 "port": "443",
...                 "protocol": "tcp",
...                 "service": "Super Apache NGINX Deluxe",
...                 "screenshot_url": "http://127.0.0.1/h3298h23.png",
...                 "url": "http://bubba.net",
...                 "open": True,
...                 "updated": 1654969137
...
...             },
...             {
...                 "port": "53",
...                 "protocol": "udp",
...                 "service": "DNS"
...             }
...         ]
...     }
... ]
>>> h.db.add_ports(results)

db.add_targets(targets)

Adds Target from the Synack API to the Database

ArgumentTypeDescription
targetslist(dict)A list of Target dictionaties returned from the Synack API

Examples

>>> h.db.add_targets([{...}, {...}, {...}])

db.add_urls(results)

Add urls results to the database

ArgumentsTypeDescription
resultslist(dict)A list of dictionaries containing results from some scan, Hydra, etc.

Examples

>>> results = [
...     {
...         "ip": "1.1.1.1",
...         "target": "7gh33tjf72",
...         "urls": [
...             {
...                 "url": "https://www.google.com",
...                 "screenshot_url": "https://imgur.com/2uregtu",
...             },
...             {
...                 "url": "https://www.ebay.com",
...                 "screenshot_url": "file:///tmp/948grt.png",
...             }
...         ]
...     }
... ]
>>> h.db.add_urls(results)

db.find_ips(ip, **kwargs)

Filters through all the ips to return ones which match a given criteria

ArgumentTypeDescription
ipstrIP Address to search for
kwargskwargsAny attribute of the Target Database Model (codename, slug, is_active, etc.)

Examples

>>> h.db.find_ips(codename="SLEEPYPUPPY")
[{'ip': '1.1.1.1, 'target': '12398h21'}, ... ]

db.find_ports(port, protocol, source, ip, **kwargs)

Filters through all the ports to return ones which match a given criteria

ArgumentTypeDescription
portintPort number to search for (443, 80, 25, etc.)
protocolstrProtocol to search for (tcp, udp, etc.)
sourcestrSource to search for (hydra, nmap, etc.)
ipstrIP Address to search for
kwargskwargsAny attribute of the Target Database Model (codename, slug, is_active, etc.)

Examples

>>> h.db.find_ports(codename="SLEEPYPUPPY")
[
  {
    'ip': '1.2.3.4', 'source': 'hydra', 'target': '123hg912',
      'ports': [
        { 'open': True, 'port': '443', 'protocol': 'tcp', 'service': 'https - Wordpress', 'updated': 1654840021 },
        ...
      ]
  },
  ...
]

db.find_targets(**kwargs)

Filters through all the targets to return ones which match a given criteria

ArgumentTypeDescription
kwargskwargsAny attribute of the Target Database Model (codename, slug, is_active, etc.)

Examples

>>> h.db.find_targets(codename="SLEEPYPUPPY")
[<class 'synack.db.models.Target'>, ...]

db.find_urls(url=None, ip=None, **kwargs)

Filters through all the ports to return ones which match a given criteria

ArgumentTypeDescription
urlstrUrl hosting a service on the IP
ipstrIP Address to search for
kwargskwargsAny attribute of the Target Database Model (codename, slug, is_active, etc.)

Examples

>>> h.db.find_ports(codename="SLEEPYPUPPY")
[
  {
    'ip': '1.2.3.4',
    'target': '123hg912',
    'ports': [
      {  
        'url': 'https://www.google.com',
        'screenshot_url': 'file:///tmp/2948geybu24.png'
      },
      ...
    ]
  },
  ...
]

db.get_config(name)

Returns a configuration from the Database.

ArgumentTypeDescription
namestrThe desired config to pull. If none provided, the entire config object will return.

Examples

>>> h.db.get_config('api_token')
'reuif...oetuhhj'
>>> g.db.get_config('user_id')
'heutih9'

db.remove_targets(**kwargs)

Remove targets from the Database based on criteria. If no criteria is provided, all entries are deleted

ArgumentTypeDescription
kwargskwargsCriteria by which to find Targets for deletion (codename, slug, etc.)

Examples

>>> h.db.remove_targets(codename='SLUGISHPARROT')

db.set_config(name, value)

Permanently sets a configuration in the Database

ArgumentTypeDescription
namestrName of the config to set
value?Value to set the config to

Examples

>>> h.db.set_config('email', '1@2.com')
>>> h.db.set_config('password', 'password1234')

db.set_migration()

Migrates the local database to include the newest changes. This may need to be run manually when SynackAPI is updated until I can figure out a better way to have it run automatically.

Examples

>>> h.db.set_migration()