<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Mohammadaassif on Medium]]></title>
        <description><![CDATA[Stories by Mohammadaassif on Medium]]></description>
        <link>https://medium.com/@mohammadaassif?source=rss-29926d996499------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*k87aMKdKM4p-IPgvw526lw.jpeg</url>
            <title>Stories by Mohammadaassif on Medium</title>
            <link>https://medium.com/@mohammadaassif?source=rss-29926d996499------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 11:20:30 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@mohammadaassif/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Efficient Coding with Bash Scripts: An In-Depth way to Learn Tutorial]]></title>
            <link>https://mohammadaassif.medium.com/efficient-coding-with-bash-scripts-an-in-depth-way-to-learn-tutorial-a6e8dcf615f9?source=rss-29926d996499------2</link>
            <guid isPermaLink="false">https://medium.com/p/a6e8dcf615f9</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[tools]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[bash-script]]></category>
            <dc:creator><![CDATA[Mohammadaassif]]></dc:creator>
            <pubDate>Sun, 03 Mar 2024 13:15:32 GMT</pubDate>
            <atom:updated>2024-03-03T13:15:32.398Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*ZEakWo1wgg_BnzQk.png" /></figure><h3>What is Bash Scripting?</h3><p>Bash scripting is a way to automate tasks on a Unix or Linux system using the Bash shell, which is a command-line interface that allows users to interact with the operating system by executing commands.</p><p>A Bash script is a series of commands that are stored in a file and can be executed as a program. Bash scripts can be used to automate repetitive tasks, such as running backups, system maintenance, or deploying applications.</p><p>Bash scripts can contain a combination of commands, control structures (such as loops and conditionals), and variables, which allow users to create more complex and flexible scripts. Bash scripts can also accept command-line arguments, allowing users to customize their behavior.</p><p>Bash is one of the most widely used shells on Unix and Linux systems, so learning Bash scripting can be useful for system administrators, developers, and anyone who needs to automate tasks on these systems.</p><h3>Frist Bash Script</h3><p>here’s an example of a simple Bash script that prints “Hello, world!” to the terminal:</p><pre>#!/bin/bash<br>echo &quot;Hello, world!&quot;</pre><p>Here’s how it works:</p><ol><li>The first line #!/bin/bash is called a shebang and tells the system that this file should be executed using the Bash shell.</li><li>The second line uses the echo command to print &quot;Hello, world!&quot; to the terminal.</li></ol><p>To run this script, you can save it to a file (e.g. hello.sh), make it executable with the chmod command (chmod +x hello.sh), and then run it using ./hello.sh. This should output &quot;Hello, world!&quot; to the terminal.</p><p>Note that in order to run this script, you need to have Bash installed on your system. Most Unix and Linux systems come with Bash pre-installed, but if you’re using a different operating system, you may need to install it first.</p><h3>Variable</h3><p>In Bash scripting, a variable is a named value that can be assigned a value, and that value can be referenced and manipulated throughout the script. Bash variables can be used to store data, perform calculations, and pass information between commands and functions.</p><p>In Bash, variables are typically defined using the syntax name=value, where name is the name of the variable and value is the value that it should be assigned. For example:</p><pre>myvar=&quot;Hello, world!&quot;</pre><p>This creates a variable called myvar and assigns it the value &quot;Hello, world!&quot;. To reference the value of a variable, you can simply use the $ symbol followed by the name of the variable. For example:</p><pre>echo $myvar</pre><p>This will output the value of the myvar variable to the terminal.</p><p>In Bash, variables can also be used in more complex expressions and operations. For example, you can perform arithmetic operations on variables like this:</p><pre>x=5<br>y=10<br>z=$((x + y))</pre><p>This creates two variables, x and y, with the values 5 and 10, and then creates a third variable, z, that stores the result of the addition of x and y.</p><p>Bash variables can also be passed as arguments to functions and scripts, allowing data to be shared and manipulated across different parts of the script.</p><p>It’s important to note that Bash variable names are case-sensitive and can include letters, numbers, and underscores, but cannot begin with a number. It’s also a good practice to use descriptive names for your variables to make your code easier to read and understand.</p><h3>Command Line Arguments</h3><p>Command line arguments are a way to pass input values to a Bash script when it is executed. These arguments are passed as strings and can be used by the script to modify its behavior or perform different actions based on the input.</p><p>In Bash, command line arguments are accessed using special variables called positional parameters. The first argument is referred to as $1, the second as $2, and so on. The $0 variable contains the name of the script itself.</p><p>Here’s an example of a Bash script that uses command-line arguments:</p><pre>#!/bin/bash</pre><pre>echo &quot;Hello, $1!&quot;</pre><p>In this script, the $1 variable is used to print a personalized greeting to the user. If the script is executed with the command ./hello.sh John, it will output &quot;Hello, John!&quot; to the terminal.</p><p>Bash scripts can also use other variables and expressions in combination with command line arguments to perform more complex operations. For example, you might use a for loop to process multiple command line arguments:</p><pre>#!/bin/bash</pre><pre>for arg in &quot;$@&quot;<br>do<br>    echo &quot;Processing argument: $arg&quot;<br>done</pre><p>In this script, the $@ variable is used to iterate over all of the command line arguments and print a message for each one. If the script is executed with the command ./process.sh apple orange banana, it will output:</p><pre>Processing argument: apple<br>Processing argument: orange<br>Processing argument: banana</pre><p>Using command line arguments in Bash scripts can make your code more flexible and customizable, allowing users to provide input data and modify the behavior of your scripts.</p><h3>System Variable</h3><p>In Bash scripting, there are several system variables that are predefined and can be used to access information about the current environment, user, and system. These system variables can be very useful in writing Bash scripts that automate tasks and perform system administration tasks.</p><p>Here are some of the most commonly used system variables in Bash scripting:</p><ol><li>$HOME - The path to the current user&#39;s home directory.</li><li>$USER - The name of the current user.</li><li>$PWD - The current working directory.</li><li>$HOSTNAME - The name of the current host.</li><li>$PATH - The list of directories that the shell searches for executables.</li><li>$SHELL - The path to the current user&#39;s shell.</li><li>$PS1 - The primary prompt string for the shell.</li><li>$PS2 - The secondary prompt string for the shell.</li><li>$OSTYPE - The type of operating system that the shell is running on.</li><li>$LINENO - The current line number in the script.</li><li>$0: This variable contains the name of the script or shell being executed.</li><li>$1-$9: These variables contain the first nine command line arguments passed to the script. $1 contains the first argument, $2 contains the second argument, and so on. If there are more than nine arguments, you can access them using the $10, $11, and so on.</li><li>$#: This variable contains the number of command line arguments passed to the script.</li><li>$@: This variable contains all of the command line arguments passed to the script, separated by spaces. You can use this variable to iterate over all of the arguments using a loop or perform other operations.</li><li>$?: This variable contains the exit status of the last executed command or script. An exit status of 0 indicates success, while any other value indicates an error or failure.</li><li>$$: This variable contains the process ID (PID) of the currently running script or shell.</li><li>$SECONDS: This variable contains the number of seconds that the script has been running. This can be useful for measuring the execution time of your scripts or for implementing time-based logic.</li><li>$RANDOM: This variable contains a random integer between 0 and 32767. You can use this variable to generate random numbers for your scripts or to implement random behavior.</li></ol><h3>Quotes</h3><p>Quotes are an important concept in Bash scripting as they are used to control how the shell interprets arguments and variables. In Bash, there are three types of quotes that can be used:</p><p><strong>1. Single quotes (</strong><strong>&#39;):</strong> When a string is enclosed in single quotes, the shell treats it as a literal string, with no special characters or variables interpreted. For example:</p><pre>echo &#39;Hello $USER&#39;  # Output: Hello $USER</pre><p>In this example, the $USER variable is not interpreted because it is enclosed in single quotes.</p><p><strong>2. Double quotes (</strong><strong>&quot;):</strong> When a string is enclosed in double quotes, the shell interprets variables and some special characters within the string. For example:</p><pre>echo &quot;Hello $USER&quot;  # Output: Hello &lt;your username&gt;</pre><p>In this example, the $USER variable is interpreted and replaced with the current username.</p><p>Double quotes can also be used to preserve whitespace within a string. For example:</p><pre>echo &quot;This     string  contains  multiple      spaces.&quot;  # Output: This     string  contains  multiple      spaces.</pre><p>In this example, the multiple spaces within the string are preserved.</p><p><strong>3. Backticks (</strong><strong>`):</strong> Backticks are used to execute a command and return the output as a string. For example:</p><pre>echo &quot;The current date is: `date`&quot;  # Output: The current date is: &lt;current date and time&gt;</pre><p>In this example, the date command is executed and its output is returned as a string, which is then included in the larger string.</p><p>It’s also worth noting that within double quotes, some special characters, such as $, !, and \, can still be interpreted by the shell. To prevent this, you can use a backslash (\) to escape the character. For example:</p><pre>echo &quot;The \$USER variable is: $USER&quot;  # Output: The $USER variable is: &lt;your username&gt;</pre><p>In this example, the $ character is escaped with a backslash to prevent it from being interpreted as a variable.</p><h3>Command Substitution</h3><p>Command substitution is a feature in Bash scripting that allows the output of a command to be substituted as a value within another command or expression. Command substitution is denoted by enclosing a command within $( and ). There are two ways to perform command substitution in Bash:</p><p><strong>1. Using </strong><strong>$() syntax: </strong>This is the recommended way to perform command substitution in Bash. For example:</p><pre>echo &quot;The current working directory is: $(pwd)&quot;</pre><p>In this example, the pwd command is executed and its output is substituted as the argument to echo.</p><p><strong>2. Using backticks:</strong> Backticks can also be used to perform command substitution, but it is less recommended as it can lead to parsing errors if the command contains backticks or other special characters. For example:</p><pre>echo &quot;The current working directory is: `pwd`&quot;</pre><p>This example is equivalent to the previous example, but uses backticks instead of $() syntax.</p><p>Command substitution can be used to simplify complex expressions or to pass the output of one command as an argument to another command. For example, you can use command substitution to count the number of files in a directory:</p><pre>echo &quot;There are $(ls | wc -l) files in this directory&quot;</pre><p>In this example, the ls command is executed to list the files in the current directory, and the output is piped to the wc -l command to count the number of lines (which is equal to the number of files). The resulting count is then substituted as the argument to echo.</p><p>Overall, command substitution is a useful feature in Bash that can help to simplify complex commands and expressions, and make your scripts more efficient and readable.</p><h3>Exporting variable</h3><p>In Bash scripting, variables are by default only available within the current shell session or script. If you want to make a variable available to other processes or sub-shells, you can use the export command.</p><p>The export command allows you to mark a variable for automatic export to the environment of subsequently executed commands. When a variable is exported, its value is copied to the environment of child processes and sub-shells. The general syntax for exporting a variable is as follows:</p><pre>export VARIABLE_NAME=value</pre><p>For example, to export a variable named MY_VAR with the value hello world, you would use the following command:</p><pre>export MY_VAR=&quot;hello world&quot;</pre><p>Once the variable is exported, you can access its value from any subsequently executed command or script. For example, if you execute the following script:</p><pre>#!/bin/bash</pre><pre>export MY_VAR=&quot;hello world&quot;</pre><pre>./other_script.sh</pre><p>And other_script.sh contains the following line:</p><pre>echo &quot;The value of MY_VAR is: $MY_VAR&quot;</pre><p>Then the output of other_script.sh will be:</p><pre>The value of MY_VAR is: hello world</pre><p>Note that when you export a variable, it will be visible to all child processes and sub-shells, but not to the parent process or parent shell. To make the variable available to the parent process or shell, you can use the source command to execute the script in the current shell session:</p><pre>source myscript.sh</pre><p>Or use the dot operator (.) which is an alias for the source command:</p><pre>. myscript.sh</pre><p>Overall, exporting variables can be a useful way to share data between different processes or sub-shells, and can help to simplify complex scripts and make them more modular.</p><h3>Environment Variable or exporting variable permanently</h3><p>In Bash scripting, you can make a variable available to all processes and sessions by setting it as an environment variable. Environment variables are variables that are set in the shell environment and are available to all processes that are executed from the shell. They can be used to configure system-wide settings, set default paths, or define global variables that can be accessed by all users and processes.</p><p>To set an environment variable in Bash, you can use the export command followed by the variable name and value:</p><pre>export VARIABLE_NAME=value</pre><p>For example, to set an environment variable named MY_VAR with the value hello world, you would use the following command:</p><pre>export MY_VAR=&quot;hello world&quot;</pre><p>However, this command only sets the variable for the current session. To make the variable permanent, you need to add it to your shell’s configuration file, which is typically located at ~/.bashrc or ~/.bash_profile.</p><p>To set an environment variable permanently, add the export command to the end of the configuration file:</p><pre>echo &#39;export MY_VAR=&quot;hello world&quot;&#39; &gt;&gt; ~/.bashrc</pre><p>This will append the export command to the end of the .bashrc file, which will be executed every time you start a new Bash session. Alternatively, you can open the .bashrc file in a text editor and add the export command manually.</p><p>Once you have added the environment variable to the configuration file and restarted your terminal or opened a new shell session, the variable will be available to all processes and scripts that are executed from that session. You can access the variable in your scripts using the $VARIABLE_NAME syntax.</p><p>Overall, using environment variables can be a powerful way to configure your system and make global settings available to all processes and users. However, it is important to be careful when modifying system-wide settings, as they can have unintended consequences and may affect the behavior of other programs and users.</p><h3>User Input</h3><p>In Bash scripting, you can prompt the user to enter input using the read command. The read command reads a line of input from the user and assigns it to a variable.</p><p>The basic syntax for read command is as follows:</p><pre>read VARIABLE_NAME</pre><p>For example, to prompt the user to enter their name and store it in a variable called name, you would use the following code:</p><pre>#!/bin/bash</pre><pre>echo &quot;What is your name?&quot;<br>read name</pre><pre>echo &quot;Hello, $name!&quot;</pre><p>When this script is executed, it will display the message “What is your name?” and wait for the user to enter their name. Once the user has entered their name and pressed Enter, the script will print a greeting using the entered name.</p><p>You can also prompt the user to enter multiple values and store them in separate variables by specifying the variable names as arguments to the read command. For example, the following code prompts the user to enter their name and age, and stores the values in the name and age variables:</p><pre>#!/bin/bash</pre><pre>echo &quot;What is your name?&quot;<br>read name</pre><pre>echo &quot;What is your age?&quot;<br>read age</pre><pre>echo &quot;Hello, $name! You are $age years old.&quot;</pre><p>The read command can also be used with the -p option to display a prompt message on the same line as the input. For example, the following code prompts the user to enter their name using a single read command with the -p option:</p><pre>#!/bin/bash</pre><pre>read -p &quot;What is your name? &quot; name</pre><pre>echo &quot;Hello, $name!&quot;</pre><p>In addition, you can use the -s option with the read command to read input without echoing it to the screen. This can be useful for reading passwords or other sensitive information. For example, the following code prompts the user to enter a password and stores it in a variable called password:</p><pre>#!/bin/bash</pre><pre>read -s -p &quot;Enter your password: &quot; password</pre><pre>echo &quot;Your password is: $password&quot;</pre><p>Overall, the read command is a simple and versatile way to prompt the user for input in Bash scripts, and can be used to create interactive command-line tools and applications.</p><h3>If Statement</h3><p>In Bash scripting, the if statement is used to conditionally execute code based on a specified condition. The basic syntax for the if statement is as follows:</p><pre>if CONDITION; then<br>    # code to be executed if condition is true<br>fi</pre><p>The if statement evaluates the specified CONDITION, and if it is true, the code inside the then block is executed. If the CONDITION is false, the code inside the then block is skipped.</p><p>The CONDITION can be any command or expression that returns a status code of 0 for success (true) or non-zero for failure (false). For example, you can use comparison operators to compare two values or test if a file or directory exists:</p><pre>if [ &quot;$var1&quot; -eq &quot;$var2&quot; ]; then<br>    # code to be executed if var1 equals var2<br>fi</pre><pre>if [ -e &quot;/path/to/file&quot; ]; then<br>    # code to be executed if file exists<br>fi</pre><p>You can also use logical operators such as &amp;&amp; (and) and || (or) to combine multiple conditions:</p><pre>if [ &quot;$var&quot; -gt 0 ] &amp;&amp; [ &quot;$var&quot; -lt 10 ]; then<br>    # code to be executed if var is between 0 and 10<br>fi</pre><pre>if [ -d &quot;/path/to/dir&quot; ] || [ -f &quot;/path/to/file&quot; ]; then<br>    # code to be executed if dir exists or file exists<br>fi</pre><p>In addition, the if statement can be combined with the elif (else if) and else statements to handle multiple conditions:</p><pre>if [ &quot;$var&quot; -eq 0 ]; then<br>    # code to be executed if var equals 0<br>elif [ &quot;$var&quot; -gt 0 ]; then<br>    # code to be executed if var is greater than 0<br>else<br>    # code to be executed if var is less than 0<br>fi</pre><p>Overall, the if statement is a fundamental tool for creating conditional logic in Bash scripts, and can be used to create powerful and flexible control flow in your code.</p><h3>If Else Statement</h3><p>In Bash scripting, the if-else statement is used to conditionally execute code based on a specified condition, and to execute an alternate code block if the condition is false. The basic syntax for the if-else statement is as follows:</p><pre>if CONDITION; then<br>    # code to be executed if condition is true<br>else<br>    # code to be executed if condition is false<br>fi</pre><p>The if-else statement evaluates the specified CONDITION, and if it is true, the code inside the then block is executed. If the CONDITION is false, the code inside the else block is executed.</p><p>The CONDITION can be any command or expression that returns a status code of 0 for success (true) or non-zero for failure (false). For example, you can use comparison operators to compare two values or test if a file or directory exists:</p><pre>if [ &quot;$var1&quot; -eq &quot;$var2&quot; ]; then<br>    # code to be executed if var1 equals var2<br>else<br>    # code to be executed if var1 does not equal var2<br>fi</pre><pre>if [ -e &quot;/path/to/file&quot; ]; then<br>    # code to be executed if file exists<br>else<br>    # code to be executed if file does not exist<br>fi</pre><p>You can also use logical operators such as &amp;&amp; (and) and || (or) to combine multiple conditions:</p><pre>if [ &quot;$var&quot; -gt 0 ] &amp;&amp; [ &quot;$var&quot; -lt 10 ]; then<br>    # code to be executed if var is between 0 and 10<br>else<br>    # code to be executed if var is not between 0 and 10<br>fi</pre><pre>if [ -d &quot;/path/to/dir&quot; ] || [ -f &quot;/path/to/file&quot; ]; then<br>    # code to be executed if dir exists or file exists<br>else<br>    # code to be executed if dir does not exist and file does not exist<br>fi</pre><p>Overall, the if-else statement is a fundamental tool for creating conditional logic in Bash scripts, and can be used to create powerful and flexible control flow in your code.</p><h3>Test Condition</h3><p>In the if statement, the square brackets ([]) are used to test a condition or expression. The square brackets are actually an alias for the test command, which evaluates the condition and returns a status code of 0 (true) or non-zero (false).</p><p>The if statement checks the exit status of the test command to determine whether the condition is true or false. The syntax for using the test command is:</p><pre>[ CONDITION ]</pre><p>For example, the following if statement tests if the variable $var is equal to the string &quot;hello&quot;:</p><pre>if [ &quot;$var&quot; = &quot;hello&quot; ]; then<br>    echo &quot;The variable is equal to hello.&quot;<br>fi</pre><p>The expression inside the square brackets evaluates to true if $var is equal to &quot;hello&quot;, and the code inside the if block is executed. If the expression is false, the code inside the if block is skipped.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/768/0*tD7GNbBDZ49EL-NY.png" /></figure><h3>For Loop</h3><p>In Bash scripting, the for loop is used to iterate over a set of values and perform a set of actions for each value. The basic syntax for the for loop is as follows:</p><pre>for VAR in VALUE1 VALUE2 ... VALUEN; do<br>    # code to be executed for each value<br>done</pre><p>In this syntax, VAR is a variable that is used to store each value from the list of values. The values are specified after the in keyword, separated by spaces.</p><p>Here’s an example of using the for loop to iterate over a list of values and print each value:</p><pre>#!/bin/bash</pre><pre>for COLOR in red green blue; do<br>    echo $COLOR<br>done</pre><p>This script will output the following:</p><pre>red<br>green<br>blue</pre><p>You can also use variables in the list of values, and use the seq command to generate a sequence of numbers. For example:</p><pre>#!/bin/bash</pre><pre>for i in {1..5}; do<br>    echo &quot;Number: $i&quot;<br>done</pre><pre>for i in $(seq 1 5); do<br>    echo &quot;Number: $i&quot;<br>done</pre><p>Both of these loops will output the same result:</p><pre>Number: 1<br>Number: 2<br>Number: 3<br>Number: 4<br>Number: 5</pre><p>The for loop is a powerful tool for iterating over lists of values and performing repetitive tasks. You can use it to perform a wide variety of tasks, from processing files and directories to managing data and resources.</p><h3>While Loop</h3><p>In Bash scripting, the while loop is used to execute a set of commands repeatedly as long as a certain condition is true. The basic syntax of a while loop is as follows:</p><pre>while [ CONDITION ]; do<br>    # code to be executed while CONDITION is true<br>done</pre><p>In this syntax, CONDITION is a test that is evaluated before each iteration of the loop. If the test evaluates to true, the loop executes the code inside the do and done statements, and then re-evaluates the CONDITION test. If the test is still true, the loop continues to execute, otherwise, it exits.</p><p>Here’s an example of using a while loop to iterate over a list of numbers and print each one:</p><pre>#!/bin/bash</pre><pre>i=1<br>while [ $i -le 5 ]; do<br>    echo &quot;Number: $i&quot;<br>    i=$((i+1))<br>done</pre><p>This script will output the following:</p><pre>Number: 1<br>Number: 2<br>Number: 3<br>Number: 4<br>Number: 5</pre><p>In this example, the CONDITION test is [ $i -le 5 ], which checks if the value of $i is less than or equal to 5. The loop continues to execute as long as this test evaluates to true. The code inside the loop prints the value of $i and then increments it by 1 using the expression i=$((i+1)).</p><p>The while loop is useful when you want to execute a set of commands repeatedly as long as a certain condition is true. You can use it to process data, read input, and manage resources in your Bash scripts.</p><h3>Real-Time Example</h3><p>One of the most important real-time examples of Bash scripting is automating system administration tasks. Bash scripts can be used to automate a wide variety of tasks that are typically performed by system administrators, such as system maintenance, backups, and software updates.</p><p>Here’s an example of a Bash script that automates the process of backing up a directory:</p><pre>#!/bin/bash</pre><pre># Directory to backup<br>dir=&quot;/home/user/Documents&quot;</pre><pre># Backup destination directory<br>backup_dir=&quot;/mnt/backup&quot;</pre><pre># Backup file name<br>backup_file=&quot;backup_$(date +%Y-%m-%d_%H-%M-%S).tar.gz&quot;</pre><pre># Create backup directory if it does not exist<br>if [ ! -d &quot;$backup_dir&quot; ]; then<br>  mkdir &quot;$backup_dir&quot;<br>fi</pre><pre># Create backup file<br>tar -czf &quot;$backup_dir/$backup_file&quot; &quot;$dir&quot;</pre><pre># Delete backup files older than 30 days<br>find &quot;$backup_dir&quot; -type f -name &quot;backup_*.tar.gz&quot; -mtime +30 -delete</pre><pre>echo &quot;Backup created: $backup_dir/$backup_file&quot;</pre><p>In this script, the dir variable specifies the directory to be backed up, while the backup_dir variable specifies the location where the backup should be saved. The backup_file variable is used to generate a filename for the backup that includes the current date and time.</p><p>The script first checks if the backup directory exists, and creates it if it does not. It then creates the backup file using the tar command and deletes any backup files that are older than 30 days using the find command.</p><p>By scheduling this script to run periodically using a tool like cron, you can automate the process of backing up your files and ensure that your data is safe and secure.</p><p>This is just one example of how Bash scripting can be used in real-time scenarios to automate system administration tasks. By combining Bash with other tools and technologies, you can create powerful scripts that can save time and improve efficiency in your work.</p><h3>How to set up SSH Keys Using bash scripting</h3><p>SSH keys are a secure and convenient way to authenticate and connect to remote servers without having to enter a password each time. You can set up SSH keys in Bash scripting by following these steps:</p><p><strong>1. Check for existing SSH keys:</strong> Before generating new SSH keys, it’s a good idea to check if you already have existing SSH keys. You can check for existing keys by running the following command in your terminal:</p><pre>ls ~/.ssh/id_*</pre><p>If you see any files listed, you already have SSH keys.</p><p><strong>2. Generate new SSH keys:</strong> If you don’t have SSH keys, you can generate new ones by running the following command in your terminal:</p><pre>ssh-keygen -t rsa -b 4096 -C &quot;your_email@example.com&quot;</pre><p>This command will generate a new SSH key pair, consisting of a private key and a public key. The private key will be saved to ~/.ssh/id_rsa, and the public key will be saved to ~/.ssh/id_rsa.pub.</p><p><strong>3. Add your public key to the remote server:</strong> To connect to a remote server using SSH keys, you need to add your public key to the remote server’s authorized_keys file. You can do this by copying your public key to the remote server using the ssh-copy-id command:</p><pre>ssh-copy-id user@remote_server</pre><p>This command will copy your public key to the remote server and add it to the authorized_keys file.</p><p><strong>4. Test your SSH connection:</strong> Once you have set up your SSH keys, you can test your connection to the remote server by running the following command in your terminal:</p><pre>ssh user@remote_server</pre><p>This command will connect you to the remote server using your SSH keys, and you should not be prompted for a password.</p><p>You can use these steps in Bash scripting to automate the process of setting up SSH keys for multiple servers or users. By creating a Bash script that generates and copies SSH keys, you can save time and improve the security of your remote connections.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a6e8dcf615f9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Bash Scripting Tryhackme writeup]]></title>
            <link>https://mohammadaassif.medium.com/bash-scripting-tryhackme-writeup-adf54bb5844d?source=rss-29926d996499------2</link>
            <guid isPermaLink="false">https://medium.com/p/adf54bb5844d</guid>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[bash]]></category>
            <category><![CDATA[bash-script]]></category>
            <category><![CDATA[hacks]]></category>
            <dc:creator><![CDATA[Mohammadaassif]]></dc:creator>
            <pubDate>Sun, 03 Mar 2024 06:13:26 GMT</pubDate>
            <atom:updated>2024-03-03T06:13:26.563Z</atom:updated>
            <content:encoded><![CDATA[<p><strong>This is a Writeup of Tryhackme room “Bash Scripting”</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/479/0*7tQNJbC-I6VnfvHW.png" /></figure><p><a href="https://tryhackme.com/room/bashscripting">https://tryhackme.com/room/bashscripting</a></p><p><strong>Room link:</strong> <a href="https://tryhackme.com/room/bashscripting">https://tryhackme.com/room/bashscripting</a><br><strong>Note: This room is free</strong></p><h3>Task 2: Our first simple bash scripts</h3><p>Ok now that we have had a brief introduction to what bash is and what it is used for let’s jump right into some examples!</p><p>First of all let’s lay out our structure.</p><p>A bash script always starts with the following line of code at the top of the script.</p><p>Image source <a href="https://carbon.now.sh/">https://carbon.now.sh/</a></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/662/0*IE49Qo6NMvQAb6qm.png" /></figure><p>This is so your shell (whatever type of it) knows that it needs to run your file using bash in the terminal.</p><p>Lets get into some basic examples.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/796/0*w3KLGgWyEg-a6n1H.png" /></figure><p>This will return the string “Hello World”. The command “echo” is used to output text to the screen, the same way as “print” in python. I suggest you test this out in your terminal to get to grips with bash!</p><p>You can also perform normal Linux commands inside your bash script and it will be executed if formatted right. For example we can run the command “ls” inside our bash script and we will see the output when we run the file. So lets make it do this!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/780/0*7eGOCb50FiZDkXQ5.png" /></figure><p>Now from here on I am going to assume that you have a basic understanding of Linux and its commands, if you don’t please go make sure to check out the Linux fundamentals 1 and then come back and try again. <a href="https://tryhackme.com/room/linux1"><strong>https://tryhackme.com/room/linux1</strong></a></p><p>I’m also not going to include the #!/bin/bash at the start of my code snippets otherwise it will take up a lot of room so be aware that you need it always at the start of your files!</p><p>Now to run our bash script we must first give it executable permissions</p><p>Chmod +x yourfile.sh</p><p>And then we run it using ./</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*n7MCOuhJNUmjv0G0.png" /></figure><p>Please run this for yourself and see what you get.</p><p>We can see it has outputted the results of the commands “whoami” and “id”.</p><p><strong>#1</strong>: What piece of code can we insert at the start of a line to comment out our code?</p><blockquote><strong><em>Answer: #</em></strong></blockquote><p><strong>#1</strong>: What will the following script output to the screen, echo “BishBashBosh”</p><blockquote><strong><em>Answer: BishBashBosh</em></strong></blockquote><h3>Task 3: Variables</h3><p>Now we are moving onto variables,</p><p>in bash these are quite simple and we create them like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/502/0*2gV-1Oc7P1j4Tr8I.png" /></figure><p>Where we give the value of Jammy and assign it to the variable name.</p><p>Please note that for variables to work you cannot leave a space between the variable name, the ”<strong>=</strong>” and the value. They cannot have spaces in.</p><p>So how would we now use our variable? Well its also very simple.</p><p>We have to add a $ onto front of our variable name in order to use it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/678/0*MKE-6nqmIFgmLtX8.png" /></figure><p>If we test this out in our own terminal we get something like this:</p><p>$ name=&quot;Jammy&quot;</p><p>$ echo $name</p><p>Jammy</p><p>This would output “<strong>Jammy</strong>” to the screen.</p><p>Variables make it much easier to store data and rather than typing out the same thing in multiple places we could simply insert our variable with $var and then declare that to a certain value making it easier to fall back on if you do something wrong and need to change it. So how can we debug our code?</p><p>Debugging is a very important part of programming so we should get used to problem solving and fixing errors as early as possible. And bash has a few built in features that make our life simple.</p><p>When running at the command line you can do:</p><p>bash -x ./file.sh</p><p>You can make a simple bash script(now you know some basic syntax) and make something completely wrong. Then step through your program with debug mode and see what it looks like when it throws errors!</p><p>This tells you which lines are working and which lines are not. If you want to debug at a certain point you can insert set -x into your script and set +x to end the section like the following:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*RlwCeadnazGoM5tv.png" /></figure><p>So lets look at an example. This is our script from earlier being ran with bash -x ./example.sh</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*DkpAiBE9FnkUtN2J.png" /></figure><p>You can see its outputting a <strong>+</strong> for the command and then the output of what that command executed. If there was an error it would output a <strong>— </strong>on that line this makes it easy to spot where you have gone wrong so you can fix them.</p><p>We can also use multiple variables in something like an echo statement. You aren’t just limited to using 1!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*So4dDGAhthyFnbLf.png" /></figure><p>Answer the following questions and use this piece of code to guide you.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*HOcqRrg7KIHTklce.png" /></figure><p><strong>#1</strong>: What would this code return?</p><blockquote><strong><em>Answer: Jammy is 21 years old</em></strong></blockquote><p><strong>#2</strong>: How would you print out the city to the screen?</p><blockquote><strong><em>Answer: echo $city</em></strong></blockquote><p><strong>#3</strong>: How would you print out the country to the screen?</p><blockquote><strong><em>Answer: echo $country</em></strong></blockquote><h3>Task 4: Parameters</h3><p>We will now look at one of the main features of bash and that’s using parameters.</p><p>We will firstly look at parameters specified using the command line when running the file. These come in many forms but often have the “$” prefix because a parameter is still a variable.</p><p>Lets start by declaring a parameter that is going to be our first argument when running our bash script.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/646/0*ibJon44KLeoqBtbW.png" /></figure><p>We now run our script with ./example.sh Alex</p><p>And sure enough we get returned with “Alex”</p><p>So what if we wanted the 2nd argument? Well the process is very simple and we simply add a $2 instead of name=$1</p><p>Then run with ./example.sh Alex Tony</p><p>What do you think it would return?</p><p>And it would return “Tony”.</p><p>What if we didn’t want to supply them like this however, and instead it would let us type in our name in a more interactive way, we can do this using read.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*sIzqsi2PPjY_OmhD.png" /></figure><p>This code will hang after its ran, this gives you the opportunity to type in your name.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/762/0*w_BbReGyTvAlj5Ef.png" /></figure><p>And we can see that it worked!</p><p>Maybe try making a little biography maker, where you take the name, age, and job as parameters. Store them inside a variable and then output them to the screen inside a sentence.</p><p>However there is so much more that you can do with parameters and I advice you to play around with them, after all practice is what makes you better!</p><p><strong>#1</strong>: How can we get the number of arguments supplied to a script?</p><blockquote><strong><em>Answer: $#</em></strong></blockquote><p><strong>#2</strong>: How can we get the filename of our current script(aka our first argument)?</p><blockquote><strong><em>Answer: $0</em></strong></blockquote><p><strong>#3</strong>: How can we get the 4th argument supplied to the script?</p><blockquote><strong><em>Answer: $4</em></strong></blockquote><p><strong>#4</strong>: If a script asks us for input how can we direct our input into a variable called ‘test’ using “read”</p><blockquote><strong><em>Answer: read test</em></strong></blockquote><p><strong>#5</strong>: What will the output of “echo $1 $3” if the script was ran with “./script.sh hello hola aloha”</p><blockquote><strong><em>Answer: hello aloha</em></strong></blockquote><h3>Task 5: Arrays</h3><p>For this module i suggest you follow along in the attackbox or a standard linux terminal to make it easier to understand.</p><p>Arrays are used to store multiple pieces of data in one variable, which can then be extracted by using an index. Most commonly notated as var[index_position].</p><p>Arrays use indexing meaning that each item in an array stands for a number.</p><p>In the array [&#39;car&#39;, &#39;train&#39;, &#39;bike&#39;, &#39;bus&#39;] each item has a corresponding index.</p><p>All indexes start at position 0</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/696/0*2DSxnsHsBAWROgph.png" /></figure><p>Now we have covered this, let’s make an array in bash.</p><p>The syntax is as follows.</p><p>We have the variable name, in our case ‘transport’</p><p>We then wrap each item in brackets leaving a space between each item.</p><p>transport=(&#39;car&#39; &#39;train&#39; &#39;bike&#39; &#39;bus&#39;)</p><p>We can then echo out all the elements in our array like this:</p><p>echo &quot;${transport[@]}&quot;</p><p>You can try this in your own terminal and see what it outputs.</p><p>Where the “@” means all arguments, and the [] wrapped around it specifies its index.</p><p>So what if we wanted to print out the item train.</p><p>We would simply type:</p><p>echo &quot;${transport[1]}&quot;</p><p>because the train is at index position 1.</p><p>The last thing we will cover is if we want to change an element, or delete it. If we wanted to remove an element we would use the unset utility.</p><p>unset transport[1]</p><p>This now removes the train item, if we wanted to we could echo it back out and see that it is indeed gone,</p><p>Now lets set it to something else. We can do:</p><p>transport[1]=&#39;trainride&#39;</p><p>If we echo the array then we get:</p><p>car trainride bike bus</p><p>So we successfully managed to swap out an element in our array!</p><p>As a little side project try building on your previosu project of a biography maker, include arrays so that you can store multiple names and multiple facts about the person. Then in the next module we can expand even further.</p><p>Given the array please answer the following questions</p><p>cars=(&#39;honda&#39; &#39;audi&#39; &#39;bmw&#39; &#39;tesla&#39;)</p><p><strong>#1</strong>: What would be the command to print audi to the screen using indexing.</p><blockquote><strong><em>Answer: echo “${cars[1]}”</em></strong></blockquote><p><strong>#2</strong>: If we wanted to remove tesla from the array how would we do so?</p><blockquote><strong><em>Answer: unset cars[3]</em></strong></blockquote><p><strong>#3</strong>: How could we insert a new value called toyota to replace tesla?</p><blockquote><strong><em>Answer: cars[3]=”toyota”</em></strong></blockquote><h3>Task 6: Conditionals</h3><p><a href="https://i.ibb.co/k2DgyGg/carbon-19.pnghttps://i.ibb.co/k2DgyGg/carbon-19.pngWhen">https://i.ibb.co/k2DgyGg/carbon-19.pnghttps://i.ibb.co/k2DgyGg/carbon-19.pngWhen</a> we talk about conditionals it means that a certain piece of code relies on a condition being met, this is often determined with relational operators, such as equal to, greater than, and less than.</p><p>We will make a simple “if” statement to check if a variable is equal to a value, we will also make a script that checks if a file exists and that it is writeable, if it is we will write a message to that file, if not writeable it will delete it and make a new one. A Lot of new things will be taught here so pay attention.</p><p>First we will discuss the basic syntax of an if statement.</p><p>All if statements look like so:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*FoqVSLwocQhizyth.png" /></figure><p>Let&#39;s look at an example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*dbKsSH2tHyDGZkJ8.png" /></figure><p>If statements always use a pair of brackets and in the case of the [] we need to leave a space on both sides of the text(the bash syntax). We also always need to end the if statement with fi</p><p>Here a variable is being declared as 10 and in the top line of the if statement the variable $count is being compared to the integer 10.</p><p>If they are equal then it outputs <strong>true</strong>, if its false it outputs <strong>false</strong>. As we know 10 is equal to 10 so it outputs true.</p><p>The <strong>-eq</strong> is one way of doing this, you could also use “<strong>=</strong>”</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*wmxlwLDk71kYhqaF.png" /></figure><p>These are some examples.</p><p>So now let’s use this to make a little script that compares an input(a parameter) and checks it against a value to check if it’s true or not. A guessing game if you will.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*tMU_T5j-eb9NHoEX.png" /></figure><p>Now let’s test this in our terminal.</p><p># ./example.sh guessme</p><p>&quot;They are equal&quot;</p><p># ./example.sh hi</p><p>&quot;They are not equal&quot;</p><p>And we can see that it works!</p><p>Feel free to play around with these and try making different combinations and using different operators.</p><p>Now lets create another script where we will use 2 conditions simultaneously and coming back to a concept we learnt in the first lesson.</p><p>Lets begin.</p><p>We want to make a script that we will perform on a file given by a <strong>parameter</strong>.</p><p>We then check if it exists and if it has <strong>write</strong> permissions. If it has write perms then we echo “<strong>hello</strong>” to it. If it is either non-accessible or doesn’t exist we will create the file and echo “hello” to it. Lets begin!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*gVpmJi_1TdwAMops.png" /></figure><p>─# ./example.sh hello.txt ─# cat hello.txt</p><p>hello</p><p>And we can see that it worked!!</p><p>The -f checked if the file existed.</p><p>The -w checked if the file was writable, without write permissions we wouldn’t be able to output our text into the file.</p><p>To finish off our little project from the previous task. You can build on your script using an if/else statement. Test to see if the age is under 18, if it is then echo out their name with “You are not elegible for work” or something along theese lines, if they are over 18 then ask them for their job, you can do this with read</p><p>Feel free to add anything you like and make it as complicated as you wish and good luck with your project!</p><p><strong>#1</strong>: What is the flag to check if we have read access to a file?</p><blockquote><strong><em>Answer: -r</em></strong></blockquote><p><strong>#2</strong>: What is the flag to check to see if it’s a directory?</p><blockquote><strong><em>Answer: -d</em></strong></blockquote><h3>Task 7 Further reading</h3><p>Hi there and thank you so much for completing this room on bash scripting! I want to congratulate you on persevering when things got tough and completing the room.</p><p>If you want to further extend your knowledge of bash or coding in general I really suggest the following websites:</p><ul><li><a href="https://www.codewars.com/">https://www.codewars.com/</a></li><li><a href="https://www.hackerrank.com/">https://www.hackerrank.com/</a></li><li>And of course, Google!</li></ul><p>Thanks again. If you want to ask me about anything or have any queries about the room, you can reach me on twitter <a href="https://twitter.com/fieldraccoon">https://twitter.com/M</a>ohammadaassif</p><p>Good luck on your bash journey!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=adf54bb5844d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hacker101 Micro-CMS v1 CTF Walkthrough]]></title>
            <link>https://mohammadaassif.medium.com/hacker101-micro-cms-v1-ctf-walkthrough-1e2bced91d82?source=rss-29926d996499------2</link>
            <guid isPermaLink="false">https://medium.com/p/1e2bced91d82</guid>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[hackthebox]]></category>
            <dc:creator><![CDATA[Mohammadaassif]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 20:37:28 GMT</pubDate>
            <atom:updated>2022-04-01T22:05:07.908Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_kMQQSns6ua8kROTgFyxrQ.jpeg" /></figure><p>My first CTF will involve a hacker101 set of provided CTFs, Micro-CMS v1. The CTF is located here: <a href="https://ctf.hacker101.com/ctf">https://ctf.hacker101.com/ctf</a>. It is an easy CTF to solve hence would be a good starting point for a beginner.</p><p><strong>Flag0: Stored XSS</strong></p><p>Opening Micro-CMS v1, I get three:</p><ul><li><a href="https://www.hacker101.com/sessions/xss">XSS and Authorization</a></li><li><a href="https://owasp.org/www-project-web-security-testing-guide/latest/4-Web_Application_Security_Testing/07-Input_Validation_Testing/01-Testing_for_Reflected_Cross_Site_Scripting">WSTG - Latest | OWASP Foundation</a></li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/888/1*-zs_DtepBstcrv5eBi9nUw.png" /></figure><p>I first visit the ‘create a new page’ link. When I create a new page, the details of the new page are reflected in the response. This is a good indication that the website might be vulnerable to XSS (Cross-site scripting). I test for XSS by editing the page title with this payload:</p><blockquote>hello&lt;script&gt;alert(1);&lt;/script&gt;</blockquote><p>Going back home, the payload executes and I get the first flag. 😊</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/563/1*j35Nfas1qEaEHOgLX3UZaA.png" /></figure><p><strong>Flag1: Unauthorized Access</strong></p><p>When I created my first page, I observed that it was assigned an id of 8</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/818/1*Ii0ISbvJnmXg9XkoTMdQ6w.png" /></figure><p>When I visit the two pages provided before, I observe that the pages have an id of 1 and 2. So I try to retrieve pages between 2 and 8. Page 5 responds with a 403 forbidden error while others respond with 404.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*gFWfc6JvlJ1L3fA4YqZdWg.png" /></figure><p>I poke around the system to look for other areas the page id is present and observe that the page id is also used when retrieving a page for editing.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*DDUG9Xa1Okw9R_3OhiQteg.png" /></figure><p>I switch the page id to 5, refresh the page and get the third flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/947/1*eOwgrkFEBnmOcNmopBsGWw.png" /></figure><p><strong>Flag2: SQLi</strong></p><p>When editing a page, I notice that the page id is passed in the URL. I test this parameter for SQL injection by placing a ‘ (single quote) at the end of the id parameter and I get the second flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/1*vu_6pBzJVTRzbSsQQ0LR3w.png" /></figure><p><strong>Flag3: Stored XSS</strong></p><p>Since the input is reflected in the page, I have to find a way to bypass the markdown filter to execute XSS. After searching and trying different payloads, I come across this payload:</p><p>&lt;button onclick=alert(‘xss’)&gt;click&lt;/button&gt;</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*NI9FAd58WRQfkUSJRp9zyA.png" /></figure><p>The payload executes successfully but there is no flag displayed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/567/1*3Vb1PFxO9rGTAgiDHjWeag.png" /></figure><p>Viewing the source code, I find the flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b4zqCOpkq2e7SZxbZdosYw.png" /></figure><p>Thank you for reading. If you enjoyed this article.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1e2bced91d82" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hacker101:A little something to get you started-CTF Walkthrough]]></title>
            <link>https://mohammadaassif.medium.com/hacker101-a-little-something-to-get-you-started-ctf-walkthrough-73b20a764527?source=rss-29926d996499------2</link>
            <guid isPermaLink="false">https://medium.com/p/73b20a764527</guid>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[hacker]]></category>
            <category><![CDATA[ctf]]></category>
            <dc:creator><![CDATA[Mohammadaassif]]></dc:creator>
            <pubDate>Wed, 30 Mar 2022 06:56:29 GMT</pubDate>
            <atom:updated>2022-03-30T06:56:32.983Z</atom:updated>
            <content:encoded><![CDATA[<p>Hello everyone. I am Mohammadaassif and a cybersecurity enthusiast. This article is the beginning of a series of cybersecurity posts where I will be sharing my knowledge of hacking by CTF (Capture the Flag) walkthroughs. A CTF is a game designed to let you learn to hack in a safe, rewarding environment.</p><p>First of all, I am not an expert in this field. try to learn and better understand, My goal is to share the knowledge I have as I continue learning cybersecurity.</p><p>My first CTF will involve a hacker101 set of provided CTFs, Micro-CMS v1. The CTF is located here: <a href="https://ctf.hacker101.com/ctf">https://ctf.hacker101.com/ctf.</a> It is an easy CTF to solve hence would be a good starting point for a beginner.</p><p>After opening the link one gets a below page as shown in the figure.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*7c6yylcTUvyPfMFh3o2Tmg.png" /><figcaption>Click to Stat</figcaption></figure><p>then after the new page opens.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/737/1*iOdlraqjQvhUhmEm1x-RuQ.png" /><figcaption>Right-click on page view page source code</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/727/1*S62ZUFIXUdJ5kaK7SUIwxA.png" /><figcaption>copy the background.png and paste url /background</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/650/1*caXYLjsNxYxMvG0hjlR0ug.png" /><figcaption>Flag copy whole word and paste</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/805/1*_LT8mvEEEohqKilDvMEZ8A.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*qeX7Qaa82aE1RDoT_9o67A.png" /><figcaption>Submit the flag</figcaption></figure><p>Completed A little something to get you started-CTF Walkthrough.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=73b20a764527" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Jr Penetration Tester]]></title>
            <link>https://mohammadaassif.medium.com/jr-penetration-tester-776f7373bd15?source=rss-29926d996499------2</link>
            <guid isPermaLink="false">https://medium.com/p/776f7373bd15</guid>
            <dc:creator><![CDATA[Mohammadaassif]]></dc:creator>
            <pubDate>Thu, 06 Jan 2022 10:41:35 GMT</pubDate>
            <atom:updated>2022-01-06T10:41:35.280Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn the practical skills required to start your career as a Professional Penetration Tester.</p><p>SECTION 1</p><p>Introduction to Pentesting</p><p><strong><em>1-Pentesting Fundamentals:</em></strong></p><p><strong><em>2-Principles Of Security:</em></strong></p><p>Learn the principles of information security that secures data and protects systems from abuse,</p><p><strong><em>Task 1 Introduction</em></strong></p><p>The following room is going to outline some of the fundamental principles of information security. The frameworks used to protect data and systems to the elements of what exactly makes data secure.</p><p>The measures, frameworks, and protocols discussed throughout this room all play a small part in “Defence in Depth.”</p><p>Defense in Depth is the use of multiple varied layers of security to an organization’s systems and data in the hopes that multiple layers will provide redundancy in an organization’s security perimeter.</p><p><strong><em>Answer the questions below</em></strong></p><p>Let’s proceed!</p><p><strong><em>Task 2 The CIA Triad</em></strong></p><p>The CIA triad is an information security model that is used in consideration throughout creating a security policy. This model has an extensive background, ranging from being used in 1998.</p><p>This history is because the security of information (information security) does not start and/or end with cybersecurity, but instead, applies to scenarios like filing, record storage, etc.</p><p>Consisting of three sections: <strong>C</strong>onfidentiality, <strong>I</strong>ntegrity, and <strong>A</strong>vailability (<strong>CIA</strong>), this model has quickly become an industry-standard today. This model should help determine the value of data that it applies to, and in turn, the attention it needs from the business.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/449/0*oqKO2sRFZulkF7LP.png" /></figure><p>The CIA triad is unlike a traditional model where you have individual sections; instead, it is a continuous cycle. Whilst the three elements to the CIA triad can arguably overlap, if even just one element is not met, then the other two are rendered useless (similar to the fire triangle). If a security policy does not answer these three sections, it is seldom an effective security policy.</p><p>Whilst the three elements to the CIA triad are arguably self-explanatory, let’s explore these and contextualize them into cybersecurity.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*K1H2eukChV1aOf2s.png" /></figure><p><strong>Confidentiality</strong></p><p>This element is the protection of data from unauthorized access and misuse. Organizations will always have some form of sensitive data stored on their systems. To provide confidentiality is to protect this data from parties that it is not intended for.</p><p>There are many real-world examples for this, for example, employee records and accounting documents will be considered sensitive. Confidentiality will be provided in the sense that only HR administrators will access employee records, where vetting and tight access controls are in place. Accounting records are less valuable (and therefore less sensitive), so not as stringent access controls would be in place for these documents. Or, for example, governments using a sensitivity classification rating system (top-secret, classified, unclassified)</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*4yhZCag0QTn9iOLQ.png" /></figure><p><strong>Integrity</strong></p><p>The CIA triad element of integrity is the condition where information is kept accurate and consistent unless authorized changes are made. It is possible for the information to change because of careless access and use, errors in the information system, or unauthorized access and use. In the CIA triad, integrity is maintained when the information remains unchanged during storage, transmission, and usage not involving modification to the information. Steps must be taken to ensure data cannot be altered by unauthorized people (for example, in a breach of confidentiality).</p><p>Many defenses to ensure integrity can be put in place. Access control and rigorous authentication can help prevent authorized users from making unauthorized changes. Hash verifications and digital signatures can help ensure that transactions are authentic and that files have not been modified or corrupted.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/0*4FaQyqoMwBit7E69.png" /></figure><p><strong>Availability</strong></p><p>In order for data to be useful, it must be available and accessible by the user.</p><p>The main concern in the CIA triad is that the information should be available when authorized users need to access it.</p><p>Availability is very often a key benchmark for an organization. For example, having 99.99% uptime on their websites or systems (this is laid out in Service Level Agreements). When a system is unavailable, it often results in damage to an organization&#39;s reputation and loss of finances. Availability is achieved through a combination of many elements, including:</p><ul><li>Having reliable and well-tested hardware for their information technology servers (i.e. reputable servers)</li><li>Having redundant technology and services in the case of failure of the primary</li><li>Implementing well-versed security protocols to protect technology and services from attack</li></ul><p><strong><em>Answer the questions below</em></strong></p><blockquote>What element of the CIA triad ensures that data cannot be altered by <strong>unauthorised</strong> people?</blockquote><p><em>Ans=Integrity</em></p><blockquote>What element of the CIA triad ensures that data is available?</blockquote><p><em>Ans=Availability</em></p><blockquote>What element of the CIA triad ensures that data is only accessed by <strong>authorised</strong> people?</blockquote><p><em>Ans=Confidentiality</em></p><p><strong><em>Task 3 Principles of Privileges</em></strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*bcF3biK0jM9CVkT3.png" /></figure><p>It is vital to administrate and correctly define the various levels of access to an information technology system individuals require.</p><p>The levels of access given to individuals are determined on two primary factors:</p><ul><li>The individual’s role/function within the organization</li><li>The sensitivity of the information being stored on the system</li></ul><p>Two key concepts are used to assign and manage the access rights of individuals, two key concepts are used: Privileged Identity Management (PIM) and Privileged Access Management (or PAM for short).</p><p>Initially, these two concepts can seem to overlap; however, they are different from one another. PIM is used to translate a user’s role within an organization into an access role on a system. Whereas PAM is the management of the privileges a system’s access role has, amongst other things.</p><p>What is essential when discussing privilege and access controls is the principle of least privilege. Simply, users should be given the minimum amount of privileges, and only those that are absolutely necessary for them to perform their duties. Other people should be able to trust what people write to.</p><p>As we previously mentioned, PAM incorporates more than assigning access. It also encompasses enforcing security policies such as password management, auditing policies, and reducing the attack surface a system faces.</p><p><strong><em>Answer the questions below</em></strong></p><blockquote>What does the acronym “PIM” stand for?</blockquote><p><em>Ans=Privileged Identity Management</em></p><blockquote>What does the acronym “PAM” stand for?</blockquote><p><em>Ans=Privileged Access Management</em></p><blockquote>If you wanted to manage the privileges a system access role had, what methodology would you use?</blockquote><p><em>Ans=PAM</em></p><blockquote>If you wanted to create a system role that is based on a users role/responsibilities with an organisation, what methodology is this?</blockquote><p><em>Ans=PIM</em></p><p><strong><em>Task 4 Security Models Continued</em></strong></p><p>Before discussing security models further, let’s recall the three elements of the CIA triad: Confidentiality, Integrity and Availability. We’ve previously outlined what these elements are and their importance. However, there is a formal way of achieving this.</p><p>According to a security model, any system or piece of technology storing information is called an information system, which is how we will reference systems and devices in this task.</p><p>Let’s explore some popular and effective security models used to achieve the three elements of the CIA triad.</p><p><strong>The Bell-La Padula Model</strong></p><p>The Bell-La Padula Model is used to achieve confidentiality. This model has a few assumptions, such as an organisation’s hierarchical structure it is used in, where everyone’s responsibilities/roles are well-defined.</p><p>The model works by granting access to pieces of data (called objects) on a strictly need to know basis. This model uses the rule “no write down, no read up”.</p><p><strong><em>Answer the questions below:</em></strong></p><blockquote>What is the name of the model that uses the rule “<strong>can’t </strong>read up, can read down”?</blockquote><p><strong><em>Ans=The Bell-La Padula Model</em></strong></p><blockquote>What is the name of the model that uses the rule “<strong>can </strong>read up, can’t read down”?</blockquote><p><strong><em>Ans=The Biba Model</em></strong></p><blockquote>If you were a military, what security model would you use?</blockquote><p><strong><em>Ans=The Bell LaPadula Model</em></strong></p><blockquote>If you were a software developer, what security model would the company perhaps use?</blockquote><p><strong><em>Ans=The Biba Model</em></strong></p><p><strong><em>Task 5 Threat Modelling &amp; Incident Response</em></strong></p><p>Threat modelling is the process of reviewing, improving, and testing the security protocols in place in an organisation’s information technology infrastructure and services.</p><p>A critical stage of the threat modelling process is identifying likely threats that an application or system may face, the vulnerabilities a system or application may be vulnerable to.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/361/0*WopBrYKHhBehZ_Pe.png" /></figure><p>The threat modelling process is very similar to a risk assessment made in workplaces for employees and customers. The principles all return to:</p><ul><li>Preparation</li><li>Identification</li><li>Mitigations</li><li>Review</li></ul><p>It is, however, a complex process that needs constant review and discussion with a dedicated team. An effective threat model includes:</p><ul><li>Threat intelligence</li><li>Asset identification</li><li>Mitigation capabilities</li><li>Risk assessment</li></ul><p>To help with this, there are frameworks such as <strong>STRIDE </strong>(<strong>S</strong>poofing identity,<strong> T</strong>ampering with data,<strong> R</strong>epudiation threats,<strong> I</strong>nformation disclosure, <strong>D</strong>enial of Service and<strong> E</strong>levation of privileges) and <strong>PASTA</strong> (<strong>P</strong>rocess for <strong>A</strong>ttack <strong>S</strong>imulation and <strong>T</strong>hreat <strong>A</strong>nalysis) infosec never tasted so good!. Let’s detail STRIDE below. STRIDE, authored by two Microsoft security researchers in 1999 is still very relevant today. STRIDE includes six main principles, which I have detailed in the table below:</p><p>Answer the questions below</p><blockquote>What model outlines “Spoofing”?</blockquote><p><strong><em>Ans=Stride</em></strong></p><blockquote><em>What does the acronym “IR” stand for?</em></blockquote><p><strong><em>Ans=incident response</em></strong></p><blockquote><em>You are tasked with adding some measures to an application to improve the integrity of data, what STRIDE principle is this?</em></blockquote><p><em>Ans=Tampering</em></p><blockquote>An attacker has penetrated your organisation’s security and stolen data. It is your task to return the organisation to business as usual. What incident response stage is this?</blockquote><p>Ans=Recovery</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=776f7373bd15" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Pentesting Fundamentals TryHackMe]]></title>
            <link>https://mohammadaassif.medium.com/pentesting-fundamentals-tryhackme-a95ed0a3d9bc?source=rss-29926d996499------2</link>
            <guid isPermaLink="false">https://medium.com/p/a95ed0a3d9bc</guid>
            <category><![CDATA[pentesting]]></category>
            <category><![CDATA[penetration-testing]]></category>
            <category><![CDATA[tryhackme]]></category>
            <category><![CDATA[tryhackme-walkthrough]]></category>
            <category><![CDATA[tryhackme-writeup]]></category>
            <dc:creator><![CDATA[Mohammadaassif]]></dc:creator>
            <pubDate>Mon, 03 Jan 2022 11:21:24 GMT</pubDate>
            <atom:updated>2022-01-03T11:21:24.135Z</atom:updated>
            <content:encoded><![CDATA[<p>Learn the important ethics and methodologies behind every pentest</p><p>A new interesting topic is Pentesting Fundamentals and what are things inside these topics, let try this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*L8igNNwiczGeNDOixSTRTQ.png" /></figure><blockquote><strong>Task 1 What is Penetration Testing?</strong></blockquote><p>Before teaching you the technical hands-on aspects of ethical hacking, you’ll need to understand more about what a penetration tester’s job responsibilities are and what processes are followed in performing pentests (finding vulnerabilities in a client&#39;s application or system).</p><p>The importance and relevancy of cybersecurity are ever-increasing and can be in every walk of life. News headlines fill our screens, reporting yet another hack or data leak.</p><p>Cybersecurity is relevant to all people in the modern world, including a strong password policy to protect your emails or to businesses and other organizations needing to protect both devices and data from damages.</p><p>A Penetration test or pentest is an ethically-driven attempt to test and analyze the security defenses to protect these assets and pieces of information. A penetration test involves using the same tools, techniques, and methodologies that someone with malicious intent would use and is similar to an audit.</p><p>According to<a href="https://www.securitymagazine.com/articles/87787-hackers-attack-every-39-seconds"> Security Magazine</a>, a cybersecurity industry magazine, there are over 2,200 cyber attacks every day — 1 attack every 39 seconds.</p><p><em>Answer the questions below</em></p><p><em>Read me!</em></p><p>No Answer Needed</p><blockquote><strong>Task 2 Penetration Testing Ethics</strong></blockquote><p>The battle of legality and ethics in cybersecurity, let alone penetration testing is always controversial. Labels like “hacking” and “hacker” often hold negative connotations, especially in pop culture, thanks to a few bad apples. The idea of legally gaining access to a computer system is a challenging concept to grasp — after all, what makes it legal exactly?</p><p>Recall that a penetration test is an <strong>authorized audit</strong> of a computer system’s security and defenses as agreed by the owners of the systems. The legality of penetration is pretty clear-cut in this sense; anything that falls outside of this agreement is deemed unauthorized.</p><p>Before a penetration test starts, a formal discussion occurs between the penetration tester and the system owner. Various tools, techniques, and systems to be tested are agreed on. This discussion <strong>forms the scope of the penetration testing agreement</strong> and will determine the course the penetration test takes.</p><p>Companies that provide penetration testing services are held against legal frameworks and industry accreditation. For example, the National Cyber Security Centre (NCSC) has the CHECK accreditation scheme in the UK. This check means that only <em>“[CHECK] approved companies can conduct authorized penetration tests of public sector and CNI systems and networks.” (NCSC).</em></p><p>Ethics is the moral debate between right and wrong; where an action may be legal, it may go against an individual’s belief system of right and wrong.</p><p>Penetration testers will often be faced with potentially morally questionable decisions during a penetration test. For example, they are gaining access to a database and being presented with potentially sensitive data. Or they are, perhaps, performing a phishing attack on an employee to test an organization’s human security. If that action has been agreed upon during the initial stages, it is legal — however ethically questionable.</p><p>Hackers are sorted into three hats, where their ethics and motivations behind their actions determine what hat category they are placed into. Let’s cover these three in the table below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*FIxkRzycplOjpPGRfqkvKQ.png" /></figure><p><strong>Rules of Engagement (ROE)</strong></p><p>The ROE is a document that is created at the initial stages of a penetration testing engagement. This document consists of three main sections (explained in the table below), which are ultimately responsible for deciding how the engagement is carried out. The SANS institute has a great example of this document which you can view online <a href="https://sansorg.egnyte.com/dl/bF4I3yCcnt/?">here</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*zpBwj9DQDUrfA2bxAEI1Ew.png" /></figure><p><em>Answer the questions below</em></p><blockquote><strong>You are given permission to perform a security audit on an organization; what type of hacker would you be?</strong></blockquote><p><em>Ans=White Hat</em></p><blockquote><strong><em>You attack an organization and steal their data, what type of hacker would you be?</em></strong></blockquote><p><em>Ans=Black Hat</em></p><blockquote><strong>What document defines how a penetration testing engagement should be carried out?</strong></blockquote><p><em>Ans=Rules of Engagement</em></p><blockquote><strong>Task 3 Penetration Testing Methodologies:</strong></blockquote><p>Penetration tests can have a wide variety of objectives and targets within scope. Because of this, no penetration test is the same, and there are no one-case fits all as to how a penetration tester should approach it.</p><p>The steps a penetration tester takes during an engagement is known as the methodology. A practical methodology is a smart one, where the steps taken are relevant to the situation at hand. For example, having a methodology that you would use to test the security of a web application is not practical when you have to test the security of a network.</p><p>Before discussing some different industry-standard methodologies, we should note that all of them have a general theme of the following stages:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xVNzUCN_XY6IV1ZLPLxF9w.png" /></figure><p><strong>OSSTMM</strong></p><p><a href="https://www.isecom.org/OSSTMM.3.pdf">The Open Source Security Testing Methodology Manual</a> provides a detailed framework of testing strategies for systems, software, applications, communications and the human aspect of cybersecurity.</p><p>The methodology focuses primarily on how these systems, applications communicate, so it includes a methodology for:</p><ol><li><strong>Telecommunications (phones, VoIP, etc.)</strong></li><li>Wired Networks</li><li>Wireless communications</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9iY7ZPAr3b0LRl13d3CEgg.png" /></figure><p><strong>OWASP</strong></p><p>The “<a href="https://owasp.org/">Open Web Application Security Project</a>” framework is a community-driven and frequently updated framework used solely to test the security of web applications and services.</p><p>The foundation regularly <a href="https://owasp.org/www-project-top-ten/2017/">writes reports</a> stating the top ten security vulnerabilities a web application may have, the testing approach, and remediation.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fEg-VK-PiMRkR1DXCrm7zQ.png" /></figure><p><strong>NIST Cybersecurity Framework 1.1</strong></p><p>The<a href="https://www.nist.gov/cyberframework"> NIST Cybersecurity Framework </a>is a popular framework used to improve an organisations cybersecurity standards and manage the risk of cyber threats. This framework is a bit of an honourable mention because of its popularity and detail.</p><p>The framework provides guidelines on security controls &amp; benchmarks for success for organisations from critical infrastructure (power plants, etc.) all through to commercial. There is a limited section on a standard guideline for the methodology a penetration tester should take.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*X4l9n7KtQ1wOqbhPc2Sv2Q.png" /></figure><p><strong>NCSC CAF</strong></p><p>The <a href="https://www.ncsc.gov.uk/collection/caf/caf-principles-and-guidance">Cyber Assessment Framework</a> (CAF) is an extensive framework of fourteen principles used to assess the risk of various cyber threats and an organisation’s defences against these.</p><p>The framework applies to organisations considered to perform “vitally important services and activities” such as critical infrastructure, banking, and the likes. The framework mainly focuses on and assesses the following topics:</p><ul><li>Data security</li><li>System security</li><li>Identity and access control</li><li>Resiliency</li><li>Monitoring</li><li>Response and recovery planning</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dIrvrpfatbpdMcwEtfzc8w.png" /></figure><p><em>Answer the questions below</em></p><blockquote><strong>What stage of penetration testing involves using publicly available information?</strong></blockquote><p><em>Ans=Information Gathering</em></p><blockquote><strong>If you wanted to use a framework for pentesting telecommunications, what framework would you use? Note: We’re looking for the acronym here and not the full name.</strong></blockquote><p><em>Ans=OSSTMM</em></p><blockquote><strong>What framework focuses on the testing of web applications?</strong></blockquote><p>Ans=OWASP</p><blockquote><strong>Task 4 Black box, White box, Grey box Penetration Testing</strong></blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*HOIqzhFvS_fQEyss.png" /></figure><p>There are three primary scopes when testing an application or service. Your understanding of your target will determine the level of testing that you perform in your penetration testing engagement. In this task, we’ll cover these three different scopes of testing.</p><p><strong>Black-Box Testing</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/210/0*xxhrdagPSoWuOJfe.png" /></figure><p>This testing process is a high-level process where the tester is not given any information about the inner workings of the application or service.</p><p>The tester acts as a regular user testing the functionality and interaction of the application or piece of software. This testing can involve interacting with the interface, i.e. buttons, and testing to see whether the intended result is returned. No knowledge of programming or understanding of the programme is necessary for this type of testing.</p><p>Black-Box testing significantly increases the amount of time spent during the information gathering and enumeration phase to understand the attack surface of the target.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/294/0*oq3CzFgjckPhjMNc.png" /></figure><p><strong>Grey-Box Testing</strong></p><p>This testing process is the most popular for things such as penetration testing. It is a combination of both black-box and white-box testing processes. The tester will have some <strong>limited </strong>knowledge of the internal components of the application or piece of software. Still, it will be interacting with the application as if it were a black-box scenario and then using their knowledge of the application to try and resolve issues as they find them.</p><p>With Grey-Box testing, the limited knowledge given saves time, and is often chosen for extremely well-hardened attack surfaces.</p><p><strong>White-Box Testing</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/220/0*VZkRx2p_Qu4sW56h.png" /></figure><p>This testing process is a low-level process usually done by a software developer who knows programming and application logic. The tester will be testing the internal components of the application or piece of software and, for example, ensuring that specific functions work correctly and within a reasonable amount of time.</p><p>The tester will have <strong>full </strong>knowledge of the application and its expected behaviour and is much more time consuming than black-box testing. The full knowledge in a White-Box testing scenario provides a testing approach that guarantees the entire attack surface can be validated.</p><p><strong><em>Answer the questions below</em></strong></p><blockquote><strong>You are asked to test an application but are not given access to its source code — what testing process is this?</strong></blockquote><p><em>Ans=Black Box</em></p><blockquote><strong>You are asked to test a website, and you are given access to the source code — what testing process is this?</strong></blockquote><p><em>Ans=White Box</em></p><blockquote><strong>Task 5 Practical: ACME Penetration Test</strong></blockquote><p>ACME has approached you for an assignment. They want you to carry out the stages of a penetration test on their infrastructure. View the site (by clicking the green button on this task) and follow the guided instructions to complete this exercise.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/651/1*wryGMHjscZECW8-9Dc8DpA.png" /></figure><p>We want to follow some steps to get the flag.</p><p>Click Next and we move on to the information gathering step</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/436/1*Hjf9j-xGog1LaObLnV3vBw.png" /></figure><p>One person, the Linkedin profile is shown here with email disclosed</p><p>After the enumeration step, I collected their IP and made a scan</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/940/1*LwBlFEfbKc7ttRp1RYmcyA.png" /></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/934/1*zoLX97iIqS9FPfDXsTp9PA.png" /></figure><p><em>Answer the questions below</em></p><blockquote><strong>Complete the penetration test engagement against ACME’s infrastructure.</strong></blockquote><p>Ans=<em>THM{PENTEST_COMPLETE}</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a95ed0a3d9bc" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Kioptrix: Level 1 (#1) Walkthrough]]></title>
            <link>https://mohammadaassif.medium.com/kioptrix-level-1-1-walkthrough-771065787014?source=rss-29926d996499------2</link>
            <guid isPermaLink="false">https://medium.com/p/771065787014</guid>
            <category><![CDATA[hackthebox]]></category>
            <category><![CDATA[writing]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[Mohammadaassif]]></dc:creator>
            <pubDate>Wed, 17 Nov 2021 11:44:58 GMT</pubDate>
            <atom:updated>2021-11-17T12:58:07.369Z</atom:updated>
            <content:encoded><![CDATA[<p><a href="https://www.vulnhub.com/"><strong>Vulnhub</strong></a> is a platform that provides VM(virtual machine) images, which are vulnerable by design and help to gain practical hands-on experience in Pentesting.</p><p><strong>Kioptrix </strong>is a series of CTF(Capture The Flag) like VM’s, where need to gain root privileges on the machine. Kioptrix is a boot2rooot machine.</p><p>Link to the image of Kioptrix file:</p><blockquote>https://www.vulnhub.com/entry/kioptrix-level-1-1,22/</blockquote><h3>Enumeration:</h3><p>So, now we need to know the Internal IP address of the Kioptrix machine so we the command in the terminal</p><blockquote>netdiscover -r 192.168.231.0/24</blockquote><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*sGzrwCTfXZptD-6oSoz1BA.png" /><figcaption>The highlighted part is our Kioptrix machine</figcaption></figure><h3>Nmap Scan:</h3><blockquote>nmap -sS -T4 -A -p- 192.168.231.1</blockquote><p>┌──(kali㉿kali)-[~/VulHub/VulnHubKioptrixLevel1]<br>└─$ sudo nmap -sS -T4 -A -p- 192.168.231.1 <br>[sudo] password for kali: <br>Starting Nmap 7.92 ( <a href="https://nmap.org/">https://nmap.org</a> ) at 2021–11–15 12:47 EST<br>Warning: 192.168.231.1 giving up on port because retransmission cap hit (6).<br>Stats: 0:01:04 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 0.47% done<br>Stats: 0:01:58 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 1.07% done; ETC: 15:30 (2:40:47 remaining)<br>Stats: 0:08:25 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 4.98% done; ETC: 15:32 (2:36:11 remaining)<br>Stats: 0:26:46 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 16.77% done; ETC: 15:26 (2:11:42 remaining)<br>Stats: 0:41:06 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 25.75% done; ETC: 15:26 (1:57:52 remaining)<br>Stats: 0:52:06 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 32.47% done; ETC: 15:27 (1:47:53 remaining)<br>Stats: 1:12:30 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 45.29% done; ETC: 15:27 (1:27:18 remaining)<br>Stats: 1:19:55 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 50.02% done; ETC: 15:27 (1:19:36 remaining)<br>Stats: 1:31:04 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 57.07% done; ETC: 15:27 (1:08:19 remaining)<br>Stats: 1:45:18 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 65.91% done; ETC: 15:27 (0:54:21 remaining)<br>Stats: 1:57:09 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 72.94% done; ETC: 15:28 (0:43:23 remaining)<br>Stats: 2:02:41 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 76.28% done; ETC: 15:28 (0:38:05 remaining)<br>Stats: 2:07:51 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 79.28% done; ETC: 15:28 (0:33:21 remaining)<br>Stats: 2:22:32 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 88.24% done; ETC: 15:29 (0:18:58 remaining)<br>Stats: 2:33:45 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 94.98% done; ETC: 15:29 (0:08:07 remaining)<br>Stats: 2:38:34 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 97.85% done; ETC: 15:29 (0:03:28 remaining)<br>Stats: 2:46:05 elapsed; 0 hosts completed (1 up), 1 undergoing SYN Stealth Scan<br>SYN Stealth Scan Timing: About 99.99% done; ETC: 15:33 (0:00:01 remaining)<br>Nmap scan report for 192.168.231.1<br>Host is up (0.0016s latency).<br>Not shown: 51155 filtered tcp ports (no-response), 14368 closed tcp ports (reset)<br>PORT STATE SERVICE VERSION<br>139/tcp open netbios-ssn Microsoft Windows netbios-ssn<br>445/tcp open microsoft-ds?<br>903/tcp open ssl/vmware-auth VMware Authentication Daemon 1.10 (Uses VNC, SOAP)<br>913/tcp open vmware-auth VMware Authentication Daemon 1.0 (Uses VNC, SOAP)<br>1536/tcp open msrpc Microsoft Windows RPC<br>1537/tcp open msrpc Microsoft Windows RPC<br>1538/tcp open msrpc Microsoft Windows RPC<br>1539/tcp open msrpc Microsoft Windows RPC<br>1540/tcp open msrpc Microsoft Windows RPC<br>1547/tcp open msrpc Microsoft Windows RPC<br>5040/tcp open unknown<br>7880/tcp open ssl/pss?<br>| tls-alpn: <br>|_ http/1.1<br>| fingerprint-strings: <br>| DNSStatusRequestTCP, DNSVersionBindReqTCP, Help, Kerberos, LANDesk-RC, LDAPBindReq, LDAPSearchReq, LPDString, RPCCheck, RTSPRequest, SIPOptions, SMBProgNeg, SSLSessionReq, TLSSessionReq, TerminalServerCookie, X11Probe: <br>| HTTP/1.1 400 Bad Request<br>| FourOhFourRequest, HTTPOptions: <br>| HTTP/1.1 404 Not Found<br>| Content-Type: text/plain<br>| Strict-Transport-Security: max-age=31536000; includeSubdomains<br>| X-Frame-Options: SAMEORIGIN<br>| X-Content-Type-Options: nosniff<br>| Connection: close<br>| Date: Mon, 15 Nov 2021 20:36:52 GMT<br>| Found<br>| GetRequest: <br>| HTTP/1.1 404 Not Found<br>| Content-Type: text/plain<br>| Strict-Transport-Security: max-age=31536000; includeSubdomains<br>| X-Frame-Options: SAMEORIGIN<br>| X-Content-Type-Options: nosniff<br>| Connection: close<br>| Date: Mon, 15 Nov 2021 20:36:51 GMT<br>|_ Found<br>|_ssl-date: TLS randomness does not represent time<br>| ssl-cert: Subject: commonName=localhost/organizationName=Acunetix Ltd<br>| Subject Alternative Name: DNS:localhost<br>| Not valid before: 2021–07–01T06:51:13<br>|_Not valid after: 2031–06–29T06:51:13<br>1 service unrecognized despite returning data. If you know the service/version, please submit the following fingerprint at <a href="https://nmap.org/cgi-bin/submit.cgi?new-service">https://nmap.org/cgi-bin/submit.cgi?new-service</a> :<br>SF-Port7880-TCP:V=7.92%T=SSL%I=7%D=11/15%Time=6192C4E4%P=x86_64-pc-linux-g<br>SF:nu%r(GetRequest,F8,”HTTP/1\.1\x20404\x20Not\x20Found\r\nContent-Type:\x<br>SF:20text/plain\r\nStrict-Transport-Security:\x20max-age=31536000;\x20incl<br>SF:udeSubdomains\r\nX-Frame-Options:\x20SAMEORIGIN\r\nX-Content-Type-Optio<br>SF:ns:\x20nosniff\r\nConnection:\x20close\r\nDate:\x20Mon,\x2015\x20Nov\x2<br>SF:02021\x2020:36:51\x20GMT\r\n\r\n404\x20Not\x20Found\n”)%r(HTTPOptions,F<br>SF:8,”HTTP/1\.1\x20404\x20Not\x20Found\r\nContent-Type:\x20text/plain\r\nS<br>SF:trict-Transport-Security:\x20max-age=31536000;\x20includeSubdomains\r\n<br>SF:X-Frame-Options:\x20SAMEORIGIN\r\nX-Content-Type-Options:\x20nosniff\r\<br>SF:nConnection:\x20close\r\nDate:\x20Mon,\x2015\x20Nov\x202021\x2020:36:52<br>SF:\x20GMT\r\n\r\n404\x20Not\x20Found\n”)%r(RTSPRequest,1C,”HTTP/1\.1\x204<br>SF:00\x20Bad\x20Request\r\n\r\n”)%r(RPCCheck,1C,”HTTP/1\.1\x20400\x20Bad\x<br>SF:20Request\r\n\r\n”)%r(DNSVersionBindReqTCP,1C,”HTTP/1\.1\x20400\x20Bad\<br>SF:x20Request\r\n\r\n”)%r(DNSStatusRequestTCP,1C,”HTTP/1\.1\x20400\x20Bad\<br>SF:x20Request\r\n\r\n”)%r(Help,1C,”HTTP/1\.1\x20400\x20Bad\x20Request\r\n\<br>SF:r\n”)%r(SSLSessionReq,1C,”HTTP/1\.1\x20400\x20Bad\x20Request\r\n\r\n”)%<br>SF:r(TerminalServerCookie,1C,”HTTP/1\.1\x20400\x20Bad\x20Request\r\n\r\n”)<br>SF:%r(TLSSessionReq,1C,”HTTP/1\.1\x20400\x20Bad\x20Request\r\n\r\n”)%r(Ker<br>SF:beros,1C,”HTTP/1\.1\x20400\x20Bad\x20Request\r\n\r\n”)%r(SMBProgNeg,1C,<br>SF:”HTTP/1\.1\x20400\x20Bad\x20Request\r\n\r\n”)%r(X11Probe,1C,”HTTP/1\.1\<br>SF:x20400\x20Bad\x20Request\r\n\r\n”)%r(FourOhFourRequest,F8,”HTTP/1\.1\x2<br>SF:0404\x20Not\x20Found\r\nContent-Type:\x20text/plain\r\nStrict-Transport<br>SF:-Security:\x20max-age=31536000;\x20includeSubdomains\r\nX-Frame-Options<br>SF::\x20SAMEORIGIN\r\nX-Content-Type-Options:\x20nosniff\r\nConnection:\x2<br>SF:0close\r\nDate:\x20Mon,\x2015\x20Nov\x202021\x2020:36:52\x20GMT\r\n\r\n<br>SF:404\x20Not\x20Found\n”)%r(LPDString,1C,”HTTP/1\.1\x20400\x20Bad\x20Requ<br>SF:est\r\n\r\n”)%r(LDAPSearchReq,1C,”HTTP/1\.1\x20400\x20Bad\x20Request\r\<br>SF:n\r\n”)%r(LDAPBindReq,1C,”HTTP/1\.1\x20400\x20Bad\x20Request\r\n\r\n”)%<br>SF:r(SIPOptions,1C,”HTTP/1\.1\x20400\x20Bad\x20Request\r\n\r\n”)%r(LANDesk<br>SF:-RC,1C,”HTTP/1\.1\x20400\x20Bad\x20Request\r\n\r\n”);<br>MAC Address: 00:50:56:C0:00:08 (VMware)<br>Device type: general purpose<br>Running (JUST GUESSING): Microsoft Windows 10|Longhorn|7|2008|8.1|Vista|Embedded Compact 7 (96%)<br>OS CPE: cpe:/o:microsoft:windows_10 cpe:/o:microsoft:windows cpe:/o:microsoft:windows_7 cpe:/o:microsoft:windows_server_2008:r2 cpe:/o:microsoft:windows_8 cpe:/o:microsoft:windows_8.1 cpe:/o:microsoft:windows_vista cpe:/o:microsoft:windows_embedded_compact_7<br>Aggressive OS guesses: Microsoft Windows 10 1709–1803 (96%), Microsoft Windows 10 1709–1909 (96%), Microsoft Windows Longhorn (95%), Microsoft Windows 7 or Windows Server 2008 R2 (93%), Microsoft Windows 10 10586–14393 (92%), Microsoft Windows 10 1507–1607 (92%), Microsoft Server 2008 R2 SP1 (92%), Microsoft Windows 7 Professional (92%), Microsoft Windows 7 SP0 — SP1, Windows Server 2008 SP1, Windows Server 2008 R2, Windows 8, or Windows 8.1 Update 1 (92%), Microsoft Windows 7 Ultimate (92%)<br>No exact OS matches for host (test conditions non-ideal).<br>Network Distance: 1 hop<br>Service Info: OS: Windows; CPE: cpe:/o:microsoft:windows</p><p>Host script results:<br>|_nbstat: NetBIOS name: LAPTOP-I4UUL2N1, NetBIOS user: &lt;unknown&gt;, NetBIOS MAC: 00:50:56:c0:00:08 (VMware)<br>| smb2-time: <br>| date: 2021–11–15T20:39:10<br>|_ start_date: N/A<br>| smb2-security-mode: <br>| 3.1.1: <br>|_ Message signing enabled but not required</p><p>TRACEROUTE<br>HOP RTT ADDRESS<br>1 1.57 ms 192.168.231.1</p><p>OS and Service detection performed. Please report any incorrect results at <a href="https://nmap.org/submit/">https://nmap.org/submit/</a> .<br>Nmap done: 1 IP address (1 host up) scanned in 10328.80 seconds</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=771065787014" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>