0

I have a binary "crackme" which i want to try all ASCII characters as parameters, here's what i've done so far.

 #!/bin/bash                                                                                                                                                                                   

for ((i=32;i<127;i++))
do
    c="\\$(printf %03o "$i")";
    echo $c;
    ./crackme $c;
done

The command executed is "./crackme \65" and obviously i'm trying to execute "./crackme A".

  • i've tried lot of thing like what you've flagged, the main problem is that i can't figure out how to store the ascii value in a variable, every post are about simply printing the ascii value – Titouan Pautier May 13 '19 at 16:06
  • 2
    Using the top answer from the duplicate: `i=65; printf "\x$(printf %x "$i")"` – Benjamin W. May 13 '19 at 16:08

2 Answers2

4

For posterity, a couple of useful functions:

# 65 -> A
chr() { printf "\\x$(printf "%x" "$1")"; }
# A -> 65
ord() { printf "%d" "'$1"; }

The odd final parameter of the ord printf command is documented:

Arguments to non-string format specifiers are treated as C language constants, except that a leading plus or minus sign is allowed, and if the leading character is a single or double quote, the value is the ASCII value of the following character.

then

for ((i = 32; i < 127; i++)); do
    ./crackme "$(chr $i)"
done
glenn jackman
  • 238,783
  • 38
  • 220
  • 352
  • I never understood why bash (or ksh) does not have those as built-ins, just about every other language has them. – cdarke May 13 '19 at 17:13
0

Not pretty, but this works:

for ((i=32;i<127;i++))
do
    printf -v c '\\x%x' "$i"
    ./crackme "$(echo -e $c)"
done
cdarke
  • 42,728
  • 8
  • 80
  • 84