Skip to content
This repository has been archived by the owner on Apr 26, 2021. It is now read-only.

Commit

Permalink
keep track of the route that is taken in the end
Browse files Browse the repository at this point in the history
Based on the route we can determine whether it is possible to connect to
hosts on the internet during the analysis.
  • Loading branch information
jbremer committed Nov 21, 2015
1 parent f8a637e commit 4d0a3f6
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 2 deletions.
24 changes: 23 additions & 1 deletion lib/cuckoo/core/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

log = logging.getLogger(__name__)

SCHEMA_VERSION = "4a04f40d4ab4"
SCHEMA_VERSION = "1070cd314621"
TASK_PENDING = "pending"
TASK_RUNNING = "running"
TASK_COMPLETED = "completed"
Expand Down Expand Up @@ -277,6 +277,7 @@ class Task(Base):
nullable=False)
sample_id = Column(Integer, ForeignKey("samples.id"), nullable=True)
processing = Column(String(16), nullable=True)
route = Column(String(16), nullable=True)
sample = relationship("Sample", backref="tasks")
guest = relationship("Guest", uselist=False, backref="tasks", cascade="save-update, delete")
errors = relationship("Error", backref="tasks", cascade="save-update, delete")
Expand Down Expand Up @@ -521,6 +522,27 @@ def set_status(self, task_id, status):
finally:
session.close()

@classlock
def set_route(self, task_id, route):
"""Set the taken route of this task.
@param task_id: task identifier
@param route: route string
@return: operation status
"""
session = self.Session()
try:
row = session.query(Task).get(task_id)
if not row:
return

row.route = route
session.commit()
except SQLAlchemyError as e:
log.debug("Database error setting route: {0}".format(e))
session.rollback()
finally:
session.close()

@classlock
def fetch(self, lock=True, machine=""):
"""Fetches a task waiting to be processed and locks it for running.
Expand Down
5 changes: 4 additions & 1 deletion lib/cuckoo/core/scheduler.py
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ def route_network(self):

if route == "none":
self.interface = None
elif route == "internet":
elif route == "internet" and self.cfg.routing.internet != "none":
self.interface = self.cfg.routing.internet
elif route in vpns:
self.interface = vpns[route].interface
Expand All @@ -241,6 +241,9 @@ def route_network(self):
rooter("forward_enable", self.machine.interface,
self.interface, self.machine.ip)

# Propagate the taken route to the database.
self.db.set_route(self.task.id, route)

def unroute_network(self):
if self.interface:
rooter("forward_disable", self.machine.interface,
Expand Down
1 change: 1 addition & 0 deletions modules/processing/analysisinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,4 +71,5 @@ def run(self):
package=self.task["package"],
platform=self.task["platform"],
options=self.task["options"],
route=self.task["route"],
)
24 changes: 24 additions & 0 deletions utils/db_migration/versions/from_1_2_to_2_0-taken-route.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
# Copyright (C) 2010-2015 Cuckoo Foundation.
# This file is part of Cuckoo Sandbox - http://www.cuckoosandbox.org
# See the file 'docs/LICENSE' for copying permission.

"""taken route
Revision ID: 1070cd314621
Revises: 4a04f40d4ab4
Create Date: 2015-11-21 23:10:04.724813
"""

# revision identifiers, used by Alembic.
revision = "1070cd314621"
down_revision = "4a04f40d4ab4"

from alembic import op
import sqlalchemy as sa

def upgrade():
op.add_column("tasks", sa.Column("route", sa.String(length=16), nullable=True))

def downgrade():
op.drop_column("tasks", "route")

0 comments on commit 4d0a3f6

Please sign in to comment.