Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7784544583 | ||
|
|
f742937296 | ||
|
|
5fd9242291 | ||
|
|
9f343196a9 | ||
|
|
5468eded04 | ||
|
|
1b97758fc9 | ||
|
|
b2e8e49447 | ||
|
|
3eec781139 | ||
|
|
b6f1977fa0 | ||
|
|
e0aa080f00 | ||
|
|
66aa76c836 | ||
|
|
bb9444e1ae | ||
|
|
6c9bfa7755 | ||
|
|
c4fa849290 | ||
|
|
4807e2c410 | ||
|
|
5388efdebc | ||
|
|
1d656de7ba | ||
|
|
eaa1d725a9 | ||
|
|
dea2150d63 | ||
|
|
80f9d6cf75 | ||
|
|
7430d38594 | ||
|
|
6804e4af9f | ||
|
|
138756c31d | ||
|
|
349bc293c6 | ||
|
|
2f87cd10f2 | ||
|
|
fc50eafcca | ||
|
|
b48e20a727 | ||
|
|
ce7ed2e6eb | ||
|
|
043d71e0ff | ||
|
|
1855ae0e1d | ||
|
|
77323a50df | ||
|
|
1c2f6b85ca | ||
|
|
2b5c478e4b | ||
|
|
90fd83a81f | ||
|
|
8fa2a166f3 | ||
|
|
e8cc45ebe7 | ||
|
|
eb87117b91 | ||
|
|
3799dfa1e8 | ||
|
|
163c7fd680 | ||
|
|
44ca762f69 | ||
|
|
8db311ba33 | ||
|
|
99d8604db4 | ||
|
|
90aa88daeb | ||
|
|
ae6eebad4d | ||
|
|
cd31ce1c38 | ||
|
|
ed3846e451 | ||
|
|
0c79cf8e37 | ||
|
|
81c7e16c0e | ||
|
|
16c03095b8 | ||
|
|
b5dab3aa22 | ||
|
|
e4a3c871f8 | ||
|
|
a2fe947b08 | ||
|
|
8df49ecfc1 | ||
|
|
526b9bd4c7 | ||
|
|
c67ff3d936 | ||
|
|
417b17da98 | ||
|
|
4ca19a4eb0 | ||
|
|
e834dfb7ee | ||
|
|
5e1ff74fb3 | ||
|
|
7a1d0f2ca7 | ||
|
|
b305522106 | ||
|
|
ff3495645a | ||
|
|
ddc000321f | ||
|
|
fe4e6af3b9 | ||
|
|
a1a83cc32c | ||
|
|
e37665218b | ||
|
|
2a876f4136 | ||
|
|
290d8e8a64 | ||
|
|
121bce529f | ||
|
|
1232d98573 | ||
|
|
208d9150b0 | ||
|
|
351bf7725e | ||
|
|
a547776766 | ||
|
|
86a8d20757 | ||
|
|
760c420f95 | ||
|
|
44c2edf58e | ||
|
|
e88207c232 | ||
|
|
f6b2450fcd | ||
|
|
a124ecd3ed | ||
|
|
34fcc3d29e | ||
|
|
5f3011eebc | ||
|
|
d4464edb6c | ||
|
|
1dc89a80db | ||
|
|
bd23599770 | ||
|
|
bda6ff80da | ||
|
|
16bee9825f | ||
|
|
5e4a4c4e8f | ||
|
|
0a03093333 | ||
|
|
960b1d53f7 | ||
|
|
f09dee6a52 | ||
|
|
301e1e56d1 | ||
|
|
6b2dbd382d | ||
|
|
e6f526c766 | ||
|
|
06cca669a0 | ||
|
|
f89ccea208 | ||
|
|
0728f2d995 | ||
|
|
c7a7a61c9a | ||
|
|
aca11e66a8 | ||
|
|
46c7a001c2 | ||
|
|
d6aa3c50a3 | ||
|
|
caaadc5cf3 | ||
|
|
14d703903c | ||
|
|
76fa14ab01 | ||
|
|
d1afe255e5 | ||
|
|
8f27739331 | ||
|
|
7a6aba5a2a | ||
|
|
ca0ec1f99d | ||
|
|
4e167486a1 | ||
|
|
503bbcd995 | ||
|
|
b160d2f634 | ||
|
|
2e7628a837 | ||
|
|
1259948ed7 | ||
|
|
81881ae1a4 | ||
|
|
0b5c581aca | ||
|
|
eb3614ed0c | ||
|
|
eb50513277 | ||
|
|
c3af73b8cf | ||
|
|
b552164a13 | ||
|
|
b6dc9ecadb | ||
|
|
0723dc8dbb | ||
|
|
0b1fffb5bf | ||
|
|
a39d87e5c5 | ||
|
|
0b0c3310cf | ||
|
|
f75c3750a5 | ||
|
|
3da760721b | ||
|
|
a9ad3feeec | ||
|
|
479c4ade67 | ||
|
|
84afa3e714 | ||
|
|
9a69665bab | ||
|
|
fea34ee937 | ||
|
|
ff2412c65d | ||
|
|
658953860a | ||
|
|
b473783527 | ||
|
|
7e590d4925 | ||
|
|
232fd3e2f2 | ||
|
|
9ea25fb77c | ||
|
|
6c47136de3 | ||
|
|
6fae29b488 | ||
|
|
7ed8cc9380 | ||
|
|
142e9d1028 | ||
|
|
c96c30ff9a | ||
|
|
337f1cc100 | ||
|
|
c3cb89dbea | ||
|
|
445bd1f668 | ||
|
|
1bded908c1 | ||
|
|
8d9dea4b08 | ||
|
|
4e98d6d8ce | ||
|
|
55b5cd939e | ||
|
|
d72f5a43c8 | ||
|
|
b406d8d30b | ||
|
|
f9c91c9ba0 | ||
|
|
0213d7eeb4 | ||
|
|
048c5c0970 | ||
|
|
728542fce8 | ||
|
|
81ca24c7a2 | ||
|
|
32ec272253 | ||
|
|
758982b660 | ||
|
|
a83bba10e3 | ||
|
|
4b9342fa8b | ||
|
|
a48162cf4a | ||
|
|
3fa61e777c | ||
|
|
01a2c55207 | ||
|
|
1a2376e6b7 | ||
|
|
dab0d6a47f | ||
|
|
b5d90b5cb7 | ||
|
|
25fd0bd2af | ||
|
|
a4bb63fcd4 | ||
|
|
9d85785c27 | ||
|
|
4206242627 | ||
|
|
f0149be9ad | ||
|
|
5d56a1f0e0 | ||
|
|
ad06c75058 | ||
|
|
d5b6e17e59 | ||
|
|
ffe2514e11 | ||
|
|
8621bed5d4 | ||
|
|
634031e6dc | ||
|
|
11fae36469 | ||
|
|
3d01e36a71 | ||
|
|
c2082b1ac5 | ||
|
|
c94bbf84fe | ||
|
|
930363cd3f | ||
|
|
085ca9eb58 | ||
|
|
f486d44804 | ||
|
|
1b4fbd3449 | ||
|
|
43ad7bf646 | ||
|
|
64921c3308 | ||
|
|
7a0e6a00c5 | ||
|
|
1332dd2c0e | ||
|
|
d52628bed2 | ||
|
|
981ec006b2 | ||
|
|
7da05cf678 | ||
|
|
316882bcd0 | ||
|
|
b204e52297 | ||
|
|
f82a63f4c8 | ||
|
|
cb0f2108a4 | ||
|
|
300b7a7a68 | ||
|
|
c3852ca60d | ||
|
|
a5fb735c93 | ||
|
|
d0b04ba84f | ||
|
|
9552742a39 | ||
|
|
8e9bdf6c0c | ||
|
|
818cc48502 | ||
|
|
adc4e28eb8 | ||
|
|
2e3a4d3bf1 | ||
|
|
d9bcac78e7 | ||
|
|
2342947849 | ||
|
|
19204dee8d | ||
|
|
863fa90b80 | ||
|
|
6fdef4a8f1 | ||
|
|
9469ceaa02 | ||
|
|
857f184409 | ||
|
|
a2f4a725f5 | ||
|
|
d12449bbb9 | ||
|
|
a41f4711dd | ||
|
|
3c2b018d49 | ||
|
|
e221a09709 | ||
|
|
26ff4bd843 | ||
|
|
d8e28f384a | ||
|
|
65e68c3cc4 | ||
|
|
7b76ab2a59 | ||
|
|
ae2a01b463 | ||
|
|
cda022a9f4 | ||
|
|
672e48c5f8 | ||
|
|
6fbdb1354f | ||
|
|
79bc7fd443 | ||
|
|
5578dd3339 | ||
|
|
0232dbd196 | ||
|
|
d44e192eaa | ||
|
|
4f12b19cf8 | ||
|
|
392ac1b1c7 | ||
|
|
8ad175aca3 | ||
|
|
6afa58c42b | ||
|
|
8be03cf232 | ||
|
|
23ea53d3ff | ||
|
|
294f40e7ac | ||
|
|
4f5f706ee5 | ||
|
|
27c1a7b4e4 | ||
|
|
cfaa5be6d7 | ||
|
|
a6942280a0 | ||
|
|
159124e6a3 | ||
|
|
6e63293a3c | ||
|
|
9a9dc0d788 | ||
|
|
e201cd074c | ||
|
|
0fd49a6e1c | ||
|
|
6169a85464 | ||
|
|
e583344fee | ||
|
|
dcee00394c | ||
|
|
e48dc99dc0 | ||
|
|
3ba3dda384 | ||
|
|
bbf1ce993c | ||
|
|
56245a8c9b | ||
|
|
4f2e65094c | ||
|
|
0bf456cbc8 | ||
|
|
9213d0da16 | ||
|
|
13f2ece0ff | ||
|
|
45c2a74c94 | ||
|
|
b1b3e90e9b | ||
|
|
90ef841dae | ||
|
|
b46000e8eb | ||
|
|
b24891355d | ||
|
|
14bde5a790 | ||
|
|
d6445f17e3 | ||
|
|
6124c3fe40 | ||
|
|
5531a4b194 | ||
|
|
839a0bbd42 | ||
|
|
1ba6272e4e | ||
|
|
fdd86815ef | ||
|
|
c8091fdc84 |
No files matched your search
@@ -1,34 +0,0 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
:: Check for permissions
|
||||
>nul 2>&1 "%SYSTEMROOT%\system32\icacls.exe" "%SYSTEMROOT%\system32\config\system"
|
||||
|
||||
if %errorlevel% NEQ 0 goto NoAdmin
|
||||
goto gotAdmin
|
||||
|
||||
:NoAdmin
|
||||
echo You do not have administrator rights, please run this script as administrator.
|
||||
pause
|
||||
exit /B
|
||||
|
||||
:gotAdmin
|
||||
if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs"
|
||||
|
||||
set "script_dir=%~dp0"
|
||||
set "script_dir=%script_dir:~0,-1%"
|
||||
|
||||
bcdedit -debug on
|
||||
bcdedit /set testsigning on
|
||||
bcdedit /deletevalue {current} safeboot
|
||||
|
||||
powershell.exe -ExecutionPolicy Bypass -Command ^
|
||||
"$endDate = (Get-Date).AddYears(100); ^
|
||||
$cert = New-SelfSignedCertificate -DnsName PYAS -CertStoreLocation cert:\LocalMachine\My -Type CodeSigning -NotAfter $endDate; ^
|
||||
$pwd = ConvertTo-SecureString -String 'PYAS' -Force -AsPlainText; ^
|
||||
Export-PfxCertificate -Cert $cert -FilePath '%script_dir%\PYAS.pfx' -Password $pwd;"
|
||||
"%script_dir%\signtool.exe" sign /f "%script_dir%\PYAS.pfx" /p PYAS "%script_dir%\PYAS_Driver.sys"
|
||||
sc create PYAS_Driver type= kernel start= demand binPath= "%script_dir%\PYAS_Driver.sys"
|
||||
|
||||
shutdown -r -t 0
|
||||
endlocal
|
||||
Whitespace-only changes.
Binary file not shown.
@@ -1,25 +0,0 @@
|
||||
@echo off
|
||||
setlocal
|
||||
|
||||
:: Check for permissions
|
||||
>nul 2>&1 "%SYSTEMROOT%\system32\icacls.exe" "%SYSTEMROOT%\system32\config\system"
|
||||
|
||||
if %errorlevel% NEQ 0 goto NoAdmin
|
||||
goto gotAdmin
|
||||
|
||||
:NoAdmin
|
||||
echo You do not have administrator rights, please run this script as administrator.
|
||||
pause
|
||||
exit /B
|
||||
|
||||
:gotAdmin
|
||||
if exist "%temp%\getadmin.vbs" del "%temp%\getadmin.vbs"
|
||||
|
||||
sc stop PYAS_Driver
|
||||
sc delete PYAS_Driver
|
||||
|
||||
bcdedit /set testsigning off
|
||||
bcdedit -debug off
|
||||
|
||||
shutdown -r -t 0
|
||||
endlocal
|
||||
Binary file not shown.
@@ -0,0 +1,73 @@
|
||||
from PIL import Image
|
||||
import numpy, pefile, os
|
||||
|
||||
def file_to_images(file_data, output_dir, file_name, target_size=(224, 224)):#
|
||||
wah = int(numpy.ceil(numpy.sqrt(len(file_data))))
|
||||
file_data = numpy.frombuffer(file_data, dtype=numpy.uint8)
|
||||
image_array = numpy.zeros((wah * wah,), dtype=numpy.uint8)
|
||||
image_array[:len(file_data)] = file_data
|
||||
image = Image.fromarray(image_array.reshape((wah, wah)), 'L')
|
||||
image = image.resize(target_size, Image.Resampling.NEAREST)
|
||||
image.save(os.path.join(output_dir, f"{file_name}.png"))
|
||||
|
||||
def check_file_type(file_path):
|
||||
try:
|
||||
shell_section = ["0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
|
||||
"cry", "tvm", "dec", "enc", "vmp", "upx", "aes", "lzma", "press",
|
||||
"pack", "enigma", "protect", "secur"]
|
||||
|
||||
unknown_section = ["asmstub", "base", "bss", "clr_uef", "cursors",
|
||||
"engine", "fio", "fothk", "h~;", "icapsec", "malloc_h", "miniex",
|
||||
"mssmixer", "ndr64", "nsys_wr", "obr", "wow", "wow64svc", "wpp_sf",
|
||||
"pad", "pgae", "poolmi", "proxy", "qihoo", "res", "retpol", "uedbg",
|
||||
"rwexec", "rygs", "s:@", "sanontcp", "segm", "test", "tracesup",
|
||||
"transit", "trs_age", "wisevec"]
|
||||
|
||||
unimportant_section = ["viahwaes", "orpc", "nep", "ace", "extjmp",
|
||||
"no_bbt", "data", "page", "hexpthk"]
|
||||
|
||||
shells = shell_section + unimportant_section + unknown_section
|
||||
|
||||
ftype = str(f".{file_path.split('.')[-1]}").lower()
|
||||
|
||||
if ftype in [".bat", ".cmd", ".ps1", ".vbs", ".wsf", ".js", ".html"]:
|
||||
with open(file_path, 'rb') as f:
|
||||
return [f.read()]
|
||||
|
||||
match_data = []
|
||||
if ftype in [".com", ".exe", ".dll", ".sys", ".scr"]:
|
||||
with pefile.PE(file_path, fast_load=True) as pe:
|
||||
for section in pe.sections:
|
||||
section_name = section.Name.rstrip(b'\x00').decode('latin1')
|
||||
#if (section.Characteristics & 0x00000020 and not
|
||||
#any(shell in section_name.lower() for shell in shells)):
|
||||
if section.Characteristics & 0x00000020:
|
||||
match_data.append(section.get_data())
|
||||
return match_data
|
||||
return False
|
||||
except Exception as e:
|
||||
print(e)
|
||||
return False
|
||||
|
||||
def batch_file_to_images(input_dir, output_dir):
|
||||
for root, dirs, files in os.walk(input_dir):
|
||||
for file in files:
|
||||
try:
|
||||
file_path = os.path.join(root, file)
|
||||
file_data = check_file_type(file_path)
|
||||
if file_data:
|
||||
for i, data in enumerate(file_data, 1):
|
||||
print(i, file_path)
|
||||
relative_path = os.path.relpath(root, input_dir)
|
||||
output_path_dir = os.path.join(output_dir, relative_path)
|
||||
if not os.path.exists(output_path_dir):
|
||||
os.makedirs(output_path_dir)
|
||||
file_to_images(data, output_path_dir, f"{i}_{file}")
|
||||
except Exception as e:
|
||||
print(e)
|
||||
pass
|
||||
|
||||
input_directory = input('Enter the folder path: ')
|
||||
output_directory = "./Image_File"
|
||||
batch_file_to_images(input_directory, output_directory)
|
||||
input('Conversion Complete')
|
||||
@@ -0,0 +1,29 @@
|
||||
import os, hashlib
|
||||
|
||||
def calc_sha256(path):
|
||||
with open(path, "rb") as f:
|
||||
return hashlib.sha256(f.read()).digest()
|
||||
|
||||
def dedup_realtime(root):
|
||||
seen = set()
|
||||
deleted = 0
|
||||
for dirpath, _, files in os.walk(root):
|
||||
for name in files:
|
||||
p = os.path.join(dirpath, name)
|
||||
try:
|
||||
h = calc_sha256(p)
|
||||
except Exception:
|
||||
continue
|
||||
if h in seen:
|
||||
try:
|
||||
os.remove(p)
|
||||
print(p)
|
||||
deleted += 1
|
||||
except Exception:
|
||||
pass
|
||||
else:
|
||||
seen.add(h)
|
||||
print(f"deleted {deleted}")
|
||||
|
||||
if __name__ == "__main__":
|
||||
dedup_realtime(r".\Image_File")
|
||||
@@ -0,0 +1,112 @@
|
||||
import tensorflow as tf
|
||||
import os, tf2onnx, numpy, random
|
||||
from PIL import Image
|
||||
from tensorflow.keras import *
|
||||
|
||||
Image.MAX_IMAGE_PIXELS = None
|
||||
tf.keras.mixed_precision.set_global_policy('mixed_float16')
|
||||
|
||||
def get_file_list(directory):
|
||||
file_paths, labels, class_indices = [], [], {}
|
||||
for i, cls in enumerate(sorted([d for d in os.listdir(directory) if os.path.isdir(os.path.join(directory, d))])):
|
||||
class_indices[cls] = i
|
||||
cls_dir = os.path.join(directory, cls)
|
||||
for root, _, files in os.walk(cls_dir):
|
||||
for file in files:
|
||||
if file.lower().endswith(('.jpg', '.jpeg', '.png', '.bmp', '.gif')):
|
||||
file_paths.append(os.path.join(root, file))
|
||||
labels.append(i)
|
||||
return file_paths, labels, class_indices
|
||||
|
||||
def load_dataset(train_dir, val_dir, val_split=0.01, batch_size=128, color_mode="grayscale"):
|
||||
channels = 1 if color_mode == "grayscale" else 3
|
||||
if train_dir == val_dir:
|
||||
file_paths, labels, class_indices = get_file_list(train_dir)
|
||||
combined = list(zip(file_paths, labels))
|
||||
random.shuffle(combined)
|
||||
file_paths[:], labels[:] = zip(*combined)
|
||||
num_val = int(val_split * len(file_paths))
|
||||
train_files = file_paths[num_val:]
|
||||
train_labels = labels[num_val:]
|
||||
val_files = file_paths[:num_val]
|
||||
val_labels = labels[:num_val]
|
||||
else:
|
||||
train_files, train_labels, class_indices = get_file_list(train_dir)
|
||||
val_files, val_labels, _ = get_file_list(val_dir)
|
||||
num_classes = len(class_indices)
|
||||
|
||||
def parse_fn(filename, label):
|
||||
img = tf.io.read_file(filename)
|
||||
img = tf.image.decode_image(img, channels=channels, expand_animations=False)
|
||||
img = tf.cast(img, tf.float32) / 255.0
|
||||
label = tf.one_hot(label, depth=num_classes)
|
||||
return img, label
|
||||
|
||||
train_ds = tf.data.Dataset.from_tensor_slices((train_files, train_labels))
|
||||
train_ds = train_ds.map(parse_fn, num_parallel_calls=tf.data.AUTOTUNE)
|
||||
train_ds = train_ds.batch(batch_size).prefetch(tf.data.AUTOTUNE)
|
||||
val_ds = tf.data.Dataset.from_tensor_slices((val_files, val_labels))
|
||||
val_ds = val_ds.map(parse_fn, num_parallel_calls=tf.data.AUTOTUNE)
|
||||
val_ds = val_ds.batch(batch_size).prefetch(tf.data.AUTOTUNE)
|
||||
train_ds.class_indices = class_indices
|
||||
return train_ds, val_ds
|
||||
|
||||
def gated_conv(x, strides):
|
||||
c = layers.DepthwiseConv2D(3, strides=strides, padding='same', activation='gelu')(x)
|
||||
g = layers.DepthwiseConv2D(3, strides=strides, padding='same', activation='sigmoid')(x)
|
||||
return layers.Multiply()([c, g])
|
||||
|
||||
def multi_conv(x, strides):
|
||||
convs = [layers.DepthwiseConv2D(kernel_size=k, strides=strides, padding='same')(x) for k in [1, 3, 5, 7]]
|
||||
x = layers.Concatenate()(convs)
|
||||
x = layers.BatchNormalization()(x)
|
||||
return layers.Activation('gelu')(x)
|
||||
|
||||
def se_block(x, reduction):
|
||||
filters = x.shape[-1]
|
||||
s = layers.Conv2D(filters // reduction, 1, padding='same', activation='gelu')(x)
|
||||
s = layers.BatchNormalization()(s)
|
||||
s = layers.Conv2D(filters, 1, padding='same', activation='sigmoid')(s)
|
||||
return layers.multiply([x, s])
|
||||
|
||||
def build_model(input_shape, num_classes):
|
||||
i = layers.Input(shape=input_shape)
|
||||
x = multi_conv(i, strides=1)
|
||||
x = multi_conv(x, strides=2)
|
||||
x = gated_conv(x, strides=2)
|
||||
x = multi_conv(x, strides=2)
|
||||
x = multi_conv(x, strides=2)
|
||||
x = multi_conv(x, strides=2)
|
||||
x = se_block(x, reduction=2)
|
||||
x = layers.GlobalAveragePooling2D()(x)
|
||||
o = layers.Dense(num_classes, activation='softmax', dtype='float32')(x)
|
||||
return models.Model(i, o)
|
||||
|
||||
def lr_scheduler(epoch, lr):
|
||||
return 1e-3 * (0.7 ** epoch)
|
||||
|
||||
class CustomModelCheckpoint(callbacks.Callback):
|
||||
def on_epoch_end(self, epoch, logs=False):
|
||||
models.save_model(self.model, f"PYAS_Model_Epoch_{epoch + 1}.h5")
|
||||
spec = (tf.TensorSpec((None,) + train_ds.image_shape, tf.float32),)
|
||||
model_proto, _ = tf2onnx.convert.from_keras(self.model, input_signature=spec, opset=18)
|
||||
with open(f"PYAS_Model_Epoch_{epoch + 1}.onnx", "wb") as f:
|
||||
f.write(model_proto.SerializeToString())
|
||||
|
||||
train_ds, val_ds = load_dataset(r'./Image_File', r'./Image_File')
|
||||
for imgs, _ in train_ds.take(1):
|
||||
train_ds.image_shape = imgs.shape[1:]
|
||||
break
|
||||
|
||||
strategy = tf.distribute.MirroredStrategy(cross_device_ops=tf.distribute.HierarchicalCopyAllReduce())
|
||||
with strategy.scope():
|
||||
try:
|
||||
model = models.load_model('PYAS_Model_Epoch_0.h5')
|
||||
print("Load model from disk")
|
||||
except:
|
||||
print("Creating a new model")
|
||||
model = build_model(train_ds.image_shape, len(train_ds.class_indices))
|
||||
print(f"Total parameters: {model.count_params()}")
|
||||
model.compile(optimizer='adam', loss='categorical_crossentropy', metrics=['accuracy'])
|
||||
model.fit(train_ds, epochs=30, callbacks=[CustomModelCheckpoint(), callbacks.LearningRateScheduler(lr_scheduler)], validation_data=val_ds)
|
||||
input("Training complete.")
|
||||
@@ -1,8 +1,8 @@
|
||||
import "pe"
|
||||
|
||||
rule PYAS_Rules_A_1 {
|
||||
rule General_1 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_1"
|
||||
description = "1"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -57,9 +57,9 @@ rule PYAS_Rules_A_1 {
|
||||
1 of ($x*) and 8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_2 {
|
||||
rule General_2 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_2"
|
||||
description = "2"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -82,9 +82,9 @@ rule PYAS_Rules_A_2 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_3 {
|
||||
rule General_3 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_3"
|
||||
description = "3"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -106,7 +106,7 @@ rule PYAS_Rules_A_3 {
|
||||
$x1 and 8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_4 {
|
||||
rule General_4 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A4"
|
||||
author = "PYAS Security"
|
||||
@@ -124,9 +124,9 @@ rule PYAS_Rules_A_4 {
|
||||
($x1 and $x2) and 5 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_5 {
|
||||
rule General_5 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_5"
|
||||
description = "5"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -147,9 +147,9 @@ rule PYAS_Rules_A_5 {
|
||||
$x1 and 3 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_6 {
|
||||
rule General_6 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_6"
|
||||
description = "6"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -214,9 +214,9 @@ rule PYAS_Rules_A_6 {
|
||||
1 of ($x*) and 5 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_7 {
|
||||
rule General_7 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_462"
|
||||
description = "7"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -247,9 +247,9 @@ rule PYAS_Rules_A_7 {
|
||||
10 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_8 {
|
||||
rule General_8 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_8"
|
||||
description = "8"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -278,9 +278,9 @@ rule PYAS_Rules_A_8 {
|
||||
2 of ($x*) and 6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_9 {
|
||||
rule General_9 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_9"
|
||||
description = "9"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -303,9 +303,9 @@ rule PYAS_Rules_A_9 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_10 {
|
||||
rule General_10 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_10"
|
||||
description = "10"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -329,9 +329,9 @@ rule PYAS_Rules_A_10 {
|
||||
($x1 and $x2) and 6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_11 {
|
||||
rule General_11 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_11"
|
||||
description = "11"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -349,9 +349,9 @@ rule PYAS_Rules_A_11 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_12 {
|
||||
rule General_12 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_12"
|
||||
description = "12"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -376,9 +376,9 @@ rule PYAS_Rules_A_12 {
|
||||
1 of ($x*) and 5 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_13 {
|
||||
rule General_13 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_13"
|
||||
description = "13"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -404,9 +404,9 @@ rule PYAS_Rules_A_13 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_14 {
|
||||
rule General_14 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_14"
|
||||
description = "14"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -430,9 +430,9 @@ rule PYAS_Rules_A_14 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_15 {
|
||||
rule General_15 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_15"
|
||||
description = "15"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -459,9 +459,9 @@ rule PYAS_Rules_A_15 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_16 {
|
||||
rule General_16 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_16"
|
||||
description = "16"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -485,9 +485,9 @@ rule PYAS_Rules_A_16 {
|
||||
($x1 and $x2) and 6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_17 {
|
||||
rule General_17 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_17"
|
||||
description = "17"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -508,9 +508,9 @@ rule PYAS_Rules_A_17 {
|
||||
$x1 and 8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_18 {
|
||||
rule General_18 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_18"
|
||||
description = "18"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -531,9 +531,9 @@ rule PYAS_Rules_A_18 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_19 {
|
||||
rule General_19 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_19"
|
||||
description = "19"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -560,9 +560,9 @@ rule PYAS_Rules_A_19 {
|
||||
($x1 and $x2) and 8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_20 {
|
||||
rule General_20 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_20"
|
||||
description = "20"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -589,9 +589,9 @@ rule PYAS_Rules_A_20 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_21 {
|
||||
rule General_21 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_21"
|
||||
description = "21"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -616,9 +616,9 @@ rule PYAS_Rules_A_21 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_22 {
|
||||
rule General_22 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_22"
|
||||
description = "22"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -635,10 +635,9 @@ rule PYAS_Rules_A_22 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
import "pe"
|
||||
rule PYAS_Rules_A_23 {
|
||||
rule General_23 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_23"
|
||||
description = "23"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -658,10 +657,9 @@ rule PYAS_Rules_A_23 {
|
||||
7 of them
|
||||
}
|
||||
|
||||
import "pe"
|
||||
rule PYAS_Rules_A_24 {
|
||||
rule General_24 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_24"
|
||||
description = "24"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -688,9 +686,9 @@ rule PYAS_Rules_A_24 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_25 {
|
||||
rule General_25 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_25"
|
||||
description = "25"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -716,9 +714,9 @@ rule PYAS_Rules_A_25 {
|
||||
$x1 and 5 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_26 {
|
||||
rule General_26 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_26"
|
||||
description = "26"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -742,9 +740,9 @@ rule PYAS_Rules_A_26 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_27 {
|
||||
rule General_27 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_27"
|
||||
description = "27"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -768,42 +766,37 @@ rule PYAS_Rules_A_27 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_28 {
|
||||
rule General_28 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_28"
|
||||
description = "28"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
$s1 = "GNU C11 6.3.0" ascii
|
||||
$s2 = "GCC: (MinGW.org GCC-6.3.0-1) 6.3.0" fullword ascii
|
||||
$s3 = "___mingw_readdir" fullword ascii
|
||||
$s4 = "___mingw_closedir" fullword ascii
|
||||
$s5 = "___mingw_seekdir" fullword ascii
|
||||
$s6 = "%d is not a prime number." fullword ascii
|
||||
$s7 = "___mingw_rewinddir" fullword ascii
|
||||
$s8 = "__mingw32_init_mainargs" fullword ascii
|
||||
$s9 = "___mingw_telldir" fullword ascii
|
||||
$s10 = "Enter an integer: " fullword ascii
|
||||
$s11 = "___mingw_opendir" fullword ascii
|
||||
$s12 = "/home/keith/" ascii
|
||||
$s13 = "../../../src/gcc-6.3.0/libgcc" ascii
|
||||
$s14 = "___mingw_dirname" fullword ascii
|
||||
$s15 = "_isPrime`" fullword ascii
|
||||
$s16 = "%d is a prime number." fullword ascii
|
||||
$s17 = ".weak.__Jv_RegisterClasses.___EH_FRAME_BEGIN__" fullword ascii
|
||||
$s18 = "-mtune=generic" ascii
|
||||
$s19 = "-march=i586" ascii
|
||||
$s20 = "-g -g -g -O2 -O2 -O2" ascii
|
||||
$s21 = "-fbuilding-libgcc" ascii
|
||||
$s22 = "-fno-stack-protector" ascii
|
||||
$x1 = "schemas.microsoft.com" wide
|
||||
$x2 = "Client Worker Thread" ascii
|
||||
$s1 = "A6BFEA43-501F-456F-A845-983D3AD7B8F0" wide
|
||||
$s2 = "upgrader" wide
|
||||
$s3 = "rtvscan.exe" wide
|
||||
$s4 = "Enable-WindowsOptionalFeature -FeatureName" wide
|
||||
$s5 = "remupd.exe" fullword wide
|
||||
$s6 = "Mcshield.exe" fullword wide
|
||||
$s7 = "mssecess.exe" fullword wide
|
||||
$s8 = "RavMonD.exe" fullword wide
|
||||
$s9 = "KvMonXP.exe" fullword wide
|
||||
$s10 = "baiduSafeTray.exe" fullword wide
|
||||
$s11 = "Qavanijeb.exe" fullword wide
|
||||
$s12 = "%s --> Error: %d, EC: %d" fullword ascii
|
||||
$s13 = "wscript.exe //E:vbscript" wide
|
||||
$s14 = "upgrader_64" wide
|
||||
$s15 = "Process Data Error" fullword wide
|
||||
condition:
|
||||
uint16(0) == 0x5a4d and filesize < 500KB and
|
||||
8 of them
|
||||
uint16(0) == 0x5a4d and filesize < 1000KB and
|
||||
1 of ($x*) and 6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_29 {
|
||||
rule General_29 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_29"
|
||||
description = "29"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -837,9 +830,9 @@ rule PYAS_Rules_A_29 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_30 {
|
||||
rule General_30 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_30"
|
||||
description = "30"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -858,9 +851,9 @@ rule PYAS_Rules_A_30 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_31 {
|
||||
rule General_31 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_31"
|
||||
description = "31"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -878,9 +871,9 @@ rule PYAS_Rules_A_31 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_32 {
|
||||
rule General_32 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_32"
|
||||
description = "32"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -909,9 +902,9 @@ rule PYAS_Rules_A_32 {
|
||||
$x1 and 8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_33 {
|
||||
rule General_33 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_33"
|
||||
description = "33"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -937,9 +930,9 @@ rule PYAS_Rules_A_33 {
|
||||
$x1 and 8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_34 {
|
||||
rule General_34 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_30"
|
||||
description = "34"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -965,9 +958,9 @@ rule PYAS_Rules_A_34 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_35 {
|
||||
rule General_35 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_35"
|
||||
description = "35"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -996,9 +989,9 @@ rule PYAS_Rules_A_35 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_36 {
|
||||
rule General_36 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_36"
|
||||
description = "36"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1023,9 +1016,9 @@ rule PYAS_Rules_A_36 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_37 {
|
||||
rule General_37 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_37"
|
||||
description = "37"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1053,9 +1046,9 @@ rule PYAS_Rules_A_37 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_38 {
|
||||
rule General_38 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_38"
|
||||
description = "38"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1083,9 +1076,9 @@ rule PYAS_Rules_A_38 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_39 {
|
||||
rule General_39 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_39"
|
||||
description = "39"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1104,9 +1097,9 @@ rule PYAS_Rules_A_39 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_40 {
|
||||
rule General_40 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_40"
|
||||
description = "40"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1136,9 +1129,9 @@ rule PYAS_Rules_A_40 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_41 {
|
||||
rule General_41 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_41"
|
||||
description = "41"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1160,9 +1153,9 @@ rule PYAS_Rules_A_41 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_42 {
|
||||
rule General_42 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_42"
|
||||
description = "42"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1182,9 +1175,9 @@ rule PYAS_Rules_A_42 {
|
||||
6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_43 {
|
||||
rule General_43 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_43"
|
||||
description = "43"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1209,9 +1202,9 @@ rule PYAS_Rules_A_43 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_44 {
|
||||
rule General_44 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_44"
|
||||
description = "44"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1239,9 +1232,9 @@ rule PYAS_Rules_A_44 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_45 {
|
||||
rule General_45 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_45"
|
||||
description = "45"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1268,9 +1261,9 @@ rule PYAS_Rules_A_45 {
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_46 {
|
||||
rule General_46 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_46"
|
||||
description = "46"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1298,9 +1291,9 @@ rule PYAS_Rules_A_46 {
|
||||
$x1 and 8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_47 {
|
||||
rule General_47 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_47"
|
||||
description = "47"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1329,9 +1322,9 @@ rule PYAS_Rules_A_47 {
|
||||
1 of ($x*) and 5 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_48 {
|
||||
rule General_48 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_48"
|
||||
description = "48"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1350,9 +1343,9 @@ rule PYAS_Rules_A_48 {
|
||||
2 of ($x*) and 6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_49 {
|
||||
rule General_49 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_49"
|
||||
description = "49"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1378,9 +1371,9 @@ rule PYAS_Rules_A_49 {
|
||||
3 of ($x*) and 5 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_50 {
|
||||
rule General_50 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_50"
|
||||
description = "50"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1400,9 +1393,9 @@ rule PYAS_Rules_A_50 {
|
||||
$x1 and 6 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_51 {
|
||||
rule General_51 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_51"
|
||||
description = "51"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
@@ -1420,9 +1413,9 @@ rule PYAS_Rules_A_51 {
|
||||
1 of ($x*) and 4 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_52 {
|
||||
rule General_52 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_52"
|
||||
description = "52"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-13"
|
||||
strings:
|
||||
@@ -1444,31 +1437,3 @@ rule PYAS_Rules_A_52 {
|
||||
uint16(0) == 0x5a4d and filesize < 2000KB and
|
||||
8 of them
|
||||
}
|
||||
|
||||
rule PYAS_Rules_A_53 {
|
||||
meta:
|
||||
description = "PYAS_Rules_A_53"
|
||||
author = "PYAS Security"
|
||||
date = "2024-06-12"
|
||||
strings:
|
||||
$x1 = "schemas.microsoft.com" wide
|
||||
$x2 = "Client Worker Thread" ascii
|
||||
$s1 = "A6BFEA43-501F-456F-A845-983D3AD7B8F0" wide
|
||||
$s2 = "upgrader" wide
|
||||
$s3 = "rtvscan.exe" wide
|
||||
$s4 = "Enable-WindowsOptionalFeature -FeatureName" wide
|
||||
$s5 = "remupd.exe" fullword wide
|
||||
$s6 = "Mcshield.exe" fullword wide
|
||||
$s7 = "mssecess.exe" fullword wide
|
||||
$s8 = "RavMonD.exe" fullword wide
|
||||
$s9 = "KvMonXP.exe" fullword wide
|
||||
$s10 = "baiduSafeTray.exe" fullword wide
|
||||
$s11 = "Qavanijeb.exe" fullword wide
|
||||
$s12 = "%s --> Error: %d, EC: %d" fullword ascii
|
||||
$s13 = "wscript.exe //E:vbscript" wide
|
||||
$s14 = "upgrader_64" wide
|
||||
$s15 = "Process Data Error" fullword wide
|
||||
condition:
|
||||
uint16(0) == 0x5a4d and filesize < 1000KB and
|
||||
1 of ($x*) and 6 of them
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1,15 +0,0 @@
|
||||
ExcludeXMD =
|
||||
Extensions = exe;com;dll;ocx;scr;bin;dat;386;vxd;sys;wdm;cla;class;ovl;ole;hlp;doc;dot;xls;ppt;wbk;wiz;pot;ppa;xla;xlt;vbs;vbe;mdb;rtf;htm;hta;html;xml;xtp;php;asp;js;shs;chm;lnk;pif;prc;url;smm;pfd;msi;ini;csc;cmd;bas;nws;
|
||||
ExcludeExtensions =
|
||||
ConfigFile = bdc.ini
|
||||
HttpProxy =
|
||||
InfectedFolder = Infected
|
||||
SuspectedFolder = Suspected
|
||||
LogMaxSize = 1024
|
||||
RenameExtension = vir
|
||||
PluginsPaths = Plugins
|
||||
LogName = bdc.log
|
||||
UpdateHttpLocation = http://upgrade.bitdefender.com/av32bit-eps
|
||||
XMD = *
|
||||
LastUpdate = Wed Feb 18 16:39:59 2009
|
||||
ProductID = {AAD1516D-28AB-4EB5-B7C8-DF54FE4442E9}
|
||||
Binary file not shown.
@@ -1,14 +0,0 @@
|
||||
<p>AVCORE v2.2 Windows/i386 11.0.1.21 (August 15, 2021)</p>
|
||||
<p>disp.xmd - Dispatcher (0.00) 0x1[997] (r)</p>
|
||||
<p>pyinstaller.xmd - PYInstaller unpacker (1.0) 0x8[12] (r)</p>
|
||||
<p>rar.xmd - RAR5 unpacker (0.5) 0xA[12] (r)</p>
|
||||
<p>thebat.xmd - TheBat Engine (0.03a) 0x4010[12] (r) +</p>
|
||||
<p>html.xmd - HTML Parser (1.0) 0x4008[11] (r) +</p>
|
||||
<p>mdx.xmd - Macro Defense Expert (3.57b) 0x1[11] 1[0] (r)</p>
|
||||
<p>cevakrnl.xmd - CEVA (0.03a) 0x1[10] (r)</p>
|
||||
<p>pdf.xmd - PDF Engine (2.0) 0x4009[10] (r) +</p>
|
||||
<p>imp.xmd - IMP (1.4.2) 0x2[9] (r)</p>
|
||||
<p>sfx.xmd - Sfx Engine (1.8.6) 0xA[9] (r)</p>
|
||||
<p>sdx.xmd - SDX () 0x1[5] 191729[0] (r)</p>
|
||||
<p>jpeg.xmd - JPEG Engine (0.05) 0x1[1] 14[1] (r)</p>
|
||||
<p>rtf.xmd - RTF (1.0) 0x4008[0] (r) +</p>
|
||||
Binary file not shown.
-21
@@ -1,21 +0,0 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2020-2024 87owo (PYAS Security)
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
PYAS Security Software Development License Agreement
|
||||
Last updated: 2025-08-15
|
||||
|
||||
1. License & Ownership
|
||||
– A single device key may be required to activate the software or source code.
|
||||
– Non exclusive, non transferable, and for personal, internal use only.
|
||||
– 87owo reserves all rights. Intellectual property rights are not transferred.
|
||||
|
||||
2. Use & Prohibitions
|
||||
– Private redistribution, sublicensing, or rental is prohibited.
|
||||
– Private reverse engineering or removal of notices is prohibited.
|
||||
– Any of the above requires prior authorization from the original author.
|
||||
– Only personal internal use or modification of the source code is permitted.
|
||||
– Use of the software or source code for any illegal purpose is prohibited.
|
||||
|
||||
3. License Components
|
||||
– All project script archives and executable files are proprietary.
|
||||
|
||||
4. Updates & Terms
|
||||
– Updates to new versions may include patches, enhancements, or modifications.
|
||||
– Continued use constitutes your acceptance of these features or terms.
|
||||
|
||||
5. Warranty & Liability
|
||||
– This software is provided "as is," without warranty of any kind.
|
||||
– In no event shall there be any liability for consequential damages.
|
||||
|
||||
© 2020–2025 87owo (PYAS Security). All rights reserved.
|
||||
@@ -1 +0,0 @@
|
||||
{"Unknown": [38413146381396798812836662586219087594480760119241756145287379993031670453973, 96759775057307603829199050115151442660431386536877578909394799687553144825391], "White": [92860071170291586757870565976957954052649178883790647665503983139114277816413, 50625869624179221836524636484722091669820057030729734765256925026245308185143, 79303266820014134748061006437377483029320717142203104125806969476209010566146, 50391760446499089493384482654016917630509060287507523223191455177998253781572, 34733894651460458125941968926483828168477919119649839915356573816494375383659, 16447578251589668808184123721615810667991570306415913809506896532563163557975, 18668853151306203943053249777678854424409647574074706653144503993068509738028, 16447129799599854768187525514242197965987640167415805965954293039200573272151, 42965648781535883376480003940402366467478625051031283341289116138472520399484, 45637511530246203537935382208327538642024163565740899790237852717178844340385, 100662025713257198141308144602569453810226448934776598411982222249289646045820, 2813878798545665948450767843887867208740292941021073849284371582085785669685, 54695748401254225125045716155327877471149349614359435230254611073117412307518, 27428665293760567560050957450577436769403462770366418052177943137905489504373, 32018095881556959863902669246154132691484124511748151111295836576906027842532, 82735669648112373508385530969898006750362429118827185652448450648454052106395, 27853809242729492000984914092533936796891917926358854729439436487683423285261, 20030429995379197455160031864140436552884002299333955332088108013764717533796, 82338140557728967648601024370995428985866052631101882076231147335348455671038, 71339449324799277130427957011381342555145697382104653874846579353871764366968, 2432232479351500614611699169184443988440809841079862157291791071419485606436, 9463527399566410848087352636323112952591923803840644609432039785310381355253, 17287926889345790925003722717807755244540044472850272987265624141065166747251, 31507509644511868166890345905396462199402122513677304280568315890707028374136, 92802443753971611323223428952970105040389824130209263287070763891097867755624, 60491018752293550079699763462944244393253888103551546202593483014975813742967, 45133408084728538869955951560598604064861024543940290379768365214821771604584, 6759146298068049614085390992799666053918974602489525613718797088468975708017, 43161770374046173333870752071317153674965637163816017117315179871715332666383, 55200886519442939000007636174371797768786544863806926514781108850256791225983, 102124766481586899841647737641698083212305154684644839980199278690335383712492, 52992286898317605666180786036367620316269750824654214415314225077986227890804, 96307454545313440124283308270263825589093792315386382296096934270155352236733, 36073459579994433898643313577597321150634749356791285363958792075031385371364, 5354562433688861244299028006341553420425390015040147574513776499404802540118, 2671602537216404752611755689384448521170725107261295121211275163689399347529, 31174448189678483951801405655647041557287598300853213718404097030076935043252, 817984956081990458969224676381868506770627801582748844000835755782736667191, 6997953573828232905847825866256444005094471443450029313008738013465446666864, 41288968033780608769032189481784193916730262129846893330891418484950645535282, 56724589038911745751056508177185337741291265472470897077742981563488398484126, 3353938097938067320481103667469354721822387389147415219233498938990215839034, 21195721951654457114265478558602466514207347021822959737607658828495062116920, 2916561284514958799877078174216081002558870786437593202464334407456915288119, 93137488384582768487662730765406914258099784103320160609442537879778117334700, 21195721951654457114265478558602377311225888285332501136798116331518898022972, 85036278951571446667616241901438186945472743486751871120301019617002115253240, 14623491695050192413097067629676318500123044497134202517578785087180871258165, 2022308710750553104057453378681448926020203033444470910346149752954363011822, 16435447118324352510213480738895714506136417806014749563314727656196027207884, 20110908101408861236178371339075650317185505287106087252378028881915405550816, 97262306467112548995108413358594977802790545321935863056096364390382492643957, 96614497885586867524036482497010189662872359368622249290846422070379022959337, 1895288773648887609359329471072769468085207279473521707976899919066265183340, 2651591106060448314208209841614702280337184080195391257416359882876000875095, 114619913163036058498985801603082782363327281628924544162718017899237779173997, 2481883953883130814217575190747389944608730963897863224598923997640828351014, 45000300637061336566799421885334051647634671537987073940268834014403441552901, 79047998258892679051555952202178856054614923426747250310189496005785954516966, 92887093185298651693450115442544102614083847612212241647641096093293220418098, 7140769773119319253009453104401896171570019200295580355390762162793695491644, 17012496707Line truncated
|
||||
+129
@@ -0,0 +1,129 @@
|
||||
translate_dict = {
|
||||
"traditional_switch": {"开启":"開啟","关闭":"關閉","On":"開啟","Off":"關閉"},
|
||||
|
||||
"simplified_switch": {"開啟":"开启","關閉":"关闭","On":"开启","Off":"关闭",
|
||||
"錯誤":"错误","發現":"发现","關閉":"关闭","裝置":"设备","記憶體":"内存",
|
||||
"軟體":"软件","檔案":"文件","確定":"确认","設定":"设置","關於":"关于",
|
||||
"總數":"总数","註冊":"注册","圖標":"图标","路徑":"路径","網路":"网络",
|
||||
"位元":"字节","靈敏":"敏感","複製":"复制","開啟":"开启","靜態":"静态",
|
||||
"訊":"讯","項":"项","掃":"扫","試":"试","黃":"黄","嗎":"吗","防":"保",
|
||||
"鑰":"钥","當":"当","後":"后","護":"护","導":"导","區":"区","復":"复",
|
||||
"攔":"拦","請":"请","統":"统","刪":"删","進":"进","個":"个","選":"选",
|
||||
"啟":"启","監":"监","並":"并","徑":"径","盤":"盘","隱":"隐","動":"动",
|
||||
"狀":"状","誌":"志","這":"这","會":"会","題":"题","擇":"择","語":"语",
|
||||
"無":"无","顯":"显","變":"变","戶":"户","碼":"码","雲":"云","介":"界",
|
||||
"稱":"称","類":"类","輸":"输","執":"执","數":"数","尋":"寻","網":"网",
|
||||
"詢":"询","製":"制","員":"员","許":"许","條":"条","藍":"蓝","紅":"红",
|
||||
"綠":"绿","態":"态","務":"务","連":"连","檢":"检","測":"测","關":"关",
|
||||
"強":"强","驅":"驱","為":"为","腳":"脚","單":"单","開":"开","擴":"扩",
|
||||
"惡":"恶","據":"据","庫":"库","經":"经","敗":"败","謝":"谢","別":"别",
|
||||
"載":"载","誤":"误","報":"报","鏈":"链","竄":"窜","蹤":"踪","與":"与",
|
||||
"異":"异","實":"实","時":"时","彈":"弹","窗":"窗","暫":"暂","訂":"订",
|
||||
"資":"资","產":"产","金":"密","離":"离","規":"规","則":"则","來":"来",
|
||||
"殼":"壳","碼":"码","線":"线","餘":"余",},
|
||||
|
||||
"english_switch": {"開啟":"On","關閉":"Off","开启":"On","关闭":"Off",",":", ",
|
||||
"立即刪除":"Delete Now","安全模式":"Safe Mode","官方網站":"Official Website ",
|
||||
"腳本":"Script ","鏈式":"Chain ","記憶體":"Memory ","加載":"Load ",
|
||||
"行為":"Behavior ","可疑":"Suspicious ","勒索":"Ransom ","主要":"Main ",
|
||||
"許可條款":"License Terms ","惡意":"Malicious", "開發":"Developers ",
|
||||
"啟用":"Enable ","禁用":"Disable ","正在初始化中":"Initializing ",
|
||||
"正在掃描":"Scanning ","正在刪除":"Deleting ","正在追蹤":"Tracking ",
|
||||
"最小化到":"Minimize To ","靈敏度":"Sensitivity ","正在檢查":"Checking ",
|
||||
"確定要":"Sure Want To ","引擎靈敏度":"Sensitivity ","更新":"Update ",
|
||||
"白色主題":"White","黃色主題":"Yellow","紅色主題":"Red","語言":"Language ",
|
||||
"藍色主題":"Blue","綠色主題":"Green","自訂主題":"Custom","黑色主題":"Black",
|
||||
"特別感謝":"Contributors ","版本資訊":"Information","通訊":"Connect ",
|
||||
"註冊":"Registry ","退出":"Quit ","檔案":"File ","當前":"Currently ",
|
||||
"狀態":"State ","掃描":"Scan ","工具":"Tools ","防護":"Protect ",
|
||||
"失敗":"Failed ","請":"Please ","路徑":"Path ","方式":"Method ",
|
||||
"需要":"Need ","病毒":"Virus ","選擇":"Select ","返回":"Back",
|
||||
"受到":"Been ","錯誤":"Error","完成":"Complete ","引擎":"Engine ",
|
||||
"托盤":"Tray ","圖標":"Icon ","不安全":"Unsafe","增強":"Enhance ",
|
||||
"系統":"System ","雲端":"Cloud ","重啟":"Reboot ","修復":"Repair ",
|
||||
"裝置":"Device ","發現":"Found ","成功":"Success ","清理":"Cleanup ",
|
||||
"確定":"OK","執行":"Execute ","警告":"Warning ","使用":"Use ",
|
||||
"網路":"Network ","變更":"Change ","總數":"Total","結束":"End ",
|
||||
"選項":"Options ","監控":"Monitor ","連接":"Connect ","可以":"Can ",
|
||||
"進程":"Process ","攔截":"Block ","引導":"Boot ","刪除":"Delete ",
|
||||
"分區":"Partition ","設定":"Setting ","關於":"About","模式":"Mode ",
|
||||
"提高":"Improve ","安全":"Security ","顯色":"Color ","顏色":"Color ",
|
||||
"主題":"Theme ", "回收":"Collect ", "無用":"Useless ","導入":"Import ",
|
||||
"風險":"Risk ","介面":"UI ","核心":"Core ","服務":"Services ",
|
||||
"管理":"Manage","所有":"All ","您":"You ","取消":"Cancel ","未":"Not ",
|
||||
"垃圾":"Junk ","位元":"byte ","本機":"Computer ","停止":"Stop ",
|
||||
"到":"To ","白名單":"White List ","軟體":"Software ","正在":"",
|
||||
"增加":"Add ","移除":"Delete ","項目":"Items ","生成":"Create ","稱":"",
|
||||
"複製":"Copy ","此":"This ","並":"And ","全盤":"Full ","最新":"Latest ",
|
||||
"已存在":"Already ","數據庫":"Database ","誤報":"False Positive ",
|
||||
"高":"High ","新":"New ","和":"And ","可能會":"Possible ","會":"Can ",
|
||||
"日誌":"Log","已":"Has ","彈窗":"Window ","要":"To ","驅動":"Driver ",
|
||||
"的":"","顯示":"","個":"","嗎":"","了":"","行":"","立即":"","規則":"Rule ",
|
||||
"密鑰":"Key ","檢測":"Detect ","製作":"Maker ","運行":"Running",
|
||||
"擴展":"Extension ","套件":"Kit ","自動":"Auto ","上報":"Report ",
|
||||
"分析":"Analysis ","自身":"Self ","其他":"Other ","配置":"Config ",
|
||||
"丟失":"Lost ","網站":"Website ","不兼容":"Not Compatible ","列表":"List ",
|
||||
"竄改":"Tamper ","第三方":"Other ","實時":"Real Time ","查看":"View ",
|
||||
"指定":"Specify ","清空":"Empty ","資源回收桶":"Recycle Bin ", "無法":"Cannot ",
|
||||
"與":"With ","當":"When ","功能":"Function ","異常":"Abnormal ", "來":"To ",
|
||||
"重置":"Reset ","窗口":"Window ","暫存":"Temp ","自訂":"Custom ",
|
||||
"不支持":"Not Support ","共":"Total ","秒":"Seconds ","耗時":"Takes ",
|
||||
"沙箱":"Sandbox ", "虛擬":"Virtual ", "隔離":"Quarantine ", "時":"",
|
||||
"建立":"Create ","環境":"Environment ","沙箱":"Sandbox ","化":"", "表":"",
|
||||
"達":"Reached ", "上限":"Limit ", "區":"", "金鑰":"Key ", "產品":"Product ",
|
||||
"托管":"CLR ","殼碼":"Shellcode ","線程":"Thread ","注入":"Inject ",
|
||||
"前往":"Go ","檢查":"Check ","可用":"Available ","靜態":"Static ",
|
||||
"版本":"Version ","是":"","剩餘":"Remain "," ":" "},
|
||||
|
||||
"white_switch": {
|
||||
"_white": "_black",},
|
||||
"red_switch": {
|
||||
"235, 235, 235": "255, 235, 235",
|
||||
"245, 245, 245": "255, 225, 225",
|
||||
"255, 255, 255": "255, 245, 245",
|
||||
"240, 240, 240": "255, 220, 220",
|
||||
"250, 250, 250": "255, 210, 210",
|
||||
"220, 255, 220": "255, 220, 220",
|
||||
"210, 255, 210": "255, 210, 210",
|
||||
"_white": "_black"
|
||||
},
|
||||
"yellow_switch": {
|
||||
"235, 235, 235": "255, 255, 235",
|
||||
"245, 245, 245": "255, 255, 225",
|
||||
"255, 255, 255": "255, 255, 245",
|
||||
"240, 240, 240": "255, 255, 220",
|
||||
"250, 250, 250": "255, 255, 210",
|
||||
"220, 255, 220": "255, 255, 220",
|
||||
"210, 255, 210": "255, 255, 210",
|
||||
"_white": "_black"
|
||||
},
|
||||
"green_switch": {
|
||||
"235, 235, 235": "235, 255, 235",
|
||||
"245, 245, 245": "225, 255, 225",
|
||||
"255, 255, 255": "245, 255, 245",
|
||||
"240, 240, 240": "220, 255, 220",
|
||||
"250, 250, 250": "210, 255, 210",
|
||||
"_white": "_black"
|
||||
},
|
||||
"blue_switch": {
|
||||
"235, 235, 235": "235, 235, 255",
|
||||
"245, 245, 245": "225, 225, 255",
|
||||
"255, 255, 255": "245, 245, 255",
|
||||
"240, 240, 240": "220, 220, 255",
|
||||
"250, 250, 250": "210, 210, 255",
|
||||
"220, 255, 220": "220, 220, 255",
|
||||
"210, 255, 210": "210, 210, 255",
|
||||
"_white": "_black"
|
||||
},
|
||||
"black_switch": {
|
||||
"255, 255, 255": "55, 55, 55",
|
||||
"245, 245, 245": "75, 75, 75",
|
||||
"235, 235, 235": "65, 65, 65",
|
||||
"240, 240, 240": "80, 80, 80",
|
||||
"250, 250, 250": "90, 90, 90",
|
||||
"220, 255, 220": "80, 80, 80",
|
||||
"210, 255, 210": "90, 90, 90",
|
||||
"0, 0, 0": "255, 255, 255",
|
||||
"_black": "_white"
|
||||
}
|
||||
}
|
||||
+132
-72
@@ -1,84 +1,144 @@
|
||||
import time, json, hashlib, numpy
|
||||
from collections import Counter
|
||||
import os, yara, numpy, locale, pefile, onnxruntime
|
||||
from PIL import Image
|
||||
|
||||
class ListSimHash:
|
||||
class rule_scanner:
|
||||
def __init__(self):
|
||||
self.model = {}
|
||||
self.rules = {}
|
||||
self.network = []
|
||||
|
||||
def save_model(self, file_name):
|
||||
with open(file_name, 'w') as f:
|
||||
json.dump(self.model, f)
|
||||
print(f"\nModel Is Saved In {file_name}")
|
||||
def load_path(self, path):
|
||||
for root, _, files in os.walk(path):
|
||||
for file in files:
|
||||
self.load_file(os.path.join(root, file))
|
||||
|
||||
def load_model(self, model_data):
|
||||
if isinstance(model_data, str):
|
||||
with open(model_data, 'r') as f:
|
||||
model_data = json.load(f)
|
||||
self.model = model_data
|
||||
def load_file(self, file):
|
||||
ext = os.path.splitext(file)[1].lower()
|
||||
try:
|
||||
if ext in ('.yara', '.yar'):
|
||||
self.rules[file] = yara.compile(file)
|
||||
elif ext in ('.yc', '.yrc'):
|
||||
self.rules[file] = yara.load(file)
|
||||
elif ext in ('.ip', '.txt'):
|
||||
with open(file, "r", encoding="utf-8", errors="ignore") as f:
|
||||
self.network.extend(line.strip() for line in f if line.strip())
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def get_model(self, label):
|
||||
return self.model[label]
|
||||
def yara_scan(self, file_path):
|
||||
try:
|
||||
data = open(file_path, "rb").read() if isinstance(file_path, str) else file_path
|
||||
for rules in self.rules.values():
|
||||
matches = rules.match(data=data)
|
||||
if matches:
|
||||
rule_name = str(matches[0])
|
||||
label = rule_name.split("_")[0]
|
||||
level = rule_name.split("_")[-1]
|
||||
return f"Rules/{label}", level
|
||||
return False, False
|
||||
except Exception:
|
||||
return False, False
|
||||
|
||||
def train_model(self, label, data):
|
||||
start = time.time()
|
||||
print(f"Convert {label}")
|
||||
if label not in self.model:
|
||||
self.model[label] = []
|
||||
for i, x in enumerate(data, 1):
|
||||
self.model[label].append(self.build_text(x))
|
||||
used = "{0:.2f}".format(time.time()-start)
|
||||
prefix, suffix = f'{i}/{len(data)}:', f'{used}s'
|
||||
self.progress_bar(i, len(data), prefix, suffix)
|
||||
class model_scanner:
|
||||
def __init__(self):
|
||||
self.models = {}
|
||||
self.suffix = {
|
||||
".com", ".dll", ".drv", ".exe", ".ocx", ".scr", ".sys",
|
||||
".bat", ".cmd", ".html", ".js", ".php", ".ps1", ".vbs", ".wsf", ".xml"
|
||||
}
|
||||
self.labels = [
|
||||
"Pefile/White", "Script/White", "Pefile/General", "Script/General"
|
||||
]
|
||||
self.detect = {
|
||||
"Pefile/General", "Script/General"
|
||||
}
|
||||
self.resize = (224, 224)
|
||||
|
||||
def build_text(self, content):
|
||||
sums, batch, count = [], [], 0
|
||||
features = dict(Counter(sorted(content)))
|
||||
for f, w in features.items():
|
||||
count += w
|
||||
batch.append(hashlib.sha256(json.dumps(f).encode('utf-8')).digest() * w)
|
||||
if len(batch) >= 10000:
|
||||
sums.append(self.sum_hashes(batch))
|
||||
batch = []
|
||||
if batch:
|
||||
sums.append(self.sum_hashes(batch))
|
||||
combined_sums = numpy.sum(sums, 0)
|
||||
v = numpy.packbits(combined_sums > count / 2).tobytes()
|
||||
return int.from_bytes(v, 'big')
|
||||
def load_path(self, path):
|
||||
for root, _, files in os.walk(path):
|
||||
for file in files:
|
||||
self.load_file(os.path.join(root, file))
|
||||
|
||||
def sum_hashes(self, digests):
|
||||
bitarray = numpy.unpackbits(numpy.frombuffer(b''.join(digests), dtype='>B'))
|
||||
return numpy.sum(numpy.reshape(bitarray, (-1, 256)), 0)
|
||||
def load_file(self, file):
|
||||
if file.lower().endswith('.onnx'):
|
||||
try:
|
||||
self.models[file] = onnxruntime.InferenceSession(file)
|
||||
except Exception:
|
||||
return False
|
||||
|
||||
def progress_bar(self, items, total, prefix='', suffix='', length=50, fill='█'):
|
||||
percent = min(100.0, max(0.0, 100 * (items / float(total))))
|
||||
end_char = '\n' if percent >= 100 else '\r'
|
||||
percent_string = "{0:.2f}".format(percent)
|
||||
filled_length = int(length * items // total)
|
||||
bar = fill * filled_length + ' ' * (length - filled_length)
|
||||
print(f'\r{prefix: <15} |{bar}| {percent_string}% {suffix}', end=end_char)
|
||||
def model_scan(self, file_path):
|
||||
try:
|
||||
model = next(iter(self.models.values()))
|
||||
shape = model.get_inputs()[0].shape
|
||||
channels = shape[-1] if shape[-1] in (1, 3) else (shape[1] if shape[1] in (1, 3) else 1)
|
||||
|
||||
def predict_all(self, query):
|
||||
label_similarities = {}
|
||||
query_hash = self.build_text(query)
|
||||
for label in self.model:
|
||||
max_similarity = 0
|
||||
for data_point in self.model[label]:
|
||||
similarity = self.similar(data_point, query_hash)
|
||||
if similarity > max_similarity:
|
||||
max_similarity = similarity
|
||||
label_similarities[label] = max_similarity
|
||||
return label_similarities
|
||||
file_sections = self.get_type(file_path)
|
||||
if not file_sections:
|
||||
return False, False
|
||||
|
||||
def predict(self, query):
|
||||
max_similarity, max_label = 0, None
|
||||
query_hash = self.build_text(query)
|
||||
for label in self.model:
|
||||
for data_point in self.model[label]:
|
||||
similarity = self.similar(data_point, query_hash)
|
||||
if similarity > max_similarity:
|
||||
max_similarity, max_label = similarity, label
|
||||
return max_label, max_similarity
|
||||
batch_images = [self.preprocess_image(data, self.resize, channels) for data in file_sections.values()]
|
||||
arr = numpy.stack([numpy.asarray(img).astype('float32') / 255.0 for img in batch_images])
|
||||
if arr.ndim == 3:
|
||||
arr = arr[..., None]
|
||||
if shape[-1] in (1, 3):
|
||||
model_input = arr
|
||||
elif shape[1] in (1, 3):
|
||||
model_input = arr.transpose(0, 3, 1, 2)
|
||||
else:
|
||||
return False, False
|
||||
|
||||
def similar(self, x, y):
|
||||
hamming_distance = bin(x ^ y).count('1')
|
||||
return 1 - hamming_distance / 256
|
||||
input_name = model.get_inputs()[0].name
|
||||
predictions = model.run(None, {input_name: model_input})[0]
|
||||
|
||||
label_scores = {label: [] for label in self.labels}
|
||||
for pre_answers in predictions:
|
||||
for k, score in enumerate(pre_answers):
|
||||
label_scores[self.labels[k]].append(score)
|
||||
label_percentage = {label: (sum(scores)/len(scores))*100 for label, scores in label_scores.items() if scores}
|
||||
if not label_percentage:
|
||||
return False, False
|
||||
best_label, best_conf = max(label_percentage.items(), key=lambda x: x[1])
|
||||
if best_label in self.detect:
|
||||
return best_label, int(best_conf)
|
||||
return False, False
|
||||
except Exception:
|
||||
return False, False
|
||||
|
||||
def preprocess_image(self, file_data, size, channels=1):
|
||||
width, height = size
|
||||
wah = int(numpy.ceil(numpy.sqrt(len(file_data) / channels)))
|
||||
arr = numpy.frombuffer(file_data, dtype=numpy.uint8)
|
||||
img = numpy.zeros(wah*wah*channels, dtype=numpy.uint8)
|
||||
img[:len(file_data)] = arr
|
||||
if channels == 1:
|
||||
image = Image.fromarray(img.reshape((wah, wah)), 'L')
|
||||
else:
|
||||
image = Image.fromarray(img.reshape((wah, wah, channels)), 'RGB')
|
||||
return image.resize((width, height), Image.Resampling.NEAREST)
|
||||
|
||||
def is_text_file(self, content, sample_size=1024):
|
||||
raw = content[:sample_size]
|
||||
if not raw:
|
||||
return False
|
||||
text_char = set(range(32, 127)) | {9, 10, 13}
|
||||
nontext = sum(b not in text_char for b in raw)
|
||||
return nontext / len(raw) < 0.15
|
||||
|
||||
def get_type(self, file_path):
|
||||
match_data = {}
|
||||
if not os.path.splitext(file_path)[-1].lower() in self.suffix:
|
||||
return match_data
|
||||
try:
|
||||
with pefile.PE(file_path, fast_load=True) as pe:
|
||||
sec = pe.OPTIONAL_HEADER.DATA_DIRECTORY[pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_SECURITY']]
|
||||
if bool(sec.VirtualAddress and sec.Size):
|
||||
return {}
|
||||
for section in pe.sections:
|
||||
name = section.Name.rstrip(b'\x00').decode('latin1').lower()
|
||||
if section.Characteristics & 0x00000020:
|
||||
match_data[name] = section.get_data()
|
||||
except pefile.PEFormatError:
|
||||
with open(file_path, 'rb') as f:
|
||||
file_content = f.read()
|
||||
if self.is_text_file(file_content):
|
||||
match_data[os.path.splitext(file_path)[-1].lower()] = file_content
|
||||
return match_data
|
||||
@@ -1,24 +0,0 @@
|
||||
from subprocess import *
|
||||
import os, re, sys
|
||||
|
||||
class ExtenRules:
|
||||
def __init__(self):
|
||||
self.exten = {}
|
||||
self.pyas = sys.argv[0].replace("\\", "/")
|
||||
self.dir = os.path.dirname(self.pyas)
|
||||
self.exten = os.path.join(self.dir, "Exten")
|
||||
|
||||
def bdc_scan(self, file):
|
||||
if self.exten.replace("\\", "/") not in file.replace("\\", "/"):
|
||||
cmd = f'"{self.exten}\\Bitdefender\\bdc.exe" "{file}"'
|
||||
p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True, universal_newlines=True)
|
||||
for matchs in re.finditer(r'(?P<filename>[^\s]+)\s+infected:\s+(?P<virusname>.+)', p.communicate()[0]):
|
||||
return matchs
|
||||
return False
|
||||
|
||||
def mem_scan(self, p):
|
||||
if self.exten.replace("\\", "/") not in p.exe().replace("\\", "/"):
|
||||
cmd = f'"{self.exten}\\hollows_hunter\\hollows_hunter.exe" /ofilter 2 /pid "{p.pid}"'
|
||||
p = Popen(cmd, stdout=PIPE, stderr=PIPE, shell=True, universal_newlines=True)
|
||||
return 'Detected' in p.communicate()[0]
|
||||
return False
|
||||
+1540
-1877
File diff suppressed because it is too large.
Load diff
@@ -1,59 +0,0 @@
|
||||
translate_dict = {
|
||||
"zh_TW": {"已开启":"已開啟","已关闭":"已關閉","On":"已開啟","Off":"已關閉"},
|
||||
"zh_CN": {"已開啟":"已开启","已關閉":"已关闭","On":"已开启","Off":"已关闭",
|
||||
"軟體":"软件","檔案":"文件","確定":"确认","設定":"设置","關於":"关于",
|
||||
"錯誤":"错误","實時":"实时","發現":"发现","關閉":"关闭","裝置":"设备",
|
||||
"總數":"总数","註冊":"注册","圖標":"图标","路徑":"路径","網路":"网络",
|
||||
"位元":"字节","彈窗":"弹窗","靈敏":"敏感","複製":"复制","開啟":"开启",
|
||||
"訊":"讯","項":"项","掃":"扫","試":"试","黃":"黄","嗎":"吗","防":"保",
|
||||
"鑰":"钥","當":"当","後":"后","護":"护","導":"导","區":"区","復":"复",
|
||||
"攔":"拦","請":"请","統":"统","刪":"删","進":"进","個":"个","選":"选",
|
||||
"啟":"启","監":"监","並":"并","徑":"径","盤":"盘","隱":"隐","動":"动",
|
||||
"狀":"状","誌":"志","這":"这","會":"会","題":"题","擇":"择","語":"语",
|
||||
"無":"无","顯":"显","變":"变","戶":"户","碼":"码","雲":"云","介":"界",
|
||||
"稱":"称","類":"类","輸":"输","執":"执","數":"数","尋":"寻","網":"网",
|
||||
"詢":"询","製":"制","員":"员","許":"许","條":"条","藍":"蓝","紅":"红",
|
||||
"綠":"绿","態":"态","務":"务","連":"连","檢":"检","測":"测","關":"关",
|
||||
"強":"强","驅":"驱","為":"为","腳":"脚","單":"单","開":"开","擴":"扩",
|
||||
"惡":"恶","據":"据","庫":"库","經":"经","敗":"败","謝":"谢","別":"别",
|
||||
"載":"载","誤":"误","報":"报","鏈":"链","竄":"窜","記憶體":"内存",},
|
||||
"en_US": {"已開啟":"On","已關閉":"Off","已开启":"On","已关闭":"Off",",":", ",
|
||||
"立即刪除":"Delete Now","安全模式":"Safe Mode","官方網站":"Website ",
|
||||
"腳本":"Script ","鏈式":"Chain ","記憶體":"Memory ","加載":"Load ",
|
||||
"行為":"Behavior ","可疑":"Suspicious ","勒索":"Ransom ",
|
||||
"許可條款":"License Terms ","惡意":"Malicious","可疑":"Suspicious",
|
||||
"啟用":"Enable ","禁用":"Disable ","正在初始化中":"Initializing ",
|
||||
"正在掃描":"Scanning ","正在刪除":"Deleting ","最小化到":"Minimize To ",
|
||||
"確定要":"Sure Want To ","靈敏度":"Sensitivity ","更新":"Update ",
|
||||
"白色主題":"White","黃色主題":"Yellow","紅色主題":"Red","語言":"Language ",
|
||||
"藍色主題":"Blue","綠色主題":"Green","自定主題":"Custom","最新":"Latest ",
|
||||
"特別感謝":"Contributors ","版本資訊":"Information","通訊":"Connect ",
|
||||
"註冊表":"Registry ","退出":"Quit ","檔案":"File ","當前":"Currently ",
|
||||
"狀態":"State ","掃描":"Scan ","工具":"Tools ","防護":"Protect ",
|
||||
"失敗":"Failed ","請":"Please ","路徑":"Path ","方式":"Method ",
|
||||
"需要":"Need ","病毒":"Virus ","選擇":"Select ","返回":"Back",
|
||||
"受到":"Been ","錯誤":"Error","完成":"Complete ","引擎":"Engine ",
|
||||
"托盤":"Tray ","圖標":"Icon ","不安全":"Unsafe","增強":"Enhance ",
|
||||
"系統":"System ","雲端":"Cloud ","重啟":"Reboot ","修復":"Repair ",
|
||||
"裝置":"Device ","發現":"Found ","成功":"Success ","清理":"Cleanup ",
|
||||
"確定":"OK","執行":"Execute ","警告":"Warning ","使用":"Use ",
|
||||
"網路":"Network ","變更":"Change ","總數":"Total","結束":"End ",
|
||||
"選項":"Options ","監控":"Monitor ","連接":"Connect ","可以":"To ",
|
||||
"進程":"Process ","攔截":"Block ","引導":"Boot ","刪除":"Delete ",
|
||||
"分區":"Partition ","設定":"Settings","關於":"About","模式":"Mode ",
|
||||
"提高":"Improve ","安全":"Security ","顯色":"Color ","主題":"Themes ",
|
||||
"風險":"Risk ","介面":"GUI ","核心":"Core ","服務":"Services ",
|
||||
"管理":"Manage","所有":"All ","您":"You ","取消":"Cancel ","未":"Not ",
|
||||
"垃圾":"Junk ","位元":"byte ","本機":"Computer ","停止":"Stop ",
|
||||
"增加到":"Add To ","白名單":"White List ","軟體":"Software ","正在":"Start ",
|
||||
"增加":"Add ","移除":"Delete","項目":"Items ","生成":"Create ","稱":"",
|
||||
"複製":"Copy ","開啟":"Open ","此":"This ","並":"And ","全盤":"Full ",
|
||||
"已經在":"Already ","數據庫":"Database ","誤報":"False Positive ",
|
||||
"高":"High ","新":"New ","和":"And ","可能會":"Possible ","會":"Can ",
|
||||
"日誌":"Log","已":"Has ","彈窗":"Window ","要":"To ","驅動":"Driver ",
|
||||
"的":"","顯示":"","個":"","嗎":"","中":"","了":"","行":"","立即":"",
|
||||
"密鑰":"Key ","檢測":"Detect ","製作":"Maker ","運行":"Running",
|
||||
"擴展套件":"Extension Kit ","自動":"Auto ","上報":"Report ","與":"With ",
|
||||
"分析":"Analysis ","自身":"Self ","其他":"Other ","配置":"Config ",
|
||||
"丟失":"Lost ","網站":"Website ","不兼容":"Not Compatible ","追蹤":"Tracking ",
|
||||
"竄改":"Tamper "," ":" "}}
|
||||
+14450
-9866
File diff suppressed because it is too large.
Load diff
@@ -1,11 +0,0 @@
|
||||
slist = [".exe",".dll",".com",".msi",".scr",
|
||||
".js",".bat",".cmd",".ps1",".vbs"]
|
||||
|
||||
alist = [".exe",".dll",".zip",".7z",".rar",
|
||||
".js",".bat",".cmd",".ps1",".vbs",
|
||||
".ppt",".pptx",".wps",".txt",".rtf",
|
||||
".pdf",".xls",".xlsx",".doc",".docx",
|
||||
".jpg",".jpeg",".png",".webp",".gif",
|
||||
".mp3",".wav",".aac",".ogg",".flac",
|
||||
".mp4",".avi",".mov",".wmv",".mkv",
|
||||
".aux",".cur",".mui",".ttf",".efi"]
|
||||
+1
-1
@@ -2,7 +2,7 @@ import pyinstaller_versionfile
|
||||
|
||||
pyinstaller_versionfile.create_versionfile(
|
||||
output_file="versionfile.txt",
|
||||
version='3.1.4',
|
||||
version='3.3.4',
|
||||
company_name="PYAS Security",
|
||||
file_description="Python Antivirus Software",
|
||||
internal_name="PYAS",
|
||||
|
||||
@@ -0,0 +1,224 @@
|
||||
#include <ntifs.h>
|
||||
#include "DriverEntry.h"
|
||||
#include "ProtectRules.h"
|
||||
|
||||
LARGE_INTEGER g_CmRegHandle;
|
||||
PDEVICE_OBJECT g_ControlDeviceObject;
|
||||
KSPIN_LOCK g_ProtectLock;
|
||||
FAST_MUTEX HookMutex;
|
||||
PDRIVER_OBJECT DiskDrvObj = NULL;
|
||||
KEVENT g_LogDrainEvent;
|
||||
BOOLEAN g_Unloading = FALSE;
|
||||
BOOLEAN g_CmRegActive = FALSE;
|
||||
EX_RUNDOWN_REF g_Rundown;
|
||||
PDEVICE_OBJECT g_GuardDevice = NULL;
|
||||
|
||||
volatile LONG g_LogWorkCount = 0;
|
||||
static UNICODE_STRING g_DeviceName;
|
||||
static WCHAR g_DeviceNameBuf[64];
|
||||
static UNICODE_STRING g_SymLink = RTL_CONSTANT_STRING(L"\\??\\PYAS_Driver");
|
||||
static BOOLEAN g_SymLinkCreated = FALSE;
|
||||
|
||||
static NTSTATUS CombinedDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||
{
|
||||
if (DeviceObject == g_ControlDeviceObject) {
|
||||
PIO_STACK_LOCATION s = IoGetCurrentIrpStackLocation(Irp);
|
||||
if (s->MajorFunction == IRP_MJ_CREATE || s->MajorFunction == IRP_MJ_CLOSE || s->MajorFunction == IRP_MJ_CLEANUP) {
|
||||
Irp->IoStatus.Status = STATUS_SUCCESS;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
return STATUS_INVALID_DEVICE_REQUEST;
|
||||
}
|
||||
{
|
||||
PIO_STACK_LOCATION s = IoGetCurrentIrpStackLocation(Irp);
|
||||
if (s->MajorFunction == IRP_MJ_PNP) {
|
||||
PDEVICE_OBJECT lower = (PDEVICE_OBJECT)DeviceObject->DeviceExtension;
|
||||
if (s->MinorFunction == IRP_MN_REMOVE_DEVICE) {
|
||||
NTSTATUS st;
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
st = lower ? IoCallDriver(lower, Irp) : STATUS_SUCCESS;
|
||||
if (lower) IoDetachDevice(lower);
|
||||
IoDeleteDevice(DeviceObject);
|
||||
return st;
|
||||
}
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
return IoCallDriver((PDEVICE_OBJECT)DeviceObject->DeviceExtension, Irp);
|
||||
}
|
||||
}
|
||||
return FileProtectDispatch(DeviceObject, Irp);
|
||||
}
|
||||
|
||||
static NTSTATUS AttachDiskFilters(PDRIVER_OBJECT DriverObject)
|
||||
{
|
||||
UNICODE_STRING name = RTL_CONSTANT_STRING(L"\\Driver\\Disk");
|
||||
UNICODE_STRING sym = RTL_CONSTANT_STRING(L"IoDriverObjectType");
|
||||
POBJECT_TYPE* pType = (POBJECT_TYPE*)MmGetSystemRoutineAddress(&sym);
|
||||
if (!pType || !*pType)
|
||||
return STATUS_NOT_SUPPORTED;
|
||||
|
||||
NTSTATUS status = ObReferenceObjectByName(&name, OBJ_CASE_INSENSITIVE, NULL, 0, *pType, KernelMode, NULL, (PVOID*)&DiskDrvObj);
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
ULONG done = 0;
|
||||
status = IoEnumerateDeviceObjectList(DiskDrvObj, NULL, 0, &done);
|
||||
if (status != STATUS_BUFFER_TOO_SMALL && status != STATUS_SUCCESS) {
|
||||
ObDereferenceObject(DiskDrvObj);
|
||||
DiskDrvObj = NULL;
|
||||
return status;
|
||||
}
|
||||
PDEVICE_OBJECT* list = ExAllocatePool2(POOL_FLAG_NON_PAGED, done * sizeof(PDEVICE_OBJECT), 'dskT');
|
||||
if (!list) {
|
||||
ObDereferenceObject(DiskDrvObj);
|
||||
DiskDrvObj = NULL;
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
}
|
||||
status = IoEnumerateDeviceObjectList(DiskDrvObj, list, done * sizeof(PDEVICE_OBJECT), &done);
|
||||
if (!NT_SUCCESS(status)) {
|
||||
ExFreePool2(list, 'dskT', NULL, 0);
|
||||
ObDereferenceObject(DiskDrvObj);
|
||||
DiskDrvObj = NULL;
|
||||
return status;
|
||||
}
|
||||
for (ULONG i = 0; i < done && g_MbrFilterCount < MAX_MBR_TARGETS; ++i) {
|
||||
PDEVICE_OBJECT lower = list[i], filter, attached = NULL;
|
||||
status = IoCreateDevice(DriverObject, 0, NULL, lower->DeviceType, lower->Characteristics, FALSE, &filter);
|
||||
if (!NT_SUCCESS(status))
|
||||
continue;
|
||||
|
||||
filter->Flags |= (lower->Flags & (DO_BUFFERED_IO | DO_DIRECT_IO | DO_POWER_PAGABLE));
|
||||
status = IoAttachDeviceToDeviceStackSafe(filter, lower, &attached);
|
||||
if (!NT_SUCCESS(status) || !attached) {
|
||||
IoDeleteDevice(filter);
|
||||
continue;
|
||||
}
|
||||
filter->StackSize = lower->StackSize + 1;
|
||||
filter->AlignmentRequirement = lower->AlignmentRequirement;
|
||||
filter->DeviceExtension = attached;
|
||||
filter->Flags &= ~DO_DEVICE_INITIALIZING;
|
||||
g_MbrFilterTargets[g_MbrFilterCount++] = filter;
|
||||
}
|
||||
for (ULONG i = 0; i < done; ++i)
|
||||
ObDereferenceObject(list[i]);
|
||||
ExFreePool2(list, 'dskT', NULL, 0);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS DriverEntry(PDRIVER_OBJECT DriverObject, PUNICODE_STRING RegistryPath)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(RegistryPath);
|
||||
|
||||
KeInitializeSpinLock(&g_ProtectLock);
|
||||
ExInitializeFastMutex(&HookMutex);
|
||||
KeInitializeEvent(&g_LogDrainEvent, NotificationEvent, TRUE);
|
||||
g_Unloading = FALSE;
|
||||
g_CmRegActive = FALSE;
|
||||
|
||||
InterlockedExchange(&g_LogWorkCount, 0);
|
||||
ExInitializeRundownProtection(&g_Rundown);
|
||||
{
|
||||
UNICODE_STRING guardName = RTL_CONSTANT_STRING(L"\\Device\\PYAS_Driver_Guard");
|
||||
NTSTATUS gs = IoCreateDevice(DriverObject, 0, &guardName, FILE_DEVICE_UNKNOWN, 0, FALSE, &g_GuardDevice);
|
||||
if (!NT_SUCCESS(gs))
|
||||
return STATUS_DEVICE_BUSY;
|
||||
}
|
||||
{
|
||||
LARGE_INTEGER t = KeQueryPerformanceCounter(NULL);
|
||||
g_DeviceName.Buffer = g_DeviceNameBuf;
|
||||
g_DeviceName.MaximumLength = sizeof(g_DeviceNameBuf);
|
||||
RtlStringCchPrintfW(g_DeviceName.Buffer, RTL_NUMBER_OF(g_DeviceNameBuf), L"\\Device\\PYAS_Driver_%p_%I64x", DriverObject, t.QuadPart);
|
||||
g_DeviceName.Length = (USHORT)(wcslen(g_DeviceName.Buffer) * sizeof(WCHAR));
|
||||
}
|
||||
NTSTATUS status = IoCreateDevice(DriverObject, 0, &g_DeviceName, FILE_DEVICE_UNKNOWN, 0, FALSE, &g_ControlDeviceObject);
|
||||
if (!NT_SUCCESS(status))
|
||||
return status;
|
||||
|
||||
DriverObject->DriverUnload = DriverUnload;
|
||||
for (ULONG i = 0; i < IRP_MJ_MAXIMUM_FUNCTION; ++i)
|
||||
DriverObject->MajorFunction[i] = CombinedDispatch;
|
||||
g_ControlDeviceObject->Flags &= ~DO_DEVICE_INITIALIZING;
|
||||
IoDeleteSymbolicLink(&g_SymLink);
|
||||
{
|
||||
UINT i = 0;
|
||||
for (; i < 50; ++i) {
|
||||
status = IoCreateSymbolicLink(&g_SymLink, &g_DeviceName);
|
||||
if (NT_SUCCESS(status))
|
||||
break;
|
||||
LARGE_INTEGER d = { 0 };
|
||||
d.QuadPart = -10LL * 1000LL * 10LL;
|
||||
KeDelayExecutionThread(KernelMode, FALSE, &d);
|
||||
IoDeleteSymbolicLink(&g_SymLink);
|
||||
}
|
||||
if (!NT_SUCCESS(status)) {
|
||||
IoDeleteDevice(g_ControlDeviceObject);
|
||||
g_ControlDeviceObject = NULL;
|
||||
if (g_GuardDevice) {
|
||||
IoDeleteDevice(g_GuardDevice);
|
||||
g_GuardDevice = NULL;
|
||||
}
|
||||
return status;
|
||||
}
|
||||
}
|
||||
g_SymLinkCreated = TRUE;
|
||||
{
|
||||
static WCHAR regAltBuf[32];
|
||||
static UNICODE_STRING regAlt;
|
||||
LARGE_INTEGER t = KeQueryPerformanceCounter(NULL);
|
||||
RtlStringCchPrintfW(regAltBuf, RTL_NUMBER_OF(regAltBuf), L"385100.%I64x", t.QuadPart);
|
||||
RtlInitUnicodeString(®Alt, regAltBuf);
|
||||
status = CmRegisterCallbackEx(RegistryProtectCallback, ®Alt, DriverObject, NULL, &g_CmRegHandle, NULL);
|
||||
if (NT_SUCCESS(status))
|
||||
g_CmRegActive = TRUE;
|
||||
}
|
||||
InitImageProtect();
|
||||
InitInjectProtect();
|
||||
AttachDiskFilters(DriverObject);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
|
||||
VOID DriverUnload(PDRIVER_OBJECT DriverObject)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(DriverObject);
|
||||
g_Unloading = TRUE;
|
||||
if (g_SymLinkCreated) {
|
||||
IoDeleteSymbolicLink(&g_SymLink);
|
||||
g_SymLinkCreated = FALSE;
|
||||
}
|
||||
if (g_CmRegActive) {
|
||||
CmUnRegisterCallback(g_CmRegHandle);
|
||||
g_CmRegActive = FALSE;
|
||||
}
|
||||
UninitInjectProtect();
|
||||
UninitImageProtect();
|
||||
ExWaitForRundownProtectionRelease(&g_Rundown);
|
||||
if (InterlockedCompareExchange(&g_LogWorkCount, 0, 0) != 0) {
|
||||
KeResetEvent(&g_LogDrainEvent);
|
||||
while (InterlockedCompareExchange(&g_LogWorkCount, 0, 0) != 0)
|
||||
KeWaitForSingleObject(&g_LogDrainEvent, Executive, KernelMode, FALSE, NULL);
|
||||
}
|
||||
for (ULONG i = 0; i < g_MbrFilterCount; ++i) {
|
||||
if (g_MbrFilterTargets[i]) {
|
||||
IoDetachDevice((PDEVICE_OBJECT)g_MbrFilterTargets[i]->DeviceExtension);
|
||||
IoDeleteDevice(g_MbrFilterTargets[i]);
|
||||
g_MbrFilterTargets[i] = NULL;
|
||||
}
|
||||
}
|
||||
g_MbrFilterCount = 0;
|
||||
if (DiskDrvObj) {
|
||||
ObDereferenceObject(DiskDrvObj);
|
||||
DiskDrvObj = NULL;
|
||||
}
|
||||
if (g_ControlDeviceObject) {
|
||||
IoDeleteDevice(g_ControlDeviceObject);
|
||||
g_ControlDeviceObject = NULL;
|
||||
}
|
||||
if (g_GuardDevice) {
|
||||
IoDeleteDevice(g_GuardDevice);
|
||||
g_GuardDevice = NULL;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,147 @@
|
||||
#pragma once
|
||||
#include <ntifs.h>
|
||||
#include <ntstrsafe.h>
|
||||
#include <ntdddisk.h>
|
||||
|
||||
#define PIPE_NAME L"\\??\\pipe\\PYAS_Output_Pipe"
|
||||
#define MAX_MBR_TARGETS 52
|
||||
|
||||
#ifndef POOL_FLAG_NON_PAGED
|
||||
#define POOL_FLAG_NON_PAGED 0x00000001
|
||||
#endif
|
||||
#ifndef PROCESS_CREATE_THREAD
|
||||
#define PROCESS_CREATE_THREAD 0x0002
|
||||
#endif
|
||||
#ifndef PROCESS_VM_OPERATION
|
||||
#define PROCESS_VM_OPERATION 0x0008
|
||||
#endif
|
||||
#ifndef PROCESS_VM_WRITE
|
||||
#define PROCESS_VM_WRITE 0x0020
|
||||
#endif
|
||||
#ifndef PROCESS_VM_READ
|
||||
#define PROCESS_VM_READ 0x0010
|
||||
#endif
|
||||
#ifndef PROCESS_DUP_HANDLE
|
||||
#define PROCESS_DUP_HANDLE 0x0040
|
||||
#endif
|
||||
#ifndef PROCESS_CREATE_PROCESS
|
||||
#define PROCESS_CREATE_PROCESS 0x0080
|
||||
#endif
|
||||
#ifndef PROCESS_SET_QUOTA
|
||||
#define PROCESS_SET_QUOTA 0x0100
|
||||
#endif
|
||||
#ifndef PROCESS_SET_INFORMATION
|
||||
#define PROCESS_SET_INFORMATION 0x0200
|
||||
#endif
|
||||
#ifndef PROCESS_SUSPEND_RESUME
|
||||
#define PROCESS_SUSPEND_RESUME 0x0800
|
||||
#endif
|
||||
#ifndef PROCESS_QUERY_LIMITED_INFORMATION
|
||||
#define PROCESS_QUERY_LIMITED_INFORMATION 0x1000
|
||||
#endif
|
||||
#ifndef PROCESS_SET_LIMITED_INFORMATION
|
||||
#define PROCESS_SET_LIMITED_INFORMATION 0x2000
|
||||
#endif
|
||||
#ifndef THREAD_IMPERSONATE
|
||||
#define THREAD_IMPERSONATE 0x0100
|
||||
#endif
|
||||
#ifndef THREAD_DIRECT_IMPERSONATION
|
||||
#define THREAD_DIRECT_IMPERSONATION 0x0200
|
||||
#endif
|
||||
#ifndef UINT
|
||||
typedef unsigned int UINT;
|
||||
#endif
|
||||
|
||||
extern volatile LONG g_LogWorkCount;
|
||||
extern BOOLEAN g_Unloading;
|
||||
extern KEVENT g_LogDrainEvent;
|
||||
extern PDEVICE_OBJECT g_MbrFilterTargets[MAX_MBR_TARGETS];
|
||||
extern ULONG g_MbrFilterCount;
|
||||
extern KSPIN_LOCK g_ProtectLock;
|
||||
extern LARGE_INTEGER g_CmRegHandle;
|
||||
extern POBJECT_TYPE* IoDriverObjectType;
|
||||
extern FAST_MUTEX HookMutex;
|
||||
extern PDRIVER_OBJECT DiskDrvObj;
|
||||
extern PCSTR PsGetProcessImageFileName(PEPROCESS Process);
|
||||
extern EX_RUNDOWN_REF g_Rundown;
|
||||
extern PDEVICE_OBJECT g_GuardDevice;
|
||||
|
||||
typedef PVOID(NTAPI* _pyas_ExAllocatePool2)(ULONG, SIZE_T, ULONG);
|
||||
typedef VOID(NTAPI* _pyas_ExFreePool2)(PVOID, ULONG, PVOID, ULONG);
|
||||
typedef PVOID(NTAPI* _pyas_ExAllocatePoolWithTag)(POOL_TYPE, SIZE_T, ULONG);
|
||||
typedef VOID(NTAPI* _pyas_ExFreePoolWithTag)(PVOID, ULONG);
|
||||
|
||||
static __forceinline PVOID PYAS_ExAllocatePool2(ULONG f, SIZE_T s, ULONG t) {
|
||||
static _pyas_ExAllocatePool2 p2 = 0;
|
||||
if (!p2) {
|
||||
UNICODE_STRING n = RTL_CONSTANT_STRING(L"ExAllocatePool2");
|
||||
p2 = (_pyas_ExAllocatePool2)MmGetSystemRoutineAddress(&n);
|
||||
}
|
||||
if (p2)
|
||||
return p2(f, s, t);
|
||||
static _pyas_ExAllocatePoolWithTag p1 = 0;
|
||||
if (!p1) {
|
||||
UNICODE_STRING n = RTL_CONSTANT_STRING(L"ExAllocatePoolWithTag");
|
||||
p1 = (_pyas_ExAllocatePoolWithTag)MmGetSystemRoutineAddress(&n);
|
||||
}
|
||||
if (p1)
|
||||
return p1((f & POOL_FLAG_NON_PAGED) ? NonPagedPoolNx : PagedPool, s, t);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static __forceinline VOID PYAS_ExFreePool2(PVOID a, ULONG t, PVOID h, ULONG f) {
|
||||
UNREFERENCED_PARAMETER(h);
|
||||
UNREFERENCED_PARAMETER(f);
|
||||
static _pyas_ExFreePool2 p2 = 0;
|
||||
if (!p2) {
|
||||
UNICODE_STRING n = RTL_CONSTANT_STRING(L"ExFreePool2");
|
||||
p2 = (_pyas_ExFreePool2)MmGetSystemRoutineAddress(&n);
|
||||
}
|
||||
if (p2) {
|
||||
p2(a, t, h, f);
|
||||
return;
|
||||
}
|
||||
static _pyas_ExFreePoolWithTag p1 = 0;
|
||||
if (!p1) {
|
||||
UNICODE_STRING n = RTL_CONSTANT_STRING(L"ExFreePoolWithTag");
|
||||
p1 = (_pyas_ExFreePoolWithTag)MmGetSystemRoutineAddress(&n);
|
||||
}
|
||||
if (p1) {
|
||||
p1(a, t);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#define ExAllocatePool2 PYAS_ExAllocatePool2
|
||||
#define ExFreePool2 PYAS_ExFreePool2
|
||||
|
||||
VOID DriverUnload(PDRIVER_OBJECT DriverObject);
|
||||
VOID SendPipeLog(PCSTR msg, SIZE_T len);
|
||||
VOID UninitImageProtect(VOID);
|
||||
VOID UninitInjectProtect(VOID);
|
||||
|
||||
NTSYSAPI NTSTATUS NTAPI ZwQueryInformationProcess(
|
||||
_In_ HANDLE ProcessHandle,
|
||||
_In_ PROCESSINFOCLASS ProcessInformationClass,
|
||||
_Out_writes_bytes_opt_(ProcessInformationLength) PVOID ProcessInformation,
|
||||
_In_ ULONG ProcessInformationLength,
|
||||
_Out_opt_ PULONG ReturnLength
|
||||
);
|
||||
|
||||
NTSTATUS ObReferenceObjectByName(
|
||||
IN PUNICODE_STRING ObjectName,
|
||||
IN ULONG Attributes,
|
||||
IN PACCESS_STATE PassedAccessState OPTIONAL,
|
||||
IN ACCESS_MASK DesiredAccess OPTIONAL,
|
||||
IN POBJECT_TYPE ObjectType,
|
||||
IN KPROCESSOR_MODE AccessMode,
|
||||
IN OUT PVOID ParseContext OPTIONAL,
|
||||
OUT PVOID* Object
|
||||
);
|
||||
|
||||
NTSTATUS FileProtectDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp);
|
||||
NTSTATUS RegistryProtectCallback(PVOID ctx, PVOID arg1, PVOID arg2);
|
||||
NTSTATUS InitImageProtect(VOID);
|
||||
NTSTATUS InitInjectProtect(VOID);
|
||||
|
||||
BOOLEAN GetProcessImagePathByPid(HANDLE pid, PUNICODE_STRING ProcessImagePath);
|
||||
@@ -0,0 +1,63 @@
|
||||
#include <ntifs.h>
|
||||
#include "DriverEntry.h"
|
||||
|
||||
extern PDEVICE_OBJECT g_ControlDeviceObject;
|
||||
|
||||
typedef struct _PIPE_LOG_CTX {
|
||||
PIO_WORKITEM Item;
|
||||
SIZE_T Len;
|
||||
PCHAR Buf;
|
||||
}PIPE_LOG_CTX, * PPIPE_LOG_CTX;
|
||||
|
||||
static VOID PipeLogWork(PDEVICE_OBJECT DeviceObject, PVOID Context)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(DeviceObject);
|
||||
PPIPE_LOG_CTX ctx = (PPIPE_LOG_CTX)Context;
|
||||
HANDLE h = NULL;
|
||||
UNICODE_STRING name;
|
||||
OBJECT_ATTRIBUTES oa = { 0 };
|
||||
IO_STATUS_BLOCK iosb;
|
||||
|
||||
RtlInitUnicodeString(&name, PIPE_NAME);
|
||||
InitializeObjectAttributes(&oa, &name, OBJ_CASE_INSENSITIVE | OBJ_KERNEL_HANDLE, NULL, NULL);
|
||||
if (NT_SUCCESS(ZwCreateFile(&h, FILE_GENERIC_WRITE, &oa, &iosb, NULL, 0, 0, FILE_OPEN, FILE_SYNCHRONOUS_IO_NONALERT, NULL, 0)))
|
||||
{
|
||||
ZwWriteFile(h, NULL, NULL, NULL, &iosb, ctx->Buf, (ULONG)(ctx->Len > 0xFFFFFFFF ? 0xFFFFFFFF : ctx->Len), NULL, NULL);
|
||||
ZwClose(h);
|
||||
}
|
||||
IoFreeWorkItem(ctx->Item);
|
||||
ExFreePool2(ctx->Buf, 'golP', NULL, 0);
|
||||
ExFreePool2(ctx, 'golP', NULL, 0);
|
||||
if (InterlockedDecrement(&g_LogWorkCount) == 0 && g_Unloading)
|
||||
KeSetEvent(&g_LogDrainEvent, IO_NO_INCREMENT, FALSE);
|
||||
}
|
||||
|
||||
VOID SendPipeLog(PCSTR msg, SIZE_T len)
|
||||
{
|
||||
if (!msg || len == 0)
|
||||
return;
|
||||
if (!g_ControlDeviceObject)
|
||||
return;
|
||||
if (g_Unloading)
|
||||
return;
|
||||
|
||||
PPIPE_LOG_CTX ctx = (PPIPE_LOG_CTX)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(PIPE_LOG_CTX), 'golP');
|
||||
if (!ctx)
|
||||
return;
|
||||
|
||||
ctx->Len = len;
|
||||
ctx->Buf = (PCHAR)ExAllocatePool2(POOL_FLAG_NON_PAGED, ctx->Len, 'golP');
|
||||
if (!ctx->Buf) {
|
||||
ExFreePool2(ctx, 'golP', NULL, 0);
|
||||
return;
|
||||
}
|
||||
RtlCopyMemory(ctx->Buf, msg, ctx->Len);
|
||||
ctx->Item = IoAllocateWorkItem(g_ControlDeviceObject);
|
||||
if (!ctx->Item) {
|
||||
ExFreePool2(ctx->Buf, 'golP', NULL, 0);
|
||||
ExFreePool2(ctx, 'golP', NULL, 0);
|
||||
return;
|
||||
}
|
||||
InterlockedIncrement(&g_LogWorkCount);
|
||||
IoQueueWorkItem(ctx->Item, PipeLogWork, DelayedWorkQueue, ctx);
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
[Version]
|
||||
Signature = "$WINDOWS NT$"
|
||||
Class = System
|
||||
ClassGuid = {4d36e97d-e325-11ce-bfc1-08002be10318}
|
||||
Provider = %ManufacturerName%
|
||||
CatalogFile = PYAS_Driver.cat
|
||||
PnpLockdown = 1
|
||||
DriverVer =
|
||||
|
||||
[DestinationDirs]
|
||||
DefaultDestDir = 13
|
||||
|
||||
[DefaultInstall.ntamd64]
|
||||
CopyFiles = @PYAS_Driver.sys
|
||||
AddService = PYAS_Driver,0x00000002
|
||||
|
||||
[SourceDisksFiles]
|
||||
PYAS_Driver.sys = 1
|
||||
|
||||
[SourceDisksNames]
|
||||
1 = %DiskName%,,,""
|
||||
|
||||
[Strings]
|
||||
ManufacturerName = "PYAS_Driver"
|
||||
DiskName = "PYAS_Driver"
|
||||
ServiceName="PYAS_Driver"
|
||||
ServiceDisplayName="PYAS_Driver"
|
||||
@@ -0,0 +1,123 @@
|
||||
#include <ntifs.h>
|
||||
#include "DriverEntry.h"
|
||||
#include "ProtectRules.h"
|
||||
|
||||
PDEVICE_OBJECT g_MbrFilterTargets[MAX_MBR_TARGETS] = { 0 };
|
||||
ULONG g_MbrFilterCount = 0;
|
||||
|
||||
NTSTATUS FileProtectDispatch(PDEVICE_OBJECT DeviceObject, PIRP Irp)
|
||||
{
|
||||
PDEVICE_OBJECT lower = (PDEVICE_OBJECT)DeviceObject->DeviceExtension;
|
||||
if (!lower) {
|
||||
Irp->IoStatus.Status = STATUS_INVALID_DEVICE_REQUEST;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
return STATUS_INVALID_DEVICE_REQUEST;
|
||||
}
|
||||
if (!ExAcquireRundownProtection(&g_Rundown)) {
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
return IoCallDriver(lower, Irp);
|
||||
}
|
||||
if (g_Unloading) {
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
NTSTATUS st = IoCallDriver(lower, Irp);
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return st;
|
||||
}
|
||||
PIO_STACK_LOCATION stack = IoGetCurrentIrpStackLocation(Irp);
|
||||
if (stack->MajorFunction == IRP_MJ_POWER) {
|
||||
PoStartNextPowerIrp(Irp);
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
NTSTATUS st = PoCallDriver(lower, Irp);
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return st;
|
||||
}
|
||||
HANDLE pid = PsGetCurrentProcessId();
|
||||
ULONG currentPid = (ULONG)(ULONG_PTR)pid;
|
||||
if (currentPid == 0 || currentPid == 4) {
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
NTSTATUS st = IoCallDriver(lower, Irp);
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return st;
|
||||
}
|
||||
BOOLEAN blocked = FALSE, is_white = FALSE;
|
||||
CHAR logbuf[1024] = { 0 };
|
||||
|
||||
WCHAR exeBuf[512] = { 0 };
|
||||
UNICODE_STRING exeName = { 0 };
|
||||
exeName.Buffer = exeBuf;
|
||||
exeName.MaximumLength = sizeof(exeBuf);
|
||||
exeName.Length = 0;
|
||||
|
||||
if (KeGetCurrentIrql() == PASSIVE_LEVEL) {
|
||||
if (GetProcessImagePathByPid(pid, &exeName))
|
||||
is_white = IsWhitelist(&exeName);
|
||||
else {
|
||||
PEPROCESS eproc = PsGetCurrentProcess();
|
||||
PCSTR n = PsGetProcessImageFileName(eproc);
|
||||
size_t l = n ? strlen(n) : 0;
|
||||
for (size_t i = 0; i < l && i < RTL_NUMBER_OF(exeBuf) - 1; i++)
|
||||
exeBuf[i] = (WCHAR)n[i];
|
||||
exeBuf[l] = 0;
|
||||
exeName.Length = (USHORT)(l * sizeof(WCHAR));
|
||||
}
|
||||
}
|
||||
if (!is_white) {
|
||||
UCHAR mj = stack->MajorFunction;
|
||||
BOOLEAN isDisk = (DeviceObject->DeviceType == FILE_DEVICE_DISK);
|
||||
|
||||
if (!isDisk) {
|
||||
PDEVICE_OBJECT tdo = IoGetAttachedDeviceReference(lower);
|
||||
if (tdo) {
|
||||
isDisk = (tdo->DeviceType == FILE_DEVICE_DISK || tdo->DeviceType == FILE_DEVICE_DISK_FILE_SYSTEM);
|
||||
ObDereferenceObject(tdo);
|
||||
}
|
||||
}
|
||||
if (isDisk) {
|
||||
if (mj == IRP_MJ_WRITE || mj == IRP_MJ_SET_INFORMATION || mj == IRP_MJ_DEVICE_CONTROL || mj == IRP_MJ_INTERNAL_DEVICE_CONTROL) blocked = TRUE;
|
||||
}
|
||||
}
|
||||
if (blocked) {
|
||||
if (KeGetCurrentIrql() == PASSIVE_LEVEL) {
|
||||
CHAR target[64] = "None";
|
||||
ULONG ret = 0;
|
||||
POBJECT_NAME_INFORMATION oni = (POBJECT_NAME_INFORMATION)ExAllocatePool2(POOL_FLAG_NON_PAGED, 1024, 'nOmD');
|
||||
|
||||
if (oni && NT_SUCCESS(ObQueryNameString(lower, oni, 1024, &ret)) && oni->Name.Buffer && oni->Name.Length >= sizeof(WCHAR) * 2) {
|
||||
USHORT len = oni->Name.Length / sizeof(WCHAR);
|
||||
ULONG dr = 0;
|
||||
BOOLEAN hasDr = FALSE;
|
||||
|
||||
for (USHORT i = 0; i + 2 < len; i++) {
|
||||
if (oni->Name.Buffer[i] == L'D' && oni->Name.Buffer[i + 1] == L'R') {
|
||||
USHORT j = i + 2;
|
||||
ULONG x = 0;
|
||||
|
||||
while (j < len && oni->Name.Buffer[j] >= L'0' && oni->Name.Buffer[j] <= L'9') {
|
||||
x = x * 10 + (oni->Name.Buffer[j] - L'0');
|
||||
j++;
|
||||
}
|
||||
dr = x;
|
||||
hasDr = TRUE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hasDr)
|
||||
RtlStringCchPrintfA(target, sizeof(target), "Disk\\Device\\DR%u", dr);
|
||||
}
|
||||
if (oni)
|
||||
ExFreePool2(oni, 'nOmD', NULL, 0);
|
||||
RtlStringCchPrintfA(logbuf, sizeof(logbuf), "BOOT_BLOCK | %u | %wZ | %s", currentPid, &exeName, target);
|
||||
SendPipeLog(logbuf, strlen(logbuf));
|
||||
}
|
||||
Irp->IoStatus.Status = STATUS_ACCESS_DENIED;
|
||||
Irp->IoStatus.Information = 0;
|
||||
IoCompleteRequest(Irp, IO_NO_INCREMENT);
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return STATUS_ACCESS_DENIED;
|
||||
}
|
||||
IoSkipCurrentIrpStackLocation(Irp);
|
||||
NTSTATUS st = IoCallDriver(lower, Irp);
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return st;
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
#include <ntifs.h>
|
||||
#include "DriverEntry.h"
|
||||
#include "ProtectRules.h"
|
||||
|
||||
static BOOLEAN g_ImageNotifyEnabled = FALSE;
|
||||
|
||||
static BOOLEAN StrStrI(const wchar_t* s, const wchar_t* sub) {
|
||||
if (!s || !sub)
|
||||
return FALSE;
|
||||
|
||||
size_t n = wcslen(s), m = wcslen(sub);
|
||||
if (m == 0 || n < m)
|
||||
return FALSE;
|
||||
|
||||
for (size_t i = 0; i + m <= n; i++) {
|
||||
size_t j = 0;
|
||||
for (; j < m; j++) {
|
||||
WCHAR a = s[i + j], b = sub[j];
|
||||
if (a >= L'A' && a <= L'Z')
|
||||
a += 32;
|
||||
if (b >= L'A' && b <= L'Z')
|
||||
b += 32;
|
||||
if (a != b)
|
||||
break;
|
||||
}
|
||||
if (j == m)
|
||||
return TRUE;
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOLEAN CheckStackVAD(PVOID a) {
|
||||
MEMORY_BASIC_INFORMATION mbi = { 0 };
|
||||
SIZE_T ret = 0;
|
||||
NTSTATUS s = ZwQueryVirtualMemory(NtCurrentProcess(), a, MemoryBasicInformation, &mbi, sizeof(mbi), &ret);
|
||||
|
||||
if (!NT_SUCCESS(s))
|
||||
return FALSE;
|
||||
if (mbi.State != MEM_COMMIT)
|
||||
return FALSE;
|
||||
if (mbi.Type == SEC_IMAGE)
|
||||
return FALSE;
|
||||
if (mbi.Type != MEM_PRIVATE && mbi.Type != MEM_MAPPED)
|
||||
return FALSE;
|
||||
return (mbi.Protect & (PAGE_EXECUTE | PAGE_EXECUTE_READ | PAGE_EXECUTE_READWRITE | PAGE_EXECUTE_WRITECOPY)) != 0;
|
||||
}
|
||||
|
||||
static BOOLEAN CheckShellcodeWalkStack(ULONG h) {
|
||||
#define MAXWALK 20
|
||||
PVOID frames[MAXWALK] = { 0 };
|
||||
ULONG c = RtlWalkFrameChain(frames, MAXWALK, 1);
|
||||
if (c == 0)
|
||||
return FALSE;
|
||||
|
||||
ULONG limit = RTL_NUMBER_OF(frames);
|
||||
ULONG count = c < limit ? c : limit;
|
||||
ULONG d = h < count ? h : count;
|
||||
|
||||
for (ULONG i = 0; i < d; i++) {
|
||||
PVOID p = frames[i];
|
||||
if (p && CheckStackVAD(p))
|
||||
return TRUE;
|
||||
}
|
||||
for (ULONG i = 0; i < d; i++) {
|
||||
ULONG idx = count - 1 - i;
|
||||
if (idx >= d) {
|
||||
PVOID p = frames[idx];
|
||||
if (p && CheckStackVAD(p))
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static BOOLEAN IsFrameworkClrPath(const wchar_t* s) {
|
||||
if (!s)
|
||||
return FALSE;
|
||||
if (!StrStrI(s, L"\\Windows\\Microsoft.NET\\"))
|
||||
return FALSE;
|
||||
if (!StrStrI(s, L"\\Framework\\") && !StrStrI(s, L"\\Framework64\\"))
|
||||
return FALSE;
|
||||
if (StrStrI(s, L"\\clr.dll") || StrStrI(s, L"\\mscorwks.dll"))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static VOID ImageLoadNotify(IN PUNICODE_STRING FullImageName, IN HANDLE ProcessId, IN PIMAGE_INFO ImageInfo)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(ImageInfo);
|
||||
if (g_Unloading)
|
||||
return;
|
||||
if (ProcessId == (HANDLE)0 || ProcessId == (HANDLE)4)
|
||||
return;
|
||||
if (KeGetCurrentIrql() != PASSIVE_LEVEL)
|
||||
return;
|
||||
if (!ExAcquireRundownProtection(&g_Rundown))
|
||||
return;
|
||||
|
||||
WCHAR exeBuf[512] = { 0 };
|
||||
UNICODE_STRING exeName = { 0 };
|
||||
exeName.Buffer = exeBuf;
|
||||
exeName.MaximumLength = sizeof(exeBuf);
|
||||
exeName.Length = 0;
|
||||
|
||||
if (!GetProcessImagePathByPid(ProcessId, &exeName)) {
|
||||
PEPROCESS eproc = PsGetCurrentProcess();
|
||||
PCSTR n = PsGetProcessImageFileName(eproc);
|
||||
size_t l = n ? strlen(n) : 0;
|
||||
|
||||
for (size_t i = 0; i < l && i < RTL_NUMBER_OF(exeBuf) - 1; i++)
|
||||
exeBuf[i] = (WCHAR)n[i];
|
||||
exeBuf[l] = 0;
|
||||
exeName.Length = (USHORT)(l * sizeof(WCHAR));
|
||||
}
|
||||
if (exeName.Length & 1) exeName.Length--;
|
||||
{
|
||||
size_t elen = exeName.Length / sizeof(WCHAR);
|
||||
if ((elen >= 14 && _wcsnicmp(exeName.Buffer + elen - 14, L"powershell.exe", 14) == 0) ||
|
||||
(elen >= 8 && _wcsnicmp(exeName.Buffer + elen - 8, L"pwsh.exe", 8) == 0)) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (IsWhitelist(&exeName)) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return;
|
||||
}
|
||||
CHAR logbuf[1024] = { 0 };
|
||||
if (FullImageName && FullImageName->Buffer) {
|
||||
if ((StrStrI(FullImageName->Buffer, L"clr.dll") || StrStrI(FullImageName->Buffer, L"mscorwks.dll")) && !IsFrameworkClrPath(FullImageName->Buffer)) {
|
||||
RtlStringCchPrintfA(logbuf, sizeof(logbuf), "CLR_BLOCK | %u | %wZ | %wZ", (ULONG)(ULONG_PTR)ProcessId, &exeName, FullImageName);
|
||||
SendPipeLog(logbuf, strlen(logbuf));
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (CheckShellcodeWalkStack(8)) {
|
||||
RtlStringCchPrintfA(logbuf, sizeof(logbuf), "SHELLCODE_BLOCK | %u | %wZ | None", (ULONG)(ULONG_PTR)ProcessId, &exeName);
|
||||
SendPipeLog(logbuf, strlen(logbuf));
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return;
|
||||
}
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
}
|
||||
|
||||
NTSTATUS InitImageProtect(VOID) {
|
||||
NTSTATUS s = PsSetLoadImageNotifyRoutine(ImageLoadNotify);
|
||||
if (NT_SUCCESS(s))
|
||||
g_ImageNotifyEnabled = TRUE;
|
||||
return s;
|
||||
}
|
||||
|
||||
VOID UninitImageProtect(VOID) {
|
||||
if (g_ImageNotifyEnabled) {
|
||||
PsRemoveLoadImageNotifyRoutine(ImageLoadNotify);
|
||||
g_ImageNotifyEnabled = FALSE;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,187 @@
|
||||
#include <ntifs.h>
|
||||
#include "DriverEntry.h"
|
||||
#include "ProtectRules.h"
|
||||
|
||||
static PVOID g_ObRegHandle = NULL;
|
||||
static POB_OPERATION_REGISTRATION g_ObOps = NULL;
|
||||
static OB_CALLBACK_REGISTRATION g_ObReg = { 0 };
|
||||
|
||||
static OB_PREOP_CALLBACK_STATUS PreProcessCallback(PVOID RegistrationContext, POB_PRE_OPERATION_INFORMATION Info)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(RegistrationContext);
|
||||
if (g_Unloading)
|
||||
return OB_PREOP_SUCCESS;
|
||||
if (!Info || Info->KernelHandle)
|
||||
return OB_PREOP_SUCCESS;
|
||||
if (!Info->Object)
|
||||
return OB_PREOP_SUCCESS;
|
||||
if (Info->Operation != OB_OPERATION_HANDLE_CREATE && Info->Operation != OB_OPERATION_HANDLE_DUPLICATE)
|
||||
return OB_PREOP_SUCCESS;
|
||||
if (!ExAcquireRundownProtection(&g_Rundown))
|
||||
return OB_PREOP_SUCCESS;
|
||||
|
||||
HANDLE cur = PsGetCurrentProcessId();
|
||||
if (cur == (HANDLE)0 || cur == (HANDLE)4) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return OB_PREOP_SUCCESS;
|
||||
}
|
||||
HANDLE target = PsGetProcessId((PEPROCESS)Info->Object);
|
||||
if (target == cur) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return OB_PREOP_SUCCESS;
|
||||
}
|
||||
ACCESS_MASK* desired = (Info->Operation == OB_OPERATION_HANDLE_CREATE) ? &Info->Parameters->CreateHandleInformation.DesiredAccess : &Info->Parameters->DuplicateHandleInformation.DesiredAccess;
|
||||
ACCESS_MASK mask = PROCESS_CREATE_THREAD | PROCESS_VM_OPERATION | PROCESS_VM_WRITE;
|
||||
PCSTR tn = PsGetProcessImageFileName((PEPROCESS)Info->Object);
|
||||
if (tn && (_stricmp(tn, "lsass.exe") == 0))
|
||||
mask |= PROCESS_VM_READ;
|
||||
|
||||
if ((*desired & mask) == 0) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return OB_PREOP_SUCCESS;
|
||||
}
|
||||
BOOLEAN logok = (KeGetCurrentIrql() == PASSIVE_LEVEL);
|
||||
WCHAR cbuf[512] = { 0 }, tbuf[512] = { 0 };
|
||||
UNICODE_STRING cexe = { 0 }, texe = { 0 };
|
||||
cexe.Buffer = cbuf; cexe.MaximumLength = sizeof(cbuf);
|
||||
texe.Buffer = tbuf; texe.MaximumLength = sizeof(tbuf);
|
||||
|
||||
if (logok)
|
||||
GetProcessImagePathByPid(cur, &cexe);
|
||||
if (logok && IsWhitelist(&cexe)) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return OB_PREOP_SUCCESS;
|
||||
}
|
||||
ACCESS_MASK old = *desired;
|
||||
*desired &= ~mask;
|
||||
if ((*desired) != old && logok) {
|
||||
GetProcessImagePathByPid(target, &texe);
|
||||
|
||||
if (cexe.Length == 0) {
|
||||
PEPROCESS eproc = PsGetCurrentProcess();
|
||||
PCSTR n = PsGetProcessImageFileName(eproc);
|
||||
size_t l = n ? strlen(n) : 0;
|
||||
|
||||
for (size_t i = 0; i < l && i < RTL_NUMBER_OF(cbuf) - 1; i++)
|
||||
cbuf[i] = (WCHAR)n[i];
|
||||
cbuf[l] = 0;
|
||||
cexe.Length = (USHORT)(l * sizeof(WCHAR));
|
||||
}
|
||||
CHAR logbuf[1024] = { 0 };
|
||||
RtlStringCchPrintfA(logbuf, sizeof(logbuf), "INJECT_BLOCK | %u | %wZ | %wZ", (ULONG)(ULONG_PTR)cur, &cexe, &texe);
|
||||
SendPipeLog(logbuf, strlen(logbuf));
|
||||
}
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return OB_PREOP_SUCCESS;
|
||||
}
|
||||
|
||||
static OB_PREOP_CALLBACK_STATUS PreThreadCallback(PVOID RegistrationContext, POB_PRE_OPERATION_INFORMATION Info)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(RegistrationContext);
|
||||
if (!Info || Info->KernelHandle)
|
||||
return OB_PREOP_SUCCESS;
|
||||
if (Info->Object == NULL)
|
||||
return OB_PREOP_SUCCESS;
|
||||
if (Info->Operation != OB_OPERATION_HANDLE_CREATE && Info->Operation != OB_OPERATION_HANDLE_DUPLICATE)
|
||||
return OB_PREOP_SUCCESS;
|
||||
if (!ExAcquireRundownProtection(&g_Rundown))
|
||||
return OB_PREOP_SUCCESS;
|
||||
|
||||
HANDLE cur = PsGetCurrentProcessId();
|
||||
if (cur == (HANDLE)0 || cur == (HANDLE)4) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return OB_PREOP_SUCCESS;
|
||||
}
|
||||
HANDLE owner = PsGetThreadProcessId((PETHREAD)Info->Object);
|
||||
if (owner == cur) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return OB_PREOP_SUCCESS;
|
||||
}
|
||||
ACCESS_MASK tmask = THREAD_SET_CONTEXT | THREAD_SUSPEND_RESUME | THREAD_IMPERSONATE | THREAD_DIRECT_IMPERSONATION;
|
||||
ACCESS_MASK* desired = (Info->Operation == OB_OPERATION_HANDLE_CREATE) ? &Info->Parameters->CreateHandleInformation.DesiredAccess : &Info->Parameters->DuplicateHandleInformation.DesiredAccess;
|
||||
if ((*desired & tmask) == 0) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return OB_PREOP_SUCCESS;
|
||||
}
|
||||
BOOLEAN logok = (KeGetCurrentIrql() == PASSIVE_LEVEL);
|
||||
WCHAR cbuf[512] = { 0 };
|
||||
UNICODE_STRING cexe = { 0 };
|
||||
cexe.Buffer = cbuf;
|
||||
cexe.MaximumLength = sizeof(cbuf);
|
||||
|
||||
if (logok)
|
||||
GetProcessImagePathByPid(cur, &cexe);
|
||||
if (logok && IsWhitelist(&cexe)) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return OB_PREOP_SUCCESS;
|
||||
}
|
||||
ACCESS_MASK old = *desired;
|
||||
*desired &= ~tmask;
|
||||
if ((*desired) != old && logok) {
|
||||
CHAR logbuf[1024] = { 0 };
|
||||
|
||||
if (cexe.Length == 0) {
|
||||
PEPROCESS eproc = PsGetCurrentProcess();
|
||||
PCSTR n = PsGetProcessImageFileName(eproc);
|
||||
size_t l = n ? strlen(n) : 0;
|
||||
|
||||
for (size_t i = 0; i < l && i < RTL_NUMBER_OF(cbuf) - 1; i++)
|
||||
cbuf[i] = (WCHAR)n[i];
|
||||
cbuf[l] = 0;
|
||||
cexe.Length = (USHORT)(l * sizeof(WCHAR));
|
||||
}
|
||||
RtlStringCchPrintfA(logbuf, sizeof(logbuf), "THREAD_BLOCK | %u | %wZ | %u", (ULONG)(ULONG_PTR)cur, &cexe, (ULONG)(ULONG_PTR)owner);
|
||||
SendPipeLog(logbuf, strlen(logbuf));
|
||||
}
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return OB_PREOP_SUCCESS;
|
||||
}
|
||||
|
||||
NTSTATUS InitInjectProtect(VOID)
|
||||
{
|
||||
static WCHAR obAltBuf[32];
|
||||
static UNICODE_STRING obAlt;
|
||||
LARGE_INTEGER t = KeQueryPerformanceCounter(NULL);
|
||||
RtlStringCchPrintfW(obAltBuf, RTL_NUMBER_OF(obAltBuf), L"385000.%I64x", t.QuadPart);
|
||||
RtlInitUnicodeString(&obAlt, obAltBuf);
|
||||
|
||||
g_ObOps = (POB_OPERATION_REGISTRATION)ExAllocatePool2(POOL_FLAG_NON_PAGED, sizeof(OB_OPERATION_REGISTRATION) * 2, 'bOpr');
|
||||
if (!g_ObOps)
|
||||
return STATUS_INSUFFICIENT_RESOURCES;
|
||||
|
||||
RtlZeroMemory(g_ObOps, sizeof(OB_OPERATION_REGISTRATION) * 2);
|
||||
g_ObOps[0].ObjectType = PsProcessType;
|
||||
g_ObOps[0].Operations = OB_OPERATION_HANDLE_CREATE | OB_OPERATION_HANDLE_DUPLICATE;
|
||||
g_ObOps[0].PreOperation = PreProcessCallback;
|
||||
g_ObOps[1].ObjectType = PsThreadType;
|
||||
g_ObOps[1].Operations = OB_OPERATION_HANDLE_CREATE | OB_OPERATION_HANDLE_DUPLICATE;
|
||||
g_ObOps[1].PreOperation = PreThreadCallback;
|
||||
|
||||
RtlZeroMemory(&g_ObReg, sizeof(g_ObReg));
|
||||
g_ObReg.Version = OB_FLT_REGISTRATION_VERSION;
|
||||
g_ObReg.OperationRegistrationCount = 2;
|
||||
g_ObReg.Altitude = obAlt;
|
||||
g_ObReg.RegistrationContext = NULL;
|
||||
g_ObReg.OperationRegistration = g_ObOps;
|
||||
|
||||
NTSTATUS s = ObRegisterCallbacks(&g_ObReg, &g_ObRegHandle);
|
||||
if (!NT_SUCCESS(s)) {
|
||||
ExFreePool2(g_ObOps, 'bOpr', NULL, 0);
|
||||
g_ObOps = NULL;
|
||||
RtlZeroMemory(&g_ObReg, sizeof(g_ObReg));
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
VOID UninitInjectProtect(VOID)
|
||||
{
|
||||
if (g_ObRegHandle) {
|
||||
ObUnRegisterCallbacks(g_ObRegHandle);
|
||||
g_ObRegHandle = NULL;
|
||||
}
|
||||
if (g_ObOps) {
|
||||
ExFreePool2(g_ObOps, 'bOpr', NULL, 0);
|
||||
g_ObOps = NULL;
|
||||
}
|
||||
RtlZeroMemory(&g_ObReg, sizeof(g_ObReg));
|
||||
}
|
||||
@@ -0,0 +1,119 @@
|
||||
#include <ntifs.h>
|
||||
#include "ProtectRules.h"
|
||||
#include "DriverEntry.h"
|
||||
|
||||
static BOOLEAN QueryRegPathFromObject(PVOID KeyObject, PUNICODE_STRING OutPath, POBJECT_NAME_INFORMATION* OutInfo)
|
||||
{
|
||||
ULONG len = 0;
|
||||
NTSTATUS s = ObQueryNameString(KeyObject, NULL, 0, &len);
|
||||
if (s != STATUS_INFO_LENGTH_MISMATCH)
|
||||
return FALSE;
|
||||
|
||||
POBJECT_NAME_INFORMATION p = (POBJECT_NAME_INFORMATION)ExAllocatePool2(POOL_FLAG_NON_PAGED, len, 'rgeR');
|
||||
if (!p)
|
||||
return FALSE;
|
||||
|
||||
s = ObQueryNameString(KeyObject, p, len, &len);
|
||||
if (!NT_SUCCESS(s) || !p->Name.Buffer || p->Name.Length == 0) {
|
||||
ExFreePool2(p, 'rgeR', NULL, 0);
|
||||
return FALSE;
|
||||
}
|
||||
*OutInfo = p;
|
||||
OutPath->Buffer = p->Name.Buffer;
|
||||
OutPath->Length = p->Name.Length;
|
||||
OutPath->MaximumLength = p->Name.Length;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
NTSTATUS RegistryProtectCallback(PVOID ctx, PVOID arg1, PVOID arg2)
|
||||
{
|
||||
UNREFERENCED_PARAMETER(ctx);
|
||||
if (g_Unloading)
|
||||
return STATUS_SUCCESS;
|
||||
if (!ExAcquireRundownProtection(&g_Rundown))
|
||||
return STATUS_SUCCESS;
|
||||
|
||||
REG_NOTIFY_CLASS type = (REG_NOTIFY_CLASS)(ULONG_PTR)arg1;
|
||||
NTSTATUS status = STATUS_SUCCESS;
|
||||
UNICODE_STRING checkReg = { 0 };
|
||||
POBJECT_NAME_INFORMATION nameInfo = NULL;
|
||||
|
||||
UNICODE_STRING exe = { 0 };
|
||||
WCHAR exeBuf[260] = { 0 };
|
||||
exe.Buffer = exeBuf;
|
||||
exe.MaximumLength = sizeof(exeBuf);
|
||||
exe.Length = 0;
|
||||
|
||||
HANDLE pid = PsGetCurrentProcessId();
|
||||
if (pid == (HANDLE)0 || pid == (HANDLE)4) {
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return STATUS_SUCCESS;
|
||||
}
|
||||
PUNICODE_STRING valueName = NULL;
|
||||
BOOLEAN need_log = FALSE;
|
||||
CHAR logbuf[1024] = { 0 };
|
||||
BOOLEAN canQuery = (KeGetCurrentIrql() == PASSIVE_LEVEL);
|
||||
|
||||
if (type == RegNtPreSetValueKey) {
|
||||
PREG_SET_VALUE_KEY_INFORMATION s = (PREG_SET_VALUE_KEY_INFORMATION)arg2;
|
||||
valueName = s->ValueName;
|
||||
if (canQuery)
|
||||
QueryRegPathFromObject(s->Object, &checkReg, &nameInfo);
|
||||
}
|
||||
else if (type == RegNtPreDeleteValueKey) {
|
||||
PREG_DELETE_VALUE_KEY_INFORMATION d = (PREG_DELETE_VALUE_KEY_INFORMATION)arg2;
|
||||
valueName = d->ValueName;
|
||||
if (canQuery)
|
||||
QueryRegPathFromObject(d->Object, &checkReg, &nameInfo);
|
||||
}
|
||||
else if (type == RegNtPreDeleteKey) {
|
||||
PREG_DELETE_KEY_INFORMATION d = (PREG_DELETE_KEY_INFORMATION)arg2;
|
||||
if (canQuery)
|
||||
QueryRegPathFromObject(d->Object, &checkReg, &nameInfo);
|
||||
}
|
||||
else if (type == RegNtPreRenameKey) {
|
||||
PREG_RENAME_KEY_INFORMATION r = (PREG_RENAME_KEY_INFORMATION)arg2;
|
||||
if (canQuery)
|
||||
QueryRegPathFromObject(r->Object, &checkReg, &nameInfo);
|
||||
}
|
||||
else if (type == RegNtPreCreateKeyEx) {
|
||||
PREG_CREATE_KEY_INFORMATION c = (PREG_CREATE_KEY_INFORMATION)arg2;
|
||||
if (c->CompleteName)
|
||||
checkReg = *c->CompleteName;
|
||||
}
|
||||
else if (type == RegNtPreReplaceKey) {
|
||||
PREG_REPLACE_KEY_INFORMATION rk = (PREG_REPLACE_KEY_INFORMATION)arg2;
|
||||
if (canQuery)
|
||||
QueryRegPathFromObject(rk->Object, &checkReg, &nameInfo);
|
||||
}
|
||||
else if (type == RegNtPreSaveKey) {
|
||||
PREG_SAVE_KEY_INFORMATION sk = (PREG_SAVE_KEY_INFORMATION)arg2;
|
||||
if (canQuery)
|
||||
QueryRegPathFromObject(sk->Object, &checkReg, &nameInfo);
|
||||
}
|
||||
else if (type == RegNtPreRestoreKey) {
|
||||
PREG_RESTORE_KEY_INFORMATION res = (PREG_RESTORE_KEY_INFORMATION)arg2;
|
||||
if (canQuery)
|
||||
QueryRegPathFromObject(res->Object, &checkReg, &nameInfo);
|
||||
}
|
||||
else if (type == RegNtPreLoadKey) {
|
||||
PREG_LOAD_KEY_INFORMATION lk = (PREG_LOAD_KEY_INFORMATION)arg2;
|
||||
if (lk->KeyName)
|
||||
checkReg = *lk->KeyName;
|
||||
}
|
||||
if (checkReg.Buffer || (valueName && valueName->Buffer)) {
|
||||
GetProcessImagePathByPid(pid, &exe);
|
||||
|
||||
if (IsRegistryBlock(&checkReg, valueName, &exe)) {
|
||||
RtlStringCchPrintfA(logbuf, sizeof(logbuf), "REG_BLOCK | %u | %wZ | %wZ", (ULONG)(ULONG_PTR)pid, &exe, &checkReg);
|
||||
need_log = TRUE;
|
||||
status = STATUS_ACCESS_DENIED;
|
||||
}
|
||||
}
|
||||
if (nameInfo)
|
||||
ExFreePool2(nameInfo, 'rgeR', NULL, 0);
|
||||
if (need_log)
|
||||
SendPipeLog(logbuf, strlen(logbuf));
|
||||
ExReleaseRundownProtection(&g_Rundown);
|
||||
return status;
|
||||
}
|
||||
@@ -0,0 +1,391 @@
|
||||
#include <ntifs.h>
|
||||
#include "ProtectRules.h"
|
||||
#include "DriverEntry.h"
|
||||
|
||||
wchar_t* g_Whitelist[] = {
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\**",
|
||||
L"\\Device\\HarddiskVolume*\\Program*\\**",
|
||||
L"\\Device\\HarddiskVolume*\\Users\\*\\AppData\\**",
|
||||
L"**\\PYAS*.exe",
|
||||
L"Registry",
|
||||
L"vmmem*",
|
||||
NULL
|
||||
};
|
||||
|
||||
wchar_t* g_WhitelistExcept[] = {
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\vds.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\bcdedit.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\reg.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\cmd.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\mshta.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\wscript.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\cscript.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\schtasks.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\diskpart.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\format.com",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\mountvol.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\wbadmin.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\bcdboot.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\dism.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\bootsect.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\cipher.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\net.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\net1.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\msiexec.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\Sys*\\WindowsPowerShell\\*\\powershell.exe",
|
||||
L"\\Device\\HarddiskVolume*\\Program*\\PowerShell\\*\\pwsh.exe",
|
||||
NULL
|
||||
};
|
||||
|
||||
wchar_t* g_AttachDisk[] = {
|
||||
L"\\FileSystem\\Ntfs",
|
||||
L"\\FileSystem\\Refs",
|
||||
L"\\FileSystem\\Fastfat",
|
||||
L"\\FileSystem\\exfat",
|
||||
L"\\FileSystem\\Udfs",
|
||||
NULL
|
||||
};
|
||||
|
||||
wchar_t* g_BlockFile[] = {
|
||||
L"\\DosDevices\\**",
|
||||
L"\\Device\\Harddisk*\\Partition\\**",
|
||||
L"\\Device\\HarddiskVolume*\\Boot\\**",
|
||||
L"\\Device\\HarddiskVolume*\\EFI\\**",
|
||||
L"\\Device\\HarddiskVolume*\\bootmgr",
|
||||
L"\\Device\\HarddiskVolume*\\Recovery\\**",
|
||||
L"\\Device\\HarddiskVolume*\\System Volume Information\\**",
|
||||
L"\\Device\\HarddiskVolume*\\Windows\\**",
|
||||
L"\\Device\\HarddiskVolume*\\ProgramData\\PYAS\\**",
|
||||
L"\\Device\\HarddiskVolume*\\$*\\**",
|
||||
|
||||
L"**\\CON**",
|
||||
L"**\\PRN**",
|
||||
L"**\\AUX**",
|
||||
L"**\\NUL**",
|
||||
L"**\\COM*\\**",
|
||||
L"**\\LPT*\\**",
|
||||
L"**\\evil*.exe",
|
||||
L"**\\OSDATA**",
|
||||
NULL
|
||||
};
|
||||
|
||||
wchar_t* g_BlockRansom[] = {
|
||||
L"\\Device\\HarddiskVolume*\\Users\\*\\Desktop\\**",
|
||||
L"\\Device\\HarddiskVolume*\\Users\\*\\Downloads\\**",
|
||||
L"\\Device\\HarddiskVolume*\\Users\\*\\Documents\\**",
|
||||
L"\\Device\\HarddiskVolume*\\Users\\*\\Music\\**",
|
||||
L"\\Device\\HarddiskVolume*\\Users\\*\\Pictures\\**",
|
||||
L"\\Device\\HarddiskVolume*\\Users\\*\\Videos\\**",
|
||||
NULL
|
||||
};
|
||||
|
||||
wchar_t* g_BlockReg[] = {
|
||||
L"\\REGISTRY\\MACHINE\\BCD00000000\\**",
|
||||
L"\\REGISTRY\\MACHINE\\SAM\\**",
|
||||
L"\\REGISTRY\\MACHINE\\SECURITY\\**",
|
||||
|
||||
L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Control\\**",
|
||||
L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Enum\\**",
|
||||
L"\\REGISTRY\\MACHINE\\SYSTEM\\CurrentControlSet\\Services\\**",
|
||||
L"\\REGISTRY\\MACHINE\\SYSTEM\\MountedDevices\\**",
|
||||
L"\\REGISTRY\\MACHINE\\SYSTEM\\Setup\\**",
|
||||
|
||||
L"\\REGISTRY\\MACHINE\\SOFTWARE\\Classes\\**",
|
||||
L"\\REGISTRY\\MACHINE\\SOFTWARE\\Policies\\Microsoft\\MMC\\**",
|
||||
L"\\REGISTRY\\MACHINE\\SOFTWARE\\Policies\\Microsoft\\Windows\\System\\**",
|
||||
L"\\REGISTRY\\MACHINE\\SOFTWARE\\Wow6432Node\\**",
|
||||
L"\\REGISTRY\\MACHINE\\**\\Microsoft\\Windows Defender\\**",
|
||||
|
||||
L"\\REGISTRY\\**\\SOFTWARE\\Microsoft\\Active Setup\\Installed Components\\*\\StubPath",
|
||||
L"\\REGISTRY\\**\\SOFTWARE\\Microsoft\\Windows*\\CurrentVersion\\**",
|
||||
L"\\REGISTRY\\**\\SOFTWARE\\Microsoft\\Windows Script Host\\Settings\\**",
|
||||
|
||||
L"\\REGISTRY\\USER\\*_Classes\\*\\shell\\open\\command\\**",
|
||||
L"\\REGISTRY\\USER\\*_Classes\\CLSID\\{fdb00e52-a214-4aa1-8fba-4357bb0072ec}\\**",
|
||||
L"\\REGISTRY\\USER\\S-1-*\\SOFTWARE\\NetWire\\**",
|
||||
L"\\REGISTRY\\USER\\S-1-*\\SOFTWARE\\Remcos*\\**",
|
||||
L"\\REGISTRY\\USER\\S-1-*\\SOFTWARE\\DC3_FEXEC\\**",
|
||||
|
||||
|
||||
L"DisableAntiSpyware",
|
||||
L"DisableWindowsUpdateAccess",
|
||||
L"EnableLUA",
|
||||
L"ConsentPromptBehaviorAdmin",
|
||||
L"NoControlPanel",
|
||||
L"NoDrives",
|
||||
L"NoFileMenu",
|
||||
L"NoFind",
|
||||
L"NoStartMenuPinnedList",
|
||||
L"NoSetFolders",
|
||||
L"NoSetFolderOptions",
|
||||
L"NoViewOnDrive",
|
||||
L"NoClose",
|
||||
L"NoDesktop",
|
||||
L"NoLogoff",
|
||||
L"NoFolderOptions",
|
||||
L"RestrictRun",
|
||||
L"NoViewContextMenu",
|
||||
L"HideClock",
|
||||
L"NoStartMenuMyGames",
|
||||
L"NoStartMenuMyMusic",
|
||||
L"DisableCMD",
|
||||
L"NoAddingComponents",
|
||||
L"NoWinKeys",
|
||||
L"NoStartMenuLogOff",
|
||||
L"NoSimpleNetIDList",
|
||||
L"NoLowDiskSpaceChecks",
|
||||
L"DisableLockWorkstation",
|
||||
L"Restrict_Run",
|
||||
L"DisableTaskMgr",
|
||||
L"DisableRegistryTools",
|
||||
L"DisableChangePassword",
|
||||
L"Wallpaper",
|
||||
L"NoComponents",
|
||||
L"NoStartMenuMorePrograms",
|
||||
L"NoActiveDesktop",
|
||||
L"NoSetActiveDesktop",
|
||||
L"NoRecentDocsMenu",
|
||||
L"NoWindowsUpdate",
|
||||
L"NoChangeStartMenu",
|
||||
L"NoFavoritesMenu",
|
||||
L"NoRecentDocsHistory",
|
||||
L"NoSetTaskbar",
|
||||
L"NoSMHelp",
|
||||
L"NoTrayContextMenu",
|
||||
L"NoManageMyComputerVerb",
|
||||
L"NoRealMode",
|
||||
L"NoRun",
|
||||
L"ClearRecentDocsOnExit",
|
||||
L"NoActiveDesktopChanges",
|
||||
L"NoStartMenuNetworkPlaces",
|
||||
L"NoLockScreen",
|
||||
L"HideFastUserSwitching",
|
||||
L"ConsentPromptBehaviorUser",
|
||||
L"EnableSecureUIAPaths",
|
||||
L"NoSRM",
|
||||
L"NoInteractiveServices",
|
||||
L"ShutdownWithoutLogon",
|
||||
L"AutoAdminLogon",
|
||||
L"ImagePath",
|
||||
L"BootExecute",
|
||||
L"SubSystems",
|
||||
L"FirmwareBootDevice",
|
||||
L"BootDriverFlags",
|
||||
L"SystemStartOptions",
|
||||
L"CrashDumpEnabled",
|
||||
L"DisableAutomaticRestartOnFailure",
|
||||
L"SystemBiosVersion",
|
||||
L"NoTheme",
|
||||
L"PendingFileRenameOperations",
|
||||
L"SystemSetupInProgress",
|
||||
L"CmdLine",
|
||||
L"SetupType",
|
||||
L"AutoReboot",
|
||||
L"Shell",
|
||||
L"Userinit",
|
||||
L"UIHost",
|
||||
L"Debugger",
|
||||
L"DefaultUserName",
|
||||
L"DefaultPassword",
|
||||
L"AltDefaultUserName",
|
||||
L"AltDefaultPassword",
|
||||
L"DisableCAD",
|
||||
L"LegalNoticeCaption",
|
||||
L"LegalNoticeText",
|
||||
NULL
|
||||
};
|
||||
|
||||
static BOOLEAN WildMatchN(const wchar_t* str, SIZE_T n, const wchar_t* pat)
|
||||
{
|
||||
if (*pat == 0)
|
||||
return n == 0;
|
||||
if (*pat == L'*') {
|
||||
if (pat[1] == L'*') {
|
||||
for (SIZE_T i = 0; i <= n; ++i)
|
||||
if (WildMatchN(str + i, n - i, pat + 2))
|
||||
return TRUE;
|
||||
return FALSE;
|
||||
}
|
||||
SIZE_T i = 0;
|
||||
for (; i < n && str[i] != L'\\'; ++i)
|
||||
if (WildMatchN(str + i, n - i, pat + 1))
|
||||
return TRUE;
|
||||
return WildMatchN(str + i, n - i, pat + 1);
|
||||
}
|
||||
if (*pat == L'?')
|
||||
return n > 0 && str[0] != L'\\' && WildMatchN(str + 1, n - 1, pat + 1);
|
||||
if (n == 0)
|
||||
return FALSE;
|
||||
WCHAR sc = str[0], pc = *pat;
|
||||
if (sc >= L'A' && sc <= L'Z')
|
||||
sc += 32;
|
||||
if (pc >= L'A' && pc <= L'Z')
|
||||
pc += 32;
|
||||
return sc == pc && WildMatchN(str + 1, n - 1, pat + 1);
|
||||
}
|
||||
|
||||
static BOOLEAN MatchList(PUNICODE_STRING s, wchar_t** list)
|
||||
{
|
||||
if (!s || !s->Buffer || s->Length == 0)
|
||||
return FALSE;
|
||||
size_t s_len = s->Length / sizeof(WCHAR);
|
||||
for (SIZE_T i = 0; list[i]; ++i) {
|
||||
wchar_t* pat = list[i];
|
||||
size_t pat_len = wcslen(pat);
|
||||
if (wcschr(pat, L'*') || wcschr(pat, L'?')) {
|
||||
if (WildMatchN(s->Buffer, s_len, pat))
|
||||
return TRUE;
|
||||
}
|
||||
else {
|
||||
if (s_len == pat_len && _wcsnicmp(s->Buffer, pat, pat_len) == 0)
|
||||
return TRUE;
|
||||
if (s_len > pat_len && _wcsnicmp(s->Buffer + s_len - pat_len, pat, pat_len) == 0)
|
||||
return TRUE;
|
||||
if (s_len > pat_len && _wcsnicmp(s->Buffer, pat, pat_len) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static wchar_t* MatchListGetRule(PUNICODE_STRING s, wchar_t** list)
|
||||
{
|
||||
if (!s || !s->Buffer || s->Length == 0)
|
||||
return 0;
|
||||
size_t s_len = s->Length / sizeof(WCHAR);
|
||||
for (SIZE_T i = 0; list[i]; ++i) {
|
||||
wchar_t* pat = list[i];
|
||||
size_t pat_len = wcslen(pat);
|
||||
if (wcschr(pat, L'*') || wcschr(pat, L'?')) {
|
||||
if (WildMatchN(s->Buffer, s_len, pat))
|
||||
return pat;
|
||||
}
|
||||
else {
|
||||
if (s_len == pat_len && _wcsnicmp(s->Buffer, pat, pat_len) == 0)
|
||||
return pat;
|
||||
if (s_len > pat_len && _wcsnicmp(s->Buffer + s_len - pat_len, pat, pat_len) == 0)
|
||||
return pat;
|
||||
if (s_len > pat_len && _wcsnicmp(s->Buffer, pat, pat_len) == 0)
|
||||
return pat;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static __forceinline BOOLEAN USOK(PUNICODE_STRING s)
|
||||
{
|
||||
return s && s->Buffer && s->Length;
|
||||
}
|
||||
|
||||
BOOLEAN IsRegistryBlock(PUNICODE_STRING key, PUNICODE_STRING valueName, PUNICODE_STRING exe)
|
||||
{
|
||||
if (USOK(exe)) {
|
||||
if (IsWhitelist(exe))
|
||||
return FALSE;
|
||||
}
|
||||
if (USOK(exe) && USOK(key)) {
|
||||
size_t elen = exe->Length / sizeof(WCHAR);
|
||||
size_t klen = key->Length / sizeof(WCHAR);
|
||||
if (((elen >= 12 && _wcsnicmp(exe->Buffer + elen - 12, L"services.exe", 12) == 0) ||
|
||||
(elen >= 11 && _wcsnicmp(exe->Buffer + elen - 11, L"svchost.exe", 11) == 0) ||
|
||||
(elen >= 6 && _wcsnicmp(exe->Buffer + elen - 6, L"sc.exe", 6) == 0))) {
|
||||
if (WildMatchN(key->Buffer, klen, L"\\REGISTRY\\**\\SYSTEM\\CurrentControlSet\\Services\\**"))
|
||||
return FALSE;
|
||||
}
|
||||
if ((elen >= 14 && _wcsnicmp(exe->Buffer + elen - 14, L"powershell.exe", 14) == 0) ||
|
||||
(elen >= 8 && _wcsnicmp(exe->Buffer + elen - 8, L"pwsh.exe", 8) == 0)) {
|
||||
if (WildMatchN(key->Buffer, klen, L"\\REGISTRY\\**\\CurrentVersion\\Internet Settings\\ZoneMap") ||
|
||||
WildMatchN(key->Buffer, klen, L"\\REGISTRY\\**\\CurrentVersion\\Internet Settings\\ZoneMap\\**"))
|
||||
return FALSE;
|
||||
}
|
||||
if ((elen >= 11 && _wcsnicmp(exe->Buffer + elen - 11, L"msiexec.exe", 11) == 0) ||
|
||||
(elen >= 20 && _wcsnicmp(exe->Buffer + elen - 20, L"TrustedInstaller.exe", 20) == 0)) {
|
||||
if (WildMatchN(key->Buffer, klen, L"\\REGISTRY\\**\\CurrentVersion\\Installer\\**") ||
|
||||
WildMatchN(key->Buffer, klen, L"\\REGISTRY\\**\\CurrentVersion\\Uninstall\\**") ||
|
||||
WildMatchN(key->Buffer, klen, L"\\REGISTRY\\**\\SYSTEM\\CurrentControlSet\\Services\\**"))
|
||||
return FALSE;
|
||||
}
|
||||
if (elen >= 12 && _wcsnicmp(exe->Buffer + elen - 12, L"schtasks.exe", 12) == 0) {
|
||||
if (WildMatchN(key->Buffer, klen, L"\\REGISTRY\\**\\Windows NT\\CurrentVersion\\Schedule\\TaskCache\\**"))
|
||||
return FALSE;
|
||||
}
|
||||
}
|
||||
if (USOK(key)) {
|
||||
if (MatchBlockReg(key))
|
||||
return TRUE;
|
||||
}
|
||||
if (USOK(valueName)) {
|
||||
SIZE_T n = valueName->Length / sizeof(WCHAR);
|
||||
for (SIZE_T i = 0; g_BlockReg[i]; ++i) {
|
||||
wchar_t* pat = g_BlockReg[i];
|
||||
if (wcschr(pat, L'\\') || wcschr(pat, L'*') || wcschr(pat, L'?'))
|
||||
continue;
|
||||
size_t m = wcslen(pat);
|
||||
if (n == m && _wcsnicmp(valueName->Buffer, pat, m) == 0)
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOLEAN GetProcessImagePathByPid(HANDLE pid, PUNICODE_STRING ProcessImagePath)
|
||||
{
|
||||
PEPROCESS process = NULL;
|
||||
NTSTATUS status = PsLookupProcessByProcessId(pid, &process);
|
||||
if (!NT_SUCCESS(status))
|
||||
return FALSE;
|
||||
|
||||
HANDLE h = NULL;
|
||||
status = ObOpenObjectByPointer(process, OBJ_KERNEL_HANDLE, NULL, PROCESS_QUERY_LIMITED_INFORMATION, *PsProcessType, KernelMode, &h);
|
||||
if (!NT_SUCCESS(status)) {
|
||||
ObDereferenceObject(process);
|
||||
return FALSE;
|
||||
}
|
||||
ULONG len = 0;
|
||||
status = ZwQueryInformationProcess(h, ProcessImageFileName, NULL, 0, &len);
|
||||
if (status != STATUS_INFO_LENGTH_MISMATCH || len == 0) {
|
||||
ZwClose(h);
|
||||
ObDereferenceObject(process);
|
||||
return FALSE;
|
||||
}
|
||||
PVOID buf = ExAllocatePool2(POOL_FLAG_NON_PAGED, len, 'iPgN');
|
||||
if (!buf) {
|
||||
ZwClose(h);
|
||||
ObDereferenceObject(process);
|
||||
return FALSE;
|
||||
}
|
||||
status = ZwQueryInformationProcess(h, ProcessImageFileName, buf, len, &len);
|
||||
if (NT_SUCCESS(status)) {
|
||||
PUNICODE_STRING image = (PUNICODE_STRING)buf;
|
||||
if (image->Buffer && image->Length > 0 && ProcessImagePath->MaximumLength >= image->Length + sizeof(WCHAR)) {
|
||||
RtlCopyMemory(ProcessImagePath->Buffer, image->Buffer, image->Length);
|
||||
ProcessImagePath->Length = image->Length;
|
||||
ProcessImagePath->Buffer[image->Length / sizeof(WCHAR)] = 0;
|
||||
ExFreePool2(buf, 'iPgN', NULL, 0);
|
||||
ZwClose(h);
|
||||
ObDereferenceObject(process);
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
ExFreePool2(buf, 'iPgN', NULL, 0);
|
||||
ZwClose(h);
|
||||
ObDereferenceObject(process);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
BOOLEAN IsWhitelist(PUNICODE_STRING s)
|
||||
{
|
||||
if (MatchList(s, g_WhitelistExcept))
|
||||
return FALSE;
|
||||
return MatchList(s, g_Whitelist);
|
||||
}
|
||||
|
||||
BOOLEAN MatchBlockReg(PUNICODE_STRING s)
|
||||
{
|
||||
return MatchList(s, g_BlockReg);
|
||||
}
|
||||
|
||||
wchar_t* GetMatchedBlockRegRule(PUNICODE_STRING s)
|
||||
{
|
||||
return MatchListGetRule(s, g_BlockReg);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
#pragma once
|
||||
#include <ntifs.h>
|
||||
|
||||
wchar_t* GetMatchedBlockRegRule(PUNICODE_STRING s);
|
||||
BOOLEAN MatchBlockReg(PUNICODE_STRING s);
|
||||
BOOLEAN IsWhitelist(PUNICODE_STRING s);
|
||||
BOOLEAN GetProcessImagePathByPid(HANDLE pid, PUNICODE_STRING ProcessImagePath);
|
||||
BOOLEAN IsRegistryBlock(PUNICODE_STRING key, PUNICODE_STRING valueName, PUNICODE_STRING exe);
|
||||
@@ -1,176 +1,91 @@
|
||||
# PYAS (Python Antivirus Software)
|
||||
# PYAS
|
||||
|
||||

|
||||
Antivirus software written in Python and C that blocks threats through deep learning and behavioral monitoring!
|
||||
|
||||
<img width="2245" height="1477" alt="PYAS_UI" src="https://github.com/user-attachments/assets/87d40261-7655-49ad-a19c-1ffcca60584f" />
|
||||
|
||||
## Readme Language
|
||||
|
||||
[繁體中文](https://github.com/87owo/PYAS/blob/main/README_zh_TW.md) ,
|
||||
[简体中文](https://github.com/87owo/PYAS/blob/main/README_zh_CN.md)
|
||||
English : https://github.com/87owo/PYAS/blob/main/README.md
|
||||
|
||||
## File Information
|
||||
繁體中文 : https://github.com/87owo/PYAS/blob/main/README_zh_TW.md
|
||||
|
||||
PYAS.py -> Main PYAS Program (including animation, scanning, protection functions, etc.)
|
||||
|
||||
PYAS_Engine.py -> Conversion Database (used to convert database dict and list to and from each other)
|
||||
|
||||
PYAS_Extension.py -> File Extension (including scanned file extensions and common file extensions)
|
||||
|
||||
PYAS_Model.* -> Virus Database (the virus database must be placed in the same directory)
|
||||
|
||||
PYAS_Interface.py -> PyQt5 Interface (designed by QT designer, must be matched with the main program)
|
||||
|
||||
PYAS_Resource.py -> PyQt5 Resource (status pictures, icon packages, button icons, etc.)
|
||||
|
||||
PYAS_Language.py -> Translate Dict (Traditional Chinese, Simplified Chinese, English)
|
||||
|
||||
PYAS_Version.py -> Pyinstaller Info (file information, version information, original name, etc.)
|
||||
|
||||
## Dir Information
|
||||
|
||||
```
|
||||
PYAS/
|
||||
├── Driver/
|
||||
│ ├── PYAS_Driver.sys
|
||||
│ └── ...
|
||||
│
|
||||
├── Model/
|
||||
│ ├── PYAS_Model.json
|
||||
│ ├── PYAS_Model.txt
|
||||
│ └── ...
|
||||
│
|
||||
├── Rules/
|
||||
│ ├── Yara_Rules.yar
|
||||
│ ├── Compile_Rules.yrc
|
||||
│ └── ...
|
||||
│
|
||||
├── PYAS.py
|
||||
├── PYAS_Engine.py
|
||||
└── ...
|
||||
```
|
||||
简体中文 : https://github.com/87owo/PYAS/blob/main/README_zh_CN.md
|
||||
|
||||
## Requirements
|
||||
|
||||
Use pip install requirements to install import module
|
||||
Python 3.10 is recommended. Other Python versions may require different pip commands.
|
||||
|
||||
```
|
||||
psutil==5.9.5
|
||||
pefile==2023.2.7
|
||||
requests==2.31.0
|
||||
pyperclip==1.8.2
|
||||
pywin32==306
|
||||
PyQt5==5.15.9
|
||||
pip install numpy==1.26.4
|
||||
pip install onnxruntime==1.18.1
|
||||
pip install pefile==2023.2.7
|
||||
pip install Pillow==11.0.0
|
||||
pip install pyperclip==1.9.0
|
||||
pip install PySide6==6.9.1
|
||||
pip install requests==2.32.4
|
||||
pip install yara-python==4.5.4
|
||||
```
|
||||
|
||||
## Pefile Scanning
|
||||
## File Information
|
||||
|
||||
Get the pefile file function import table for scanning
|
||||
The following lists the storage locations of all relevant code and other related documents.
|
||||
|
||||
```
|
||||
import pefile
|
||||
|
||||
def pe_scan(file):
|
||||
try:
|
||||
fn = []
|
||||
with pefile.PE(file) as pe:
|
||||
for entry in pe.DIRECTORY_ENTRY_IMPORT:
|
||||
for func in entry.imports:
|
||||
try:
|
||||
fn.append(str(func.name, "utf-8"))
|
||||
except:
|
||||
pass
|
||||
if fn in known_malicious_list:
|
||||
return "Virus"
|
||||
return "Safe"
|
||||
return "Unknown"
|
||||
except Exception as e:
|
||||
return f"Error: {e}"
|
||||
|
||||
info = pe_scan("path to file")
|
||||
print(info)
|
||||
PYAS/
|
||||
├── Engine/
|
||||
│ ├── Models/
|
||||
│ │ ├── convert.py # Convert executable files or other files to images
|
||||
│ │ └── train.py # TensorFlow CNN model training complete code
|
||||
│ │
|
||||
│ └── Rules/
|
||||
│ ├── rules.yar # Yara virus signature rule matching
|
||||
│ └── rules.ips # IP network address rule matching
|
||||
│
|
||||
├── Plugins/
|
||||
│ └── Filter/
|
||||
│ ├── DriverEntry.c # Main driver entry and initialization logic
|
||||
│ ├── DriverEntry.h # Global driver definitions, constants, and functions
|
||||
│ ├── DriverPipe.c # Kernel to user pipe logging implementation
|
||||
│ ├── ProtectBoot.c # Disk boot sector write protection
|
||||
│ ├── ProtectImage.c # Image load monitoring and shellcode detection
|
||||
│ ├── ProtectInject.c # Process thread handle access control to prevent injection
|
||||
│ ├── ProtectReg.c # Registry modification protection
|
||||
│ ├── ProtectRules.c # White, block list, and matching logic for files registry
|
||||
│ └── ProtectRules.h # Protection rule declarations
|
||||
│
|
||||
├── PYAS.py # Main application entry point and UI to engine interface
|
||||
├── PYAS_Config.py # Configuration loading, saving, and global parameters
|
||||
├── PYAS_Engine.py # Core scanning engine: YARA, IP, ONNX model execution
|
||||
├── PYAS_Interface.py # User interface components and event handling
|
||||
├── PYAS_Resource.py # Static image and icon resource management
|
||||
├── PYAS_Version.py # Version metadata for packaging and updates
|
||||
└── ... # Other supplementary folders and files
|
||||
```
|
||||
|
||||
## Process Detect
|
||||
## Program Architecture
|
||||
|
||||
Show the new process name, file path, cmd line, pid
|
||||
PYAS antivirus software complete program flow architecture diagram.
|
||||
|
||||
```
|
||||
import psutil, time
|
||||
<img width="23000" height="6000" alt="PYAS_Architecture" src="https://github.com/user-attachments/assets/3a7ce637-c2b3-4719-9658-07f286cfa879" />
|
||||
|
||||
def proc_detect():
|
||||
existing_process = set()
|
||||
for p in psutil.process_iter():
|
||||
existing_process.add(p.pid)
|
||||
while True:
|
||||
time.sleep(0.1)
|
||||
new_process = set()
|
||||
for p in psutil.process_iter():
|
||||
new_process.add(p.pid)
|
||||
for pid in new_process - existing_process:
|
||||
try:
|
||||
p = psutil.Process(pid)
|
||||
name, file, cmd = p.name(), p.exe(), p.cmdline()
|
||||
print(f"Name: {name}")
|
||||
print(f"File: {file}")
|
||||
print(f"Pid: {p.pid}")
|
||||
print(f"Cmd: {cmd}")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
existing_process = new_process
|
||||
## Packaged Releases
|
||||
|
||||
proc_detect()
|
||||
```
|
||||
|
||||
## File Detect
|
||||
|
||||
Monitor file changes under the specified path
|
||||
|
||||
```
|
||||
import os, win32file, win32con
|
||||
|
||||
def file_detect(path):
|
||||
hDir = win32file.CreateFile(path,win32con.GENERIC_READ,win32con.FILE_SHARE_READ|win32con.FILE_SHARE_WRITE|win32con.FILE_SHARE_DELETE,None,win32con.OPEN_EXISTING,win32con.FILE_FLAG_BACKUP_SEMANTICS,None)
|
||||
while True:
|
||||
for action, file in win32file.ReadDirectoryChangesW(hDir,10485760,True,win32con.FILE_NOTIFY_CHANGE_FILE_NAME|win32con.FILE_NOTIFY_CHANGE_DIR_NAME|win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES|win32con.FILE_NOTIFY_CHANGE_SIZE|win32con.FILE_NOTIFY_CHANGE_LAST_WRITE|win32con.FILE_NOTIFY_CHANGE_SECURITY,None,None):
|
||||
try:
|
||||
fpath = os.path.join(path, file)
|
||||
if action == 1:
|
||||
print(f"File Create: {fpath}")
|
||||
elif action == 2:
|
||||
print(f"File Delete: {fpath}")
|
||||
elif action == 3:
|
||||
print(f"File Modify: {fpath}")
|
||||
elif action == 4:
|
||||
print(f"File Rename: {fpath}")
|
||||
elif action == 5:
|
||||
print(f"File Rename: {fpath}")
|
||||
except:
|
||||
pass
|
||||
|
||||
file_detect("path")
|
||||
```
|
||||
|
||||
## Official Website
|
||||
|
||||
https://pyantivirus.wixsite.com/pyas
|
||||
|
||||
https://github.com/87owo/PYAS
|
||||
|
||||
## PYAS Driver
|
||||
|
||||
https://github.com/0sha0/PYAS_Protection
|
||||
|
||||
## MIT license
|
||||
|
||||
https://github.com/87owo/PYAS/blob/main/LICENSE.md
|
||||
Packaged Releases Download: https://github.com/87owo/PYAS/releases
|
||||
|
||||
## Support System
|
||||
|
||||
Windows 8.1, 10, 11 (64-bit), Ram 500MB, Rom 200MB or higher
|
||||
| Config | Permissions | System version | Processor | Memory | Storage |
|
||||
|-----------|---------------|----------------------|-----------|--------|---------|
|
||||
| Minimum | Administrator | >= Windows 10 (20H1) | 1 GHz | 200MB | 100MB |
|
||||
| Recommend | Administrator | >= Windows 10 (21H2) | 3 GHz | 500MB | 200MB |
|
||||
|
||||
Other systems may experience software malfunctions or crash
|
||||
## Official Website
|
||||
|
||||
## Special Thanks
|
||||
Official Website : https://pyantivirus.wixsite.com/pyas
|
||||
|
||||
Wix, 0sha0, mtkiao129, AV-T Team of LisectGroup
|
||||
Open Source Website : https://github.com/87owo/PYAS
|
||||
|
||||
Copyright© 2020~2024 PYAS Security By 87owo
|
||||
## Project License
|
||||
|
||||
https://github.com/87owo/PYAS/blob/main/LICENSE.txt
|
||||
+62
-142
@@ -1,171 +1,91 @@
|
||||
# PYAS (Python 杀毒软件)
|
||||
# PYAS
|
||||
|
||||

|
||||
使用 Python 和 C 编写的杀毒软件,并通过深度学习和行为监控阻止威胁!
|
||||
|
||||
## 文件信息
|
||||
<img width="2245" height="1477" alt="PYAS_UI" src="https://github.com/user-attachments/assets/87d40261-7655-49ad-a19c-1ffcca60584f" />
|
||||
|
||||
PYAS.py -> PYAS主程式(包括动画、扫描、保护功能等)
|
||||
## 说明语言
|
||||
|
||||
PYAS_Engine.py -> 转换资料库(用于相互转换资料库字典和清单)
|
||||
English : https://github.com/87owo/PYAS/blob/main/README.md
|
||||
|
||||
PYAS_Extension.py -> 副文件名(包括扫描文件副文件名和常用副文件名)
|
||||
繁體中文 : https://github.com/87owo/PYAS/blob/main/README_zh_TW.md
|
||||
|
||||
PYAS_Model.* -> 病毒库(病毒库必须放在同一目录下)
|
||||
简体中文 : https://github.com/87owo/PYAS/blob/main/README_zh_CN.md
|
||||
|
||||
PYAS_Interface.py -> PyQt5界面(由QT设计师设计,必须与主程式相符)
|
||||
## 安装需求
|
||||
|
||||
PYAS_Resource.py -> PyQt5资源(状态图片、图示包、按钮图示等)
|
||||
建议使用 Python 3.10。其他版本的 Python 可能需要不同的 pip 指令。
|
||||
|
||||
PYAS_Language.py -> 翻译字典(繁体中文、简体中文、英文)
|
||||
```
|
||||
pip install numpy==1.26.4
|
||||
pip install onnxruntime==1.18.1
|
||||
pip install pefile==2023.2.7
|
||||
pip install Pillow==11.0.0
|
||||
pip install pyperclip==1.9.0
|
||||
pip install PySide6==6.9.1
|
||||
pip install requests==2.32.4
|
||||
pip install yara-python==4.5.4
|
||||
```
|
||||
|
||||
PYAS_Version.py -> Pyinstaller资讯(文件资讯、版本资讯、原名等)
|
||||
## 文件讯息
|
||||
|
||||
## 目录信息
|
||||
以下列出所有相关代码与文件的存放位置。
|
||||
|
||||
```
|
||||
PYAS/
|
||||
├── Driver/
|
||||
│ ├── PYAS_Driver.sys
|
||||
│ └── ...
|
||||
├── Engine/
|
||||
│ ├── Models/
|
||||
│ │ ├── convert.py # 将可执行文件或其他文件转换为图片
|
||||
│ │ └── train.py # TensorFlow CNN 模型训练完整代码
|
||||
│ │
|
||||
│ └── Rules/
|
||||
│ ├── rules.yar # YARA 病毒特征码规则匹配
|
||||
│ └── rules.ips # IP 网络地址规则匹配
|
||||
│
|
||||
├── Model/
|
||||
│ ├── PYAS_Model.json
|
||||
│ ├── PYAS_Model.txt
|
||||
│ └── ...
|
||||
├── Plugins/
|
||||
│ └── Filter/
|
||||
│ ├── DriverEntry.c # 驱动主入口与初始化逻辑
|
||||
│ ├── DriverEntry.h # 全局驱动定义、常量与函数
|
||||
│ ├── DriverPipe.c # 内核与用户层的管道日志传输实现
|
||||
│ ├── ProtectBoot.c # 磁盘引导区写入保护
|
||||
│ ├── ProtectImage.c # 映像加载监控与 shellcode 检测
|
||||
│ ├── ProtectInject.c # 进程与线程控制,防止注入
|
||||
│ ├── ProtectReg.c # 注册表修改保护
|
||||
│ ├── ProtectRules.c # 白名单、阻止名单与文件/注册表匹配逻辑
|
||||
│ └── ProtectRules.h # 保护规则声明
|
||||
│
|
||||
├── Rules/
|
||||
│ ├── Yara_Rules.yar
|
||||
│ ├── Compile_Rules.yrc
|
||||
│ └── ...
|
||||
│
|
||||
├── PYAS.py
|
||||
├── PYAS_Engine.py
|
||||
└── ...
|
||||
├── PYAS.py # 主应用程序入口点与 UI 到引擎的接口
|
||||
├── PYAS_Config.py # 配置加载、保存与全局参数
|
||||
├── PYAS_Engine.py # 核心扫描引擎:YARA、IP、ONNX 模型执行
|
||||
├── PYAS_Interface.py # 用户界面组件与事件处理
|
||||
├── PYAS_Resource.py # 静态图片与图标资源管理
|
||||
├── PYAS_Version.py # 版本元数据,用于打包与更新
|
||||
└── ... # 其他补充文件夹与文件
|
||||
```
|
||||
|
||||
## 安装要求
|
||||
## 代码架构
|
||||
|
||||
使用 pip install requirements 来安装需要的模组
|
||||
PYAS 杀毒软件完整代码流程架构图。
|
||||
|
||||
```
|
||||
psutil==5.9.5
|
||||
pefile==2023.2.7
|
||||
requests==2.31.0
|
||||
pyperclip==1.8.2
|
||||
pywin32==306
|
||||
PyQt5==5.15.9
|
||||
```
|
||||
<img width="23000" height="6000" alt="PYAS_Architecture" src="https://github.com/user-attachments/assets/3a7ce637-c2b3-4719-9658-07f286cfa879" />
|
||||
|
||||
## 文件扫描
|
||||
## 安装版本
|
||||
|
||||
取得pefile文件函数导入表进行扫描
|
||||
打包发行版下载:https://github.com/87owo/PYAS/releases
|
||||
|
||||
```
|
||||
import pefile
|
||||
## 系统需求
|
||||
|
||||
def pe_scan(file):
|
||||
try:
|
||||
fn = []
|
||||
with pefile.PE(file) as pe:
|
||||
for entry in pe.DIRECTORY_ENTRY_IMPORT:
|
||||
for func in entry.imports:
|
||||
try:
|
||||
fn.append(str(func.name, "utf-8"))
|
||||
except:
|
||||
pass
|
||||
if fn in known_malicious_list:
|
||||
return "Virus"
|
||||
return "Safe"
|
||||
return "Unknown"
|
||||
except Exception as e:
|
||||
return f"Error: {e}"
|
||||
| 配置要求 | 权限 | 系统版本 | 处理器 | 可用内存空间 | 可用存储空间 |
|
||||
| ------- | ----- | ------ | ----- | ------------ | ---------- |
|
||||
| 最低配置 | 管理员 | >= Windows 10 (20H1) | 1 GHz | 200MB | 100MB |
|
||||
| 推荐配置 | 管理员 | >= Windows 10 (21H2) | 3 GHz | 300MB | 200MB |
|
||||
|
||||
info = pe_scan("path to file")
|
||||
print(info)
|
||||
```
|
||||
## 官方网站
|
||||
|
||||
## 进程监控
|
||||
官方网站 : https://pyantivirus.wixsite.com/pyas
|
||||
|
||||
显示新进程名称、文件路径、cmd 行、pid
|
||||
开源网站 : https://github.com/87owo/PYAS
|
||||
|
||||
```
|
||||
import psutil, time
|
||||
## 授权条款
|
||||
|
||||
def proc_detect():
|
||||
existing_process = set()
|
||||
for p in psutil.process_iter():
|
||||
existing_process.add(p.pid)
|
||||
while True:
|
||||
time.sleep(0.1)
|
||||
new_process = set()
|
||||
for p in psutil.process_iter():
|
||||
new_process.add(p.pid)
|
||||
for pid in new_process - existing_process:
|
||||
try:
|
||||
p = psutil.Process(pid)
|
||||
name, file, cmd = p.name(), p.exe(), p.cmdline()
|
||||
print(f"Name: {name}")
|
||||
print(f"File: {file}")
|
||||
print(f"Pid: {p.pid}")
|
||||
print(f"Cmd: {cmd}")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
existing_process = new_process
|
||||
|
||||
proc_detect()
|
||||
```
|
||||
|
||||
## 文件监控
|
||||
|
||||
监控指定路径下的文件变化
|
||||
|
||||
```
|
||||
import os, win32file, win32con
|
||||
|
||||
def file_detect(path):
|
||||
hDir = win32file.CreateFile(path,win32con.GENERIC_READ,win32con.FILE_SHARE_READ|win32con.FILE_SHARE_WRITE|win32con.FILE_SHARE_DELETE,None,win32con.OPEN_EXISTING,win32con.FILE_FLAG_BACKUP_SEMANTICS,None)
|
||||
while True:
|
||||
for action, file in win32file.ReadDirectoryChangesW(hDir,10485760,True,win32con.FILE_NOTIFY_CHANGE_FILE_NAME|win32con.FILE_NOTIFY_CHANGE_DIR_NAME|win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES|win32con.FILE_NOTIFY_CHANGE_SIZE|win32con.FILE_NOTIFY_CHANGE_LAST_WRITE|win32con.FILE_NOTIFY_CHANGE_SECURITY,None,None):
|
||||
try:
|
||||
fpath = os.path.join(path, file)
|
||||
if action == 1:
|
||||
print(f"File Create: {fpath}")
|
||||
elif action == 2:
|
||||
print(f"File Delete: {fpath}")
|
||||
elif action == 3:
|
||||
print(f"File Modify: {fpath}")
|
||||
elif action == 4:
|
||||
print(f"File Rename: {fpath}")
|
||||
elif action == 5:
|
||||
print(f"File Rename: {fpath}")
|
||||
except:
|
||||
pass
|
||||
|
||||
file_detect("path")
|
||||
```
|
||||
|
||||
## 官方网页
|
||||
|
||||
https://pyantivirus.wixsite.com/pyas
|
||||
|
||||
https://github.com/87owo/PYAS
|
||||
|
||||
## 开源协议
|
||||
|
||||
https://github.com/87owo/PYAS/blob/main/LICENSE.md
|
||||
|
||||
## 驱动程序
|
||||
|
||||
https://github.com/0sha0/PYAS_Protection
|
||||
|
||||
## 支援系统
|
||||
|
||||
Windows 8.1, 10, 11 (64-bit), 内存 500MB, 存储 200MB 或更高
|
||||
|
||||
其他系统或版本可能会遇到软体功能故障或程序崩溃
|
||||
|
||||
## 特别感谢
|
||||
|
||||
360, Wix, VirusShare, mtkiao129, AV-T Team of LisectGroup
|
||||
|
||||
Copyright© 2020~2024 PYAS Security By 87owo
|
||||
https://github.com/87owo/PYAS/blob/main/LICENSE.txt
|
||||
+69
-147
@@ -1,169 +1,91 @@
|
||||
# PYAS (Python 防毒軟體)
|
||||
# PYAS
|
||||
|
||||

|
||||
使用 Python 和 C 開發的防毒軟體,並透過深度學習和行為監控來阻止威脅!
|
||||
|
||||
<img width="2245" height="1477" alt="PYAS_UI" src="https://github.com/user-attachments/assets/87d40261-7655-49ad-a19c-1ffcca60584f" />
|
||||
|
||||
## 說明語言
|
||||
|
||||
English : https://github.com/87owo/PYAS/blob/main/README.md
|
||||
|
||||
繁體中文 : https://github.com/87owo/PYAS/blob/main/README_zh_TW.md
|
||||
|
||||
简体中文 : https://github.com/87owo/PYAS/blob/main/README_zh_CN.md
|
||||
|
||||
## 安裝需求
|
||||
|
||||
建議使用 Python 3.10。其他版本的 Python 可能需要不同的 pip 指令。
|
||||
|
||||
```
|
||||
pip install numpy==1.26.4
|
||||
pip install onnxruntime==1.18.1
|
||||
pip install pefile==2023.2.7
|
||||
pip install Pillow==11.0.0
|
||||
pip install pyperclip==1.9.0
|
||||
pip install PySide6==6.9.1
|
||||
pip install requests==2.32.4
|
||||
pip install yara-python==4.5.4
|
||||
```
|
||||
|
||||
## 檔案資訊
|
||||
|
||||
PYAS.py -> PYAS主程式(包括動畫、掃描、保護功能等)
|
||||
|
||||
PYAS_Engine.py -> 轉換資料庫(用於相互轉換資料庫字典和清單)
|
||||
|
||||
PYAS_Extension.py -> 檔案副檔名(包括掃描檔案副檔名和常用檔案副檔名)
|
||||
|
||||
PYAS_Model.* -> 病毒庫(病毒庫必須放在同一目錄下)
|
||||
|
||||
PYAS_Interface.py -> PyQt5 Interface(由QT設計師設計,必須與主程式相符)
|
||||
|
||||
PYAS_Resource.py -> PyQt5資源(狀態圖片、圖示包、按鈕圖示等)
|
||||
|
||||
PYAS_Language.py -> 翻譯字典(繁體中文、簡體中文、英文)
|
||||
|
||||
PYAS_Version.py -> Pyinstaller Info(檔案資訊、版本資訊、原名等)
|
||||
|
||||
## 目錄資訊
|
||||
以下列出所有相關程式碼與文件的存放位置。
|
||||
|
||||
```
|
||||
PYAS/
|
||||
├── Driver/
|
||||
│ ├── PYAS_Driver.sys
|
||||
│ └── ...
|
||||
├── Engine/
|
||||
│ ├── Models/
|
||||
│ │ ├── convert.py # 將可執行檔或其他檔案轉換為圖片
|
||||
│ │ └── train.py # TensorFlow CNN 模型訓練完整程式碼
|
||||
│ │
|
||||
│ └── Rules/
|
||||
│ ├── rules.yar # YARA 病毒特徵碼規則匹配
|
||||
│ └── rules.ips # IP 網路位址規則匹配
|
||||
│
|
||||
├── Model/
|
||||
│ ├── PYAS_Model.json
|
||||
│ ├── PYAS_Model.txt
|
||||
│ └── ...
|
||||
├── Plugins/
|
||||
│ └── Filter/
|
||||
│ ├── DriverEntry.c # 驅動主入口與初始化邏輯
|
||||
│ ├── DriverEntry.h # 全域驅動定義、常數與函式
|
||||
│ ├── DriverPipe.c # 核心層與使用者層的管道日誌傳輸實作
|
||||
│ ├── ProtectBoot.c # 磁碟開機區寫入保護
|
||||
│ ├── ProtectImage.c # 映像載入監控與 shellcode 偵測
|
||||
│ ├── ProtectInject.c # 程序與執行緒控制,防止注入
|
||||
│ ├── ProtectReg.c # 登錄檔修改保護
|
||||
│ ├── ProtectRules.c # 白名單、封鎖清單與檔案/登錄匹配邏輯
|
||||
│ └── ProtectRules.h # 保護規則宣告
|
||||
│
|
||||
├── Rules/
|
||||
│ ├── Yara_Rules.yar
|
||||
│ ├── Compile_Rules.yrc
|
||||
│ └── ...
|
||||
│
|
||||
├── PYAS.py
|
||||
├── PYAS_Engine.py
|
||||
└── ...
|
||||
├── PYAS.py # 主應用程式入口點與 UI 到引擎的介面
|
||||
├── PYAS_Config.py # 組態載入、儲存與全域參數
|
||||
├── PYAS_Engine.py # 核心掃描引擎:YARA、IP、ONNX 模型執行
|
||||
├── PYAS_Interface.py # 使用者介面元件與事件處理
|
||||
├── PYAS_Resource.py # 靜態圖片與圖示資源管理
|
||||
├── PYAS_Version.py # 版本中繼資料,用於打包與更新
|
||||
└── ... # 其他補充資料夾與檔案
|
||||
```
|
||||
|
||||
## 安裝要求
|
||||
## 程式架構
|
||||
|
||||
使用 pip install requirements 來安裝需要的模組
|
||||
PYAS 防毒軟體完整程式流程架構圖。
|
||||
|
||||
```
|
||||
psutil==5.9.5
|
||||
pefile==2023.2.7
|
||||
requests==2.31.0
|
||||
pyperclip==1.8.2
|
||||
pywin32==306
|
||||
PyQt5==5.15.9
|
||||
```
|
||||
<img width="23000" height="6000" alt="PYAS_Architecture" src="https://github.com/user-attachments/assets/3a7ce637-c2b3-4719-9658-07f286cfa879" />
|
||||
|
||||
## 檔案掃描
|
||||
## 安裝版本
|
||||
|
||||
取得pefile檔案函數導入表進行掃描
|
||||
打包發行版下載 : https://github.com/87owo/PYAS/releases
|
||||
|
||||
```
|
||||
import pefile
|
||||
## 系統需求
|
||||
|
||||
def pe_scan(file):
|
||||
try:
|
||||
fn = []
|
||||
with pefile.PE(file) as pe:
|
||||
for entry in pe.DIRECTORY_ENTRY_IMPORT:
|
||||
for func in entry.imports:
|
||||
try:
|
||||
fn.append(str(func.name, "utf-8"))
|
||||
except:
|
||||
pass
|
||||
if fn in known_malicious_list:
|
||||
return "Virus"
|
||||
return "Safe"
|
||||
return "Unknown"
|
||||
except Exception as e:
|
||||
return f"Error: {e}"
|
||||
| 配置要求 | 權限 | 系統版本 | 處理器 | 可用記憶體空間 | 可用儲存空間 |
|
||||
| ------- | ---- | ------- | ------ | ------------ | ----------- |
|
||||
| 最低配置 | 管理員 | >= Windows 10 (20H1) | 1 GHz | 200MB | 100MB |
|
||||
| 推薦配置 | 管理員 | >= Windows 10 (21H2) | 3 GHz | 300MB | 200MB |
|
||||
|
||||
info = pe_scan("path to file")
|
||||
print(info)
|
||||
```
|
||||
## 官方網站
|
||||
|
||||
## 進程監控
|
||||
官方網站 : https://pyantivirus.wixsite.com/pyas
|
||||
|
||||
顯示新進程名稱、檔案路徑、cmd 行、pid
|
||||
```
|
||||
import psutil, time
|
||||
開源網站 : https://github.com/87owo/PYAS
|
||||
|
||||
def proc_detect():
|
||||
existing_process = set()
|
||||
for p in psutil.process_iter():
|
||||
existing_process.add(p.pid)
|
||||
while True:
|
||||
time.sleep(0.1)
|
||||
new_process = set()
|
||||
for p in psutil.process_iter():
|
||||
new_process.add(p.pid)
|
||||
for pid in new_process - existing_process:
|
||||
try:
|
||||
p = psutil.Process(pid)
|
||||
name, file, cmd = p.name(), p.exe(), p.cmdline()
|
||||
print(f"Name: {name}")
|
||||
print(f"File: {file}")
|
||||
print(f"Pid: {p.pid}")
|
||||
print(f"Cmd: {cmd}")
|
||||
except Exception as e:
|
||||
print(f"Error: {e}")
|
||||
existing_process = new_process
|
||||
## 授權條款
|
||||
|
||||
proc_detect()
|
||||
```
|
||||
|
||||
## 檔案監控
|
||||
|
||||
監控指定路徑下的檔案變化
|
||||
```
|
||||
import os, win32file, win32con
|
||||
|
||||
def file_detect(path):
|
||||
hDir = win32file.CreateFile(path,win32con.GENERIC_READ,win32con.FILE_SHARE_READ|win32con.FILE_SHARE_WRITE|win32con.FILE_SHARE_DELETE,None,win32con.OPEN_EXISTING,win32con.FILE_FLAG_BACKUP_SEMANTICS,None)
|
||||
while True:
|
||||
for action, file in win32file.ReadDirectoryChangesW(hDir,10485760,True,win32con.FILE_NOTIFY_CHANGE_FILE_NAME|win32con.FILE_NOTIFY_CHANGE_DIR_NAME|win32con.FILE_NOTIFY_CHANGE_ATTRIBUTES|win32con.FILE_NOTIFY_CHANGE_SIZE|win32con.FILE_NOTIFY_CHANGE_LAST_WRITE|win32con.FILE_NOTIFY_CHANGE_SECURITY,None,None):
|
||||
try:
|
||||
fpath = os.path.join(path, file)
|
||||
if action == 1:
|
||||
print(f"File Create: {fpath}")
|
||||
elif action == 2:
|
||||
print(f"File Delete: {fpath}")
|
||||
elif action == 3:
|
||||
print(f"File Modify: {fpath}")
|
||||
elif action == 4:
|
||||
print(f"File Rename: {fpath}")
|
||||
elif action == 5:
|
||||
print(f"File Rename: {fpath}")
|
||||
except:
|
||||
pass
|
||||
|
||||
file_detect("path")
|
||||
```
|
||||
|
||||
## 官方網頁
|
||||
|
||||
https://pyantivirus.wixsite.com/pyas
|
||||
|
||||
https://github.com/87owo/PYAS
|
||||
|
||||
## 開源協議
|
||||
|
||||
https://github.com/87owo/PYAS/blob/main/LICENSE.md
|
||||
|
||||
## 驅動程式
|
||||
|
||||
https://github.com/0sha0/PYAS_Protection
|
||||
|
||||
## 支援系統
|
||||
|
||||
Windows 8.1, 10, 11 (64-bit),記憶體 500MB, 磁碟容量 200MB 或更高
|
||||
|
||||
其他系統或版本可能會遇到軟體功能故障或程序崩潰
|
||||
|
||||
## 特別感謝
|
||||
|
||||
Wix, 0sha0, mtkiao129, AV-T Team of LisectGroup
|
||||
|
||||
Copyright© 2020~2024 PYAS Security By 87owo
|
||||
https://github.com/87owo/PYAS/blob/main/LICENSE.txt
|
||||
Reference in new issue
Block a user