How to decode openssl enc'd data with salted password? - web-scraping

$ curl -s 'https://finance.yahoo.com/quote/MSFT/profile?p=MSFT' | awk -v ORS= 'match($0, /^ *root[.]App[.]main = (.*);$/, a) { print a[1] }' | jq -r .context.dispatcher.stores > /tmp/tmp.txt
$ file /tmp/tmp.txt
/tmp/tmp.txt: openssl enc'd data with salted password, base64 encoded
How can I decode the above data?

Related

How to decrypt AES encrypted data with openssl command? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 months ago.
Improve this question
I want to decrypt AES encrypted data with openssl command.
Encrypted data: GD5YV2naJZ/x3mQnfictWQ== (base64 encoded)
Key: uHe2MCmggLlugpGBiMVuXTck7OT8Nk8g
Cipher: AES-256-CBC
IV: LNP8U7pc6GjxzxAtgw4s3A== (base64 encoded)
Follow these steps:
$ echo GD5YV2naJZ/x3mQnfictWQ== | openssl base64 -d > data.enc
$ iv=$( echo LNP8U7pc6GjxzxAtgw4s3A== | openssl base64 -d | xxd -p | tr -d '\n' )
$ echo $iv
2cd3fc53ba5ce868f1cf102d830e2cdc
$ key=$( echo uHe2MCmggLlugpGBiMVuXTck7OT8Nk8g | xxd -p | tr -d '\n' )
$ echo $key
754865324d436d67674c6c7567704742694d56755854636b374f54384e6b38670a
$ openssl aes-256-cbc -d -in data.enc -K $key -iv $iv
s:4:"Test";
With -base64 option, the decrypt command can directly use base64 encoded data as the input:
$ echo GD5YV2naJZ/x3mQnfictWQ== | openssl aes-256-cbc -d -base64 -K $key -iv $iv
s:4:"Test";
Please follow the encryption and decryption of the string according to its documentation and follow the step as well:
to decrypt a string use the following:
Illuminate\Contracts\Encryption\DecryptException;
use Illuminate\Support\Facades\Crypt;
try {
$decrypted = Crypt::decryptString($encryptedValue);
} catch (DecryptException $e) {
//
}
for encryption use:
use Illuminate\Support\Facades\Crypt;
Crypt::encryptString($request->token)

How to decrypt a large AES encrypted data with openssl command?

I want to decrypt large AES encrypted data:
Encrypted data: 7dS560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KYpZvVn0Q== (base64 encoded)
Key: uHe2MCmggLlugpGBiMVuXTck7OT8Nk8g (base64 encoded)
Cipher: AES-256-CBC
IV: LNP8U7pc6GjxzxAtgw4s3A== (base64 encoded)
I try to use this command for it:
openssl aes-256-cbc -d -in data.enc -out data.dec -K $key -iv $iv
In $key and $iv i decoded from encoded values this way
iv=$( cat response.json | jq .iv -r | openssl base64 -d | xxd -p | tr -d '\n' )
But i have crashed data like this
^GÌ<8a>û)F"PEi~^K±jÔ^AcWSM
23NDwSOqovXSFGNfy3WatkCreYRd7kcWSM";

While loop skips the first line in output

I'm using the below command in Terminal on a Mac to read a file of email addresses and convert them to a MD5 hash.
tr -d " " < em.txt | tr '[:upper:]' '[:lower:]' | while read line; do
(echo -n $line | md5); done | awk '{print $1}' > hashes1.txt
This produces a file of hashes that are 1 row shorter than the original input file. But I can't figure out why.
This code does a few things, below.
Converts an email address to all lower case
Converts the email address to a MD5 Hash
Outputs a list of new email addresses to a hashes1.txt file
Thanks in advance!
Your tr command is wrong : it should be :
tr -d " " < em.txt |
tr '[[:upper:]]' '[[:lower:]]' |
while IFS= read -r line; do
echo -n "$line" | md5 | awk '{print $1}' >> hashes1.txt
done
or
while IFS= read -r line; do
echo -n "$line" | md5 | awk '{print $1}' >> hashes1.txt
done < <(tr -d " " < em.txt | tr '[[:upper:]]' '[[:lower:]]')
Changed the file feeding place too.
And ensure your file don't have strange characters with
od -c file
if yes, install dos2unix, then :
dos2unix file
or using perl :
perl -i -pe 's/\r//g' file

AES-CBC incorrect usage

I am trying to do AES-CBC cipher and decipher via openssl, however, I am not able to get the correct output. Please advise me. Thank you.
cipher
clr;
MSG_CIPHERED_HEX="920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a"
IV="00000000000000000000000000000000"
KEY="00000000000000000000000000000000"
echo -n "$MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -aes-128-cbc -K $KEY -iv $IV | xxd -p | tr -d '\n'
decipher
clr;
MSG_CIPHERED_HEX="734563526574204d6553734167452030300a0e0e0e0e0e0e0e0e0e0e0e0e0e0e"
echo $MSG_CIPHERED_HEX
MSG_ASCII=echo $MSG_HEX | xxd -p -r | tr -d '\n'; echo $MSG_ASCII > tmp.ciphered.file.ascii;
openssl enc -d -aes-128-cbc -K $KEY -iv $IV -in tmp.ciphered.file.ascii -out out.txt
cat out.txt | xxd -p # | tr -d '\n'
rm -rf tmp.ciphered.file.ascii out.txt
There seemed to be data formatting issue:
$ #decipher
MSG_CIPHERED_HEX="920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a" IV="00000000000000000000000000000000" KEY="00000000000000000000000000000000" echo -n "$MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -d -aes-128-cbc -K $KEY -iv $IV | xxd -p | tr -d '\n'
Ans:
734563526574204d6553734167452030300a (truncated)
$ #cipher
MSG_CIPHERED_HEX="920e5af8b78702c778a919f7969a1f8cba578f11693673035213daf02500c50a" IV="00000000000000000000000000000000" KEY="00000000000000000000000000000000" echo -n "$MSG_CIPHERED_HEX" | xxd -r -p | openssl enc -aes-128-cbc -K $KEY -iv $IV | xxd -p | tr -d '\n'
Ans:
236999001256bd4131dffa3417c29bfc597a43f6bde387ba0e42da86e67cfff42890e4f6e84c0e70753a9db754df996e
The e0e0e0e0e0e0e0e0e0e0e0e0e0e is 14 bytes of padding. If you specify padding on decryption it will be automatically removed.
See PKCS7 padding.

grep - put part of string into variable

I'm using swfdump to be able to get the ID number of an audio file. Here is what I'm using:
swfdump -D /Users/home/folder/file.swf | grep -i mp3
That is outputting:
[00e] 28999 DEFINESOUND defines id 0006 (MP3 22Khz 16Bit mono)
What I need is the id #..in this case it is 0006. i want that number in a variable. Anyone know how to do this?
the_id=`swfdump -D /Users/home/folder/file.swf | grep -i mp3 | cut -d' ' -f6`
var=$(swfdump -D /Users/home/folder/file.swf | sed '/MP3/s/.*id //;s/ (.*//')
or Bash
$ s=$(swfdump -D /Users/home/folder/file.swf)
$ var=${s/(MP3*}
$ echo $var
0006

Resources