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

Fixed offset bug, and add global, desc flags #21

Merged
merged 1 commit into from
Jan 13, 2025
Merged
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
9 changes: 6 additions & 3 deletions praetorian_cli/handlers/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
@click.option('-t', '--term', help='Enter a search term', required=True)
@click.option('-c', '--count', is_flag=True, default=False, help='Return statistics on search')
@click.option('-d', '--details', is_flag=True, default=False, help='Show detailed information')
def search(chariot, term, count, details, offset, page):
@click.option('-desc', '--desc', is_flag=True, default=False, help='Return data in descending order')
@click.option('-g', '--global', 'global_', is_flag=True, default=False, help='Use the global data set')
def search(chariot, term, count, details, offset, page, desc, global_):
""" Query Chariot for matches or counts using the search syntax

\b
Expand Down Expand Up @@ -53,9 +55,10 @@ def search(chariot, term, count, details, offset, page):
- praetorian chariot search --term "status:OH"
- praetorian chariot search --term "status:OH" --details --page all
- praetorian chariot search --term "#asset#www.example.com"
- praetorian chariot search --term "dns:https://github.com/praetorian-inc/"
- praetorian chariot search --term "dns:https://github.com/praetorian-inc/" --desc
"""
if count:
print_json(chariot.search.count(term))
else:
render_list_results(chariot.search.by_term(term, offset, pagination_size(page)), details)
render_list_results(chariot.search.by_term(term, offset, pagination_size(page), desc=desc, global_=global_),
details)
2 changes: 1 addition & 1 deletion praetorian_cli/handlers/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def render_list_results(list_results, details):
def render_offset(offset):
if offset:
click.echo('There are more results. Add the following argument to the command to view them:')
click.echo(f'--offset "{json.dumps(offset)}"')
click.echo(f'--offset {json.dumps(offset)}')


def pagination_size(page):
Expand Down
5 changes: 3 additions & 2 deletions praetorian_cli/sdk/chariot.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,13 @@ def my(self, params: dict, pages=1) -> {}:
process_failure(resp)
resp = resp.json()
extend(final_resp, resp)

if 'offset' not in resp:
break

params['offset'] = json.dumps(resp['offset'])

if 'offset' in resp:
final_resp['offset'] = json.dumps(resp['offset'])

return final_resp

def post(self, type: str, params):
Expand Down
6 changes: 5 additions & 1 deletion praetorian_cli/sdk/entities/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,16 @@ def by_ip(self, ip_prefix, offset=None, pages=10000) -> tuple:
def by_dns(self, dns_prefix, offset=None, pages=10000) -> tuple:
return self.by_term(f'dns:{dns_prefix}', offset, pages)

def by_term(self, search_term, offset=None, pages=1000, exact=False) -> tuple:
def by_term(self, search_term, offset=None, pages=1000, exact=False, desc=False, global_=False) -> tuple:
params = dict(key=search_term)
if offset:
params = params | dict(offset=offset)
if exact:
params = params | dict(exact='true')
if desc:
params = params | dict(desc='true')
if global_:
params = params | {'global': 'true'}

# extract all the different types of entities in the search results into a
# flattened list of `hits`
Expand Down
17 changes: 9 additions & 8 deletions praetorian_cli/sdk/model/globals.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,29 +83,32 @@ class AddRisk(Enum):


CAPABILITIES = (
'reverse-whois',
'csp-mine',
'tls-mine',
'azuread-discovery',
'edgar',
'cidr',
'favicon',
'reverse-csp',
'builtwith',
'nuclei',
'whois',
'subdomain',
'csp-mine',
'tls-mine',
'portscan',
'github',
'github-repository',
'secrets',
'amazon',
'bitbucket',
'azure',
'gcp',
'ns1',
'cloudflare',
'gato',
'crowdstrike',
'crawler',
'gitlab',
'ssh',
'azuread-discovery',
'edgar',
'nessus',
'nessus-import',
'insightvm',
Expand All @@ -114,11 +117,9 @@ class AddRisk(Enum):
'qualys-import',
'burp-enterprise',
'ip',
'cidr',
'website',
'reverse-whois',
'digitalocean',
'burp-internal',
'seed-import',
'builtwith'
'tenablevm',
)
3 changes: 3 additions & 0 deletions praetorian_cli/sdk/test/test_z_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ def test_search_cli(self):
self.verify(f'add asset -n {o.asset_name} -d {o.asset_dns}')

self.verify(f'search -t "#asset#{o.asset_dns}" -p all', [o.asset_key])
self.verify(f'search -t "#asset#{o.asset_dns}" -p all --desc', [o.asset_key])
self.verify(f'search -t "#asset#{o.asset_dns}" -p all -g')

self.verify(f'search -t "#asset#{o.asset_dns}" -d -p all', [o.asset_key, '"key"', '"data"'])
self.verify(f'search -t "#asset#{o.asset_dns}" -c -p all', ['"A": 1'])

Expand Down