Lognplay merupakan hasil scripting saya yang memanfaatkan command script(1) dan scriptreplay(1) pada sistem Linux dan telah di desain sedemikan rupa sehingga lebih rapih manajemen logfile-nya dan lebih mudah penggunaannya daripada harus mengetikkan 2 command itu hehe. Lognplay adalah hasil iseng-iseng ngoding shell scripting pada system Redhat saya yang terkendala tidak bisa diinstall rootsh, sepertinya sistem Redhat kekurangan library aja sih mhahaha. Inspirasi Lognplay ini berasal dari command “playlog”-nya kippo.
Oh ya, bagi yang belum familiar sama command script dan scriptreplay, akan saya jelaskan dulu dua command inti dari program simple bernama lognplay ini. “script” adalah command yang akan menyimpan seluruh keystroke yang dipencet pada keyboard di shell kemudian menyimpannya dalam sebuah file teks. Selain menyimpan semua keystroke, program “script” juga membuat file berisi timeline waktu. Untuk apa file timeline ini? Kuncinya ada di command berikutnya, scriptreplay. “scriptreplay” memanfaatkan dua file itu (file teks yang berisi huruf-huruf yang diketik user, dan file timeline). Bisa digambarkan hasilnya? Ya hasilnya seperti menonton seseorang yang ngetik di shell anda. Kalau masih butuh ilustrasi program “scriptreplay”, hmmm kira-kira seperti melihat shell session ini.
Manfaat Lognplay
Oke, kira-kira apa kegunaan lognplay yang bisa anda bayangkan? Yang saya bisa pikirkan (dan mungkin masih banyak lagi) ada di bawah ini:
- Sebagai alternatif pengganti rootsh untuk merekam aktifitas root/user.
- Sebagai alternatif pengganti media video untuk tutorial yang seluruh kegiatannya menggunakan shell (tidak ada GUI). Seperti misalnya: tutorial setup dhcp server, dns server, tutorial hacking, etc. Pembuat tutorial tinggal merekam aktifitas shell nya menggunakan tool lognplay yang akan menggenerate file log dan timeline nya. Sedangkan pelajar tutorial tinggal mengambil file log dan timeline tersebut untuk dimainkan oleh tool lognplay.
- (isi sendiri…)
Instalasi Lognplay
Hehe, ini sebenarnya hanya single shell script jadi terlalu ‘wah’ juga kalau dibilang ada cara instalasinya haha. Tapi step ini berguna bagi pemula yang mau menyimpan lognplay ditempat yang saya rekomendasikan. Berikut ini langkah-langkahnya:
- Download paket lognplay dari http://inan.tibandung.com/pub/lognplay.zip
- Extract semua file
- Lakukan pengecekan md5sum pada file lognplay.md5. Pastikan nilai md5sum sesuai dengan isi file lognplay.md5 tersebut
- Copy lognplay ke /usr/bin/ dan buat executable:
- cp lognplay /usr/bin
- chmod +x /usr/bin/lognplay
Cara Mengoperasikan Lognplay
Berikut ini cara menggunakan tool lognplay:
user@host:~$ lognplay start <session-name>
Command di atas ini akan memulai aktifitas logging shell session user. <session-name> ini opsional hanya untuk penamaan file saja. Misalnya jika ingin membuat tutorial cara setup apache, pembuat tutorial bisa menggunakan command “lognplay start tutorial-httpd”.
user@host:~$ lognplay stealth <session-name>
Sama seperti command sebelumnya, hanya saja command ini menjalankan mekanisme logging secara diam-diam. Inilah yang menjadi alesan kenapa bisa menjadi alternatif pengganti rootsh.
user@host:~$ lognplay read /path/to/logfile/filerekaman.log
Command ini untuk memainkan log file yang diinginkan user.
user@host:~$ lognplay export /path/to/logfile/filerekaman.log
Command ini untuk meng-export log sebuah shell session. Hasilnya adalah sebuah file zip. File dalam zip di encrypt dan diproteksi dengan password standar zip.
user@host:~$ lognplay import /path/to/logfile/filerekaman.zip
Command ini untuk meng-import log sebuah shell session yang sebelumnya telah di export oleh orang lain. Sebelum di import, user akan diminta memasukkan password untuk mendecrypt dan ekstrak isi file zip. Hasilnya adalah sebuah file *.log yang akan disimpan di directory kerja lognplay. Selanjutnya tinggal memainkan log nya dengan command: lognplay read /path/to/logfile/filerekaman.log
Lognplay Pengganti Rootsh
Bagaimana bisa lognplay menjadi alternatif rootsh? Sudah sedikit disinggung di atas, fitur lognplay yang saya manfaatkan adalah mode stealth atau quiet startup. Sebagai contoh implementasi, saya ingin lognplay untuk merekam semua aktifitas root yang login. Salah satu caranya (misal), saya memanfaatkan file /etc/profile untuk mentrigger lognplay dijalankan:

Contoh script di atas ini, dengan kondisional “if”, jika “id -u” adalah 0 (id milik root), segera jalankan lognplay. Demikian shell scripting sederhana bernama lognplay ini. Saya rasa tool ini bisa sedikit membantu untuk merekam aktifitas shell user. Akhir kata selamat mencoba lognplay!
Source Code:
#!/bin/sh #lognplay: log n play your shell session! #utilize script(1) and scriptreplay(1), part of "util-linux" package. #available from Linux Kernel Archive <ftp://ftp.kernel.org/pub/linux/utils/util-linux/>. #in debian systems, require "bsdutils" package. #for fun only LOL. http://inan.tibandung.com/pub/lognplay.zip #end of header. #================================================================ #this is all configurations you need before using lognplay... #================================================================ #script working directory. choose ONE suggested below. DIRECTORY="$HOME/lognplay" #DIRECTORY="/var/log/lognplay" #path to script(1) tool. LOGGING="/usr/bin/script" #path to scriptreplay(1) tool. PLAYING="/usr/bin/scriptreplay" #token for log file ID. default is using date %s (seconds since 1970-01-01 00:00:00 UTC). FILEID=$(date '+%s') #path to zip/unzip for export/import logfiles. #I prefer zip because it provide built-in encryption mechanism. ZIP="/usr/bin/zip" UNZIP="/usr/bin/unzip" #================================================================ #check script(1) or scriptreplay(1) exist. if [ ! -f $LOGGING ] || [ ! -f $PLAYING ]; then echo "WARNING: $LOGGING or $PLAYING not exist in your system. Exiting..." exit 1 fi #get username from shell. USERNAME=$USER #check args is not NULL, otherwise print usage information. if [ ! -n "$1" ]; then echo "Usage: $0 [ start <session-name> | stealth <session-name> | read <logfile.log> | export <logfile.log> | import <logfile.zip> ]" exit 1 fi #check proper command args. if [ $1 = "read" ] || [ $1 = "start" ] || [ $1 = "stealth" ] || [ $1 = "export" ] || [ $1 = "import" ]; then #check if $DIRECTORY not exist then create the $DIRECTORY. if [ ! -d "$DIRECTORY" ]; then mkdir -p $DIRECTORY fi #if user execute "lognplay read" command. if [ $1 = "read" ]; then echo "$0: Playing your log file..." $PLAYING $DIRECTORY/.$(basename ${2%\.*}).time $2 echo "$0: Play session ended." fi #if user execute "lognplay start" command. if [ $1 = "start" ]; then #check if user input second args, use it as part of log file name. if [ -n "$2" ]; then $LOGGING -t 2>$DIRECTORY/.$USERNAME-$2-$FILEID.time $DIRECTORY/$USERNAME-$2-$FILEID.log else #else, use default file naming instead. $LOGGING -t 2>$DIRECTORY/.$USERNAME-session-$FILEID.time $DIRECTORY/$USERNAME-session-$FILEID.log fi fi #if user execute "lognplay stealth" command. if [ $1 = "stealth" ]; then #check if user input second args, use it as part of log file name. if [ -n "$2" ]; then #script(1) quiet start options. $LOGGING -q -t 2>$DIRECTORY/.$USERNAME-$2-$FILEID.time $DIRECTORY/$USERNAME-$2-$FILEID.log else #else, use default file naming instead. script(1) quiet start options. $LOGGING -q -t 2>$DIRECTORY/.$USERNAME-session-$FILEID.time $DIRECTORY/$USERNAME-session-$FILEID.log fi fi #if user execute "lognplay export" command. if [ $1 = "export" ]; then #check if user input second args, use it as zip package name. if [ -n "$2" ] && [ -f "$2" ]; then echo "Your logfile will be encrypted and protected..." $ZIP -ej $DIRECTORY/$(basename ${2%\.*}).zip $DIRECTORY/$(basename ${2%\.*}).log $DIRECTORY/.$(basename ${2%\.*}).time else #else, show "lognplay export" usage. echo "WARNING: File not exist or wrong syntax!" echo "Usage of $0 \"export\" : $0 export <logfile.log>" fi fi #if user execute "lognplay import" command. if [ $1 = "import" ]; then #check if user input second args, use it as zip package name. if [ -n "$2" ] && [ -f "$2" ]; then $UNZIP $2 -d $DIRECTORY echo "Log imported to $DIRECTORY/$(basename ${2%\.*}).log." echo "Type: \"$0 read $DIRECTORY/$(basename ${2%\.*}).log\" to play the shell session." else #else, show "lognplay import" usage. echo "WARNING: File not exist or wrong syntax!" echo "Usage of $0 \"import\" : $0 import <logfile.zip>" fi fi exit 0 else #else print same usage information as above. echo "Usage: $0 [ start <session-name> | stealth <session-name> | read <logfile.log> | export <logfile.log> | import <logfile.zip> ]" exit 1 fi #EOF