# Threat Hunting. Анализ действий злоумышленников
## 1. Написать детект по событиям (в синтаксисе SIGMA) на скачивание файла с помощью certutil.exe
```
title: certutil.exe download file
id: 88b2f7db-af0b-4f1a-a3d1-42c4d7987c2c
description: Test rule to figure certutil.exe features in downloading files
author: Klykova
date: 2022/09/25
references:
- https://lolbas-project.github.io/lolbas/Binaries/Certutil/
tags:
- attack.ingress-tool-transfer
- attack.t1105
logsource:
category: process_creation
product: windows
detection:
selection_1:
Image|startswith: 'C:\Windows\System32\'
selection_2:
ParentCommandLine|contains|all:
- 'cmd.exe'
- 'certutil.exe'
- '-urlcache'
condition: selection_1 and selection_2
fields:
- CommandLine
- ParentCommandLine
falsepositives:
- Unknown
level: medium
```


## 2. Написать сетевой детект (в синтаксисе suricata) на активность из 1 задания.
```
alert tcp any -> any any (msg:"certutil.exe download file"; flow:to_server; content:"certutil.exe -urlcache"; sid:10101010; rev:2; classtype:bad-unknown)
```
## 3. Написать программу, выдающую строку по заданным произвольному началу md5-хеша и длине этой строки
```
import random
import string
import hashlib
def generate_alphanum_random_string(length):
letters_and_digits = string.ascii_letters + string.digits
rand_string = ''.join(random.sample(letters_and_digits, length))
return rand_string
hash_ = input() # вводим начало искомого хэша
lengh = int(input()) # длина искомой строки
dlina_maski = len(hash_) # длина введенного хэша
i = 1
while i == 1:
stroka = str(generate_alphanum_random_string(lengh)) # рандомная строка
hash_object = hashlib.md5(stroka.encode()).hexdigest()[:dlina_maski]
if hash_object == hash_:
print(stroka)
break
```

