Skip to content
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
6 changes: 3 additions & 3 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "polyswarm"
version = "3.19.0"
version = "3.20.0"
description = "CLI for using the PolySwarm Customer APIs"
readme = "README.md"
authors = [{ name = "PolySwarm Developers", email = "info@polyswarm.io" }]
Expand All @@ -22,7 +22,7 @@ classifiers = [
]

dependencies = [
"polyswarm_api>=3.20.0",
"polyswarm_api>=3.21.0",
"click>=7.1",
"colorama>=0.4.6",
"click-log>=0.4.0",
Expand Down Expand Up @@ -51,7 +51,7 @@ include-package-data = true
where = ["src"]

[tool.bumpversion]
current_version = "3.19.0"
current_version = "3.20.0"
commit = true
tag = false
sign_tags = true
Expand Down
2 changes: 1 addition & 1 deletion src/polyswarm/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = '3.19.0'
__version__ = '3.20.0'
29 changes: 29 additions & 0 deletions src/polyswarm/client/sandbox.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,35 @@ def submit(ctx, provider_slug, artifact_id, vm_slug, internet_disabled):
output.sandbox_task(tasks)


@sandbox.command('hash', short_help='Submit by hash (sha256/sha1/md5) to be sandboxed.')
@click.argument('provider_slug', type=click.STRING)
@click.argument('hash_value', nargs=-1, required=True)
@click.option('-r', '--hash-file', help='File of hashes, one per line.', type=click.File('r'))
@click.option('--hash-type', help='Hash type [default:autodetect, sha256|sha1|md5].', default=None)
@click.option('--vm_slug', 'vm_slug', type=click.STRING)
@click.option('--internet-disabled', 'internet_disabled', type=click.BOOL, is_flag=True, default=False)
@click.pass_context
def hash_(ctx, provider_slug, hash_value, hash_file, hash_type, vm_slug, internet_disabled):
"""
Submit a sample to the sandbox by hash. Resolves the hash to its latest
known artifact instance and sandboxes that instance.
"""
api = ctx.obj['api']
output = ctx.obj['output']
hashes = utils.parse_hashes(hash_value, hash_file=hash_file)

instance_ids = []
for h in hashes:
instance = next(iter(api.search_hashes([h], hash_type=hash_type)), None)
if instance is None:
raise click.ClickException(f'No artifact instances found for hash {h}')
instance_ids.append(instance.id)

for task in api.sandbox_instances(
instance_ids, provider_slug=provider_slug, vm_slug=vm_slug, network_enabled=not internet_disabled):
output.sandbox_task(task)


@sandbox.command('file', short_help='Submit a local file to be sandboxed.')
@click.argument('provider', type=click.STRING)
@click.argument('path', type=click.Path(exists=True), required=True)
Expand Down
24 changes: 24 additions & 0 deletions src/polyswarm/formatters/hashes.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,18 @@ def _to_json(result):
def artifact_instance(self, result, timeout=False):
click.echo(result.sha1, file=self.out)

def historical_result(self, result):
if result.sha1:
click.echo(result.sha1, file=self.out)
else:
logger.warning('Could not render historical result as sha1, value is %s', result.sha1)

def live_result(self, result):
if result.sha1:
click.echo(result.sha1, file=self.out)
else:
logger.warning('Could not render live result as sha1, value is %s', result.sha1)

def metadata(self, result):
if result.sha1:
click.echo(result.sha1, file=self.out)
Expand All @@ -62,6 +74,18 @@ def _to_json(result):
def artifact_instance(self, result, timeout=False):
click.echo(result.md5, file=self.out)

def historical_result(self, result):
if result.md5:
click.echo(result.md5, file=self.out)
else:
logger.warning('Could not render historical result as md5, value is %s', result.md5)

def live_result(self, result):
if result.md5:
click.echo(result.md5, file=self.out)
else:
logger.warning('Could not render live result as md5, value is %s', result.md5)

def metadata(self, result):
if result.md5:
click.echo(result.md5, file=self.out)
Expand Down
8 changes: 8 additions & 0 deletions src/polyswarm/formatters/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,10 @@ def historical_result(self, result, write=True):
output.append(self._blue(f'Instance Id: {result.instance_id}'))
output.append(self._white(f'Created at: {result.created}'))
output.append(self._white(f'SHA256: {result.sha256}'))
if result.sha1:
output.append(self._white(f'SHA1: {result.sha1}'))
if result.md5:
output.append(self._white(f'MD5: {result.md5}'))
output.append(self._white(f'Rule: {result.rule_name}'))
if result.malware_family:
output.append(self._red(f'Malware Family: {result.malware_family}'))
Expand Down Expand Up @@ -201,6 +205,10 @@ def live_result(self, result, write=True):
output.append(self._blue(f'Instance Id: {result.instance_id}'))
output.append(self._white(f'Created at: {result.created}'))
output.append(self._white(f'SHA256: {result.sha256}'))
if result.sha1:
output.append(self._white(f'SHA1: {result.sha1}'))
if result.md5:
output.append(self._white(f'MD5: {result.md5}'))
output.append(self._white(f'Rule: {result.rule_name}'))
if result.malware_family:
output.append(self._red(f'Malware Family: {result.malware_family}'))
Expand Down