Sunday, January 25, 2015

Command Prompt Tutorial

The aim of this tutorial is to get you familiar with the Windows command prompt. It covers basic shit such as ping, Telnet, and sending fake email, and hopefully also goes a bit farther than that, and will be a bit more helpful than only teaching you the complete, absolute, utter, basics. If you have any comments, please contact me. Thanks/shouts to Zugg for giving me the idea to write this.

The Windows command prompt is more useful than most people realize. You can perform many network-related tasks with it, as well as managing files, and the list goes on. For this tutorial, I'll be using Windows XP Pro, but most of the commands should work on earlier versions of Windows as well, although on occasion they won't, and I really can't help that, so don't blame me =). Before we get started, I think it should be noted that the command prompt is not DOS. DOS is short for Disk Operating System, and was a early text-only operating system made by Microsoft, before they had the horrible idea to start building Windows. This isn't a history od DOS tutorial though, so let's get started with the command prompt.

Open up the command prompt by going to start>programs>accessories>command prompt on Windows XP. You should see something like:

C:\Documents and Settings\Name>

This means that you are in the directory C:\Documents and Settings\Name, where name is your username. You might see something else, like just plain C\:>. Whatever it says, that's the directory you're in. You can change directories by using the CD command. First we're going to go to the directory C:>. In the command prompt, two dots, .. , always means the parent directory of the one you are in. So if we type

CD ..

it will Change Directories (CD) to the parent directory of the one we're in. If we're in C:\Documents and Settings\Name, and we type CD .., it will take us to C:\Documents and Settings. Continue to type CD .. until it takes you to your C: drive, and the prompt is now C:>. You don't have to use .. with the CD command though, you can also use it in the following syntax: CD C:\Path\To\Directory So let's say we want to go back to the Documents and Settings\Name directory. We would use the following, replacing 'Name' with your username of course:

C:\>CD C:\Documents and Settings\Name

Note that the > and anything before it, in this case C:\>, is not to be typed. It's simply the prompt that Windows will display. Ok, now let's go back to the C: drive:

C:\Documents and Settings\Name\>CD C:\

Got the hang of it? Good. The DIR command displays all the folders and files in the currect directory that you're in. So to display all of the contents of the C: drive (assuming you're keeping up with me and are at C:\), we use the following command:

C:\>DIR

We can also view the contents of other directories without going to those directories, by using the syntax DIR C:\Directory\. If we're still in the C:\ drive, and want to view the contents of C:\Documents and Settings\Name (as always replace Name with your username), we would use the following command:

C:\>DIR C:\Documents and Settings\Name

If you've ever used any form of Unix before, you'll probably have note that the DIR command is the same as he LS command in Unix, and that CD is identical to the CD command in Unix. So far we've only worked on browsing around and viewing the contents of directories, but to be honest this is useless shit, because browsing around directories gets boring pretty damn fast, and there's not much you can do. While you've been browsing around, you've probably noticed how much useless crap you have wasting space on your hard drive, so guess what? We're going to learn how to delete that useless crap. To delete folders, use the RD (remove directory) command, and to delete just a regular file use the DEL (delete) command. If we want to delete the folder C:\Documents and Settings\Name\Useless_stuff, we first navigate to C:\Documents and Settings\Name, and then delete the directory useless_stuff:

C:\>CD C:\Documents and Settings\Name\
C:\Documents and Settings\Name\>RD useless_stuff

Similarly, to delete a file, not a folder called useless_stuff, we'll call it useless_stuff.txt here, do the same thing except with the DEL command:

C:\>CD C:\Documents and Settings\Name\
C:\Documents and Settings\Name\>DEL useless_stuff

All gone. Now suppose you want to create a new folder. You use the MD command to create folders. To re-create the useless_stuff directory, use the following command:

C:\Documents nad Settings\Name\>MD useless_stuff

Files can be copied using (surprise, surprise) the COPY command. To use the COPY command, you specify a source to be copied from, and a destination to be copied to. If the source or destination is in the directory you are in, you don't need to specify the full path name. If it isn't in the directory you're in, you do need to specify the full pathname. If we want to copy our useless_stuff directory to C:\useless_stuff, we use the following command:

C:\Documents and Settings\Name\>COPY useless_stuff C:\useless_stuff

If you don't feel like having two copies of the same file, you can simply move the file using the MOVE command. The MOVE command works the same way the COPY command does, except it moves the folder/file as opposed to making another copy of it in a new directory:

C:\Documents and Settings\Name\>MOVE useless_stuff C:\useless_stuff

Enough with working with files, let's move on. Although you may see the command prompt as a blob of black ugliness, you can customize the command prompt and make it look quite nice. First of all, after all these commands, it might seem kind of crowded, so let's clear it using the CLS command. To do this, simply type CLS at the prompt, and it clears all text and gives you a new prompt. We can also change the backround and the text color of the prompt, with the COLOR command. The COLOR command uses the following syntax, where 'b' is background and 't' is text:

COLOR bt

Note that there is no space between the b and t. Each color has a hexadecimal value:

0 black
1 blue
2 green
3 aqua
4 red
5 purple
6 yellow
7 white
8 grey
9 light blue
A light green
B light aqua
C light red
D light purple
E light yellow
F bright white

So if we want bright white text on a blue backround, we use the following command:

C:\>COLOR 1F

To simply change it back to the default colors, type the COLOR command by itself with no arguments. Before we move on, it's worth looking at one more completely useless command, the ECHO command. The ECHO command is used mostly for batch files, but can also be used simply at the command prompt. It displays the text that you want (see what I mean by useless? =p). Try typing "ECHO Binary Universe 0wnz j00" (without the quotes) at the command prompt and see what happens.

You can also defragment your hard drive using the command prompt, via the DEFRAG command. To defrag your C:\ drive, simply type "DEFRAG C:\" (without the quotes). If you want to defrag another drive, replace the C:\ with that drive letter. For a full list of options that can be used with the DEFRAG command, simply type DEFRAG by itself in the command prompt. If you'd rather format a disk than defrag it, you can use the FORMAT command, with "/FS:file system" to represent the desired file system. To format your C:\ drive with NTFS, use the following command:

C:\>FORMAT C: /FS:NTFS

Before we move on to network-related commands, there is one more basic command worth discussing: the PERFMON command. The PERFMON command moniters the performance of your system, eg the CPU usage, etc. Simply type "PERFMON" (without that quotes) at the prompt, and in Windows XP a window with a graph will pop up.

Now we move on to network and internet related commands. This is an area where the semingly simple command prompt is very flexible and powerful, and in which it is the swiss-army knife of Windows -- the command prompt can be used for FTP, sending fake email, Telnet, and much more. The most basic command is PING. The PING command is used to see if a remote host can be reached. To use the PING command, you type "PING IP_address" (without the quotes), where IP_address is the IP address of the remote host. So to ping 127.0.0.1:

C:\>PING 127.0.0.1

If you get a response similar to this, all is well and you can reach the host:
---------------------------------------------
Pinging 127.0.0.1 with 32 bytes of data:

Reply from 127.0.0.1: bytes=32 time<1ms ttl="128</span">
Reply from 127.0.0.1: bytes=32 time<1ms ttl="128</span">
Reply from 127.0.0.1: bytes=32 time<1ms ttl="128</span">
Reply from 127.0.0.1: bytes=32 time<1ms ttl="128</span">
---------------------------------------------

However, if you get a reply like "request timed out", then you can't reach the host. Possible reasons for not being able to reach the host are possibly the host is offline, you mistyped the IP address/domain name, or you are not connected to the internet.

As mentioned before, we can also use the command prompt as a telnet client. To use the command prompt as a telnet client, you simply type "TELNET IP_address" (without the quotes of course), replacing IP_address with the IP address of the host you wish to telnet to. You can also specify a port to telnet to, with the syntax "TELNET IP_address PORT", which can on occasion be quite useful.

The command prompt, being the swiss army knife of Windows, can also be used as an FTP client. To FTP to a host, use the command "FTP IP_address", without the quotes and replacing IP_address with the IP address of the remote host. You will then most likely be prompted for a user name and password, and if authentication is successful you will get the following prompt:

ftp>

At this prompt you can type FTP commands. The most common reason for using FTP is to transfer files (File TRANSFER Protocol), so we'll start with the commands for uploading files to the server and downloading files from the server. To upload a file to the server, use the PUT command. The PUT command uploads a file from a specified path on your box to the directory you are currently in of the server, thus the following command uploads the file C:\file.txt to file.txt in whatever directory you are currently in of the remote machine:

ftp>PUT C:\file.txt

To change directories, you use the CD command, just as you did in the Windows command prompt earlier in this tutorial. You can download files the same way you uploaded them, except using the GET command, thus the following command copies the file something.gif in the current directory of the remote machine to the current directory of the local mahine:

ftp>GET something.gif

Most other FTP commands are used the same way the equivilant commands are used in the command prompt. For example, the FTP command LS is the same as the command DIR in the Windows command prompt, and displays the contents of the current directory. Likewise, the FTP command MKDIR is used the same way as the Windows command prompt command MD, and the command DELETE is used to delete a file. For a full list of available commands, type 'HELP' (without the quotes) after you have connected and logged in.

Another interesting thing that can be done via the command prompt is sending fake email via an SMTP server. SMTP is short for Simple Mail Transfer Protocol, and is used for sending email. Just about any SMTP server is an SMTP server that can be used to send fake email. The exception is that some ISP SMTP servers may require the host using the server to be connecting from an account on that ISP. It's not hard to find an SMTP server to try this out on. You can just pick a random website and try this on their SMTP server if they have one. Step one is to connect to the SMTP server by telnetting to the server's IP and specifying that the connection should be made to port 25 on the server, as SMTP runs on port 25. So type "TELNET site.com 25" (replace site.com with the IP address or domain name of your target). If the target isn't running an SMTP server, it'll say something like "Connection failed". If they are running an SMTP server, it'll give you information aboout what SMTP server they're running. To make sure that you've connected, type help, and it'll say something like "214 - commands supported" and give you the supported commands.

Before you start sending your fake email, be a good boy and say hello, by typing "HELO". You'll probably get a response like "250 site.com hello IP_address". Now let's send that fake email. Begin with the MAIL FROM command. This declares what address you want the email to be sent from. So to send the email from niels@site.com, you'd use the following command:

MAIL FROM:niels@site.com

Now you'll probably get a message like "250 OK". The next step is to specify the recipient of the message, using the RCPT TO command:

RCPT TO:address_to_be_mailed_to@anothersite.com

Finally, you include the data of the mess with the DATA command. End your message by putting a period on a line by itself. So altogether, you probably type this:
----------------------------------------
C:\>TELNET site.com 25

No comments:

Post a Comment