How to record (capture) with rtmpdump by pstranger

This is one of the “Tips and Tricks” written by pstranger. I found it very interesting and decided to re-post it here.

Original post can be found here.

How to record (capture) with rtmpdump.

For example I want to record (capture) live broadcast of tv:

http://rt.com/on-air/

I run:

tcpdump -ieth0 -nn -A | grep -e"rtmp" -e"connect" -e"play" > rt.txt

Sometime it’s useful to add -e"app" option in grep in spite of it can capture a lot of garbage.

I open this page, waiting broadcasting and 3-4 times reload page again to fill buffer of output file (rt.txt in this case).

I always capture packets in file (sometimes output on console may be wrong or not full).

Next I open rt.txt and looking for piece of text like this:

connect.?..........app...live..flashVer...LNX 10,1,82,76..swfUrl..'http://rt.com/s/swf/player5.4.
viral.swf..tcUrl...rtmp://fm.s5.visionip.tv/live..fpad....capabilities.@m........audioCodecs.@.........videoCodecs.@o.......
videoFunction.?.........pageUrl....http://rt.com/on-air/..objectEncoding...........
.....T93.../...........play.............RT_3

and build command in accordance with this manual:

http://rtmpdump.mplayerhq.hu/rtmpdump.1.html

You should be careful with dots in options (turn on your brain and use cut and try method) like in this example:
rtmp://fm.s5.visionip.tv should be rtmp://fms5.visionip.tv

Here is example of 60 sec record:

rtmpdump -r rtmp://fms5.visionip.tv/live
-a live
-y RT_3
-W http://rt.com/s/swf/player5.4.viral.swf
-p http://rt.com/on-air/
-f "LNX 10,1,82,76"
-o ~/russia_tooday.flv
-B 60

The simple command:

rtmpdump -r rtmp://fms5.visionip.tv/live
-y RT_3
-o ~/russia_tooday.flv
-B 60

also works but they recommend to use full syntax.

Blumberg TV

http://www.bloomberg.com/tv/

connect.?..........app...live..flashVer...LNX 10,1,82,76..swfUrl..Jhttp://cdn.
gotraffic.net/v/20110210_153738//flash/Bloomber.gMediaPlayer.swf..tcUrl..*rtmpt://cp87869.live.edgefcs.net:1935/live..fpad....capabilities.@m......
..audioCodecs.@.........video.Codecs.@o.......
videoFunction.?.........pageUrl...http://www.bloomberg.com/tv/..objectEncoding.@.........

play………….us_300@21006

rtmpdump -r rtmpt://cp87869.live.edgefcs.net:1935/live
-a live
-y us_300@21006
-W http://cdn.gotraffic.net/v/20110210_153738//flash/BloombergMediaPlayer.swf
-p http://www.bloomberg.com/tv/
-f "LNX 10,1,82,76"
-o ~/bloomberg.flv
-B 60
--live

Video on demand:

Deutsche Welle

http://www.dw-world.de/dw/0,,4756,00.html

Program Euromaxx (with Roxette):

connect.?..........app..
a4337/dwwod1/..flashVer...LNX 10,1,82,76..swfUrl..;http://mediacenter.dw-world.de/player/flash/media.player.swf..tcUrl..*rtmpt://tvone.fcod.llnwd.net/a433
7/dwwod1/..fpad....capabilities.@m........audioCodecs.@.........videoCodecs..@o.......
videoFunction.?.........pageUrl..Khttp://mediacenter.dw-world.de/english/video/#!/72620/euromaxx/Program=7555..object.Encoding.@.........
................closeStream.....................H.....P.....play............;mp4:dwtv_video/flv/eme/emagen090211-euromaxx01ep_sd_avc.mp4

rtmpdump -r rtmpt://tvone.fcod.llnwd.net/a4337/dwwod1/
-a a4337/dwwod1/
-y mp4:dwtv_video/flv/eme/emagen090211-euromaxx01ep_sd_avc.mp4
-W http://mediacenter.dw-world.de/player/flash/media.player.swf
-p rtmpt://tvone.fcod.llnwd.net/a4337/dwwod1/
-f "LNX 10,1,82,76"
-o ~/euromaxx.flv

P.S. Some servers do not talk on this language and it’s hard to get options for rtmpdump in such a way.

Thanks pstranger.

Let me just add that tcpdump and rtmpdump are not in the system by default and can be installed using

apt-get install --yes tcpdump rtmpdump

command as root. I will add here as well that tcpdump commands must be issued as root as well. Don’t forget to pass the correct interface to tcpdump.

Andy

Tightening security for SSH Server…

Hi all.

When I was setting up my server while back I have noticed 100’s of entries in my:

/var/log/auth.log

about failed log in attempts from various IP’s with various logins. I wondered what it was until I saw this:

Cracking SSH Logins Video

Conclusions? There is at least one (wishful thinking…) bot out there which will scan the entire range of IP’s for opened port 22 and will use some brute-force tool trying to crack it. Now that’s not a very positive conclusion for all the SSH users…

What can be done about this? There are 3 thing You can do.

A) Forbid the root’s log in – that’s a default option in PCLinuxOS.
B) Install fail2ban via synaptic
C) Change the SSH port from 22 to something above the 10100

I use all of them.

Forbidding the root’s log in is a must. Root is the only 100% sure login on every Linux based system. Attacker don’t have to guess it. It’s there for sure. Now all he has to do is to guess the password. Blocking root’s log in will make him to guess Your user login and password. This is more difficult for them and that’s the whole point.

PCLinuxOS uses interesting settings in its config files. If You look at the file:

/etc/ssh/denyusers

You will see that it contains a word root.

This setting is blocking all the attempts of root log in to Your SSH server and yet allows You to use su command for Your convenience. Why? Even if attacker knows root password he will not be able to log in. However user who is logged into the system via SSH can raise its privileges using su command. This is secured and comfortable in the same time. Sometimes root’s privileges are necessary so PCLinuxOS does allows You to gain root and yet You have to log in as user and know the root’s password to gain full control over the machine.

Another method – Fail2ban – (You will find it in our repositories) will add a firewall rule to block all the attempts of connecting to the SSH port for a machine that unsuccessfully tried to log in X amount of times in Y time period. Example – xxx.yyy.zzz.uuu machine tried to log in with logins jack, ann, mark 3 times in 20 minutes period so it got banned for an hour.

You can set X and Y in the fail2ban config file:

/etc/fail2ban/jail.conf

and if You have local e-mail server configured – fail2ban will send You a message with notifications about new events.

Fail2ban will protect not only SSH but also FTP, SFTP, and other protocols that are using authentication. Very cool tool.

Another thing that You can do is to change the port of the SSH server. Here is how its done.

Changing Port For SSH Server Video

Why changing the port and why above 10100? Default port for SSH is 22. All the script kiddies aka skiddies will use that port in their bots. Even if script kiddie is smart and will scan Your IP with port scanner like nmap – by default he will scan first 10000 ports only. Setting up SSH above that will cause the port scanner to find ZIP, ZERO, NADA, BIG BOBKAS. Even if skiddy is smarter then that and he will scan all the 65k ports the open port will be shown as unknown service. He would have to add few more switches to the nmap to find out that its a SSH server. Skiddies are mostly lazy and they are going after the easy prey. Making it just that little bit more difficult can be a blessing for Your security.

So far those three steps are what I have learned about securing SSH server. Maybe in the future if I will learn something new I will add it in a new post.

Remember that even the weakest protection is better then no protection at all.

Regards.

Andy

Hey! I have port XXX opened! What is using it?

Hi all.

I was messing around on my server sometime ago and I have nmap-ed myself and noticed port XXX opened. I knew I have something running on the server from the lan side and I couldn’t remember what it was!

So I googled a bit and came up with this command:

netstat -tlnp | grep XXX

It must be run as root. If You run it as user the process is root owned – You wont be given the access to the information about the process.

Lets say the open port is 22… I know its SSH but lets say I “forgot”.

Example.

As You can see user failed, but root got detailed information process and its id number.

Sometimes You need to skip some of the switches in the command like t for example coz process is not using TCP but UDP.

Thats all – simple as that…

Andy

Passwordless SSH authentication. Using authentication keys.

Hi all.

It would drive me bananas if I would have to remember password for each and every of my shell accounts… leaving the account with no password is unacceptable however from the security point of view. Solution? Use authentication keys – public and private.

How to get them? Its very easy.

Open terminal on Your local machine.

Use command:

ssh-keygen -t rsa

When asked for:

Enter file in which to save the key (/home/mylogin/.ssh/id_rsa):

Press [ENTER].

Enter passphrase (empty for no passphrase)

Press [ENTER].

Enter same passphrase again:

Press [ENTER].

Passwordless SSH - work in progress...

[mylogin@myhostname ~]$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/mylogin/.ssh/id_rsa):
Created directory '/home/mylogin/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/mylogin/.ssh/id_rsa.
Your public key has been saved in /home/mylogin/.ssh/id_rsa.pub.
The key fingerprint is:
xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:xx:7b mylogin@myhostname.local
The key's randomart image is:
+--[ RSA 2048]----+

RANDOM ART

BLAH

BLAH

+-----------------+
[mylogin@myhostname ~]$

SO what You did so far? You have generated a pair of authenticating keys. Private – which is for Your eyes only and public which can be shown to anyone.

Keys are placed in those two files:

Your identification has been saved in /home/mylogin/.ssh/id_rsa. <<< PRIVATE KEY

Your public key has been saved in /home/mylogin/.ssh/id_rsa.pub. <<< PUBLIC KEY

Run this command:

cat /home/mylogin/.ssh/id_rsa.pub

Lets say it spits out this:

ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwMplVCQ+Y33n4kTVAy0nQReGD1GXmM28/D4STzNwdEthSY9UGIBduS1dGIVLWZYnphZglNFHE0Z0eIqgo0o0GDdtxqqsV20Zq/KV2nN+E8axlin4mRNuc/HgczxXkOtqkS9/yENOq8XN7XPD57kC+v+017GGNh139WiHbw+Myn9/mamjhmjywcnReiIbrYZnlgWJjpCXJCEoQZczypUyzB6x7aUMlenGdZwtfXCEPP709VSP9lUzanosY6bq1XoF6ravL2fulAvuNQVyxL7nfqJsio0JCI400WEJYm1et8Eg2vVEtIgIEKS7DZou/DR++/QgXpQas6yxaaHQ6Q0wt mylogin@myhostname.local

Now copy this ^^^ ENTIRE line.

Now that You have generated authentication keys and copied the public one – You have to place the public key in a file on the remote machine. Not just any file. Its a specific file in a specific folder both with a specific permissions.

Passwordless SSH... Almost there but not quite yet...

Open new terminal. Ssh Yourself to the remotemachine.net

ssh -l mylogin remotemachine.net

Create directory in .ssh in Your home folder

mkdir ~/.ssh

Give it correct permissions:

chmod 700 ~/.ssh

Create file authorized_keys in the newly created directory

touch ~/.ssh/authorized_keys

Give it correct permissions:

chmod 600 ~/.ssh/authorized_keys

Paste the content previously copied from the cat /home/mylogin/.ssh/id_rsa.pub command combined with

echo "PASTE" > ~/.ssh/authorized_keys

Example:

echo "ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQCwMplVCQ+Y33n4kTVAy0nQReGD1GXmM28/D4STzNwdEthSY9UGIBduS1dGIVLWZYnphZglNFHE0Z0eIqgo0o0GDdtxqqsV20Zq/KV2nN+E8axlin4mRNuc/HgczxXkOtqkS9/yENOq8XN7XPD57kC+v+017GGNh139WiHbw+Myn9/mamjhmjywcnReiIbrYZnlgWJjpCXJCEoQZczypUyzB6x7aUMlenGdZwtfXCEPP709VSP9lUzanosY6bq1XoF6ravL2fulAvuNQVyxL7nfqJsio0JCI400WEJYm1et8Eg2vVEtIgIEKS7DZou/DR++/QgXpQas6yxaaHQ6Q0wt mylogin@myhostname.local" > ~/.ssh/authorized_keys

Logout from the remote machine:

exit

Log back in.

ssh -l mylogin remotemachine.net

Tadaaaaaaaaaaaaaaaaa...

Remote ssh server shouldn’t ask for a password. If it does – You messed up and You are reading it all tagged as FAIL! πŸ˜‰

You can use 1 private key to connect to multiple servers. Just copy the public key to all of them like I explained above. Permissions are crucial. 700 for the .ssh folder and 600 for the authorized_keys file. 99% of errors are connected to the wrong permissions of the folder / file or due to the wrong file name.

Regards.

Andy