From 64293cdc82e4b313532e46788782cd43cdbefc2c Mon Sep 17 00:00:00 2001 From: Alexander Shvedov <60114847+a-shvedov@users.noreply.github.com> Date: Thu, 30 May 2024 11:13:56 +0300 Subject: Create make_dict.sh --- utils/libtokencap/make_dict.sh | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 utils/libtokencap/make_dict.sh (limited to 'utils') diff --git a/utils/libtokencap/make_dict.sh b/utils/libtokencap/make_dict.sh new file mode 100644 index 00000000..92c383fa --- /dev/null +++ b/utils/libtokencap/make_dict.sh @@ -0,0 +1,19 @@ +#!/bin/bash + +LD_PRELOAD_PATH="/path/to/libtokencap.so" +AFL_TOKEN_FILE=${PWD}/temp_output.txt +AFL_DICT_FILE=$(basename ${target_output}) +target_bin="/path/to/target/program" +target_output="/path/to/target/output" +timeout_sec="5" + +{ +touch $AFL_TOKEN_FILE +for i in $(find ${target_output} -type f -name "id*"); do + LD_PRELOAD=${LD_PRELOAD_PATH} \ + timeout -s SIGKILL ${timeout_sec} \ + ${target_bin} ${i} +done +} >${AFL_TOKEN_FILE} + +sort -u ${AFL_TOKEN_FILE} >${AFL_DICT_FILE}.dict -- cgit 1.4.1 From eecbdd99e177698c93873db351299467a910fc0e Mon Sep 17 00:00:00 2001 From: Alexander Shvedov <60114847+a-shvedov@users.noreply.github.com> Date: Thu, 30 May 2024 22:26:24 +0300 Subject: Update and rename make_dict.sh to make_dict_v2.sh --- utils/libtokencap/make_dict.sh | 19 --------------- utils/libtokencap/make_dict_v2.sh | 51 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 51 insertions(+), 19 deletions(-) delete mode 100644 utils/libtokencap/make_dict.sh create mode 100644 utils/libtokencap/make_dict_v2.sh (limited to 'utils') diff --git a/utils/libtokencap/make_dict.sh b/utils/libtokencap/make_dict.sh deleted file mode 100644 index 92c383fa..00000000 --- a/utils/libtokencap/make_dict.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/bin/bash - -LD_PRELOAD_PATH="/path/to/libtokencap.so" -AFL_TOKEN_FILE=${PWD}/temp_output.txt -AFL_DICT_FILE=$(basename ${target_output}) -target_bin="/path/to/target/program" -target_output="/path/to/target/output" -timeout_sec="5" - -{ -touch $AFL_TOKEN_FILE -for i in $(find ${target_output} -type f -name "id*"); do - LD_PRELOAD=${LD_PRELOAD_PATH} \ - timeout -s SIGKILL ${timeout_sec} \ - ${target_bin} ${i} -done -} >${AFL_TOKEN_FILE} - -sort -u ${AFL_TOKEN_FILE} >${AFL_DICT_FILE}.dict diff --git a/utils/libtokencap/make_dict_v2.sh b/utils/libtokencap/make_dict_v2.sh new file mode 100644 index 00000000..98dfc7fe --- /dev/null +++ b/utils/libtokencap/make_dict_v2.sh @@ -0,0 +1,51 @@ +#!/bin/bash + +#default values +timeout_sec=5 +LD_PRELOAD_PATH="/home/${USER}/AFLplusplus/utils/libtokencap/libtokencap.so" + +#help +usage() { + echo "Usage: $0 -o -b [-t ] [-p ]" + echo "Options:" + echo " -o Path to target output directory" + echo " -b Path to target program binary" + echo " -t Timeout in seconds (default: 5)" + echo " -p Path to LD_PRELOAD library (default: ${LD_PRELOAD_PATH})" + exit 1 +} + +#parse cli options +while getopts ":o:b:t:p:" opt; do + case $opt in + o) target_output="$OPTARG" ;; + b) target_bin="$OPTARG" ;; + t) timeout_sec="$OPTARG" ;; + p) LD_PRELOAD_PATH="$OPTARG" ;; + \?) echo "Invalid option: -$OPTARG" >&2; usage ;; + :) echo "Option -$OPTARG requires an args" >&2; usage ;; + esac +done + +#check options +if [ -z "$target_output" ] || [ -z "$target_bin" ]; then + echo "Error: Missing mandatory opts" >&2 + usage +fi + +# initialize vars +AFL_TOKEN_FILE="${PWD}/temp_output.txt" +AFL_DICT_FILE="$(basename "$target_output").dict" + +#generate token-file +{ + touch "$AFL_TOKEN_FILE" + for i in $(find "$target_output" -type f -name "id*"); do + LD_PRELOAD="$LD_PRELOAD_PATH" \ + timeout -s SIGKILL "$timeout_sec" \ + "$target_bin" "$i" + done +} >"$AFL_TOKEN_FILE" + +# sort & remove duplicates +sort -u "$AFL_TOKEN_FILE" >"$AFL_DICT_FILE" -- cgit 1.4.1 From c202d80dea287c9aaaa6c0dd3eba49398e0b247c Mon Sep 17 00:00:00 2001 From: Alexander Shvedov <60114847+a-shvedov@users.noreply.github.com> Date: Thu, 30 May 2024 22:38:37 +0300 Subject: Update make_dict_v2.sh --- utils/libtokencap/make_dict_v2.sh | 2 -- 1 file changed, 2 deletions(-) (limited to 'utils') diff --git a/utils/libtokencap/make_dict_v2.sh b/utils/libtokencap/make_dict_v2.sh index 98dfc7fe..0e8ca531 100644 --- a/utils/libtokencap/make_dict_v2.sh +++ b/utils/libtokencap/make_dict_v2.sh @@ -1,5 +1,3 @@ -#!/bin/bash - #default values timeout_sec=5 LD_PRELOAD_PATH="/home/${USER}/AFLplusplus/utils/libtokencap/libtokencap.so" -- cgit 1.4.1 From 5e708b23c60e0d95f1d12897e5a47a08b1ade1c0 Mon Sep 17 00:00:00 2001 From: Alexander Shvedov <60114847+a-shvedov@users.noreply.github.com> Date: Sat, 1 Jun 2024 01:18:03 +0300 Subject: Update make_dict_v2.sh (-) removed default vars ; (+) added LD_PRELOAD_PATH check --- utils/libtokencap/make_dict_v2.sh | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'utils') diff --git a/utils/libtokencap/make_dict_v2.sh b/utils/libtokencap/make_dict_v2.sh index 0e8ca531..1ddec06b 100644 --- a/utils/libtokencap/make_dict_v2.sh +++ b/utils/libtokencap/make_dict_v2.sh @@ -1,32 +1,28 @@ -#default values -timeout_sec=5 -LD_PRELOAD_PATH="/home/${USER}/AFLplusplus/utils/libtokencap/libtokencap.so" - #help usage() { - echo "Usage: $0 -o -b [-t ] [-p ]" + echo "Usage: $0 -o -b -p [-t ]" echo "Options:" echo " -o Path to target output directory" echo " -b Path to target program binary" - echo " -t Timeout in seconds (default: 5)" - echo " -p Path to LD_PRELOAD library (default: ${LD_PRELOAD_PATH})" + echo " -p Path to LD_PRELOAD library" + echo " -t Timeout in seconds" exit 1 } #parse cli options -while getopts ":o:b:t:p:" opt; do +while getopts ":o:b:p:t:" opt; do case $opt in o) target_output="$OPTARG" ;; b) target_bin="$OPTARG" ;; - t) timeout_sec="$OPTARG" ;; p) LD_PRELOAD_PATH="$OPTARG" ;; + t) timeout_sec="$OPTARG" ;; \?) echo "Invalid option: -$OPTARG" >&2; usage ;; - :) echo "Option -$OPTARG requires an args" >&2; usage ;; + :) echo "Option -$OPTARG requires an argument." >&2; usage ;; esac done #check options -if [ -z "$target_output" ] || [ -z "$target_bin" ]; then +if [ -z "$target_output" ] || [ -z "$target_bin" ] || [ -z "$LD_PRELOAD_PATH" ]; then echo "Error: Missing mandatory opts" >&2 usage fi -- cgit 1.4.1 From 4cf358b58920ea843a9e7e38309fe7df37fcb81f Mon Sep 17 00:00:00 2001 From: Alexander Shvedov <60114847+a-shvedov@users.noreply.github.com> Date: Sat, 1 Jun 2024 02:06:20 +0300 Subject: Update README.md --- utils/libtokencap/README.md | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'utils') diff --git a/utils/libtokencap/README.md b/utils/libtokencap/README.md index 8705452c..0e8b7ce1 100644 --- a/utils/libtokencap/README.md +++ b/utils/libtokencap/README.md @@ -69,3 +69,21 @@ need to be changed for other OSes. Current supported OSes are: Linux, Darwin, FreeBSD (thanks to @devnexen) +Also, the following example (make_dict_v2.sh) shows how to use a script to capture tokens from the +files in the target output directory, +and then generate a dictionary file from those tokens. + +#### usage: +```bash +./make_dict_v2.sh -p /path/to/libtokencap.so -b /path/to/target/program -o /path/to/target/output -t 5 +``` +#### description opts: +- ```-o``` : Path to target output directory ; +- ```-b``` : Path to target program binary ; +- ```-p``` : Path to LD_PRELOAD library ; +- ```-t``` : Timeout in seconds + +#### output: +The script generates a temporary token file (```temp_output.txt```) in the current working directory, +containing tokens captured during the execution of the target binary. +A sorted and unique token dictionary file is created in the same directory as the target output, with a ```*.dict``` extension. -- cgit 1.4.1 From d2700c7525254e9400227afe2010d366bea2aabf Mon Sep 17 00:00:00 2001 From: Alexander Shvedov <60114847+a-shvedov@users.noreply.github.com> Date: Sat, 1 Jun 2024 13:03:22 +0300 Subject: Update README.md --- utils/libtokencap/README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'utils') diff --git a/utils/libtokencap/README.md b/utils/libtokencap/README.md index 0e8b7ce1..d1c1b8b3 100644 --- a/utils/libtokencap/README.md +++ b/utils/libtokencap/README.md @@ -69,13 +69,13 @@ need to be changed for other OSes. Current supported OSes are: Linux, Darwin, FreeBSD (thanks to @devnexen) -Also, the following example (make_dict_v2.sh) shows how to use a script to capture tokens from the +Also, the following example (generate_libtoken_dict.sh) shows how to use a script to capture tokens from the files in the target output directory, and then generate a dictionary file from those tokens. #### usage: ```bash -./make_dict_v2.sh -p /path/to/libtokencap.so -b /path/to/target/program -o /path/to/target/output -t 5 +./generate_libtoken_dict.sh -p /path/to/libtokencap.so -b /path/to/target/program -o /path/to/target/output -t 5 ``` #### description opts: - ```-o``` : Path to target output directory ; -- cgit 1.4.1 From 5fb657f56945dcc7bc2ed2817fac863b69315ac7 Mon Sep 17 00:00:00 2001 From: Alexander Shvedov <60114847+a-shvedov@users.noreply.github.com> Date: Sat, 1 Jun 2024 13:03:55 +0300 Subject: Rename make_dict_v2.sh to generate_libtoken_dict.sh --- utils/libtokencap/generate_libtoken_dict.sh | 45 +++++++++++++++++++++++++++++ utils/libtokencap/make_dict_v2.sh | 45 ----------------------------- 2 files changed, 45 insertions(+), 45 deletions(-) create mode 100644 utils/libtokencap/generate_libtoken_dict.sh delete mode 100644 utils/libtokencap/make_dict_v2.sh (limited to 'utils') diff --git a/utils/libtokencap/generate_libtoken_dict.sh b/utils/libtokencap/generate_libtoken_dict.sh new file mode 100644 index 00000000..1ddec06b --- /dev/null +++ b/utils/libtokencap/generate_libtoken_dict.sh @@ -0,0 +1,45 @@ +#help +usage() { + echo "Usage: $0 -o -b -p [-t ]" + echo "Options:" + echo " -o Path to target output directory" + echo " -b Path to target program binary" + echo " -p Path to LD_PRELOAD library" + echo " -t Timeout in seconds" + exit 1 +} + +#parse cli options +while getopts ":o:b:p:t:" opt; do + case $opt in + o) target_output="$OPTARG" ;; + b) target_bin="$OPTARG" ;; + p) LD_PRELOAD_PATH="$OPTARG" ;; + t) timeout_sec="$OPTARG" ;; + \?) echo "Invalid option: -$OPTARG" >&2; usage ;; + :) echo "Option -$OPTARG requires an argument." >&2; usage ;; + esac +done + +#check options +if [ -z "$target_output" ] || [ -z "$target_bin" ] || [ -z "$LD_PRELOAD_PATH" ]; then + echo "Error: Missing mandatory opts" >&2 + usage +fi + +# initialize vars +AFL_TOKEN_FILE="${PWD}/temp_output.txt" +AFL_DICT_FILE="$(basename "$target_output").dict" + +#generate token-file +{ + touch "$AFL_TOKEN_FILE" + for i in $(find "$target_output" -type f -name "id*"); do + LD_PRELOAD="$LD_PRELOAD_PATH" \ + timeout -s SIGKILL "$timeout_sec" \ + "$target_bin" "$i" + done +} >"$AFL_TOKEN_FILE" + +# sort & remove duplicates +sort -u "$AFL_TOKEN_FILE" >"$AFL_DICT_FILE" diff --git a/utils/libtokencap/make_dict_v2.sh b/utils/libtokencap/make_dict_v2.sh deleted file mode 100644 index 1ddec06b..00000000 --- a/utils/libtokencap/make_dict_v2.sh +++ /dev/null @@ -1,45 +0,0 @@ -#help -usage() { - echo "Usage: $0 -o -b -p [-t ]" - echo "Options:" - echo " -o Path to target output directory" - echo " -b Path to target program binary" - echo " -p Path to LD_PRELOAD library" - echo " -t Timeout in seconds" - exit 1 -} - -#parse cli options -while getopts ":o:b:p:t:" opt; do - case $opt in - o) target_output="$OPTARG" ;; - b) target_bin="$OPTARG" ;; - p) LD_PRELOAD_PATH="$OPTARG" ;; - t) timeout_sec="$OPTARG" ;; - \?) echo "Invalid option: -$OPTARG" >&2; usage ;; - :) echo "Option -$OPTARG requires an argument." >&2; usage ;; - esac -done - -#check options -if [ -z "$target_output" ] || [ -z "$target_bin" ] || [ -z "$LD_PRELOAD_PATH" ]; then - echo "Error: Missing mandatory opts" >&2 - usage -fi - -# initialize vars -AFL_TOKEN_FILE="${PWD}/temp_output.txt" -AFL_DICT_FILE="$(basename "$target_output").dict" - -#generate token-file -{ - touch "$AFL_TOKEN_FILE" - for i in $(find "$target_output" -type f -name "id*"); do - LD_PRELOAD="$LD_PRELOAD_PATH" \ - timeout -s SIGKILL "$timeout_sec" \ - "$target_bin" "$i" - done -} >"$AFL_TOKEN_FILE" - -# sort & remove duplicates -sort -u "$AFL_TOKEN_FILE" >"$AFL_DICT_FILE" -- cgit 1.4.1 From b8536ced093ca46f004bea76adbd1ad484d8a8d7 Mon Sep 17 00:00:00 2001 From: Alexander Shvedov <60114847+a-shvedov@users.noreply.github.com> Date: Mon, 3 Jun 2024 19:01:50 +0300 Subject: Update generate_libtoken_dict.sh --- utils/libtokencap/generate_libtoken_dict.sh | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'utils') diff --git a/utils/libtokencap/generate_libtoken_dict.sh b/utils/libtokencap/generate_libtoken_dict.sh index 1ddec06b..cc8c5de7 100644 --- a/utils/libtokencap/generate_libtoken_dict.sh +++ b/utils/libtokencap/generate_libtoken_dict.sh @@ -1,6 +1,6 @@ #help usage() { - echo "Usage: $0 -o -b -p [-t ]" + echo "Usage: $0 -o -b -p [-t ] -- [target_args]" echo "Options:" echo " -o Path to target output directory" echo " -b Path to target program binary" @@ -21,6 +21,9 @@ while getopts ":o:b:p:t:" opt; do esac done +#shift away the parsed opts +shift $((OPTIND - 1)) + #check options if [ -z "$target_output" ] || [ -z "$target_bin" ] || [ -z "$LD_PRELOAD_PATH" ]; then echo "Error: Missing mandatory opts" >&2 @@ -29,7 +32,7 @@ fi # initialize vars AFL_TOKEN_FILE="${PWD}/temp_output.txt" -AFL_DICT_FILE="$(basename "$target_output").dict" +AFL_DICT_FILE="${PWD}/$(basename "$target_bin")_tokens.dict" #generate token-file { @@ -37,9 +40,16 @@ AFL_DICT_FILE="$(basename "$target_output").dict" for i in $(find "$target_output" -type f -name "id*"); do LD_PRELOAD="$LD_PRELOAD_PATH" \ timeout -s SIGKILL "$timeout_sec" \ - "$target_bin" "$i" + "$target_bin" "$@" "$i" done } >"$AFL_TOKEN_FILE" # sort & remove duplicates sort -u "$AFL_TOKEN_FILE" >"$AFL_DICT_FILE" + +# delete temp-file +rm "$AFL_TOKEN_FILE" + +# print done-message +echo "Token dictionary created: $AFL_DICT_FILE" +echo "Script completed successfully" -- cgit 1.4.1 From bc2ccf464ff966adb2cbb17c0ff9957cf35ab513 Mon Sep 17 00:00:00 2001 From: Alexander Shvedov <60114847+a-shvedov@users.noreply.github.com> Date: Mon, 3 Jun 2024 19:14:04 +0300 Subject: Update README.md --- utils/libtokencap/README.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'utils') diff --git a/utils/libtokencap/README.md b/utils/libtokencap/README.md index d1c1b8b3..29225835 100644 --- a/utils/libtokencap/README.md +++ b/utils/libtokencap/README.md @@ -75,15 +75,15 @@ and then generate a dictionary file from those tokens. #### usage: ```bash -./generate_libtoken_dict.sh -p /path/to/libtokencap.so -b /path/to/target/program -o /path/to/target/output -t 5 +./generate_libtoken_dict.sh -p /path/to/libtokencap.so -b /path/to/target/program -o /path/to/target/output -t 5 -- [-program_args] ``` #### description opts: - ```-o``` : Path to target output directory ; - ```-b``` : Path to target program binary ; - ```-p``` : Path to LD_PRELOAD library ; -- ```-t``` : Timeout in seconds +- ```-t``` : Timeout in seconds ; +- ```-- [-program_args]```: Any additional arguments required by the target binary can be specified after ```--```. #### output: -The script generates a temporary token file (```temp_output.txt```) in the current working directory, -containing tokens captured during the execution of the target binary. -A sorted and unique token dictionary file is created in the same directory as the target output, with a ```*.dict``` extension. +A sorted and unique token dictionary file with the extension ``*.dict`` +is created in the same directory as the target output containing tokens captured during the execution of the target binary. -- cgit 1.4.1