Windows: cannot scan files with RLO in their filename
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 35/100
Hướng nghiên cứu
Start in yara-python.c at Rules_match and compare its PyArg_ParseTupleAndKeywords usage with the Python C API documentation for filesystem paths. Check the referenced libyara filemap.c location and linked YARA issues and pull request. Done means the supplied Windows reproducer scans files with RLO, Russian, and ordinary filenames by path while data-only scanning remains successful.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
On Windows, yara-python cannot scan files with RLO / RTLO (Right To Left Override) in their filename
it fails with could not open file : xxxx
mini reproducer (it copies cmd.exe to a temp dir with a RLO in the filename, and tries to scan from here)
EDIT: also tried with russian characters, it fails too
EDIT2: might be linked to those too :
- https://github.com/VirusTotal/yara/issues/1487
- https://github.com/VirusTotal/yara/issues/1371
- https://github.com/VirusTotal/yara/issues/644
EDIT3: might be fixed with this PR? : https://github.com/VirusTotal/yara/pull/1491/files
import tempfile
import shutil
import os
import yara
rule = """
rule cmd_check
{
strings:
$cmd = "Windows Command Processor" wide
condition:
$cmd
}
"""
source = r'c:\windows\system32\cmd.exe'
new_filename = 'cmd_with_RLO\u202efdp.exe'
new_filename2 = 'испытание'
tempdir = tempfile.mkdtemp()
destination = os.path.join(tempdir, new_filename)
shutil.copy(source, destination)
destination2 = os.path.join(tempdir, new_filename2)
shutil.copy(source, destination2)
print("[*] File {} copied to directory {}".format(source, tempdir))
compiled = yara.compile(sources={'myrule':rule})
print("[*] scanning legit cmd.exe")
try:
r = compiled.match(source)
print(" [+] scan successful")
except Exception as e:
print(" [-] scan failed : {}".format(e))
print("[*] scanning cmd with RLO")
try:
r = compiled.match(destination)
print(" [+] scan successful")
except Exception as e:
print(" [-] scan failed : {}".format(e))
print("[*] retrying with data only")
data = open(destination, "rb").read()
try:
r = compiled.match(data=data)
print(" [+] scan successful")
except Exception as e:
print(" [-] scan failed : {}".format(e))
print("[*] scanning cmd with russian")
try:
r = compiled.match(destination2)
print(" [+] scan successful")
except Exception as e:
print(" [-] scan failed : {}".format(e))
print("[*] retrying with data only")
data = open(destination2, "rb").read()
try:
r = compiled.match(data=data)
print(" [+] scan successful")
except Exception as e:
print(" [-] scan failed : {}".format(e))
shutil.rmtree(tempdir)
output :
[*] File c:\windows\system32\cmd.exe copied to directory C:\Users\user\AppData\Local\Temp\tmplxvtlrya
[*] scanning legit cmd.exe
[+] scan successful
[*] scanning cmd with RLO
[-] scan failed : could not open file "C:\Users\user\AppData\Local\Temp\tmplxvtlrya\cmd_with_RLOfdp.exe"
[*] retrying with data only
[+] scan successful
[*] scanning cmd with russian
[-] scan failed : could not open file "C:\Users\user\AppData\Local\Temp\tmplxvtlrya\испытание"
[*] retrying with data only
[+] scan successful
I didn't investigate much but it might come from here in yara lib:
EDIT: or maybe from here:
https://github.com/VirusTotal/yara-python/blob/master/yara-python.c#L1488
static PyObject* Rules_match(
PyObject* self,
PyObject* args,
PyObject* keywords)
{
....
char* filepath = NULL;
Py_buffer data = {0};
....
if (PyArg_ParseTupleAndKeywords(
args,
keywords,
"|sis*OOOiOOiO",
kwlist,
&filepath,
&pid,
https://docs.python.org/3/c-api/arg.html
If you want to accept filesystem paths and convert them to C character strings, it is preferable to use the O& format with PyUnicode_FSConverter() as converter.

- Ngôn ngữ chính
- C
- Star
- 754
- Fork
- 190
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của VirusTotal/yara-python
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
VirusTotal/yara-python#263 · 2 bình luận ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 28/100
VirusTotal/yara-python#234 · 2 bình luận ·
-
Missing python interface file Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 48/100
VirusTotal/yara-python#218 · 3 reaction ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 20/100
VirusTotal/yara-python#216 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 35/100
VirusTotal/yara-python#212 · 11 bình luận ·
Tất cả issue của VirusTotal/yara-python
Issue tương tự
-
task
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
vsanthanam/JBird#429 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
-
bug documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
es-ude/OnDeviceTraining#459 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
bilelmoussaoui/gobject-linter#199 · 1 bình luận ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
bradcypert/plum#53 ·