Kalyani Rajalingham – Linux Hint https://linuxhint.com Exploring and Master Linux Ecosystem Tue, 15 Dec 2020 22:06:49 +0000 en-US hourly 1 https://wordpress.org/?v=5.6.2 How to Convert Videos using FFMPEG in Ubuntu https://linuxhint.com/convert_videos_using_ffmpeg_ubuntu/ Tue, 15 Dec 2020 04:13:30 +0000 https://linuxhint.com/?p=81847

In the modern world, with YouTube and other social media apps as the mainstream way to view digital media, uploading videos has become a common practice. It has become so common, in fact, that creating and editing audio and video files have become the new normal in the span of only a few decades. There are obviously expensive tools out there that one can buy to fulfill one’s needs, but what if we could do this for free? What if a few lines of code could do almost any video-related task that you require?

Ffmpeg is a free and open-source video conversion, extraction, and editing tool that provides an answer to this question! What can ffmpeg not do? Almost nothing. The tasks that can be performed with the aid of ffmpeg include audio file conversion, video file conversion, photo conversion, image file extraction from video files, generating videos from image files, extracting audio from video, cropping videos and photos, trimming videos, re-sizing videos, boosting volume, and creating screen recordings.

Installing FFmpeg in Ubuntu

Ffmpeg does not come pre-installed in Ubuntu by default, so you will first have to install this program to use it. To complete the installation, you must be the root user. Next, type the following to install FFmpeg:

sudo apt-get install ffmpeg

The apt-get install command will work for all versions of Ubuntu except 14.04.

Audio Conversion

Converting an audio file’s filetype can be performed in a single line of code using the ffmpeg utility. In this case, you only need to pass two parameters: the name of the original file and the name of the new file. This command allows you to convert any file format to any other file format by automatically detecting the file types by name. As such, there is no need for additional code to specify the file types.

ffmpeg -i originial_file.mp3 converted_file.mp4

You can add your own file names and types to this line of code. This is only the basic syntax for usage.

Video Conversion

You can also convert video file types using ffmpeg. When inputting the command, all you need is the name of the original file and the name of the output file. The -i tag denotes the input file.

ffmpeg -i original_file.mp4 converted_file.webm

Photo Conversion

What is true for video and audio files applies to image files, as well. You can convert one photo format to another format quickly and easily with ffmpeg simply by using the syntax shown below:

ffmpeg -i original_file.jpg converted_file.png

Extract Image from Video File

Ffmpeg can also be used to extract images from video files. In other words, this program can take screenshots at precise times during a video and save the screenshots as a collection of image files. For example:

ffmpeg -i video.mp4 output_file.jpg

In this case, the -i tag depicts the video file from which the image file(s) will be extracted. However, we still have not given the program any specifications as to the image quality or screenshot timing. So, it is first necessary to specify these details before inputting the code.

If we write the following:

ffmpeg -i video.mp4 output_file%d.jpg

The %d value following the name of the output file represents a variable that you can customize according to the number of frames per second you would like to generate from the video. When the pictures are generated at one frame per second, each photo will be labeled output_file1.jpg; at two frames per second, output_file2.jpg; at three frames per second, output_file3.jpg; etc. If the movie has 35 frames per second, and it is one second long, then giving the %d variable a value of 1 will generate 35 photos.

Next, what if we want to capture the images at a certain frames-per-second rate? The fps value defines this in the ffmpeg syntax. To capture 1 frame per second, you would set the fps value equal to 1.

ffmpeg -i video.mp4 -vf fps=1 output_file%d.jpg

Likewise, by defining the fps value to 1/6000, the following command will generate 1 image per 6,000 seconds of video:

ffmpeg -i video.mp4 -vf fps=1/6000 output_file%6d.jpg

In the above command, the term %6d will generate a variable with six digits. The output files will be labeled as follows: output_file000001.jpg, output_file000002.jpg, etc.

Now, suppose that you do not want to capture all the frames. Instead, you want to be more selective and wish to capture a set number of images between two timeframes. Then, the syntax would look something like this:

ffmpeg -ss 00:00:01 -t 00:00:04 -i video.mp4 output_file%3d.jpg

This code will capture images, starting at 00:00:01, for 4 seconds. In other words, the image capturing will start at 00:00:01 and end at 00:00:05 in the video. As usual, the number in the name of the output file will have three digits (i.e., output_file001.jpg, output_file002.jpg, etc.).

Generate Video from Image Files

What if you want to do just the opposite and put images together to form a video? Ffmpeg comes to the rescue once again!

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p output_file.mp4

After reading the previous sections, you now know what the term img%03.png stands for – the source image files that to compile into the video. In this syntax, the -c:v tag represents the codec for the video, fps represents the frames per second value, and r represents the framerate of the output video.

Extract Audio from Video

What about extracting audio files from a video file? There are tools on the web that you can use to perform this task, but with ffmpeg, one line of code can do the job just as well.

ffmpeg -i video.mp4 -c:a libmp3lame -q:a 0 -map a output_file.mp3

In the above syntax, video.mp4 is the input video file and output_file.mp3 is the output audio file. The -map a tag takes the default audio stream and excludes any subtitles, c:a specifies the codec for the audio to be used, and q:a defines a variable bitrate for the audio.

If you would like to extract only a portion of the audio file from a video file, you can use the following syntax to do so. In the following code, only the section of audio from between 00:00:08 and 00:00:10 is extracted:

ffmpeg -i video.mp4 -ss 00:00:08 -t 00:00:10 -q:a 0 -c:a libmp3lame -q:a 0 -map a output_file.mp3

Obviously, there are many more details you can add, should you wish, but the above example is a great starting point.

Crop Videos and Photos

What if you want to crop videos? You can either take the time and money to find cropping software elsewhere, or you can use one line of code with ffmpeg to crop the video to size.

ffmpeg -i video.mp4 -filter:v "crop=w=width:h=height:x:y" output_file.mp4

For example:

ffmpeg -i video.mp4 -filter:v "crop=w=550:h=200:x=100:y=200" output_file.mp4

As an example, I took my own picture and tried to crop it with the following code:

ffmpeg -i minions.jpg -filter:v "crop=w=500:h=200" out.jpg

Trim Videos

Trimming video files requires cutting them from one specific time to another specific time. For example, cutting a video file into two or three segments would be trimming it. Once again, trimming video or audio files can be easily done using ffmpeg.

ffmpeg -i video.mp4 -ss 00:00:20 -t 00:00:10 -c:v h264 -c:a aac output_file.mp4

In this case, the -ss tag stands for start seeking, or the time at which to begin the trimming process. In the above command, we will start cutting or trimming at 00:00:20. The t tag stands for the duration of the clip. Here, the duration of the cut clip will be 10 seconds. Finally, the c:v tag is for the codec of the video used, while c:a is for the audio codec used.

Resize Video

Resizing videos is just as easy as trimming and cropping videos.

ffmpeg -i video.mp4 -vf scale=320:240 output_file.mp4

Alternatively, you can also do the following:

ffmpeg -i video.mp4 -vf scale="iw/1:ih/2" output_file.mp4

Here, the value iw defines input width, while ih defines input height. The latter will also scale it.

Boost Volume of Video

In this article, you have seen how to crop, trim, and convert video and image files, but what about boosting the volume of audio and video files?

ffmpeg -i video.mp3 -filter:a “volume=2” output_file.mp3

In the latter case, we are humbly asking ffmpeg to double the volume of the file.

Create Screen Recording

Recording your screen is a task that is frequently necessary to perform, whether it be for presentations, video sharing, or online meetings. Whatever the reason for recording your desktop, typically, you would need to run some kind of software to do so. Unlike costly alternatives, ffmpeg can do this for you for free!

ffmpeg -f gdigrab -framerate 30 -i desktop -c:v libx264 output_file.mp4 -f dshow -i audio="Stereo Mix (Realtek Audio)" output_file.mp4

In the above command, the -f tag represents the format of the video recording of your screen. Following the audio value, you will put in your audio source.

In addition, the following code will only grab the video of the screen recording, without any sound added:

ffmpeg -f gdigrab -framerate 30 -i desktop -c:v libx264 -qp 0 output.mp4

Conclusion

Overall, ffmpeg is an extremely useful program that allows you to accomplish quite a lot of things in a single line of code. You can buy expensive tools online to fulfill your editing needs, or you can try these functions out for free by installing the ffmpeg utility.

]]>
How to install and use THC Hydra? https://linuxhint.com/how-to-install-and-use-thc-hydra/ Sun, 13 Dec 2020 12:40:45 +0000 https://linuxhint.com/?p=80906 Passwords are the weakest links. If someone gets ahold of your password, it’s game over! As such, passwords are the most important security weaknesses. There are many tools that allow you to attempt username:password combinations throughout, however, none of them are as potent as THC Hydra. This is because it’s both rapid and offers a large number of protocols to brute force. In fact, it can deal with about 55 different protocols. Moreover, there are two versions of THC Hydra: a GUI version and a CLI version.

Installing THC Hydra

Download THC hydra from https://github.com/vanhauser-thc/thc-hydra.

Once downloaded, extract the files, and execute the following:

cd thc-hydra-master/
./configure
make
make install

If you’re using Ubuntu/Debian, type the following as well:

apt-get install libssl-dev libssh-dev libidn11-dev libpcre3-dev \
                libgtk2.0-dev libmysqlclient-dev libpq-dev libsvn-dev \
                firebird-dev libmemcached-dev libgpg-error-dev \
                libgcrypt11-dev libgcrypt20-dev

CLI Usage

Here, we examine how to use hydra with common protocols.

SSH/FTP/RDP/TELNET/MYSQL

One must remember that Hydra can deal with approximately 55 different protocols. These are but a few examples of the most dealt-with protocols, such as ssh, ftp, rdp, telnet, and mysql. However, the same principle applies to the remaining protocols.

In order to get Hydra to work with a protocol, you’ll need either a username (-l) or a list of usernames (-L), a list of passwords (a password file), and the target IP address associated with the protocol. You can add further parameters if you wish. For example, -V for verbosity.

hydra -l <username> -P <password> <protocol>://<ip>

Alternatively, you can also format it as follows:

hydra -l <username> -P <password file> -s <port> -V <ip> <protocol>

-l or -L: username or list of usernames to attempt
-P: password list
-s: port
-V: verbose
<protocol>: ftp/rdp/ssh/telnet/mysql/etc…
<ip>: ip address

For example, for FTP:

hydra -V -f -l <username> -P <password> ftp://&lt;ip>

Or

hydra -l <username> -P <password file> -s 21 -V &lt;ip> ftp

HTTP-GET-FORM

Depending on the type of request, GET or POST, you can use either http-get-form or http-post-form. Under the inspect element, you can figure out whether the page is a GET or POST. You can then use the http-get-form when attempting to find the password to a username:password combination on the web (for instance, a website).

hydra -l <username> -P <password> -V -f <ip> http-get-form “a:b:c:d”

-l or -L: username or list of usernames to attempt
-P: password list
-f : stop when the password is found
-V: verbose
a: login page
b: username/password combination
c: error message received if login fails
d: H=session cookie

For example, suppose we wish to hack DVWA (Damn Vulnerable Web Application). Once online using apache2, it should be at your local IP. In my case, it’s at http://10.0.2.15.

So, the:
<ip>: 10.0.2.15
a: /vulnerabilities/brute/

Next, we need b and c. So, let’s try to login with fake credentials (anything here will do). The site displays this message: “Username or password incorrect.” Therefore, we will use the message c:

c: username or password incorrect

So, b will be as follows:

b: username=^USER^&password=^PASS^&Login=Login#

Replace the credentials inputted with ^USER^ and ^PASS^. If this was a POST request, you would find this information under the inspect element > Request tab.

Next, under inspect element, copy the cookie. This will be d:

d: H=Cookie:PHPSESSID=3046g4jmq4i504ai0gnvsv0ri2;security=low

So, for example:

hydra -l admin -P /home/kalyani/rockyou.txt -V -f 10.0.2.15 http-get-form<br /><span style="color: #0000ff" data-darkreader-inline>/vulnerabilities/</span>brute/:username=^USER^&password=^PASS^&Login=Login<br />#:username or password incorrect:<br /> H=Cookie:PHPSESSID=3046g4jmq4i504ai0gnvsv0ri2;security=low”

When you run this, and if the password is in the list, then it will find it for you.

However, if this proves to be too much work for you, no need to stress out because there’s a GUI version as well. It is a lot simpler than the CLI version. The GUI version of THC hydra is called Hydra GTK.

Installing Hydra GTK

In Ubuntu, you can simply install Hydra GTK using the following command:

sudo apt-get install hydra-gtk -y

Once installed, you will need the following:

  1. A target or list of targets: This is the IP address of the protocol you wish to attack
  2. Port number: the port number associated with the protocol
  3. Protocol: ssh, ftp, mysql, etc…
  4. Username: either input a username or a list of usernames
  5. Password or Password list

Depending on whether you want to hack one or multiple targets, you can either input one or many targets into the target box. Suppose you’re attacking a single target, an SSH, located at 999.999.999.999 (a fake IP address, obviously). In the target box, you’d put 999.999.999.999, and in the port section, you’d put 22. Under the protocol, you’d put SSH. It would be advisable to tick the “be verbose” and the “show attempts” boxes as well. The “be verbose” box is equivalent to -v in THC Hydra, while the “show attempts” box is equivalent to -V in THC Hydra. The plus point about Hydra is that it can deal with a large number of protocols.

In the next tab, input the username you desire or a list of usernames (the location of the list of usernames in this case). For instance, in the “username list”, I would put “/home/kalyani/usernamelist.txt”. The same is true for passwords. The location of the password file is inputted in the box called “password list”. Once these have been filled in, the rest is easy. You can leave the tuning and specific tabs as is and click on the start button under the start tab.

Hydra GTK is a lot easier to use than THC Hydra, even though they are the same thing. Whether you use THC Hydra or Hydra GTK, both are great tools to crack passwords. The problem typically encountered will come in the form of the password list used. You can obviously use other programs such as crunch and wordlist generators to tailor your password list to your liking. However, if you can also tailor the password list to your use, Hydra can become a very powerful ally.

Happy Hacking!

]]>