Skip to content

Commit 0ab2a64

Browse files
timezone support (kevoreilly#2873)
* timezone support * Update lib/cuckoo/core/database.py Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com> * Update test_analysis_manager.py --------- Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
1 parent 7be4637 commit 0ab2a64

File tree

3 files changed

+18
-37
lines changed

3 files changed

+18
-37
lines changed

conf/default/cuckoo.conf.default

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
# Ignore Signals, will quit CAPE inmediatelly instead wait jobs to finish
44
ignore_signals = yes
55

6+
# Specify the timezone for the system (e.g., UTC, Europe/Madrid, America/New_York).
7+
# Default is utc.
8+
timezone = utc
9+
610
# Which category of tasks do you want to analyze?
711
categories = static, pcap, url, file
812

lib/cuckoo/core/database.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,7 @@
1313
from contextlib import suppress
1414
from datetime import datetime, timedelta, timezone
1515
from typing import Any, List, Optional, Union, Tuple, Dict
16-
17-
18-
def _utcnow_naive():
19-
"""Returns the current time in UTC as a naive datetime object."""
20-
return datetime.now(timezone.utc).replace(tzinfo=None)
16+
import pytz
2117

2218

2319
# Sflock does a good filetype recon
@@ -26,7 +22,6 @@ def _utcnow_naive():
2622

2723
from lib.cuckoo.common.cape_utils import static_config_lookup, static_extraction
2824
from lib.cuckoo.common.colors import red
29-
from lib.cuckoo.common.config import Config
3025
from lib.cuckoo.common.constants import CUCKOO_ROOT
3126
from lib.cuckoo.common.demux import demux_sample
3227
from lib.cuckoo.common.exceptions import (
@@ -36,6 +31,7 @@ def _utcnow_naive():
3631
CuckooOperationalError,
3732
CuckooUnserviceableTaskError,
3833
)
34+
from lib.cuckoo.common.config import Config
3935
from lib.cuckoo.common.integrations.parse_pe import PortableExecutable
4036
from lib.cuckoo.common.objects import PCAP, URL, File, Static
4137
from lib.cuckoo.common.path_utils import path_delete, path_exists
@@ -81,6 +77,17 @@ def _utcnow_naive():
8177
except ImportError: # pragma: no cover
8278
raise CuckooDependencyError("Unable to import sqlalchemy (install with `poetry install`)")
8379

80+
cfg = Config("cuckoo")
81+
tz_name = cfg.cuckoo.get("timezone", "utc")
82+
83+
def _utcnow_naive():
84+
"""Returns the current time in the configured timezone as a naive datetime object."""
85+
try:
86+
tz = pytz.timezone(tz_name)
87+
except pytz.UnknownTimeZoneError:
88+
tz = timezone.utc
89+
return datetime.now(tz).replace(tzinfo=None)
90+
8491

8592
sandbox_packages = (
8693
"access",

tests/test_analysis_manager.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -108,37 +108,7 @@ class TestAnalysisManager:
108108
def test_init(self, task: Task):
109109
mgr = AnalysisManager(task=task)
110110

111-
assert mgr.cfg.cuckoo == {
112-
"allow_static": False,
113-
"categories": "static, pcap, url, file",
114-
"freespace": 50000,
115-
"delete_original": False,
116-
"tmppath": "/tmp",
117-
"terminate_processes": False,
118-
"memory_dump": False,
119-
"delete_bin_copy": False,
120-
"max_machines_count": 10,
121-
"reschedule": False,
122-
"rooter": "/tmp/cuckoo-rooter",
123-
"machinery": "kvm",
124-
"machinery_screenshots": False,
125-
"delete_archive": True,
126-
"max_vmstartup_count": 5,
127-
"daydelta": 0,
128-
"max_analysis_count": 0,
129-
"max_len": 196,
130-
"sanitize_len": 32,
131-
"sanitize_to_len": 24,
132-
"scaling_semaphore": False,
133-
"scaling_semaphore_update_timer": 10,
134-
"task_pending_timeout": 0,
135-
"task_timeout": False,
136-
"task_timeout_scan_interval": 30,
137-
"freespace_processing": 15000,
138-
"ignore_signals": True,
139-
"periodic_log": False,
140-
"fail_unserviceable": True,
141-
}
111+
assert mgr.cfg.cuckoo == Config("cuckoo").cuckoo
142112

143113
assert mgr.task.id == task.id
144114

0 commit comments

Comments
 (0)