SlideShare a Scribd company logo
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

What's hot (20)

Ch1-Operating System Concept
Ch1-Operating System Concept
Muhammad Bilal Tariq
 
Introduction to Storage technologies
Introduction to Storage technologies
Kaivalya Shah
 
Fuzzing.pptx
Fuzzing.pptx
Abhik Roychoudhury
 
Apache hadoop hbase
Apache hadoop hbase
sheetal sharma
 
TMUX Rocks!
TMUX Rocks!
Kent Chen
 
Chapter 1 - Introduction
Chapter 1 - Introduction
Wayne Jones Jnr
 
Basic linux commands for bioinformatics
Basic linux commands for bioinformatics
Bonnie Ng
 
Evolution of os
Evolution of os
janani thirupathi
 
2. context free langauages
2. context free langauages
danhumble
 
context free language
context free language
khush_boo31
 
Multithreading Presentation
Multithreading Presentation
Neeraj Kaushik
 
Virus and its CounterMeasures -- Pruthvi Monarch
Virus and its CounterMeasures -- Pruthvi Monarch
Pruthvi Monarch
 
The Future Of Big Data
The Future Of Big Data
Matthew Dennis
 
M.c.a. (sem ii) operating systems
M.c.a. (sem ii) operating systems
Tushar Rajput
 
Difference between cts and cls
Difference between cts and cls
Umar Ali
 
Addressing
Addressing
Gichelle Amon
 
Asymptotic notations
Asymptotic notations
V.V.Vanniaperumal College for Women
 
Mutual Exclusion in Distributed Memory Systems
Mutual Exclusion in Distributed Memory Systems
Dilum Bandara
 
TOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite Automata
Mohammad Imam Hossain
 
Regular expressions
Regular expressions
Ratnakar Mikkili
 
Introduction to Storage technologies
Introduction to Storage technologies
Kaivalya Shah
 
Chapter 1 - Introduction
Chapter 1 - Introduction
Wayne Jones Jnr
 
Basic linux commands for bioinformatics
Basic linux commands for bioinformatics
Bonnie Ng
 
2. context free langauages
2. context free langauages
danhumble
 
context free language
context free language
khush_boo31
 
Multithreading Presentation
Multithreading Presentation
Neeraj Kaushik
 
Virus and its CounterMeasures -- Pruthvi Monarch
Virus and its CounterMeasures -- Pruthvi Monarch
Pruthvi Monarch
 
The Future Of Big Data
The Future Of Big Data
Matthew Dennis
 
M.c.a. (sem ii) operating systems
M.c.a. (sem ii) operating systems
Tushar Rajput
 
Difference between cts and cls
Difference between cts and cls
Umar Ali
 
Mutual Exclusion in Distributed Memory Systems
Mutual Exclusion in Distributed Memory Systems
Dilum Bandara
 
TOC 2 | Deterministic Finite Automata
TOC 2 | Deterministic Finite Automata
Mohammad Imam Hossain
 

Viewers also liked (8)

Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
Dan Morrill
 
Understanding Keylogger
Understanding Keylogger
Phannarith Ou, G-CISO
 
KeySens: Passive User Authentication Through Micro Behavior Modeling of Soft ...
KeySens: Passive User Authentication Through Micro Behavior Modeling of Soft ...
Jiang Zhu
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
Gene Chang
 
Chapters 3 4
Chapters 3 4
sakshi_20
 
We Know Your Type
We Know Your Type
CTIN
 
Keystroke dynamics
Keystroke dynamics
Tushar Kayande
 
researchpaper-Keystroke-Dynamics-Authentication-based-on-Principal-Component-...
researchpaper-Keystroke-Dynamics-Authentication-based-on-Principal-Component-...
Mina Khidhir
 
Process monitoring in UNIX shell scripting
Process monitoring in UNIX shell scripting
Dan Morrill
 
KeySens: Passive User Authentication Through Micro Behavior Modeling of Soft ...
KeySens: Passive User Authentication Through Micro Behavior Modeling of Soft ...
Jiang Zhu
 
Linux MMAP & Ioremap introduction
Linux MMAP & Ioremap introduction
Gene Chang
 
Chapters 3 4
Chapters 3 4
sakshi_20
 
We Know Your Type
We Know Your Type
CTIN
 
researchpaper-Keystroke-Dynamics-Authentication-based-on-Principal-Component-...
researchpaper-Keystroke-Dynamics-Authentication-based-on-Principal-Component-...
Mina Khidhir
 
Ad

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

linux_Commads
linux_Commads
tastedone
 
Aucklug slides - desktop tips and tricks
Aucklug slides - desktop tips and tricks
Glen Ogilvie
 
First Responders Course - Session 7 - Incident Scope Assessment [2004]
First Responders Course - Session 7 - Incident Scope Assessment [2004]
Phil Huggins FBCS CITP
 
10 awesome examples for viewing huge log files in unix
10 awesome examples for viewing huge log files in unix
chinkshady
 
Power of logs: practices for network security
Power of logs: practices for network security
Information Technology Society Nepal
 
Cybersecurity Ops With Bash Attack Defend And Analyze From The Command Line 1...
Cybersecurity Ops With Bash Attack Defend And Analyze From The Command Line 1...
guhmanlosic
 
Cis222 9
Cis222 9
Russ Ferriday
 
Elk its big log season
Elk its big log season
Eric Luellen
 
44CON London 2015 - 15-Minute Linux Incident Response Live Analysis
44CON London 2015 - 15-Minute Linux Incident Response Live Analysis
44CON
 
Unix fundamentals
Unix fundamentals
Dima Gomaa
 
MCLS 45 Lab Manual
MCLS 45 Lab Manual
Lokesh Singrol
 
Linux intermediate level
Linux intermediate level
Madhavendra Dutt
 
Unix 2 en
Unix 2 en
Simonas Kareiva
 
58518522 study-aix
58518522 study-aix
homeworkping3
 
Unix commands
Unix commands
selvamanisampath
 
Lpt lopsa
Lpt lopsa
ketancmaheshwari
 
Unit 10 investigating and managing
Unit 10 investigating and managing
root_fibo
 
Ppt linux
Ppt linux
Gurpreet Kaur
 
Ossec Lightning
Ossec Lightning
wremes
 
Backtrack
Backtrack
n|u - The Open Security Community
 
linux_Commads
linux_Commads
tastedone
 
Aucklug slides - desktop tips and tricks
Aucklug slides - desktop tips and tricks
Glen Ogilvie
 
First Responders Course - Session 7 - Incident Scope Assessment [2004]
First Responders Course - Session 7 - Incident Scope Assessment [2004]
Phil Huggins FBCS CITP
 
10 awesome examples for viewing huge log files in unix
10 awesome examples for viewing huge log files in unix
chinkshady
 
Cybersecurity Ops With Bash Attack Defend And Analyze From The Command Line 1...
Cybersecurity Ops With Bash Attack Defend And Analyze From The Command Line 1...
guhmanlosic
 
Elk its big log season
Elk its big log season
Eric Luellen
 
44CON London 2015 - 15-Minute Linux Incident Response Live Analysis
44CON London 2015 - 15-Minute Linux Incident Response Live Analysis
44CON
 
Unix fundamentals
Unix fundamentals
Dima Gomaa
 
Unit 10 investigating and managing
Unit 10 investigating and managing
root_fibo
 
Ossec Lightning
Ossec Lightning
wremes
 
Ad

More from Dan Morrill (18)

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

Recently uploaded (20)

How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Vikas Bansal Himachal Pradesh: A Visionary Transforming Himachal’s Educationa...
Himalayan Group of Professional Institutions (HGPI)
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 
How to Manage Upselling of Subscriptions in Odoo 18
How to Manage Upselling of Subscriptions in Odoo 18
Celine George
 
Unit- 4 Biostatistics & Research Methodology.pdf
Unit- 4 Biostatistics & Research Methodology.pdf
KRUTIKA CHANNE
 
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDMMIA Free Reiki Yoga S9 Grad Level Intuition II
LDM & Mia eStudios
 
How to Manage Inventory Movement in Odoo 18 POS
How to Manage Inventory Movement in Odoo 18 POS
Celine George
 
Exploring Ocean Floor Features for Middle School
Exploring Ocean Floor Features for Middle School
Marie
 
Overview of Employee in Odoo 18 - Odoo Slides
Overview of Employee in Odoo 18 - Odoo Slides
Celine George
 
What is FIle and explanation of text files.pptx
What is FIle and explanation of text files.pptx
Ramakrishna Reddy Bijjam
 
LDMMIA GRAD Student Check-in Orientation Sampler
LDMMIA GRAD Student Check-in Orientation Sampler
LDM & Mia eStudios
 
june 10 2025 ppt for madden on art science is over.pptx
june 10 2025 ppt for madden on art science is over.pptx
roger malina
 
Allomorps and word formation.pptx - Google Slides.pdf
Allomorps and word formation.pptx - Google Slides.pdf
Abha Pandey
 
Publishing Your Memoir with Brooke Warner
Publishing Your Memoir with Brooke Warner
Brooke Warner
 
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
Energy Balances Of Oecd Countries 2011 Iea Statistics 1st Edition Oecd
razelitouali
 
Overview of Off Boarding in Odoo 18 Employees
Overview of Off Boarding in Odoo 18 Employees
Celine George
 
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Basic English for Communication - Dr Hj Euis Eti Rohaeti Mpd
Restu Bias Primandhika
 
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Paper 108 | Thoreau’s Influence on Gandhi: The Evolution of Civil Disobedience
Rajdeep Bavaliya
 
How to Manage Multi Language for Invoice in Odoo 18
How to Manage Multi Language for Invoice in Odoo 18
Celine George
 
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
FEBA Sofia Univercity final diplian v3 GSDG 5.2025.pdf
ChristinaFortunova
 
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
THERAPEUTIC COMMUNICATION included definition, characteristics, nurse patient...
parmarjuli1412
 
How to Manage & Create a New Department in Odoo 18 Employee
How to Manage & Create a New Department in Odoo 18 Employee
Celine George
 

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