|
@ -8,40 +8,45 @@ if ! which osslsigncode > /dev/null 2>&1; then |
|
|
exit |
|
|
exit |
|
|
fi |
|
|
fi |
|
|
|
|
|
|
|
|
if [ $# -ne 2 ]; then |
|
|
# exit if command fails |
|
|
echo "Usage: $0 signed_binary unsigned_binary" |
|
|
set -e |
|
|
exit |
|
|
|
|
|
fi |
|
|
mkdir -p stripped >/dev/null 2>&1 |
|
|
|
|
|
|
|
|
out="$1-stripped.exe" |
|
|
cd signed |
|
|
|
|
|
|
|
|
set -ex |
|
|
echo "Found $(ls *.exe | wc -w) files to verify." |
|
|
|
|
|
for signed in $(ls *.exe); do |
|
|
echo "Step 1: Remove PE signature from signed binary" |
|
|
echo $signed |
|
|
osslsigncode remove-signature -in $1 -out $out |
|
|
mine="../dist/$signed" |
|
|
|
|
|
out="../stripped/$signed" |
|
|
echo "Step 2: Remove checksum from signed binary" |
|
|
size=$( wc -c < $mine ) |
|
|
python3 <<EOF |
|
|
# Step 1: Remove PE signature from signed binary |
|
|
|
|
|
osslsigncode remove-signature -in $signed -out $out |
|
|
|
|
|
# Step 2: Remove checksum and padding from signed binary |
|
|
|
|
|
python3 <<EOF |
|
|
pe_file = "$out" |
|
|
pe_file = "$out" |
|
|
|
|
|
size= $size |
|
|
with open(pe_file, "rb") as f: |
|
|
with open(pe_file, "rb") as f: |
|
|
binary = bytearray(f.read()) |
|
|
binary = bytearray(f.read()) |
|
|
|
|
|
|
|
|
pe_offset = int.from_bytes(binary[0x3c:0x3c+4], byteorder="little") |
|
|
pe_offset = int.from_bytes(binary[0x3c:0x3c+4], byteorder="little") |
|
|
checksum_offset = pe_offset + 88 |
|
|
checksum_offset = pe_offset + 88 |
|
|
|
|
|
|
|
|
for b in range(4): |
|
|
for b in range(4): |
|
|
binary[checksum_offset + b] = 0 |
|
|
binary[checksum_offset + b] = 0 |
|
|
|
|
|
l = len(binary) |
|
|
|
|
|
n = l - size |
|
|
|
|
|
if n > 0: |
|
|
|
|
|
assert binary[-n:] == bytearray(n) |
|
|
|
|
|
print("removing %d null bytes"% n) |
|
|
|
|
|
binary = binary[:size] |
|
|
with open(pe_file, "wb") as f: |
|
|
with open(pe_file, "wb") as f: |
|
|
f.write(binary) |
|
|
f.write(binary) |
|
|
EOF |
|
|
EOF |
|
|
|
|
|
chmod +x $out |
|
|
bytes=$( wc -c < $2 ) |
|
|
if [ ! $(diff $out $mine) ]; then |
|
|
bytes=$((8 - ($bytes%8))) |
|
|
echo "Success!" |
|
|
bytes=$(($bytes % 8)) |
|
|
gpg --sign --armor --detach $signed |
|
|
|
|
|
else |
|
|
echo "Step 3: Appending $bytes null bytes to unsigned binary" |
|
|
echo "failure" |
|
|
|
|
|
fi |
|
|
truncate -s +$bytes $2 |
|
|
done |
|
|
|
|
|
|
|
|
diff $out $2 && echo "Success!" |
|
|
|
|
|