Skip to content

Commit

Permalink
update to latest version: v1.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
su-amaas authored and 830d953e committed Aug 22, 2024
1 parent 02a74a2 commit 2620040
Show file tree
Hide file tree
Showing 8 changed files with 75 additions and 35 deletions.
10 changes: 10 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,15 @@
# CHANGELOG

## 1.4.0 - 2024-08-21

* Update README.md
* Support digest calculation bypass

## 1.3.0 - 2024-08-20

* Update README.md
* Support CA cert import

## 1.2.0 - 2024-07-05

* Support verbose scan result
Expand Down
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ Creates a new instance of the grpc Channel, and provisions essential settings, i
| region | The region you obtained your api key. Value provided must be one of the Vision One regions, e.g. `us-east-1`, `eu-central-1`, `ap-northeast-1`, `ap-southeast-2`, `ap-southeast-1`, `ap-south-1`, etc. |
| api_key | Your own Vision One API Key. |
| enable_tls | Enable or disable TLS. TLS should always be enabled when connecting to the AMaaS server. For more information, see the 'Ensuring Secure Communication with TLS' section. |
| ca_cert | `Optional` CA certificate used to connect to AMaaS server. |
| ca_cert | `Optional` CA certificate used to connect to self hosted AMaaS server. |
**_Return_**
A grpc Channel instance
Expand All @@ -216,7 +216,7 @@ Creates a new instance of the grpc aio Channel, and provisions essential setting
| region | The region you obtained your api key. Value provided must be one of the Vision One regions, e.g. `us-east-1`, `eu-central-1`, `ap-northeast-1`, `ap-southeast-2`, `ap-southeast-1`, `ap-south-1`, etc. |
| api_key | Your own Vision One API Key. |
| enable_tls | Enable or disable TLS. TLS should always be enabled when connecting to the AMaaS server. For more information, see the 'Ensuring Secure Communication with TLS' section. |
| ca_cert | `Optional` CA certificate used to connect to AMaaS server. |
| ca_cert | `Optional` CA certificate used to connect to self hosted AMaaS server. |
**_Return_**
A grpc aio Channel instance
Expand All @@ -237,6 +237,7 @@ Scan a file for malware and retrieves response data from the API.
| pml | Enable PML (Predictive Machine Learning) Detection. |
| feedback | Enable SPN feedback for Predictive Machine Learning Detection |
| verbose | Enable log verbose mode |
| digest | Calculate digests for cache search and result lookup |
**_Return_**
String the scanned result in JSON format.
Expand All @@ -255,6 +256,7 @@ AsyncIO Scan a file for malware and retrieves response data from the API.
| pml | Enable PML (Predictive Machine Learning) Detection. |
| feedback | Enable SPN feedback for Predictive Machine Learning Detection |
| verbose | Enable log verbose mode |
| digest | Calculate digests for cache search and result lookup |
**_Return_**
String the scanned result in JSON format.
Expand Down
2 changes: 1 addition & 1 deletion VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.2.0
1.4.0
20 changes: 13 additions & 7 deletions amaas/grpc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,13 +122,19 @@ def quit(handle):


def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, identifier: str, tags: List[str],
pml: bool, feedback: bool, verbose: bool) -> str:
pml: bool, feedback: bool, verbose: bool, digest: bool) -> str:
_validate_tags(tags)
stub = scan_pb2_grpc.ScanStub(channel)
pipeline = _Pipeline()
stats = {}
result = None
bulk = True
file_sha1 = ""
file_sha256 = ""

if digest:
file_sha1 = "sha1:" + _digest_hex(data_reader, "sha1")
file_sha256 = "sha256:" + _digest_hex(data_reader, "sha256")

try:
metadata = (
Expand All @@ -143,8 +149,8 @@ def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, identifi
chunk=None,
trendx=pml,
tags=tags,
file_sha1="sha1:" + _digest_hex(data_reader, "sha1"),
file_sha256="sha256:" + _digest_hex(data_reader, "sha256"),
file_sha1=file_sha1,
file_sha256=file_sha256,
bulk=bulk,
spn_feedback=feedback,
verbose=verbose)
Expand Down Expand Up @@ -182,7 +188,7 @@ def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, identifi


def scan_file(channel: grpc.Channel, file_name: str, tags: List[str] = None,
pml: bool = False, feedback: bool = False, verbose: bool = False) -> str:
pml: bool = False, feedback: bool = False, verbose: bool = False, digest: bool = True) -> str:
try:
f = open(file_name, "rb")
fid = os.path.basename(file_name)
Expand All @@ -194,10 +200,10 @@ def scan_file(channel: grpc.Channel, file_name: str, tags: List[str] = None,
logger.debug("Permission error: " + str(err))
raise AMaasException(AMaasErrorCode.MSG_ID_ERR_FILE_NO_PERMISSION, file_name)

return _scan_data(channel, f, n, fid, tags, pml, feedback, verbose)
return _scan_data(channel, f, n, fid, tags, pml, feedback, verbose, digest)


def scan_buffer(channel: grpc.Channel, bytes_buffer: bytes, uid: str, tags: List[str] = None,
pml: bool = False, feedback: bool = False, verbose: bool = False) -> str:
pml: bool = False, feedback: bool = False, verbose: bool = False, digest: bool = True) -> str:
f = io.BytesIO(bytes_buffer)
return _scan_data(channel, f, len(bytes_buffer), uid, tags, pml, feedback, verbose)
return _scan_data(channel, f, len(bytes_buffer), uid, tags, pml, feedback, verbose, digest)
20 changes: 13 additions & 7 deletions amaas/grpc/aio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,18 @@ async def quit(handle):


async def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, identifier: str, tags: List[str],
pml: bool, feedback: bool, verbose: bool) -> str:
pml: bool, feedback: bool, verbose: bool, digest: bool) -> str:
_validate_tags(tags)
stub = scan_pb2_grpc.ScanStub(channel)
stats = {}
result = None
bulk = True
file_sha1 = ""
file_sha256 = ""

if digest:
file_sha1 = "sha1:" + _digest_hex(data_reader, "sha1")
file_sha256 = "sha256:" + _digest_hex(data_reader, "sha256")

try:
metadata = (
Expand All @@ -60,8 +66,8 @@ async def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, id
chunk=None,
tags=tags,
trendx=pml,
file_sha1="sha1:" + _digest_hex(data_reader, "sha1"),
file_sha256="sha256:" + _digest_hex(data_reader, "sha256"),
file_sha1=file_sha1,
file_sha256=file_sha256,
bulk=bulk,
spn_feedback=feedback,
verbose=verbose)
Expand Down Expand Up @@ -140,7 +146,7 @@ async def _scan_data(channel: grpc.Channel, data_reader: BinaryIO, size: int, id


async def scan_file(channel: grpc.Channel, file_name: str, tags: List[str] = None,
pml: bool = False, feedback: bool = False, verbose: bool = False) -> str:
pml: bool = False, feedback: bool = False, verbose: bool = False, digest: bool = True) -> str:
try:
f = open(file_name, "rb")
fid = os.path.basename(file_name)
Expand All @@ -151,10 +157,10 @@ async def scan_file(channel: grpc.Channel, file_name: str, tags: List[str] = Non
except (PermissionError, IOError) as err:
logger.debug("Permission error: " + str(err))
raise AMaasException(AMaasErrorCode.MSG_ID_ERR_FILE_NO_PERMISSION, file_name)
return await _scan_data(channel, f, n, fid, tags, pml, feedback, verbose)
return await _scan_data(channel, f, n, fid, tags, pml, feedback, verbose, digest)


async def scan_buffer(channel: grpc.Channel, bytes_buffer: bytes, uid: str, tags: List[str] = None,
pml: bool = False, feedback: bool = False, verbose: bool = False) -> str:
pml: bool = False, feedback: bool = False, verbose: bool = False, digest: bool = True) -> str:
f = io.BytesIO(bytes_buffer)
return await _scan_data(channel, f, len(bytes_buffer), uid, tags, pml, feedback, verbose)
return await _scan_data(channel, f, len(bytes_buffer), uid, tags, pml, feedback, verbose, digest)
22 changes: 13 additions & 9 deletions examples/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,19 @@ If you plan on using a Trend Vision One region, be sure to pass in region parame

3. Current Python examples support following command line arguments

| Command Line Arguments | Value | Optional |
|------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
| --region or -r | The region you obtained your API key. Value provided must be one of the Vision One regions, e.g. `us-east-1`, `eu-central-1`, `ap-southeast-1`, `ap-southeast-2`, `ap-northeast-1`, `ap-south-1` | Yes, either -r or -a |
| --addr or -a | Trend Vision One File Security server, such as: antimalware.__REGION__.cloudone.trendmicro.com:443 | Yes, either -r or -a |
| --api_key | Vision One API Key | No |
| --filename or -f | File to be scanned | No |
| --pml | Predictive Machine Learning | Yes |
| --tags or -t | List of tags | Yes |
| --verbose or -v | Log verbose mode | Yes |
| Command Line Arguments | Value | Optional |
|--------------------------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|----------------------|
| -f FILENAME, --filename FILENAME | File to be scanned | No |
| -a ADDR, --addr ADDR | Trend Vision One File Security server | Yes, either -r or -a |
| -r REGION, --region REGION | The region you obtained your API key. Value provided must be one of the Vision One regions, e.g. `us-east-1`, `eu-central-1`, `ap-southeast-1`, `ap-southeast-2`, `ap-northeast-1`, `ap-south-1` | Yes, either -r or -a |
| --api_key API_KEY | Vision One API Key | Yes |
| --tls, --no-tls | Enable or disable TLS | Yes |
| --ca_cert CA_CERT | CA certificate used to connect to self hosted AMaaS | Yes |
| --pml, --no-pml | Predictive Machine Learning | Yes |
| -t TAGS [TAGS ...], --tags TAGS [TAGS ...] | List of tags | Yes |
| --feedback, --no-feedback | Feedback for Predictive Machine Learning detection | Yes |
| -v, --verbose, --no-verbose | Log verbose mode | Yes |
| --digest, --no-digest | Calculate digests for cache search and result lookup | Yes |

4. Run one of the examples.

Expand Down
14 changes: 9 additions & 5 deletions examples/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,19 @@
parser.add_argument('--api_key', action='store',
help='api key for authentication')
parser.add_argument('--tls', action=argparse.BooleanOptionalAction, default=False,
help='enable TLS gRPC ')
help='enable/disable TLS gRPC ')
parser.add_argument('--ca_cert', action='store',
help='CA certificate')
parser.add_argument('--pml', action=argparse.BooleanOptionalAction, default=False,
help='enable predictive machine learning detection')
help='enable/disable predictive machine learning detection')
parser.add_argument('-t', '--tags', action='store', nargs='+',
help='list of tags')
parser.add_argument('--feedback', action=argparse.BooleanOptionalAction, default=False,
help='enable feedback for predictive machine learning detection')
help='enable/disable feedback for predictive machine learning detection')
parser.add_argument('-v', '--verbose', action=argparse.BooleanOptionalAction, default=False,
help='enable log verbose mode')
help='enable/disable log verbose mode')
parser.add_argument('--digest', action=argparse.BooleanOptionalAction, default=True,
help='enable/disable digest calculation')

args = parser.parse_args()

Expand All @@ -39,7 +41,9 @@
s = time.perf_counter()

try:
result = amaas.grpc.scan_file(handle, file_name=args.filename, pml=args.pml, tags=args.tags, feedback=args.feedback, verbose=args.verbose)
result = amaas.grpc.scan_file(
channel=handle, file_name=args.filename, pml=args.pml,
tags=args.tags, feedback=args.feedback, verbose=args.verbose, digest=args.digest)
elapsed = time.perf_counter() - s
print(f"scan executed in {elapsed:0.2f} seconds.")
print(result)
Expand Down
16 changes: 12 additions & 4 deletions examples/client_aio.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ async def main(args):

tasks = set()
for file_name in args.filename:
task = asyncio.create_task(amaas.grpc.aio.scan_file(handle, file_name=file_name, pml=args.pml, tags=args.tags, feedback=args.feedback))
task = asyncio.create_task(
amaas.grpc.aio.scan_file(
channel=handle, file_name=file_name, pml=args.pml,
tags=args.tags, feedback=args.feedback, verbose=args.verbose, digest=args.digest)
)
tasks.add(task)

s = time.perf_counter()
Expand Down Expand Up @@ -41,15 +45,19 @@ async def main(args):
parser.add_argument('--api_key', action='store',
help='api key for authentication')
parser.add_argument('--tls', action=argparse.BooleanOptionalAction, default=False,
help='enable TLS gRPC ')
help='enable/disable TLS gRPC ')
parser.add_argument('--ca_cert', action='store',
help='CA certificate')
parser.add_argument('--pml', action=argparse.BooleanOptionalAction, default=False,
help='enable predictive machine learning detection')
help='enable/disable predictive machine learning detection')
parser.add_argument('-t', '--tags', action='store', nargs='+',
help='list of tags')
parser.add_argument('--feedback', action=argparse.BooleanOptionalAction, default=False,
help='enable feedback for predictive machine learning detection')
help='enable/disable feedback for predictive machine learning detection')
parser.add_argument('-v', '--verbose', action=argparse.BooleanOptionalAction, default=False,
help='enable/disable log verbose mode')
parser.add_argument('--digest', action=argparse.BooleanOptionalAction, default=True,
help='enable/disable digest calculation')

arguments = parser.parse_args()

Expand Down

0 comments on commit 2620040

Please sign in to comment.