HHS En2 Essential Commands.v2

download HHS En2 Essential Commands.v2

of 25

Transcript of HHS En2 Essential Commands.v2

  • 8/11/2019 HHS En2 Essential Commands.v2

    1/25

    LESSON 2

    ESSENTIAL COMMANDS

  • 8/11/2019 HHS En2 Essential Commands.v2

    2/25

    WARNING

    The Hacker Highschool Project is a learning tool and as with any learning tool there are

    dangers. Some lessons, if abused, may result in physical injury. Some additional dangersmay also exist where there is not enough research on possible effects of emanations fromparticular technologies. Students using these lessons should be supervised yet encouragedto learn, try, and do. However S!"#$ cannot accept responsibility for how anyinformation herein is abused.

    The following lessons and workbooks are open and publicly available under the followingterms and conditions of S!"#$%

    &ll works in the Hacker Highschool Project are provided for non'commercial use withelementary school students, junior high school students, and high school students whetherin a public institution, private institution, or a part of home'schooling. These materials maynot be reproduced for sale in any form. The provision of any class, course, training, orcamp with these materials for which a fee is charged is expressly forbidden without alicense, including college classes, university classes, trade'school classes, summer orcomputer camps, and similar. To purchase a license, visit the ("!)S! section of the HHSweb page at http%**www.hackerhighschool.org*licensing.html.

    The Hacker Highschool Project Project is an open community effort and if you find value inthis project, we ask that you support us through the purchase of a license, a donation, orsponsorship.

    2

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    3/25

    Table of Contentsntroduction and #bjectives....................................................................................................................+e-uirements and Setup..........................................................................................................................

    e-uirements.........................................................................................................................................Setup.......................................................................................................................................................#perating System% /indows ...................................................................................................................0

    How to open a "( window.................................................................................................................0"ommands and Tools 1/indows*2#S3..............................................................................................0

    "ommands......................................................................................................................................4Tools...................................................................................................................................................5

    6ame #n% Taking "ommand...........................................................................................................78#perating System% (inux.........................................................................................................................79

    :eed ;our Head% "onsole, Terminal or Shell...........................................................................................................................74

    How to open a Terminal window......................................................................................................74"ommands and Tools 1#S>3..............................................................................................................75

    "ommands....................................................................................................................................75Tools.................................................................................................................................................87

    ?asic "ommand !-uivalences for /indows, #S> and (inux...........................................................8=

    3

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    4/25

    Contribtors

    Pete Her@og, S!"#$

    6lenn )orman, S!"#$

    $arta ?arcelA, S!"#$

    ?ob $onroe, S!"#$

    $arco valdi, S!"#$

    6reg Playle, S!"#$

    Simone #nofri, S!"#$

    Bim Truett, S!"#$

    Caume &bella, S!"#$

    Tom Thomas, S!"#$

    Cairo HernDnde@

    &neesh 2ogra

    !

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    5/25

    Introd"tion and Ob#e"ti$es

    /hether you imagine Hugh Cackman in the movie Swordfishor think of Trinity hacking into

    a E)> system in The Matrix Reloaded, when you picture a hacker theyFre working at thecommand line. :or good reason.

    ;ou can do very big, very powerful things in the command line interface 1 CLI3. ;oudonFt have to be a master at the command line but you should be comfortableworking with it.

    #nce youFve mastered the basics of the "(, you can start using these commands in textfiles 1called s"ri%ts3G itFs the easiest programming ever.

    /e will discuss commands and basic tools for /indows, #S> and (inux operating systems.;ouFll need to know them for exercises in the following lessons. &t the end of this lesson,you should be familiar with%

    6eneral /indows, (inux and #S> commands

    ?asic network commands and tools, including

    ping

    tracert/traceroute

    netstat

    ipconfig/ifconfig

    route

    &

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    6/25

    Re'irements and Set%

    Re'irements

    To complete this lesson you will need%

    & P" running /indows

    & P" running (inux

    #ptionally a $ac running #S>

    &ccess to the nternet

    Set%

    (i)re 2*+:6eneral )etwork Setup

    This is the network in which weFll do most of our work. t consists of your P", the nternet, andthe S!"#$ Hacker Highschool test network, which you will access through the nternet.

    )ote that access to the S!"#$ test network is restricted. n order to gain access to it, yourinstructor must contact the system administrator, as detailed on thehttp%**www.hackerhighschool.org web site.

    However, you can also substitute any test network for these exercises. NE,ERrun tests againstcomputers you donFt own That may be a criminal offense, and can be dangerous in lots ofother ways.

    f you want to set up your own test network, it can be as easy as testing another computer inyour classroom or home. )o special set'up is needed #f course if you want something morerobust or something that lets you experience the challenges and flaws of accessing anothercomputer over the nternet, then youFll need an nternet'based test network. This can also bedone by making alliances with other schools or homes and letting them access certaincomputers of yours remotely and you access theirs. ?ut make sure you know what youFredoing in setting it up because what you donFt want is for those open computers to gethijacked by some random person on the nternet who does damage for which you will beresponsible.

    -

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    7/25

    O%eratin) S.stem: Windo/s

    n the days of yore, if we werenFt working in E)>, we all worked in 2#S. /e didnFt need to

    open a "(G we lived in one. Then E)> developed IwindowJ interfaces, an idea thateventually came to the P" with $icrosoft /indows.

    #nce /indows arrived, we opened 2#S in a window on our desktop and called that a"ommand %rom%t. (ong after /indows had moved beyond being 2#S'based, /indowsstill has a "( K and many people still call it a DOS bo0. tFs not really 2#S any more, but forour purposes, it doesnFt matter. HereFs how you open one.

    1o/ to o%en a CLI /indo/

    The procedure is similar for all versions of /indows.

    +* "lick the ST&T button.

    2* "hoose the E) option 1skip this in Lista and later3.

    3* Type "ommandif you are using /indows 5+*54 or "mdfor all other versions of/indows and press !nter or click #B.

    !* & window similar to the following will appear%

    &* )ow you can use the commands and tools listed below.

    Commands and Tools Windo/sDOS4

    "ommands provide built'in operating system functions. Tools do more% they probenetworks, search for 5osts1which is, by the way, what we call computers attached to a

    network3, and let you see or set your hostFs routing information.

    6

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    8/25

    Commands

    /ords in italics are options that you must enter.Some commands have both long and short versions.

    Command 7r%ose

    date 2isplay or set the date

    time 2isplay or set the time

    ver 2isplay the $S'2#S or /indows version

    dir 2isplay the list of subdirectories and files in a directory.

    cls "lear the screen.

    mkdir directoryor

    md directory

    $ake a directory with the name directory%

    md tools

    chdir directoryor

    cd directory

    "hange the current directory to another directory%

    cd tools

    rmdir directoryor

    rd directory

    2elete the directory%

    rd tools

    tree directory2isplay the structure of folders and files in text'graphic format%

    tree c:\tools

    chkdsk"heck a disk and show a status report.

    memShow the amount of memory used and free in the system.

    rename sourcedest

    or

    ren source dest

    "hange the name of files%

    ren pictures MyPics

    copy source dest"opy one or more files to another location%

    copy c:\tools\myfile.txt c:\tmp\

    move source dest$ove files and change the name of files and directories%

    move c:\tools c:\tmp

    typefile2isplay the content of one or more text files%

    type c:\tools\myfile.txt

    more file2isplay the information screen by screen%

    more c:\tools\myfile.txt

    delete fileor

    del file

    2elete one or more files%

    del c:\tools\myfile.txt

    8

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    9/25

    Tools

    /ords in italics are options that you must enter.

    Tool 7r%ose

    ping host Lerify contact with the machine host.

    This command sends "$P 1nternet "ontrol $essage Protocol3 pingpackets to another computer to see how long it takes to respond, or if itresponds at all. ;ou can use a hostname or an P address%

    ping hackerhighschool.org

    ping 216.92.116.13

    #ptions include%

    ping -n 100 hackerhighschool.org

    which sends 7MM ping packets, and

    ping -t 216.92.116.13

    which pings the host until stopped with "T(N".

    To see more options%

    ping /h

    tracert host Show the route that packets follow to reach the machine host.

    The 2#S tra"ert command is an adaptation of the E)> tra"erote*12#S commands could only be eight characters long, back in the day.3?oth allow you to find the route that a packet follows from your host tothe destination host, tracert also tracks how long each hop takes and

    travels, at the most, 9M hops. #ften you can see the hostnames of themachines through which the packets travel%

    tracert hackerhighschool.org

    tracert 216.92.116.13

    Some options are%

    tracert -n 25 hackerhighschool.org

    to specify ), at the most, jumps, and

    tracert -d 216.92.116.13

    to hide hostnames.

    To see more options%

    tracert /?

    9

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    10/25

    Tool 7r%ose

    ipconfig Esed alone, displays information on your hostFs active network interfaces1ethernet, ppp, etc.3. t is similar to (inux if"onfi).

    Some options are%

    ipconfig /all

    to show more details

    ipconfig /renew

    to renew the network connection when automatic configuration with2H"P is used, and

    ipconfig /release

    to deactivate networking when 2H"P is used.

    $ore options%

    ipconfig /?

    route print 2isplays the routing table. rotecan also be used to set up or erasestatic routes.

    Some options%

    route print

    to show the list of routes,

    route delete

    to delete a route, and

    route add

    to add a route.

    $ore options%

    route/?

    +

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    11/25

    Tool 7r%ose

    netstat 2isplays information on the status of the network and establishedconnections with remote machines.

    Some options%

    netstat -a

    to check all the connections and listening ports,

    netstat -n

    to display addresses and port numbers in numeric form, and

    netstat -e

    to sample !thernet statistics.

    #ptions can be used together%

    netstat -an

    To see more options%

    netstat/?

    :or additional information on these commands and tools try these options%

    command/h

    command/?

    help command

    from a "( window.

    :or example, for additional information on the tool netstat, you have three possibilities%

    netstat /h

    netstat /?

    help netstat

    E0er"ises

    8.7 #pen a "( window.

    8.8 dentify the version of 2#S or /indows that you are using.

    8.9 dentify the date and time of the system. f they are incorrect, correct them.

    8.= dentify all the directories and files that are in c%O.

    8.+ "reate the directory c%OhhsOlesson8. "opy to this directory the files with theextension .sys that are in c%O. /hat files have you found> file edirect the normal screen output of commandto file. f the filealready exists, it a%%endsthe output to the end of the file.

    !xample%

    ls '' listing.t#t

    man command Show the pages of the online manual about command%

    !an ls

    :or additional information on these commands and tools try these options%

    command -h

    command --help

    !an command

    help command

    info command

    :or example, for additional information on the lscommand, type in either of these twopossibilities%

    ls (-help

    !an ls

    +-

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    17/25

    Tools

    /ords in italics are options that you must enter.

    Tool 7r%ose

    ping host Lerify the contact with the machine host%

    ping www.google.co!

    traceroute host Show the route that the packets follow to reach the machine host%

    tracert www.google.co!

    ifconfig 2isplay information on active network interfaces 1ethernet, ppp,etc.3.

    route 2isplay the routing table.

    netstat 2isplay information on your network connections.

    netstat -an

    E0er"ises

    8.4 dentify the owner of the file %ass/d. 1)ote% first locate where this file is.3

    8.5 "reate the directory /or;in your own home directory 1for example, if your login is fred,create the directory in *home*fred3, and copy the file passwd to the directory workthat you just created. dentify the owner of the passwd copy.

    8.7M "reate the directory *5ide in the work directory 1notice that the file name begins witha dot3. (ist the contents of this directory. /hat did you have to do to see the contentsof directory .hide this

    application is called Terminal.

    #S> is based on )et?S2 and :ree?S2 E)>, ancestors of (inux. ts 6E and "( approach issimilar to (inux% you can do everything you could possibly do in any 6E tool, plus vastlymore.

    1o/ to o%en a Terminal /indo/

    +* "lick on the S%otli)5ticon, an icon of a magnifying glass typically located on the topright of your screen, and search for Terminal.

    2* Then press !nter or click on it. ;ou will see the Terminal window.

    Typically Terminal is located under A%%li"ations Btilities. mpress your friends by changingthe Terminal style depending on your preferences. Press both the "ommand and commakeys to get the Preference dialog for Terminal and choose your preferred colors. Esuallythis keyboard shortcut gives you access to program preferences in #S>.

    +8

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    19/25

    Commands and Tools OS@4

    $ac ships with a bash shell, so almost all typical (inux commands work on #S> as well.

    Commands

    /ords in italics are options that you must enter.

    Command 7r%ose

    date2isplay or set the date.

    time command2isplay how long it takes for commandto execute.

    fsck"heck a file system and show a status report. f you use an #S>

    journaled volume such as $ac #S> 7M.9 or later, in which

    journaling is enabled by default, you probably wonFt need to runthis command.

    catfile2isplay the content of one or more text files%

    cat /etc/passwd

    pwd 2isplay the name of the current directory.

    hostname 2isplay the name of the computer you are currently using.

    finger user 2isplay information on a user%

    finger root

    ls (ist the contents of the current directory%

    ls -la

    (ist the contents of another directory%

    ls -la /etc

    cd directory "hange from current directory to directory. f no directory nameis specified it changes to the userFs home directory.

    :or the login name IfredJ the command

    cd

    changes the directory to *Esers*fred, and

    cd -

    changes to the last visited directory 1think of IsubtractingJ onedirectory3, and

    cd /t!p

    changes to the *tmp directory.

    cp source dest "opy the filesourceto the file dest.

    cp /etc/passwd /t!p/"unnies

    rm file 2elete files. #nly users with proper access permissions 1or root3can delete certain files.

    r! letter.t#t

    +9

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    20/25

    Command 7r%ose

    mv source dest $ove or rename files and directories.

    !$ secrets.%ip innocent.%ip

    mkdir directory $ake a directory with the name directory.

    !kdir tools

    rmdir directory 2elete the directory with the name directory but only if it isempty%

    r!dir tools

    ?onus -uestion% how do you delete a directory with files in it file Redire"tthe normal screen output of commandto file%

    ls ' listing.t#t

    f this file already exist, it will get "lobbered, meaningoverwritten

    command >> file edirect the normal screen output of commandto file. f the filealready exists, it a%%endsthe output to the end of the file.

    !xample%

    ls '' listing.t#t

    man command Show the pages of the online manual about command%

    !an ls

    :or additional information on these commands and tools try these options%

    command -h

    command --help

    !an command

    help command

    info command

    :or example, for additional information on the lscommand, type in either of these twopossibilities%

    ls (-help

    !an ls

    2

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    21/25

    Tools

    /ords in italics are options that you must enter.

    Tool 7r%ose

    ping host Lerify contact with the machine host.

    This command sends ping packets using "$P 1nternet "ontrol$essage Protocol3 to another computer to see how long it takes torespond, or if it responds at all. ;ou can use a hostname or an Paddress%

    ping www.hackerhighschool.org

    ping 216.92.116.13

    #ptions include%

    ping -c 100 www.hackerhighschool.org

    which sends 7MM ping packets, and

    ping -t 216.92.116.13

    which pings the host until stopped with "T(N".

    $ore options%

    !an ping

    traceroutehost

    Show the route that packets follow to reach the machine host.

    tra"erote has the same scope as /indows tra"ertbut uses differentnetwork protocols% traceroute uses E2P 1Eser 2atagram Protocol3 andtracert uses "$P 1nternet "ontrol $essage Protocol3. ;ou may obtain

    different results using tracert and traceroute from same network sourceand destination.

    ?oth allow you to find the route that a packet follows from your host tothe destination host. !ach also tracks how long each hop takes andtravels for, at the most, 9M hops. #ften you can see the hostnames ofthe machines through which the packets travel%

    traceroute www.hackerhighschool.org

    traceroute 216.92.116.13

    To specify the maximum 1'm3 number of hops%

    traceroute -! 25 www.hackerhighschool.org

    To save 2)S lookups by showing the P address rather than a hostname%

    traceroute -n 216.92.116.13

    To see more options%

    !an traceroute

    2+

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    22/25

    Tool 7r%ose

    ifconfig Esed alone, displays information on your hostFs active network interfaces1ethernet, ppp, etc.3. t is similar to /indows i%"onfi).

    To show more details, meaning to be $erbose%

    ifconfig -$

    To show only the en1 network interface information%

    ipconfig en1

    To deactivate the network interface%

    ifconfig en1 down

    To bring it up%

    ifconfig en1 up

    )ote% you must have permission to use this command, so you may needto put sdoin front of these commands. Then you will have to enter yourpassword. Bse sdo "arefll.

    sudo ifconfig en1 up

    $ore options%

    !an ifconfig

    netstat 2isplays information on the status of the network and establishedconnections with remote machines. #n ?S2'like systems, netstat is alsoused to see your routing table.

    To sample all the connections and listening ports%

    netstat -a

    To display the routing table%

    netstat -r

    Esed with 'n to show addresses numerically%

    netstat -nr

    To show information for en1network interface.

    netstat -r -ii en1

    To see more options%

    !an netstat

    22

    Lesson 2: Essential Commands

  • 8/11/2019 HHS En2 Essential Commands.v2

    23/25

    E0er"ises

    8.78 dentify the name and the P address of your machine.

    8.79 Trace the route to www.hackerhighschool.org. dentify P addresses of theintermediate routers and find your path.

    8.7= n /indows use tra"ertto see the path between you and www.hackerhighscool.org assee by /indows, and send the output on a file named ot%t*t0tfor further analysis.

    8.7+ Then run the e-uivalent traceroute command on #S> and (inux from the samenetwork, putting the output in files named ot%t2OS@*t0tand ot%t2Lin0*t0t. (ook atthe output files carefully.

    +* &re the paths the same or are there differences