Linux Basics for Hacking and Hackers Latest Technics 2

May 21, 2019

This is the second part of my series about the basic Linux skills that every hacker needs to know. Although some hacking tools are available for Windows and Mac, but every real hacker uses Linux for good reasons.

In this section, we will examine how to manage files and directories in Linux, that is, copy, rename, move, and view. Then we will look a bit at the network and command ifconfig.

Step 1: Copy Files (cp)

In the previous section, we created a 1file file in the / usr / share / wireshark directory.

Let’s imagine that we need a copy of this file in the home directory and the root user directory. We can do this:

cp 1file / root
MarkupCopy

We cp simply copy the 1file file from our current directory to the root user directory (do not get this directory with directory / error). If the 1file file is in our current directory, we do not need to specify the path of the directory where it is located.

The copy command creates a copy of the file and places it in the specified directory, and the original file is intact and remains unchanged so we now have two copies of the original file.

You can see the above image when we change the cd directory to the root user and list the files (ls), a copy of the 1file file will appear in that directory.

What if we want to copy a file from a directory that is not in our current directory? In this case, we need to specify the path to that directory, such as:

cp / etc / file / root
MarkupCopy

Also note that we do not need to specify the file name to copy. This command simply creates a master copy of the “1file” file.

Step 2: Move files (mv)

Unfortunately, Linux does not have a rename command to rename files. So most users use the move (mv) command to transfer files and rename them. Now imagine that we put 1file in the wrong directory and we really wanted it in the root directory (/).

We can use the mv command to do this.

mv / root / 1file /

This command tells you to transfer 1file from the root user directory to the root directory (/). Note that 1file is moved to the root directory.

Sometimes we just want to change the filename and do not actually transfer it to another location. The mv command can be used.

We simply tell Linux to transfer the original file to a new file in the new file. For example, we put 1file in the wireshark directory.

Now we want to rename this file to “sniff”. We can easily type:

mv 1file sniff

Note here that I did not use the directory path because the file was moved to my current directory. If we list the directory, we can see that 1file has gone and now there is sniff.

Step 3: View files (Cat, More, Less).

Using the command line in the terminal, we can view the contents of the files using the cat command.

Now in the / usr / share / wireshark directory. Let’s see some files with the cat. First, let’s get a list of files in this directory.

Note in the directory list there is a file called manuf. Let’s take a look at the contents of this file.

cat manuf

When you run this command, you will see the entire text across the screen. When the command is complete, we can move the terminal scroll using the scroll key to read the whole text. There is another way, which may be simpler.

There are two other commands that work like a cat, but do not easily run the text across the page until you finish the file.

These are two more and less. They are very similar, each showing only one page of information on your screen until you scroll it down.

 Let’s try again.

more manuf

As you can see, when I use more with the filename you use, it shows the file until the screen is full and waiting for more instructions from me.

If I enter, a scroll will be scrolled down, while if I move space, it moves to a next page.

Now let’s try less (in some Linux circles, “less is less -less is more”, which means that it has less power than the more).

less manuf

As you can see, when I use less with the filename you use, it displays the manfu file again. Perhaps the most important feature is the ability to search the text that it lacks more.

I can search the text for my case in this file. By typing Slash forward / with the name of the thing I’m looking for. One of my main reasons is that I prefer less.

Press Q to exit the command, or press ctrl + z whenever you want.

Step 4: Network (ifconfig)

Before I finish this tutorial, I would like to show you one of the simple commands for the network ifconfig.

As you know, using the ipconfig command in Windows, we can see the key configuration information for your network. Ifconfig in Linux looks a lot like that, just a different letter.

Let’s see ifconfig what tells us.

ifconfig

As you can see, there are a lot of key information I need to know about the configuration of your network system, including IP address, netmask, broadcast address, interfaces, MAC address, and so on. In the future, we will spend more time on Linux in Linux.

As a hacker, there is no substitute for Linux skills. Linux beginners often find it difficult to find files and programs, especially with regard to the Linux directory structure that is completely different from the Mac or Windows operating system. So I assign this tutorial to find files on Linux.

Step 1: Find the files in the directory (Find)

The first command I want to show is the find command. This command checks the directories looking for the file.

By default, this command is a recursive, which means that it checks the file in all subcategories and displays a list of places where the file exists.

For example, if we are looking for aircrack-ng, we can type:

find -name aircrack-ng

جستجو فایل ها در لینوکس

Notice that we should say to Linux that we want to search by file name after the -name switch.

Then shows the full path where aircrack-ng is found. We can specify more and ask Linux to find aircrack-ng in the / usr / bin directory. By typing this command:

find / usr / bin-name aircrack-ng

جستجو فایل‌ها در لینوکس

This command says: Look at the / usr / bin directory and all its subfolders and tell me what you find aircrack-ng.

Step 2: Find binaries in variable or local paths (Which)

The next search command I want to show is the Which statement. This command enables us to search for binaries that are in our variable path.

Binary files are equivalent to executable files in Windows. These are files that have something like echo, ls, cd, mv, and so on. Our variable path is a variable that holds the directory path in our binaries.

Usually our binaries are in the / bin directory (bin stands for binaries) or directories / sbin are reflected in our variable path. With echo, we can check our variable path settings. By typing this command:

echo $ PATH
MarkupCopy

Linux responds to the amount in our variable path. These are places that search for binaries. So when we type:

which ls

Returns the path to the binary. If we use the following command to search aircrack-ng:

which aircrack-ng

We see that Linux returns / usr / bin / aircrack-ng. If aircrack-ng was not in our directory, this command could not help us.

Step 3: Find any file in any directory (whereis)

Unlike that, the whereis command for binary searches is not limited to our path. This command identifies the files in each directory, and in addition identifies the files as help pages or man pages. So when we type:

whereis aircrack-ng

We can see whereis returns the path of the aircrack-ng locations that contain the help pages.

Step 4: Finding Files Using the Database (Locate)

The locate command can also be used to find files, which is usually much faster than where and where.
Because locate uses a database containing all the files, the search is performed faster.

The locate problem is that it does not find new files, because the database is usually updated only daily.

locate aircrack-ng