~alienagain/sec_scripts

ac766432dfc60a4a639e198159c448936b173f16 — paula 1 year, 2 months ago 3f4162a
añado todo un script que cifra los bytes de un binario segun una pass
1 files changed, 75 insertions(+), 0 deletions(-)

A partial_enc/simulacro_2.sh
A partial_enc/simulacro_2.sh => partial_enc/simulacro_2.sh +75 -0
@@ 0,0 1,75 @@
#!/bin/bash

#position in where to change the contents
pos=$1

#binary file
bfile=$2

# saving the hex info in a tmp file to manipulate the contents
xxd $bfile > tmp

# read the desired line and save it
line=$(head -n $pos tmp | tail -1)
#echo "$line"

rm tmp

#keeping only the hex value
tmp_hex=${line#*:}
tmp_hex=${tmp_hex:0:40}

#echo "DEBUG $tmp_hex"

#encrypting
echo "$tmp_hex" | xxd -r -p | openssl enc -e -base64 -aes-128-ctr -nopad -nosalt -k test > tmp 

#echo "#################"

#cleaning so to leave the warnings aside and keeping the content of the encryption

#strings tmp | tail -1

enc_hex=$(strings tmp | tail -1)
rm tmp

#echo "DEBUG $final"

# encrypted to hex

# string to hex
enc_s2=$(echo $enc_hex | od -A n -t x1)
#formatting
# delete spaces
enc_s2=${enc_s2//" "}

# add spaces aech 4 characters
count=0
nstr=""

for i in $(seq 1 ${#enc_s2})
do 
        if [ $count -eq 4 ]; then 
                nstr="${nstr} "
                count=0; 
        else 
                nstr="${nstr}${enc_s2:i-1:1}" 
                count=$(($count + 1))
        fi 
done

#injecting 

# position where to inject
npos=$(($pos*32))

echo -e "the position where to inject the encrypted: $nstr is\n $npos"

read -p"continue? Y/N " DUMMY

dd conv=notrunc obs=1 if=<(xxd -r -p -o 1 -s +$npos <(echo $nstr)) of=$bfile

echo "Done!"