SlideShare a Scribd company logo
2
Most read
6
Most read
7
Most read
CIS 216
        Dan Morrill
Highline Community College
 While most companies will purchase software to do keystroke
  logging sometimes based on a court order, or a request/order
  from the legal department, or other party in the company, a
  system admin will be asked to record the keystrokes of an
  employee.
 Keystroke Loggers are Illegal?
    Not Necessarily – companies can and often do keystroke log their
     employees
    Courts in some jurisdictions have declined to take the step to
     prohibit the surreptitious use of keyloggers, despite the apparent
     option to apply state legislation. This posture leaves individuals
     vulnerable to having their private information exploited by their
     employers. Given alternative methods of surveillance, lack of
     federal regulation, and advancing technology, extending state
     statutes is necessary and just. (Harvard Law, 2012)
 Keylogging - Employers sometimes install keylogging programs that
  record every single keystroke you use on your computer. This allows
  them to see everything you are typing, including your passwords. The
  Stored Communication Act and Federal Wiretap Act, along with some
  state laws may offer limited protection, but so far most employers are
  getting away with this intrusive practice.
 Email monitoring - Many companies have written policies saying the
  company can monitor your email. That means that they may look at
  your personal emails sent on company computers and devices, even if
  you used your personal email address.
 Website monitoring - Your employer is almost certainly monitoring
  your internet usage. That means if you're checking out porn
  sites, visiting YouTube, updating Facebook, or doing your holiday
  shopping, your employer will know about it. You may be violating a
  company Internet usage policy. If you aren't working the hours you're
  paid for, the employer may well discipline you for your Internet usage.
  (AOL, 2012)
 The Fourth Amendment applies whenever the
  government — whether local, state or federal —
  conducts a search or seizure. It protects you from an
  unreasonable search or seizure by any government
  official or agent, not just the police.
 The Fourth Amendment does not protect you from
  privacy invasions by people other than the
  government, even if they later hand over what they
  found to the government — unless the government
  directed them to search your things in the first place.
  (EFF, 2006)
 The most common methods used to construct
 keylogging software are as follows:
   A system hook which intercepts notification that a key
    has been pressed (installed using WinAPI
    SetWindowsHook for messages sent by the window
    procedure. It is most often written in C);
   A cyclical information keyboard request from the
    keyboard (using WinAPI Get(Async)KeyState or
    GetKeyboardState – most often written in Visual
    Basic, sometimes in Borland Delphi);
   Using a filter driver (requires specialized knowledge and
    is written in C). (SecureList, 2007)
 Declare the variables:
   log_dir=/home/
    current_user=$(whoami)
    log_time=$(date +%m%d%y%H%M%S)
    log_file="current_user$log_time"
    attempt="0"
    test_log_file="$log_file"
 Write the function:
   create_log()
    {
    while [ -e $test_log_file ] # Checks for an existing file with the
    name found in $log_file.
    do # If $log_file is found, increment by one and try again.
       attempt="$attempt+1"
       test_log_file="$log_file""_$attempt"
    done
    log_file="$test_log_file"
    touch $log_file # Once a viable filename has been found, this
    file is created.
    chmod 600 $log_file # Make $log_file writable for logging.
    }
   Do the work
       close_log()
        {
        if [ -e $log_file ] # Tests for the existence of $log_file.
        then
           echo "" >> $log_file
           echo "****************************************" >> $log_file
           echo "Logfile closing at $(date +%m%d%y%H%M%S)." >> $log_file # Adds final
        date/time entry to log
        else
           echo "Test 3b"
           echo "Logfile did not exist. No record of keystroke logging exists." >> $log_file # If log
        does not exist, creates log and logs failure
           echo "Created $log_file to report this error." >> $log_file
           echo "Logfile created at $(date +%m%d%y%H%M%S)." >> $log_file
           echo "Logfile will now close."
        fi
        chmod 400 $log_file # Guarantees log is left in read-only mode, even if trap triggered
        during logging.
        kill -9 > /dev/null # Guarantees ending of this process.
        }
 Trap the users input and create the log
   trap 'close_log; exit 0' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
    18 19 20 26
    create_log
    script $log_file
    close_log
    exit
 Setup reporting via e-mail as a distro list
   LOG_MANAGER="logman"           # List to e-mail audit log
   Logman is the distro-email
 Setup the cleanup routine so no logs are left behind on the system
  being monitored
    cleanup_exit () # This will do the cleanup execute and exit function.
     {
     # This function is executed on any type of exit except of course
     # a kill -9, which cannot be trapped. The script log file is
     # e-mailed either locally or remotely and the log file is
     # compressed. The last "exit" is needed so the user does not
     # have the ability to get to the command line without logging.
     if [[ -s ${LOGDIR}/${LOGFILE} ]]
     then
        mailx -s "$TS - $LOGNAME Audit Report" $LOG_MANAGER 
            < ${LOGDIR}/${LOGFILE}
        compress ${LOGDIR}/${LOGFILE} 2>/dev/null
     fi
     exit
     }
 Set the exit trap
   trap 'cleanup_exit' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
    19 20 26
 Declare the variables
        TS=$(date +%m%d%y%H%M%S)               # File time stamp
        THISHOST=$(hostname|cut -f1-2 -d.)        # This is the host name of this
       machine
         LOGDIR=/home/ganesh/other/logger_files # Log files are saved on the
       logger files
                    # automatically and also
                    # This is the path that hold to the logs
         LOGFILE=${THISHOST}.${LOGNAME}.$TS            # Creates the name of the
       log file
         touch $LOGDIR/$LOGFILE              # Creates the actual file
         set -o vi 2>/dev/null        # Previous commands recall
       # Set the command prompt
         export PS1="[THISHOST]@"'$PWD> '
 Running parameters
   chmod 774 ${LOGDIR}/${LOGFILE}        # giving full
    control/permission to for the owner & Group
               # and read and write permissons to the other.

    script ${LOGDIR}/${LOGFILE}       # Start the script
    monitoring session

    chmod 774 ${LOGDIR}/${LOGFILE} # Set permission to
    read, write and execute for the owner and group
                # and read and write permission to other.

    cleanup_exit             # Execute the cleanup and exit
    function
 There is always more than one solution
 Sometimes you need to write a key logger that is
  required for work, and you will not want to trigger an
  Anti-virus/malware response
 Be careful – this is pretty cool, but leads to liability
  work if not suffencently covered by authorization from
  management

More Related Content

PDF
Final Report - morse code.pdf
PPTX
Chapter 3 mathematical modeling of dynamic system
PPTX
1-Crystallography.pptx
PDF
Table of transformation of laplace & z
PDF
On chip stress analysis in a package interaction test chip
PPT
1.Chapter 5 – Flip-Flops and Related Devices.ppt
PPTX
Gradient divergence curl
PDF
Solutions manual for calculus an applied approach brief international metric ...
Final Report - morse code.pdf
Chapter 3 mathematical modeling of dynamic system
1-Crystallography.pptx
Table of transformation of laplace & z
On chip stress analysis in a package interaction test chip
1.Chapter 5 – Flip-Flops and Related Devices.ppt
Gradient divergence curl
Solutions manual for calculus an applied approach brief international metric ...

Viewers also liked (8)

PPTX
Process monitoring in UNIX shell scripting
PDF
Understanding Keylogger
PPTX
KeySens: Passive User Authentication Through Micro Behavior Modeling of Soft ...
PPTX
Linux MMAP & Ioremap introduction
PPT
Chapters 3 4
PDF
We Know Your Type
PPTX
Keystroke dynamics
PDF
researchpaper-Keystroke-Dynamics-Authentication-based-on-Principal-Component-...
Process monitoring in UNIX shell scripting
Understanding Keylogger
KeySens: Passive User Authentication Through Micro Behavior Modeling of Soft ...
Linux MMAP & Ioremap introduction
Chapters 3 4
We Know Your Type
Keystroke dynamics
researchpaper-Keystroke-Dynamics-Authentication-based-on-Principal-Component-...
Ad

Similar to Creating a keystroke logger in unix shell scripting (20)

PDF
Debugging: Rules & Tools
PDF
Course 102: Lecture 8: Composite Commands
PDF
OS_lab_file.pdf
PDF
Codeigniter4の比較と検証
PDF
How to recognise that the user has just uninstalled your app
PDF
Monitor all the things - Confoo
PDF
exercises-log-management-rsyslog.pdf
PDF
Penetrating Windows 8 with syringe utility
PPT
Download It
ODP
Troubleshooting Plone
PDF
Linux advanced privilege escalation
PDF
Debugging: Rules And Tools - PHPTek 11 Version
DOCX
Iwatch tech 1
PDF
Php logging
ODP
Easy Web Project Development & Management with Django & Mercurial
PPTX
How to recognise that the user has just uninstalled your android app droidc...
PPTX
How to recognise that the user has just uninstalled your android app
ODP
The why and how of moving to PHP 5.4/5.5
PDF
MacOS forensics and anti-forensics (DC Lviv 2019) presentation
Debugging: Rules & Tools
Course 102: Lecture 8: Composite Commands
OS_lab_file.pdf
Codeigniter4の比較と検証
How to recognise that the user has just uninstalled your app
Monitor all the things - Confoo
exercises-log-management-rsyslog.pdf
Penetrating Windows 8 with syringe utility
Download It
Troubleshooting Plone
Linux advanced privilege escalation
Debugging: Rules And Tools - PHPTek 11 Version
Iwatch tech 1
Php logging
Easy Web Project Development & Management with Django & Mercurial
How to recognise that the user has just uninstalled your android app droidc...
How to recognise that the user has just uninstalled your android app
The why and how of moving to PHP 5.4/5.5
MacOS forensics and anti-forensics (DC Lviv 2019) presentation
Ad

More from Dan Morrill (18)

PPTX
Windows power shell and active directory
PPTX
Windows power shell basics
PPTX
Understanding web site analytics
PPTX
Understanding UNIX CASE and TPUT
PPTX
Information security principles
PPTX
Using Regular Expressions in Grep
PPTX
Understanding the security_organization
PPTX
You should ask before copying that media
PPTX
Cis 216 – shell scripting
PPTX
Understanding advanced persistent threats (APT)
PPTX
AWS Hadoop and PIG and overview
PPTX
What is cloud computing
PPT
Social Media Plan for CityU of Seattle
PPT
BSIS Overview
PPT
Case Studies In Social Media Chinese
PPT
Case Studies In Social Media
PPT
Turn On Tune In Step Out
PPT
Technology And The Future Of Management
Windows power shell and active directory
Windows power shell basics
Understanding web site analytics
Understanding UNIX CASE and TPUT
Information security principles
Using Regular Expressions in Grep
Understanding the security_organization
You should ask before copying that media
Cis 216 – shell scripting
Understanding advanced persistent threats (APT)
AWS Hadoop and PIG and overview
What is cloud computing
Social Media Plan for CityU of Seattle
BSIS Overview
Case Studies In Social Media Chinese
Case Studies In Social Media
Turn On Tune In Step Out
Technology And The Future Of Management

Recently uploaded (20)

PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
PPTX
Pharma ospi slides which help in ospi learning
PDF
Abdominal Access Techniques with Prof. Dr. R K Mishra
PDF
VCE English Exam - Section C Student Revision Booklet
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PDF
Complications of Minimal Access Surgery at WLH
PPTX
202450812 BayCHI UCSC-SV 20250812 v17.pptx
PDF
A systematic review of self-coping strategies used by university students to ...
PDF
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
STATICS OF THE RIGID BODIES Hibbelers.pdf
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Chinmaya Tiranga quiz Grand Finale.pdf
Supply Chain Operations Speaking Notes -ICLT Program
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
Introduction-to-Literarature-and-Literary-Studies-week-Prelim-coverage.pptx
Pharma ospi slides which help in ospi learning
Abdominal Access Techniques with Prof. Dr. R K Mishra
VCE English Exam - Section C Student Revision Booklet
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
Final Presentation General Medicine 03-08-2024.pptx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Complications of Minimal Access Surgery at WLH
202450812 BayCHI UCSC-SV 20250812 v17.pptx
A systematic review of self-coping strategies used by university students to ...
3rd Neelam Sanjeevareddy Memorial Lecture.pdf
Cell Structure & Organelles in detailed.
IMMUNITY IMMUNITY refers to protection against infection, and the immune syst...

Creating a keystroke logger in unix shell scripting

  • 1. CIS 216 Dan Morrill Highline Community College
  • 2.  While most companies will purchase software to do keystroke logging sometimes based on a court order, or a request/order from the legal department, or other party in the company, a system admin will be asked to record the keystrokes of an employee.  Keystroke Loggers are Illegal?  Not Necessarily – companies can and often do keystroke log their employees  Courts in some jurisdictions have declined to take the step to prohibit the surreptitious use of keyloggers, despite the apparent option to apply state legislation. This posture leaves individuals vulnerable to having their private information exploited by their employers. Given alternative methods of surveillance, lack of federal regulation, and advancing technology, extending state statutes is necessary and just. (Harvard Law, 2012)
  • 3.  Keylogging - Employers sometimes install keylogging programs that record every single keystroke you use on your computer. This allows them to see everything you are typing, including your passwords. The Stored Communication Act and Federal Wiretap Act, along with some state laws may offer limited protection, but so far most employers are getting away with this intrusive practice.  Email monitoring - Many companies have written policies saying the company can monitor your email. That means that they may look at your personal emails sent on company computers and devices, even if you used your personal email address.  Website monitoring - Your employer is almost certainly monitoring your internet usage. That means if you're checking out porn sites, visiting YouTube, updating Facebook, or doing your holiday shopping, your employer will know about it. You may be violating a company Internet usage policy. If you aren't working the hours you're paid for, the employer may well discipline you for your Internet usage. (AOL, 2012)
  • 4.  The Fourth Amendment applies whenever the government — whether local, state or federal — conducts a search or seizure. It protects you from an unreasonable search or seizure by any government official or agent, not just the police.  The Fourth Amendment does not protect you from privacy invasions by people other than the government, even if they later hand over what they found to the government — unless the government directed them to search your things in the first place. (EFF, 2006)
  • 5.  The most common methods used to construct keylogging software are as follows:  A system hook which intercepts notification that a key has been pressed (installed using WinAPI SetWindowsHook for messages sent by the window procedure. It is most often written in C);  A cyclical information keyboard request from the keyboard (using WinAPI Get(Async)KeyState or GetKeyboardState – most often written in Visual Basic, sometimes in Borland Delphi);  Using a filter driver (requires specialized knowledge and is written in C). (SecureList, 2007)
  • 6.  Declare the variables:  log_dir=/home/ current_user=$(whoami) log_time=$(date +%m%d%y%H%M%S) log_file="current_user$log_time" attempt="0" test_log_file="$log_file"
  • 7.  Write the function:  create_log() { while [ -e $test_log_file ] # Checks for an existing file with the name found in $log_file. do # If $log_file is found, increment by one and try again. attempt="$attempt+1" test_log_file="$log_file""_$attempt" done log_file="$test_log_file" touch $log_file # Once a viable filename has been found, this file is created. chmod 600 $log_file # Make $log_file writable for logging. }
  • 8. Do the work  close_log() { if [ -e $log_file ] # Tests for the existence of $log_file. then echo "" >> $log_file echo "****************************************" >> $log_file echo "Logfile closing at $(date +%m%d%y%H%M%S)." >> $log_file # Adds final date/time entry to log else echo "Test 3b" echo "Logfile did not exist. No record of keystroke logging exists." >> $log_file # If log does not exist, creates log and logs failure echo "Created $log_file to report this error." >> $log_file echo "Logfile created at $(date +%m%d%y%H%M%S)." >> $log_file echo "Logfile will now close." fi chmod 400 $log_file # Guarantees log is left in read-only mode, even if trap triggered during logging. kill -9 > /dev/null # Guarantees ending of this process. }
  • 9.  Trap the users input and create the log  trap 'close_log; exit 0' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 26 create_log script $log_file close_log exit
  • 10.  Setup reporting via e-mail as a distro list  LOG_MANAGER="logman" # List to e-mail audit log  Logman is the distro-email
  • 11.  Setup the cleanup routine so no logs are left behind on the system being monitored  cleanup_exit () # This will do the cleanup execute and exit function. { # This function is executed on any type of exit except of course # a kill -9, which cannot be trapped. The script log file is # e-mailed either locally or remotely and the log file is # compressed. The last "exit" is needed so the user does not # have the ability to get to the command line without logging. if [[ -s ${LOGDIR}/${LOGFILE} ]] then mailx -s "$TS - $LOGNAME Audit Report" $LOG_MANAGER < ${LOGDIR}/${LOGFILE} compress ${LOGDIR}/${LOGFILE} 2>/dev/null fi exit }
  • 12.  Set the exit trap  trap 'cleanup_exit' 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 26
  • 13.  Declare the variables  TS=$(date +%m%d%y%H%M%S) # File time stamp THISHOST=$(hostname|cut -f1-2 -d.) # This is the host name of this machine LOGDIR=/home/ganesh/other/logger_files # Log files are saved on the logger files # automatically and also # This is the path that hold to the logs LOGFILE=${THISHOST}.${LOGNAME}.$TS # Creates the name of the log file touch $LOGDIR/$LOGFILE # Creates the actual file set -o vi 2>/dev/null # Previous commands recall # Set the command prompt export PS1="[THISHOST]@"'$PWD> '
  • 14.  Running parameters  chmod 774 ${LOGDIR}/${LOGFILE} # giving full control/permission to for the owner & Group # and read and write permissons to the other. script ${LOGDIR}/${LOGFILE} # Start the script monitoring session chmod 774 ${LOGDIR}/${LOGFILE} # Set permission to read, write and execute for the owner and group # and read and write permission to other. cleanup_exit # Execute the cleanup and exit function
  • 15.  There is always more than one solution  Sometimes you need to write a key logger that is required for work, and you will not want to trigger an Anti-virus/malware response  Be careful – this is pretty cool, but leads to liability work if not suffencently covered by authorization from management

Editor's Notes

  • #3: http://jolt.law.harvard.edu/digest/software/federal-and-state-wiretap-act-regulation-of-keyloggers-in-the-workplace
  • #4: http://jobs.aol.com/articles/2012/12/09/employer-spy-workers-legally-snoop/
  • #5: https://ssd.eff.org/book/export/html/16
  • #6: http://www.securelist.com/en/analysis?pubid=204791931