Skip to content

Instantly share code, notes, and snippets.

@rafacouto
Created January 2, 2020 01:30
Show Gist options
  • Save rafacouto/290d2cd910a595c3e70a641d68c65837 to your computer and use it in GitHub Desktop.
Save rafacouto/290d2cd910a595c3e70a641d68c65837 to your computer and use it in GitHub Desktop.
2pass - a bash importer from raw password list (exported from revelation)
#!/bin/bash
# Requirements: xml2 package
# Export the Revelation file as XML and:
# cat exported.xml | xml2 | 2pass
reset_entry()
{
a_fields=()
a_values=()
a_notes=()
}
level()
{
[[ $line =~ ^/revelationdata((/entry)+)/ ]]
IFS='/' read -ra str <<< "${BASH_REMATCH[1]}"
echo $((${#str[@]} - 1))
}
new_folder()
{
#echo "folder[$f_level]: $f_name"
a_path[$f_level]="$f_name"
}
extract_passwd()
{
for f in ${!a_fields[*]} ; do
local field="${a_fields[$f]}"
local value="${a_values[$f]}"
if [[ $field =~ (generic-password|generic-pin|creditcard-ccv) ]]
then
echo "$value"
return
fi
done
echo "-no password here-"
}
import_entry()
{
path_str='z_imported/'
for p in $(seq $((f_level - 1))) ; do path_str="$path_str${a_path[$p]}/" ; done
local title="$path_str$f_name ($f_type)"
local passwd=$(extract_passwd)
local fields=$(for f in ${!a_fields[*]} ; do echo "${a_fields[$f]}: ${a_values[$f]}" ; done)
local notes=$(for n in ${!a_notes[*]} ; do echo "note:${a_notes[$n]}" ; done)
echo -e "${passwd}\n${fields}\n${notes}" | pass insert -m "$title"
}
new_entry()
{
f_type="$f_type_next"
f_type_next="$1"
f_level=$f_level_next
f_level_next=$(level)
[ -z "$f_name" ] && return
case "$f_type" in
folder) new_folder ;;
*) import_entry ;;
esac
reset_entry
}
new_field()
{
[ -z $2 ] || field_id="$2"
a_fields+=("$field_id")
a_values+=("$1")
}
new_note()
{
a_notes[${#a_notes[*]}]="$1"
}
parse_line()
{
[[ $line =~ entry/@type=(.+) ]] && new_entry "${BASH_REMATCH[1]}"
[[ $line =~ entry/name=(.+) ]] && f_name="${BASH_REMATCH[1]}"
[[ $line =~ entry/field/@id=(.+) ]] && field_id="${BASH_REMATCH[1]}"
[[ $line =~ entry/field=(.+) ]] && new_field "${BASH_REMATCH[1]}"
[[ $line =~ entry/description=(.+) ]] && new_field "${BASH_REMATCH[1]}" description
[[ $line =~ entry/notes=(.+) ]] && new_note "${BASH_REMATCH[1]}"
}
f_level=1
a_path=()
reset_entry
while read line ; do
[[ $line =~ ^/revelationdata/entry ]] || continue
parse_line
#echo "line: $line"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment