top of page
Writer's pictureotw

IP Camera Hacking: The FFmpeg Tool for Streaming Camera Video

Welcome back, aspiring cyberwarriors!


As you know, Hackers-Arise has been deeply involved in the cyberwar to help save Ukraine from the brutal Russian aggression. As part of that effort, we were asked by the Ukrainian military to hack IP cameras throughout Ukraine in order to spy on Russian activities.


As part of that task, we have developed a wealth of knowledge about these IP cameras and these use and abuse. One of the tools we have used in this regard is ffmeg (to learn more sign up for our upcoming IP Camera Hacking training). Although not technically a hacking tool, it can be used to view video streams from cameras you have accessed.


In previous articles, we have already shown you of the simpler techniques to gain access to a significant number of these online cameras. In this article, let’s take a look at the utility for handling streams from IP cameras—FFmpeg.


FFmpeg is one of the most important open-source tools for video and audio processing. The name comes from 'FF' for 'Fast Forward' and 'MPEG' for the Moving Picture Experts Group, which shows its original purpose as a fast video tool for MPEG formats. It is now capable of converting just about any video stream into video output format.


The project started in 2000 by Fabrice Bellard, who created it while working on his own video codec. What began as a simple tool for encoding and decoding video has grown into a powerful framework used in many applications, streaming services, and media tools around the world.


Installing ffmpeg


FFmpeg can be installed on most Linux distributions through their package managers. Here are the installation commands for Kali Linux:


kali > sudo apt update


kali > sudo apt install ffmpeg


To verify the installation:


kali > ffmpeg -version



ffmpeg version


Reading RTSP Streams


Combining RTSP with FFmpeg allows users to handle live media streams effectively. FFmpeg can decode RTSP/RTP streams from servers, process the media data, and save or transform it as needed. This combination is widely used in various applications, from live event broadcasting to security camera monitoring, due to its flexibility and broad support for different media formats and protocols.


The simplest way to connect to an RTSP stream is:


kali > ffmpeg -i rtsp://username:password@camera_ip:554/stream -c copy output.mp4


This command tells FFmpeg to capture a video stream from an RTSP source and save it as an MP4 file. The -i flag specifies the input stream, which in this case is an RTSP URL that includes the username, password, camera IP address, port, and the stream path. The -c copy option tells FFmpeg to copy the video and audio streams directly, without re-encoding, ensuring the process is fast. Finally, output.mp4 is the name of the file where the stream will be saved.


If you're experiencing connection issues, using TCP transport often helps:


kali> ffmpeg -rtsp_transport tcp -i


If you're experiencing connection issues, using TCP transport often helps:


kali> ffmpeg -rtsp_transport tcp -i rtsp://username:password@camera_ip:554/stream -c copy output.mp4


This option forces FFmpeg to use TCP for the RTSP stream transport instead of the default UDP. TCP is more reliable because it ensures the delivery of all packets, which can be helpful in situations where the network might be unstable or if UDP packets are getting dropped.


Taking Screenshots from RTSP Streams


To capture a single frame from the stream:


kali> ffmpeg -rtsp_transport tcp -i rtsp://username:password@camera_ip:554/stream -frames:v 1 screenshot.jpg


If authentication is not configured, you can simply use the command:


kali> ffmpeg -rtsp_transport tcp -i rtsp://camera_ip:554/stream -frames:v 1 screenshot.jpg



Here we see a message that says we need to change the name of the screenshot to ensure it doesn’t conflict with an image sequence expectation. Let's edit our command:


kali> ffmpeg -rtsp_transport tcp -i rtsp://camera_ip:554/stream -frames:v 1 screenshot_%03d.jpg





kali> ffmpeg -rtsp_transport tcp -i rtsp://camera_ip:554/stream -vf "fps=1/10" -strftime 1 "screenshot-%Y%m%d-%H%M%S.jpg"



The option -vf "fps=1/10" in FFmpeg applies a video filter (-vf) that controls the frame rate of the video output. Specifically, "fps=1/10" means: capture 1 frame every 10 seconds.



Summary


IP camera hacking is not just for the voyeur. It can also have strategic and national security implications. With IP cameras all over the world, who ever has access to these cameras will have a leg up on reconnaissance and data on the target.


I hope this short article has provided you with an insight into the potential of FFmpeg, especially in the context of current cyber warfare, where access to security cameras can offer a significant advantage and insight into the enemy's plans.


If you want to learn more about camera hacking, check out the IP Camera Hacking course.

bottom of page