Skip to content

Instantly share code, notes, and snippets.

@fr0gger
Last active October 30, 2024 00:02
Show Gist options
  • Save fr0gger/99b1dde4abcc505aafd53257402eac26 to your computer and use it in GitHub Desktop.
Save fr0gger/99b1dde4abcc505aafd53257402eac26 to your computer and use it in GitHub Desktop.
Simple script to upload a sample to Any.Run and retrieve the report
import requests
import time
import sys
import os
from tqdm import tqdm
# Specify your API KEY after API-Key
API_KEY = "API-Key "
BASE_URL = "https://api.any.run/v1"
HEADERS = {"Authorization": API_KEY}
def submit_sample(file_path):
url = f"{BASE_URL}/analysis/"
try:
with open(file_path, 'rb') as f:
files = {'file': f}
data = {
'env_os': 'windows',
'env_bitness': 64,
'env_version': '10',
'env_type': 'complete'
}
response = requests.post(url, headers=HEADERS, files=files, data=data)
response.raise_for_status()
task_id = response.json()['data']['taskid']
print(f"Task submitted. Task ID: {task_id}")
return task_id
except Exception as e:
print(f"Error : {e}")
return None
def get_report(task_id):
url = f"{BASE_URL}/analysis/{task_id}"
while True:
response = requests.get(url, headers=HEADERS)
if response.status_code == 200:
data = response.json()
if data["error"]:
print("Error:", data["message"])
break
else:
print("Report data:", data["data"])
break
elif response.status_code == 404:
print("Waiting for the report to be ready...")
time.sleep(10)
else:
print(f"Error: {response.text}")
break
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python script.py <sample_file_path|task_id>")
sys.exit(1)
input_arg = sys.argv[1]
if os.path.isfile(input_arg):
task_id = submit_sample(input_arg)
if task_id:
get_report(task_id)
else:
print(f"Fetching report for Task ID: {input_arg}")
get_report(input_arg)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment