Guest User

Untitled

a guest
Mar 21st, 2018
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #!/bin/bash
  2. # Конвертация выгрузки ключей CryptoPro из реестра Windows в папочку с бинарными ключами
  3. # Из реестра выгружать ветку HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Crypto Pro\Settings\Users\<кто-то>\Keys
  4.  
  5. # Converting the exported CryptoPro keys from the Windows registry to the container folder with binary keys
  6. # Dump regedit path from the registry HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Crypto Pro\Settings\Users\<username>\Keys
  7.  
  8. curpath=./
  9. temp=$curpath/temp
  10.  
  11. filename[1]=name.key
  12. filename[2]=masks.key
  13. filename[3]=masks2.key
  14. filename[4]=primary.key
  15. filename[5]=primary2.key
  16. filename[6]=header.key
  17.  
  18. if [ ! -d "$temp" ]; then
  19. mkdir "$temp"
  20. fi
  21.  
  22. if [ ! -d "$curpath/keys" ]; then
  23. mkdir "$curpath/keys"
  24. fi
  25.  
  26. # UTF-16 -> UTF8, CRLF -> LF
  27. iconv -f utf-16le -t utf-8 < $1 | perl -pe 's/\x0d//' > $temp/$1
  28.  
  29. # Записываем имена всех ключей во временный файл
  30. # Write the names of all keys to a temporary file
  31. cat $temp/$1 | ggrep -oP '(?<=Keys\\)[\w-]+' > $temp/keysname
  32.  
  33. while read key; do
  34. # Записываем полное содержимое ключа в отдельный файл с его именем
  35. # Write the full contents of the key in a separate file with its name
  36. cat $temp/$1 | sed -e '/./{H;$!d;}' -e "x;/$key]/!d" | sed -n "/$key]/!p" > $temp/$key
  37.  
  38. # Разделяем ключи (name, primary, masks, header...) и записываем в отдельные файлы в папку с именем ключа
  39. # Separate the keys (name, primary, masks, header ...) and write to separate files in the folder with the name of the key
  40. mkdir -p "$curpath/keys/$key"
  41.  
  42. for i in {1..6}; do
  43. hex=$(cat $temp/$key | tr -d '\n' | sed -E 's/\\//g; s/ //g; s/\$//g' | ggrep -E -o "${filename[$i]}\"=hex:(\w{2},?)+?" | sed -E "s/${filename[$i]}\"=hex://; s/,//g" | sed -E 's/\w{2}/\\x&/g')
  44. echo -e -n "$hex" > "$curpath/keys/$key/${filename[$i]}"
  45. done
  46. done < $temp/keysname
  47.  
  48. exit 0
Add Comment
Please, Sign In to add comment