Skip to content

Commit b396985

Browse files
Merge pull request #10 from MislavReversingLabs/main
Add directory scanning
2 parents d8e57f6 + e836b31 commit b396985

File tree

3 files changed

+237
-0
lines changed

3 files changed

+237
-0
lines changed

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
credentials.json
2+
ticloud_credentials.json
3+
deepscan_credentials.json
4+
a1000_credentials.json
5+
Scenarios and Workflows/credentials.json
6+
TitaniumCloud/ticloud_credentials.json
7+
Cloud Deep Scan/deepscan_credentials.json
8+
A1000/a1000_credentials.json
9+
.idea

Scenarios and Workflows/README.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Scenarios and Workflows
2+
3+
This directory contains useful examples of analysis workflows and examples.
4+
In order to see how to put ReversingLabs SDK functionalities to good use in real-life scenarios, follow this readme and choose a desired notebook.
5+
6+
7+
### Using the notebooks
8+
Each notebook in this directory contains instructions and code snippets gathered around a certain type of usecase, analysis scenario or workflow.
9+
To use a selected notebook, open it and run each code snippet one by one. See the following authentication instructions to learn how to store and use your ReversingLabs credentials.
10+
11+
12+
### Authentication
13+
Since this directory, at some point, uses all ReversingLabs SDK modules, the `credentials.json` file needs to contain credentials for all of them.
14+
- TitaniumCloud uses a **username and password** pair (**basic authentication**).
15+
- A1000 uses a **token**.
16+
- TitaniumScale uses a **token**.
17+
18+
To obtain the required credentials, visit https://www.reversinglabs.com
19+
Each username can have a certain number of roles for API-s assigned to it. In case your username does not have the required role for your desired action, you will receive an error stating so.
20+
21+
#### Storing and using the credentials
22+
We will store the credentials in the `credentials.json` file and then load them in our code.
23+
24+
1. Create a JSON file named `credentials.json` in this current folder.
25+
2. Create the following data in that file and replace the placeholder values with your actual username and password:
26+
```json
27+
{
28+
"ticloud": {
29+
"username": "your_actual_username",
30+
"password": "your_actual_password"
31+
},
32+
"a1000": {
33+
"a1000_url": "a1000_url",
34+
"token": "your_actual_token"
35+
},
36+
"tiscale": {
37+
"tiscale_url": "tiscale_url",
38+
"token": "your_actual_token"
39+
}
40+
}
41+
```
42+
3. Save the file.
43+
44+
**NOTE:** The `credentials.json` file must have this exact structure to work.
45+
46+
Instead of doing this step and loading the credentials from the file,
47+
you can paste your credentials directly into the Python code everytime you create an API object.
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "markdown",
5+
"source": [
6+
"# Directory Scanning\n",
7+
"This notebook contains and example of how to use the ReversingLabs SDK to **collect files from a local directory and send them for analysis on TitaniumCloud and A1000**."
8+
],
9+
"metadata": {
10+
"collapsed": false
11+
},
12+
"id": "b8d2177c5214b66a"
13+
},
14+
{
15+
"cell_type": "markdown",
16+
"source": [
17+
"### Used TitaniumCloud classes\n",
18+
"- **FileUpload** (*TCA-0202-0203 - File Upload*)\n",
19+
"\n",
20+
"### Used A1000 functions\n",
21+
"- **upload_sample_from_path**\n",
22+
"\n",
23+
"### Credentials\n",
24+
"Credentials are loaded from a local file instead of being written here in plain text.\n",
25+
"To learn how to creat the credentials file, see the **Storing and using the credentials** section in the [README file](./README.md)"
26+
],
27+
"metadata": {
28+
"collapsed": false
29+
},
30+
"id": "3c66cec58fcbe655"
31+
},
32+
{
33+
"cell_type": "markdown",
34+
"source": [
35+
"### 1. Scanning the files with TitaniumCloud\n",
36+
"To collect files from a local directory and send them for analysis on TitaniumCloud, see the following code example. "
37+
],
38+
"metadata": {
39+
"collapsed": false
40+
},
41+
"id": "67ada420ce3509a"
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": null,
46+
"outputs": [],
47+
"source": [
48+
"import json\n",
49+
"import os\n",
50+
"from ReversingLabs.SDK.ticloud import FileUpload\n",
51+
"\n",
52+
"# Linux and Unix systems - Edit before use\n",
53+
"FOLDER_PATH_LINUX = \"/full/path/to/folder\"\n",
54+
"\n",
55+
"# Windows systems - Edit before use\n",
56+
"FOLDER_PATH_WINDOWS = \"C:\\\\full\\\\path\\\\to\\\\folder\"\n",
57+
"\n",
58+
"# Change this so the FOLDER_PATH variable fits your local system\n",
59+
"FOLDER_PATH = FOLDER_PATH_LINUX\n",
60+
"\n",
61+
"CREDENTIALS = json.load(open(\"credentials.json\"))\n",
62+
"USERNAME = CREDENTIALS.get(\"ticloud\").get(\"username\")\n",
63+
"PASSWORD = CREDENTIALS.get(\"ticloud\").get(\"password\")\n",
64+
"\n",
65+
"\n",
66+
"file_upload = FileUpload(\n",
67+
" host=\"https://data.reversinglabs.com\",\n",
68+
" username=USERNAME,\n",
69+
" password=PASSWORD\n",
70+
")\n",
71+
"\n",
72+
"# Files that should not be analyzed can be added to this list\n",
73+
"skip_files = [\"file_name_1\", \"file_name_2\"]\n",
74+
"\n",
75+
"\n",
76+
"for file_name in os.listdir(FOLDER_PATH):\n",
77+
" if file_name in skip_files:\n",
78+
" continue\n",
79+
" \n",
80+
" file_path = os.path.join(FOLDER_PATH, file_name)\n",
81+
" \n",
82+
" try:\n",
83+
" file_upload.upload_sample_from_path(file_path=file_path)\n",
84+
" \n",
85+
" except Exception as e:\n",
86+
" if hasattr(e, \"response_object\"):\n",
87+
" raise Exception(e.response_object.content)\n",
88+
" \n",
89+
" raise \n"
90+
],
91+
"metadata": {
92+
"collapsed": false
93+
},
94+
"id": "9c39940f6b968b5"
95+
},
96+
{
97+
"cell_type": "markdown",
98+
"source": [
99+
"### 2. Scanning the files with A1000\n",
100+
"To collect files from a local directory and send them for analysis on A1000, see the following code example."
101+
],
102+
"metadata": {
103+
"collapsed": false
104+
},
105+
"id": "987943a79bf60f06"
106+
},
107+
{
108+
"cell_type": "code",
109+
"execution_count": null,
110+
"outputs": [],
111+
"source": [
112+
"import json\n",
113+
"import os\n",
114+
"from ReversingLabs.SDK.a1000 import A1000\n",
115+
"\n",
116+
"# Linux and Unix systems - Edit before use\n",
117+
"FOLDER_PATH_LINUX = \"/full/path/to/folder\"\n",
118+
"\n",
119+
"# Windows systems - Edit before use\n",
120+
"FOLDER_PATH_WINDOWS = \"C:\\\\full\\\\path\\\\to\\\\folder\"\n",
121+
"\n",
122+
"# Change this so the FOLDER_PATH variable fits your local system\n",
123+
"FOLDER_PATH = FOLDER_PATH_LINUX\n",
124+
"\n",
125+
"CREDENTIALS = json.load(open(\"credentials.json\"))\n",
126+
"HOST = CREDENTIALS.get(\"a1000\").get(\"a1000_url\")\n",
127+
"TOKEN = CREDENTIALS.get(\"a1000\").get(\"token\")\n",
128+
"\n",
129+
"# Set the verify parameter to False if your A1000 instance doesn't have a valid CA certificate\n",
130+
"a1000 = A1000(\n",
131+
" host=HOST,\n",
132+
" token=TOKEN,\n",
133+
" verify=True\n",
134+
")\n",
135+
"\n",
136+
"# Files that should not be analyzed can be added to this list\n",
137+
"skip_files = [\"file_name_1\", \"file_name_2\"]\n",
138+
"\n",
139+
"for file_name in os.listdir(FOLDER_PATH):\n",
140+
" if file_name in skip_files:\n",
141+
" continue\n",
142+
" \n",
143+
" file_path = os.path.join(FOLDER_PATH, file_name)\n",
144+
" \n",
145+
" try:\n",
146+
" a1000.upload_sample_from_path(file_path=file_path)\n",
147+
" \n",
148+
" except Exception as e:\n",
149+
" if hasattr(e, \"response_object\"):\n",
150+
" raise Exception(e.response_object.content)\n",
151+
" \n",
152+
" raise \n"
153+
],
154+
"metadata": {
155+
"collapsed": false
156+
},
157+
"id": "6b6774a15517020b"
158+
}
159+
],
160+
"metadata": {
161+
"kernelspec": {
162+
"display_name": "Python 3",
163+
"language": "python",
164+
"name": "python3"
165+
},
166+
"language_info": {
167+
"codemirror_mode": {
168+
"name": "ipython",
169+
"version": 2
170+
},
171+
"file_extension": ".py",
172+
"mimetype": "text/x-python",
173+
"name": "python",
174+
"nbconvert_exporter": "python",
175+
"pygments_lexer": "ipython2",
176+
"version": "2.7.6"
177+
}
178+
},
179+
"nbformat": 4,
180+
"nbformat_minor": 5
181+
}

0 commit comments

Comments
 (0)