CSN08101 Digital Forensics Lecture 2: Essential Linux for Forensics Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak.

Slides:



Advertisements
Similar presentations
การใช้ระบบปฏิบัติการ UNIX พื้นฐาน บทที่ 4 File Manipulation วิบูลย์ วราสิทธิชัย นักวิชาการคอมพิวเตอร์ ศูนย์คอมพิวเตอร์ ม. สงขลานครินทร์ เวอร์ชั่น 1 วันที่
Advertisements

NETW-240 Shells Last Update Copyright Kenneth M. Chipps Ph.D. 1.
Lab6 CPCS361 I.Mona Alshehri. Working with Files and Directories Creating files Create a file with the cat command type the command cat > name_of_file.
Cosc 4750 Getting Started in UNIX Don’t be afraid of the prompt, in linux it can be your best friend. In some cases, the only way to do certain things.
Linux File & Folder permissions. File Permissions In Ubuntu, files and folders can be set up so that only specific users can view, modify, or run them.
Introducing the Command Line CMSC 121 Introduction to UNIX Much of the material in these slides was taken from Dan Hood’s CMSC 121 Lecture Notes.
File Security. Viewing Permissions ls –l Permission Values.
File security and Permissions A file is owned by the user who created it That user can then specify who can read, write and execute that file A file when.
T UTORIAL OF U NIX C OMMAND & SHELL SCRIPT S 5027 Professor: Dr. Shu-Ching Chen TA: Samira Pouyanfar Spring 2015.
Lecture 02CS311 – Operating Systems 1 1 CS311 – Lecture 02 Outline UNIX/Linux features – Redirection – pipes – Terminating a command – Running program.
Introduction to Unix – CS 21 Lecture 5. Lecture Overview Lab Review Useful commands that will illustrate today’s lecture Streams of input and output File.
Using Linux Commands Lab 4. Using the Shell in Linux Commands Syntax  Options: could be added to the commands to change their behavior (-a, -la, --help)
Getting Started with Linux Linux System Administration Permissions.
L INUX C OMMAND L INE I NTERFACE G UNAANBAN.G
CS 141 Labs are mandatory. Attendance will be taken in each lab. Make account on moodle. Projects will be submitted via moodle.
"Two of the most famous products of Berkeley are LSD and Unix. I don't think that this is a coincidence.” Anonymous.
COMP1070/2002/lec4/H.Melikian COMP1070 Lecture #5  Files and directories in UNIX  Various types of files  File attributes  Notion of pathname  Commands.
Filesystem Hierarchy Standard (FHS) –Standard of outlining the location of set files and directories on a Linux system –Gives Linux software developers.
Unix Primer. Unix Shell The shell is a command programming language that provides an interface to the UNIX operating system. The shell is a “regular”
Chapter 9 Part II Linux Command Line Access to Linux Authenticated login using a Linux account is required to access a Linux system. The Linux prompt will.
CHAPTER 1 UNIX FOR NONPROGRAMMERS By U ğ ur Halıcı.
Linux Directory Navigation. File & Directory Commands This is a minimal list of Unix commands that you must know for file management: ls (list) mkdir.
Files & Directories Objectives –to be able to describe and use the Unix file system model and concepts Contents –directory structure –file system concepts.
Linux environment ● Graphical interface – X-window + window manager ● Text interface – terminal + shell.
1 Lecture 2 Working with Files and Directories COP 3344 Introduction to UNIX.
June 1, 1999Manipulating Files1 Introduction to UNIX E. Manipulating Files.
CSN08101 Digital Forensics Lecture 1B: Essential Linux and Caine Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak.
File Processing. Introduction More UNIX commands for handling files Regular Expressions and Searching files Redirection and pipes Bash facilities.
– Introduction to the Shell 10/1/2015 Introduction to the Shell – Session Introduction to the Shell – Session 2 · Permissions · Users.
Working with Linux Lab 1 1. Login and logout Account – username & password – Note: Linux is case-sensitive Administrator: username = root Logout: exit,
System Administration Introduction to Unix Session 2 – Fri 02 Nov 2007 Reference:  chapter 1, The Unix Programming Environment, Kernighan & Pike, ISBN.
CSN08101 Digital Forensics Lecture 5: Data management and Autopsy Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak.
Linux Operations and Administration
Lesson 9-Setting and Using Permissions. Overview Describing file permissions. Using execute permissions with a file. Changing file permissions using mnemonics.
CSN08101 Digital Forensics Lecture 4: System Level Disk Control Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak.
CSN08101 Digital Forensics Lecture 3: Linux Searching Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak.
Managing Files. Module 5 Managing Files ♦ Introduction “On a Linux system, everything is a file; if something is not a file, it is a process.” ♦ Topics.
Linux file system "On a UNIX system, everything is a file; if something is not a file, it is a process." Sorts of files (on a Linux system) Directories:
Using Commands Unix / Linux Preparation Course May 6, 2012 Serrekunda, The Gambia.
Introduction to Unix – CS 21 Lecture 4. Lecture Overview * cp, mv, and rm Looking into files The file command head and tail cat and more What we’ve seen.
Chapter Two Exploring the UNIX File System and File Security.
File Security and Permissions. File Permissions (1) u With respect to a particular file, Unix divides the set of all users on a system into three categories:
Chapter 4: File Security & Permissions Also: Hard and Soft Links, see p77-80 &
E X C E E D I N G E X P E C T A T I O N S Basic LINUX Linux System Administration Dr. Hoganson Kennesaw State University Operating Systems Directory structure:
Linux+ Guide to Linux Certification, Third Edition
Workbook 4 User & Group Permissions RH030 Linux Computing Essentials.
PacNOG 6: Nadi, Fiji UNIX ™/ /Linux Permissions Hervey Allen Network Startup Resource Center.
Using Linux Commands Lab 4. Using the Shell in Linux Commands Syntax  Options: could be added to the commands to change their behavior (-a, -la, --help)
Using the “CLI” Unix / Linux Preparation Course June 9, 2013 Lusaka, Zambia.
Linux Commands C151 Multi-User Operating Systems.
2 Manual & Filestore Mauro Jaskelioff. Introduction Using the manual The UNIX filestore File permissions.
1 Lecture 2 Working with Files and Directories COP 3353 Introduction to UNIX.
UNIX filesystem CS 2204 Class meeting 2 *Notes by Doug Bowman and other members of the CS faculty at Virginia Tech. Copyright
Linux+ Guide to Linux Certification, Second Edition Chapter 4 Exploring Linux Filesystems.
1 CS3695 – Network Vulnerability Assessment & Risk Mitigation – Introduction to Unix & Linux.
Agenda The Linux File System (chapter 4 in text) Setting Access Permissions Directory vs File Permissions chmod Utility Symbolic Method Absolute Method.
The Unix File System R Bigelow. The UNIX File System The file system refers to the way in which UNIX implements files and directories. The UNIX file system.
File Management commands cat Cat command cat cal.txt cat command displays the contents of a file here cal.txt on screen (or standard out).
Linux Tutorial Lesson Two *Getting Help in Linux *Data movement and manipulation *Relative and Absolute path *Processes Note: see chapter 1,2,3 from Linux.
Tutorial of Unix Command & shell scriptS 5027
Linux 101 Training Module Linux Basics.
Lecture 2 Working with Files and Directories
C151 Multi-User Operating Systems
Tutorial of Unix Command & shell scriptS 5027
Basic UNIX OLC Training.
Tutorial of Unix Command & shell scriptS 5027
Using Linux Commands Lab 3.
Tutorial of Unix Command & shell scriptS 5027
CSE 303 Concepts and Tools for Software Development
January 26th, 2004 Class Meeting 2
Presentation transcript:

CSN08101 Digital Forensics Lecture 2: Essential Linux for Forensics Module Leader: Dr Gordon Russell Lecturers: Robert Ludwiniak

Essential Linux for Forensics You will learn in this lecture: Essential file manipulation in Linux Command Summary: –cp –mv –cat –less –more –tail –head –wc –chmod Concepts Summary –Pipe and redirection –Basic permissions –Filename wildcard expansions

cp Duplicates a file. Takes 2 parameters: –1. the file being copied –2. the new file being created $ ls file1 $ cp file1 file2 $ ls file1 file2

Rel/Abs demo /home/caine file1 file2 file4file3 file5 dir1 dir2 $ cd /home/caine $ cp dir1/file4 /home/caine/dir2/ New file is called “file4” $ cp dir1/file3 /home/caine/dir2/file6 $ cp../caine/file2./dir1 “.” is the current directory $ cd dir2 $ cp file5.. “..” is the directory above

Rel/Abs questions /home/caine file1 file2 file4file3 file5 dir1 dir2 1.Copy file2 into dir2 $ cd /home/caine $ cp file2../__???___/__???___/file2 2.Copy file5 into dir1 $ cd dir1 $ cp ?????????/file5.

mv Renames a file. Takes 2 parameters: –1. the file being renamed –2. the new filename $ ls file1 $ mv file1 file2 $ ls file2

Rel/Abs demo /home/caine file1 file2 file4file3 file5 dir1 dir2 $ cd /home/caine $ mv dir1/file4 /home/caine/dir2/ New file is called “file4” but new directory $ mv dir1/file3 /home/caine/dir2/file6 $ mv../caine/file2./dir1 $ cd dir2 $ mv file5..

Rel/Abs questions /home/caine file1 file2 file4file3 file5 dir1 dir2 1.Rename file2 as filenew $ cd /home/caine $ mv file2 dir2/__???___/filenew 2.Rename file4 in dir1 as file10 in /home/caine $ cd dir2 $ mv ?????????/file4 ????????/file10

cat Displays the contents of a file to the screen. $ cat file1 Hello this is the contents of file1 Goodbye $ cat file2 Bonjour ici is the contents of file2 Goodbye $ cat file1 file2 Hello this is the contents of file1 Goodbye Bonjour ici is the contents of file2 Goodbye

Rel/Abs questions /home/caine file1 file2 file4file3 file5 dir1 dir2 1.Display the content of file2, file3, and file5 one after the other in a single cat command $ cd /home/caine $ cat ??? ??? ???

more The user-friendly cat Just like “cat” but stops after each full page and says --More--(50%) Press “spacebar” to continue for another full page Press “return/enter” to continue for 1 more line. Press “q” to quit out of more before the end of the file.

less The user-friendly “more”! Just like “more” but you can move backwards. Great if you have fat fingers and keep paging past the information you want... Same keys as “more”, but also: –“Page Up” to go back a page –“Page Down” to go on a page –Cursor key up arrow to go back 1 line –Cursor key down arrow to go on 1 line Does not automatically quit at the end. You need to press “q”.

head Prints the first “n” lines of a file –“n” is 10 by default –The first parameter can be “-number”, to give that number of lines from the start of the file –Example: you can say “-5” before the name of the file to get the first 5 lines. $ head -2 file10 This is line 1 This is line 2 $ head -3 file10 This is line 1 This is line 2 This is line 3

tail Prints the last “n” lines of a file –“n” is 10 by default –The first parameter can be “-number”, to give that number of lines from the end of the file –Example: you can say “-5” before the name of the file to get the last 5 lines. $ tail -2 file10 This is line 99 This is line 100 $ tail -3 file10 This is line 98 This is line 99 This is line 100

wc Stands for “word count”. By default tells you the number of lines, words, and characters in a file $ wc /etc/passwd /etc/passwd Useful options include “-l” or “-c” or “-w” to see just the number of lines, characters, or words. $ wc –l /etc/passwd 46 /etc/passwd

Redirect to a file If a command normally prints to the screen you can save this output to a file. Simply end the line with “> filename” $ ls -l /etc/hosts -rw-r--r--. 1 root root 187 Jun /etc/hosts $ ls –l /etc/hosts > theoutput $ cat theoutput -rw-r--r--. 1 root root 187 Jun /etc/hosts

Rel/Abs demo /home/caine file1 file2 file4file3 file5 dir1 dir2 1.Create file10 as the concatenation of file1 and file2. $ cd /home/caine $ cat file1 file2 > file10 2.Create file11 as the concatenation of file1, file3 and file5 $ cat file1 dir1/file3 dir2/file5 > file11

Rel/Abs questions /home/caine file1 file2 file4file3 file5 dir1 dir2 1.Concat file2 and file4 into file55 in /home/caine. $ cd /home/caine/dir2 $ cat ????/file2 ????/file4 > ?????/file55 2.Duplicate the contents of file1 3 times and save that new file as file9 in dir2. $ cd $ cat ???????????? > ????

Redirect to another command You can pass the output of one command into the input of the next command in a list of 2 or more commands, all in a single line. Example: what is the first file in /etc $ ls /etc > list $ head -1 list abrt Without the intermediate file “list”: $ ls /etc | head -1 abrt

Pipe passes data left to right $ ls /etc | head -1 abrt acpi adjtime aliases aliases.db alternatives anacrontab asound.conf at.deny at-spi2... abrt

Two pipe example: 5 th file in /etc $ ls /etc | head -5| tail -1 abrt acpi adjtime aliases aliases.db alternatives anacrontab asound.conf at.deny at-spi2... abrt acpi adjtime aliases aliases.db

Putting it together What is line 3 of the concatination of file1 and file2? $ cat file1 file2 | head -3 | tail -1 How many words are on line 7 of /home/caine/mystuff $ head ???? /home/caine/mystuff | ?????? | ????? How many characters are on the third last line of file3? $ cat file3 | ???????????????????????????????????????

User Permissions All modern OSes have a concept of file ownership Each file has an owner. Often each file also has one or more groups to which is belongs to. In Linux, files by default are considered to have 1 owner and 1 group. The “ls -l” command allows you to view this easily.

ls –l $ ls –l file1 -rw-r--r--. 1 caine users 1025 Jun file1 File group: users The user “caine” likely belongs to the group “users” File Owner: caine This file has likely been created by the user “caine”

Permissions A file or directory has various permissions and ownerships applied to it. Three file permissions: –r – read permission –w – write permission –x – execute permission Three permission levels: –u – User (the creator of the object) –g – Group (a group identifier) –o – Other (everyone not in the User or Group specified)

> ls –l /etc/passwd -rw-r--r--. 1 root root 1639 Sep 14 14:38 /etc/passwd Owned by root, with group root bytes in size. Created on Sep 14 th at 14:38. 1 link. rw by user root r by group root r by other

- rwxrwxrwx. OwnerGroupOther Alternative Access methods The first character indicates the type of the object.

File types - means normal file d means directory c means a character device (mouse, keyboard) b means a block device (ide disk, scsi disk) There are more types to discover!

> ls –ld /home drwxr-xr-x. 2 root root 4096 Jul 27 13:38 /home /home is a directory Owned by root in group root. UID root can do anything, group root can rx All others can rx. Size is not really useful for directories.

Demo /home/caine file1 file2 file4file3 file5 dir1 dir2 $ ls -l drwxrwxr-x. 2 caine caine 4096 Jan 30 11:52 dir1 drwxr-x--x. 2 caine caine 4096 Jan 30 11:52 dir2 -rw-r--r--. 1 caine caine 187 Jan 30 11:51 file1 -rw-rw-r--. 1 caine caine 374 Jan 30 11:51 file2 1.What permission do “others” have on file1 ? 2.What permission does group “caine” have on dir2 ? 3.What permission does group “gordon” have on dir1 ?

Demo 2 /home/caine file1 file2 file4file3 file5 dir1 dir2 $ ls -l -rw-r-xrw-. 1 caine users 187 Jan 30 11:51 file3 -r--rw-rwx. 1 gordon caine 374 Jan 30 11:51 file4 1.What permission does user “gordon”, group “users” have on file3 ? 2.What permission does user “gordon”, group “users” have on file4 ? 3.What permission does user “caine”, group “users” have on file4 ? 4.Can user “gordon” delete file4?

chmod This allows the permissions of a file to be controlled. It stands for “CHange the MODe” of a file... Parameter 1 is the change requested. Parameter 2 is the file or directory name being changed The change is one or more of “ugo”, then “+-=“, then zero or more of “rwx”. –“+” adds permissions to the current set. –“-” takes permissions away –“=“ does not care what the current permissions are, and deletes them before setting the permissions to that you have specified.

Demo 1 /home/caine file1 file2 file4file3 file5 dir1 dir2 $ ls -l file3 -rw-r-xrw-. 1 caine users 187 Jan 30 11:51 file3 $ chmod g+w file3 $ ls -l file3 -rw-rwxrw-. 1 caine users 187 Jan 30 11:51 file3 ^

Demo 2 /home/caine file1 file2 file4file3 file5 dir1 dir2 $ ls -l file3 -rw-rwxrw-. 1 caine users 187 Jan 30 11:51 file3 $ chmod ugo-w file3 $ ls -l file3 -r--r-xr--. 1 caine users 187 Jan 30 11:51 file3 ^ ^ ^

Demo 3 /home/caine file1 file2 file4file3 file5 dir1 dir2 $ ls -l file3 -rwxrw-r--. 1 caine users 187 Jan 30 11:51 file3 1.Give the chmod command for giving file3 execute access for others. 2.Give the chmod command for removing write access to group and owner. 3.What chmod command would remove all permissions for group.

Numeric Notation An older way of looking at permissions. Still needed for some commands, and a fast way of changing multiple permissions. Based on octal, 4 digits long. Digit 0 is usually 0, 1 is OWNER, 2 GROUP, 3 OTHER. Values: OctalBinaryPermsOctalBinaryPerms 7111rwx3011-wx 6110rw-2010-w- 5101r-x1001--x 4100r

Example If User rwx, Group rx, Other rx, –Symbolic –rwxr-xr-x –Numeric 0755 If User rwx, Group x, Other none –Symbolic –rwx--x--- –Numeric 0710

Demo 1 /home/caine file1 file2 file4file3 file5 dir1 dir2 $ ls -l file3 -rw-r-xrw-. 1 caine users 187 Jan 30 11:51 file3 $ chmod 676 file3 $ ls -l file3 -rw-rwxrw-. 1 caine users 187 Jan 30 11:51 file3 ^

Demo 2 /home/caine file1 file2 file4file3 file5 dir1 dir2 $ ls -l file3 -rw-rwxrw-. 1 caine users 187 Jan 30 11:51 file3 [ It was previously chmod ugo-w file3 ] $ chmod 454 file3 $ ls -l file3 -r--r-xr--. 1 caine users 187 Jan 30 11:51 file3 ^ ^ ^

Demo 3 /home/caine file1 file2 file4file3 file5 dir1 dir2 $ ls -l file3 -rwxrw-r--. 1 caine users 187 Jan 30 11:51 file3 1.Give the chmod command for giving file3 execute access for others. 2.Give the chmod command for removing write access to group and owner. 3.What chmod command would remove all permissions for group.

Executable scripts Executable scripts are programs which contain commands. These can be executed at the command prompt. To do the module you need to create a number of scripts. –In each case the script will be supplied to you, but you may have to prepare it. If you want to create a file to contain everything from a webpage: –Select what you want and then “cut” –Use putty to ssh or telnet to your machine –If, say, your script is to be called “demo”, go to the right directory and do: $ cat > demo Paste by pressing the right mouse button Once it is all pasted in, press CTRL-D once –Now you need to make the script executable $ chmod ogu+x demo –Now you can run the script $./demo

File Wildcard Expansions When a command takes a filename parameter you can specify the exact name. But sometimes it is more useful to specify a “wildcard” which allows you to specify a range of filenames. For example, you may want to: –Copy all files which end “.doc”. –Delete all files which end “.deleteme” –See how many lines in total are in all the files “evidence01.dat” to “evidence99.dat”. When you use this to describe filenames, it is called filename expansion, or globbing, or filename wildcards. Do not confuse this with regular expressions, which we will cover in a later lecture. They are not interchangable.

Wildcards Parameters which match filenames don’t have to be complete. You can pattern match with the characters “?” for a single character and “*” for a number of characters. $ ls aaa aab abb $ ls aa? aaa aab $ ls a* aaa aab abb

Wildcard [set] You can pattern match with a set of characters. For instance, you want files which end with a or b. $ ls aaa aab aac zzb zzc $ ls aa[ab] aaa aab $ ls *[ab] aaa aab zzb

Example 1 /home/caine file1 file2 file4file3 file5 dir1 dir2 $ cd /home/caine $ ls f* file1 file2 $ ls *i* file1 file2 dir1: file3 file4 dir2: file5

Example 2 /home/caine file1 file2 file4file3 file5 dir1 dir2 The “ls” command always wants to show you the contents of specified directories. This can be annoying. To disable this behaviour use “-d”. $ ls -d *i* dir1dir2file1 file2

Example 3 /home/caine file1 file2 file4file3 file5 dir1 dir2 $ cd /home/caine 1.How many files in the current directory have the number 1 in them? –Hint: the “ls” command senses it is in a pipe, and outputs each file on a seperate line. $ ls ??????? | wc ????? 2 2.In alphanumeric order, what is the second file in /home/caine which ends in the character “2” ? $ ls ???????? | ?????????????? | ?????????????

Assessment: Short-Answer Examples The short answer class test has no past papers yet (as this is a new module for this year). This section contains example questions which are of the same style as you might expect in the actual past paper. Obviously it is likely that the actual questions shown here are not the ACTUAL questions which will appear in the exam! Remember this short answer exam is CLOSED BOOK. You are not permitted to use the internet or access your notes during the exam.

Q1 There are 3 files in the current directory, “myfile1”, “myfile2”, and “myfile3”. Produce a 1 line command which displays the number of characters which can be found in the last 20 lines of the concatenation of all three files in alphanumeric order. Insert answer here:

Q2 How many characters make up the third-last filename shown in a directory listing of the current directory? Your answer should be in the form of a single statement. Insert answer here:

Q3 Produce a filename expansion which finds all the files which start with the name “test” and end with the string “data”, and where the data between “test” and “data” takes the form of a two-digit number (i.e. 01, 55, 99, etc). The expansion should not match any other possible filenames. Insert answer here:

Q4 A file currently has the numeric permissions 753. What would the resulting numeric permissions be if group was set to read and write only and the owner’s permissions had execute removed? Insert answer here:

Q5 Consider the following command: $ ls -l file3 -rw-r-xrw-. 1 caine users 187 Jan 30 11:51 file3 What chmod command, using the symbolic notation, would allow user “gordon” in group “forensics” to run this file as a script? Insert answer here: